Refactor chassisInterfaces into chassis_utils
Some (e.g. IBM) do not use the
`xyz.openbmc_project.Inventory.Item.Board` interface for chassis
objects. To handle the use pattern easier, this refactors the Chassis
interface into one location and it is referenced from the needed places
(e.g. `getValidChassisPath()`).
Moreover, this part is repeated many times, which goes against best
practices.
Tested:
- GET Chassis related API and check they are the same as before
- Redfish Service Validator passes
Change-Id: Id4a51986262892c5dc81b1a3bc46fa5be7c0e9da
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 14e543d..879ae38 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -18,6 +18,7 @@
#include "logging.hpp"
#include "query.hpp"
#include "registries/privilege_registry.hpp"
+#include "utils/chassis_utils.hpp"
#include "utils/collection.hpp"
#include "utils/dbus_utils.hpp"
#include "utils/json_utils.hpp"
@@ -256,11 +257,8 @@
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
asyncResp->res.jsonValue["Name"] = "Chassis Collection";
- constexpr std::array<std::string_view, 2> interfaces{
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
collection_util::getCollectionMembers(
- asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces,
+ asyncResp, boost::urls::url("/redfish/v1/Chassis"), chassisInterfaces,
"/xyz/openbmc_project/inventory");
}
@@ -351,20 +349,17 @@
{
BMCWEB_LOG_DEBUG("Get chassis connectivity");
- constexpr std::array<std::string_view, 2> interfaces{
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
-
dbus::utility::getAssociatedSubTreePaths(
chassisPath + "/contained_by",
sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
- interfaces,
+ chassisInterfaces,
std::bind_front(getChassisContainedBy, asyncResp, chassisId));
dbus::utility::getAssociatedSubTreePaths(
chassisPath + "/containing",
sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
- interfaces, std::bind_front(getChassisContains, asyncResp, chassisId));
+ chassisInterfaces,
+ std::bind_front(getChassisContains, asyncResp, chassisId));
}
/**
@@ -731,12 +726,9 @@
{
return;
}
- 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,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
std::bind_front(handleChassisGetSubTree, asyncResp, chassisId));
constexpr std::array<std::string_view, 1> interfaces2 = {
@@ -785,14 +777,10 @@
"299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
}
- constexpr std::array<std::string_view, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
-
const std::string& chassisId = param;
dbus::utility::getSubTree(
- "/xyz/openbmc_project/inventory", 0, interfaces,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
[asyncResp, chassisId, locationIndicatorActive,
indicatorLed](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {