Skip to content

systems.hpp - initial multi-host implementation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Redfish.md
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ other.
#### FabricAdapter

- Location
- LocationIndicatorActive
- Model
- PartNumber
- SerialNumber
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "async_resp.hpp"
#include "google/google_service_root.hpp"
#include "google_service_root.hpp"
#include "http_request.hpp"
#include "http_response.hpp"

Expand Down
2 changes: 2 additions & 0 deletions features/google/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
incdir += include_directories('.')
test_sources += files('google_service_root_test.cpp')
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "http_response.hpp"
#include "ibm/management_console_rest.hpp"
#include "ibm_management_console_rest.hpp"

#include <string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "app.hpp"
#include "async_resp.hpp"
#include "http_request.hpp"
#include "ibm/utils.hpp"
#include "logging.hpp"
#include "str_utility.hpp"
#include "utils.hpp"
#include "utils/json_utils.hpp"

#include <boost/beast/core/string_type.hpp>
Expand Down
2 changes: 2 additions & 0 deletions features/ibm/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
incdir += include_directories('.')
test_sources += files('configfile_test.cpp')
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions features/kvm/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
incdir += include_directories('.')
7 changes: 7 additions & 0 deletions features/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
subdir('google')
subdir('ibm')
subdir('kvm')
subdir('openbmc_rest')
subdir('serial')
subdir('virtual_media')
subdir('webui_login')
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions features/openbmc_rest/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
incdir += include_directories('.')
test_sources += files('openbmc_dbus_rest_test.cpp')
1 change: 1 addition & 0 deletions features/redfish
1 change: 1 addition & 0 deletions features/serial/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
incdir += include_directories('.')
File renamed without changes.
1 change: 1 addition & 0 deletions features/virtual_media/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
incdir += include_directories('.')
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions features/webui_login/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
incdir += include_directories('.')
22 changes: 12 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ if (get_option('optimization') == '0')
endif

# Include Directories
incdir = [
include_directories(
'include',
'redfish-core/include',
'redfish-core/lib',
'http',
),
]

incdir = include_directories(
'include',
'redfish-core/include',
'redfish-core/lib',
'http',
)
incdir_cli = include_directories('http', 'include')

# Add compiler arguments
Expand Down Expand Up @@ -371,6 +373,9 @@ subdir('config')
bmcweb_dependencies += conf_h_dep
bmcweb_cli_dependencies += conf_h_dep

test_sources = []
subdir('features')

# Source files
fs = import('fs')

Expand Down Expand Up @@ -449,13 +454,10 @@ srcfiles_unittest = files(
'test/include/async_resolve_test.cpp',
'test/include/credential_pipe_test.cpp',
'test/include/dbus_utility_test.cpp',
'test/include/google/google_service_root_test.cpp',
'test/include/http_utility_test.cpp',
'test/include/human_sort_test.cpp',
'test/include/ibm/configfile_test.cpp',
'test/include/json_html_serializer.cpp',
'test/include/multipart_test.cpp',
'test/include/openbmc_dbus_rest_test.cpp',
'test/include/ossl_random.cpp',
'test/include/sessions_test.cpp',
'test/include/ssl_key_handler_test.cpp',
Expand Down Expand Up @@ -491,7 +493,7 @@ srcfiles_unittest = files(
'test/redfish-core/lib/systems_logservices_postcode.cpp',
'test/redfish-core/lib/thermal_subsystem_test.cpp',
'test/redfish-core/lib/update_service_test.cpp',
)
) + test_sources

if (get_option('tests').allowed())
gtest = dependency(
Expand Down
5 changes: 5 additions & 0 deletions redfish-core/include/snmp_trap_event_clients.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ inline void getSnmpTrapClientdata(
asyncResp->res.jsonValue["EventFormatType"] =
event_destination::EventFormatType::Event;

/* Context is required Redfish field,
* but SNMP backend doesn't support a context string.
*/
asyncResp->res.jsonValue["Context"] = "";

dbus::utility::getAllProperties(
"xyz.openbmc_project.Network.SNMP", objectPath,
"xyz.openbmc_project.Network.Client",
Expand Down
142 changes: 142 additions & 0 deletions redfish-core/include/utils/systems_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "bmcweb_config.h"

#include "async_resp.hpp"
#include "dbus_singleton.hpp"
#include "dbus_utility.hpp"
#include "error_messages.hpp"
#include "human_sort.hpp"
Expand All @@ -17,6 +18,7 @@

#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
Expand Down Expand Up @@ -116,4 +118,144 @@ inline void getSystemCollectionMembers(
"/xyz/openbmc_project/inventory", 0, interfaces,
std::bind_front(handleSystemCollectionMembers, asyncResp));
}

inline void getManagedHostProperty(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName, const std::string& systemPath,
std::function<void(const uint64_t computerSystemIndex)> callback)
{
dbus::utility::getProperty<uint64_t>(
"xyz.openbmc_project.EntityManager", systemPath,
"xyz.openbmc_project.Inventory.Decorator.ManagedHost", "HostIndex",
[asyncResp, systemName, systemPath, callback = std::move(callback)](
const boost::system::error_code& ec, const uint64_t hostIndex) {
if (ec)
{
BMCWEB_LOG_WARNING("DBUS response error {}", ec);
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}
BMCWEB_LOG_DEBUG("Got index {} for path {}", hostIndex, systemPath);
callback(hostIndex);
});
}

inline void afterGetComputerSystemSubTree(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName,
std::function<void(const uint64_t computerSystemIndex)>& callback,
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse& objects)
{
sdbusplus::message::object_path systemPath;
if (ec)
{
if (ec.value() == boost::system::errc::io_error)
{
BMCWEB_LOG_WARNING("EIO - System not found");
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}

BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value());
messages::internalError(asyncResp->res);
return;
}

const auto& found = std::ranges::find_if(
objects, [systemName](const sdbusplus::message::object_path& path) {
return path.filename() == systemName;
});

if (found == objects.end())
{
BMCWEB_LOG_WARNING("Failed to match systemName: {}", systemName);
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
systemName);
return;
}

systemPath = *found;

getManagedHostProperty(asyncResp, systemName, systemPath,
std::move(callback));
}

/**
* @brief Retrieve the index associated with the requested system based on the
* ManagedHost interface
*
* @param[i] asyncResp Async response object
* @param[i] systemName The requested system
* @param[i] callback Callback to call once the index has been found
*
* @return None
*/
inline void getComputerSystemIndex(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& systemName,
std::function<void(const uint64_t computerSystemIndex)>&& callback)
{
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
constexpr std::array<std::string_view, 1> interfaces{
"xyz.openbmc_project.Inventory.Decorator.ManagedHost"};
dbus::utility::getSubTreePaths(
"/xyz/openbmc_project/inventory", 0, interfaces,
std::bind_front(afterGetComputerSystemSubTree, asyncResp,
systemName, std::move(callback)));
}
else
{
// on single-host, fallback to index 0
BMCWEB_LOG_DEBUG(
"Single-host detected, fallback to computerSystemIndex 0");
callback(0);
}
}

inline sdbusplus::message::object_path getHostStateObjectPath(
const uint64_t computerSystemIndex)
{
const sdbusplus::message::object_path hostStatePath(
"/xyz/openbmc_project/state/host" +
std::to_string(computerSystemIndex));

return hostStatePath;
}

inline std::string getHostStateServiceName(const uint64_t computerSystemIndex)
{
std::string hostStateService = "xyz.openbmc_project.State.Host";
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
hostStateService += std::to_string(computerSystemIndex);
}

return hostStateService;
}

inline sdbusplus::message::object_path getChassisStateObjectPath(
const uint64_t computerSystemIndex)
{
const sdbusplus::message::object_path chassisStatePath(
"/xyz/openbmc_project/state/chassis" +
std::to_string(computerSystemIndex));

return chassisStatePath;
}

inline std::string getChassisStateServiceName(
const uint64_t computerSystemIndex)
{
std::string chassisStateService = "xyz.openbmc_project.State.Chassis";
if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
chassisStateService += std::to_string(computerSystemIndex);
}

return chassisStateService;
}
} // namespace redfish
Loading