From b109c3d3a94b17de84ddd325ba0154a5519d8dbf Mon Sep 17 00:00:00 2001 From: Oliver Brewka Date: Fri, 22 Nov 2024 19:44:21 +0100 Subject: [PATCH] Adapt getMainChassisId to support multi-host 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 --- redfish-core/lib/redfish_util.hpp | 31 +++++++++++++++++++++---------- redfish-core/lib/systems.hpp | 21 ++++++++++++--------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp index 4164e10775..8fc4f131d0 100644 --- a/redfish-core/lib/redfish_util.hpp +++ b/redfish-core/lib/redfish_util.hpp @@ -60,17 +60,27 @@ using UnitStruct = template void getMainChassisId(std::shared_ptr asyncResp, - CallbackFunc&& callback) + CallbackFunc&& callback, uint64_t computerSystemIndex = 0) { + std::vector 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 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(callback), - asyncResp](const boost::system::error_code& ec, - const dbus::utility::MapperGetSubTreeResponse& subtree) { + [callback = std::forward(callback), asyncResp, + computerSystemIndex]( + const boost::system::error_code& ec, + const dbus::utility::MapperGetSubTreeResponse& subtree) { if (ec) { BMCWEB_LOG_ERROR("{}", ec); @@ -82,15 +92,16 @@ void getMainChassisId(std::shared_ptr asyncResp, return; } - std::size_t idPos = subtree[0].first.rfind('/'); + std::size_t idx = static_cast(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); }); diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 60c8752b57..88998566ad 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -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& 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& 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);