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/include/utils/chassis_utils.hpp b/redfish-core/include/utils/chassis_utils.hpp
index 3a71048..d9fcf59 100644
--- a/redfish-core/include/utils/chassis_utils.hpp
+++ b/redfish-core/include/utils/chassis_utils.hpp
@@ -18,6 +18,10 @@
namespace redfish
{
+static constexpr std::array<std::string_view, 2> chassisInterfaces = {
+ "xyz.openbmc_project.Inventory.Item.Board",
+ "xyz.openbmc_project.Inventory.Item.Chassis"};
+
namespace chassis_utils
{
/**
@@ -30,13 +34,10 @@
const std::string& chassisId, Callback&& callback)
{
BMCWEB_LOG_DEBUG("checkChassisId enter");
- constexpr std::array<std::string_view, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
// Get the Chassis Collection
dbus::utility::getSubTreePaths(
- "/xyz/openbmc_project/inventory", 0, interfaces,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
[callback = std::forward<Callback>(callback), asyncResp,
chassisId](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse&
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) {
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index 50e466c..1d7a59f 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -24,7 +24,6 @@
#include <nlohmann/json.hpp>
#include <sdbusplus/message/native_types.hpp>
-#include <array>
#include <cmath>
#include <cstddef>
#include <cstdint>
@@ -286,12 +285,8 @@
// This prevents things like power supplies providing the
// chassis power limit
- constexpr std::array<std::string_view, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
-
dbus::utility::getSubTreePaths(
- "/xyz/openbmc_project/inventory", 0, interfaces,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
std::bind_front(afterGetChassis, sensorAsyncResp));
}
diff --git a/redfish-core/lib/power_supply.hpp b/redfish-core/lib/power_supply.hpp
index 9d2d3ce..09093a3 100644
--- a/redfish-core/lib/power_supply.hpp
+++ b/redfish-core/lib/power_supply.hpp
@@ -130,13 +130,10 @@
return;
}
- constexpr std::array<std::string_view, 2> chasisInterfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
const std::string reqpath = "/xyz/openbmc_project/inventory";
dbus::utility::getAssociatedSubTreePathsById(
- chassisId, reqpath, chasisInterfaces, "powered_by",
+ chassisId, reqpath, chassisInterfaces, "powered_by",
powerSupplyInterface,
[asyncResp, chassisId](
const boost::system::error_code& ec,
@@ -194,13 +191,10 @@
std::function<void(const std::string& powerSupplyPath,
const std::string& service)>&& callback)
{
- constexpr std::array<std::string_view, 2> chasisInterfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
const std::string reqpath = "/xyz/openbmc_project/inventory";
dbus::utility::getAssociatedSubTreeById(
- chassisId, reqpath, chasisInterfaces, "powered_by",
+ chassisId, reqpath, chassisInterfaces, "powered_by",
powerSupplyInterface,
[asyncResp, chassisId, powerSupplyId, callback{std::move(callback)}](
const boost::system::error_code& ec,
diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp
index aa0d861..0b10a1b 100644
--- a/redfish-core/lib/redfish_util.hpp
+++ b/redfish-core/lib/redfish_util.hpp
@@ -8,13 +8,13 @@
#include "dbus_utility.hpp"
#include "error_messages.hpp"
#include "logging.hpp"
+#include "utils/chassis_utils.hpp"
#include <boost/system/errc.hpp>
#include <boost/system/error_code.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <algorithm>
-#include <array>
#include <charconv>
#include <cstddef>
#include <cstdint>
@@ -64,11 +64,8 @@
CallbackFunc&& callback)
{
// 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,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
[callback = std::forward<CallbackFunc>(callback),
asyncResp](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 2675e7f..9151d59 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -17,6 +17,7 @@
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "str_utility.hpp"
+#include "utils/chassis_utils.hpp"
#include "utils/dbus_utils.hpp"
#include "utils/json_utils.hpp"
#include "utils/query_param.hpp"
@@ -413,13 +414,10 @@
Callback&& callback)
{
BMCWEB_LOG_DEBUG("getChassis enter");
- constexpr std::array<std::string_view, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
// Get the Chassis Collection
dbus::utility::getSubTreePaths(
- "/xyz/openbmc_project/inventory", 0, interfaces,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
[callback = std::forward<Callback>(callback), asyncResp,
chassisIdStr{std::string(chassisId)},
chassisSubNode{std::string(chassisSubNode)},
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 6fafcce..5b2d78e 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -18,6 +18,7 @@
#include "query.hpp"
#include "redfish_util.hpp"
#include "registries/privilege_registry.hpp"
+#include "utils/chassis_utils.hpp"
#include "utils/collection.hpp"
#include "utils/dbus_utils.hpp"
@@ -816,11 +817,8 @@
}
// mapper call lambda
- 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(afterChassisDriveCollectionSubtreeGet, asyncResp,
chassisId));
}
@@ -915,13 +913,10 @@
{
return;
}
- constexpr std::array<std::string_view, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
// mapper call chassis
dbus::utility::getSubTree(
- "/xyz/openbmc_project/inventory", 0, interfaces,
+ "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
[asyncResp, chassisId,
driveName](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {