Skip to content

Commit

Permalink
Adapt getMainChassisId to support multi-host
Browse files Browse the repository at this point in the history
In order for getMainChassisId to support multi-host we have to pass it
the index that is associated with the requested system, to find
the corresponding chassis object. Unlike on single-host, we cannot
constrain the GetSubTree call to the
xyz.openbmc_project.Inventory.Item.Board interface for multi-host since
we would end up adding the wrong uri to the response. This is why we
only want to constrain it to the
xyz.openbmc_project.Inventory.Item.Chassis interface.

Testing: todo

Change-Id: I1314da46fb2ecd13a5373a291d8a14f1f087c391
Signed-off-by: Oliver Brewka <[email protected]>
  • Loading branch information
Oliver Brewka committed Nov 22, 2024
1 parent 690de55 commit b109c3d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
31 changes: 21 additions & 10 deletions redfish-core/lib/redfish_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,27 @@ using UnitStruct =

template <typename CallbackFunc>
void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
CallbackFunc&& callback)
CallbackFunc&& callback, uint64_t computerSystemIndex = 0)
{
std::vector<std::string_view> interfaces;

if (computerSystemIndex == 0)
{
interfaces = {"xyz.openbmc_project.Inventory.Item.Board",
"xyz.openbmc_project.Inventory.Item.Chassis"};
}
else
{
interfaces = {"xyz.openbmc_project.Inventory.Item.Chassis"};
}

// Find managed chassis
constexpr std::array<std::string_view, 2> interfaces = {
"xyz.openbmc_project.Inventory.Item.Board",
"xyz.openbmc_project.Inventory.Item.Chassis"};
dbus::utility::getSubTree(
"/xyz/openbmc_project/inventory", 0, interfaces,
[callback = std::forward<CallbackFunc>(callback),
asyncResp](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
[callback = std::forward<CallbackFunc>(callback), asyncResp,
computerSystemIndex](
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec)
{
BMCWEB_LOG_ERROR("{}", ec);
Expand All @@ -82,15 +92,16 @@ void getMainChassisId(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
return;
}

std::size_t idPos = subtree[0].first.rfind('/');
std::size_t idx = static_cast<size_t>(computerSystemIndex);
std::size_t idPos = subtree[idx].first.rfind('/');
if (idPos == std::string::npos ||
(idPos + 1) >= subtree[0].first.size())
(idPos + 1) >= subtree[idx].first.size())
{
messages::internalError(asyncResp->res);
BMCWEB_LOG_DEBUG("Can't parse chassis ID!");
return;
}
std::string chassisId = subtree[0].first.substr(idPos + 1);
std::string chassisId = subtree[idx].first.substr(idPos + 1);
BMCWEB_LOG_DEBUG("chassisId = {}", chassisId);
callback(chassisId, asyncResp);
});
Expand Down
21 changes: 12 additions & 9 deletions redfish-core/lib/systems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,16 +3072,19 @@ inline void processComputerSystemGet(
getTrustedModuleRequiredToBoot(asyncResp, computerSystemIndex);
getPowerMode(asyncResp, computerSystemIndex);
getIdlePowerSaver(asyncResp, computerSystemIndex);
});

getMainChassisId(
asyncResp, [](const std::string& chassisId,
const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
nlohmann::json::array_t chassisArray;
nlohmann::json& chassis = chassisArray.emplace_back();
chassis["@odata.id"] =
boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
aRsp->res.jsonValue["Links"]["Chassis"] = std::move(chassisArray);
getMainChassisId(
asyncResp,
[](const std::string& chassisId,
const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
nlohmann::json::array_t chassisArray;
nlohmann::json& chassis = chassisArray.emplace_back();
chassis["@odata.id"] = boost::urls::format(
"/redfish/v1/Chassis/{}", chassisId);
aRsp->res.jsonValue["Links"]["Chassis"] =
std::move(chassisArray);
},
computerSystemIndex);
});

getSystemLocationIndicatorActive(asyncResp);
Expand Down

0 comments on commit b109c3d

Please sign in to comment.