summaryrefslogtreecommitdiff
path: root/redfish-core/lib/pcie.hpp
diff options
context:
space:
mode:
authorJohn Edward Broadbent <jebr@google.com>2021-04-09 01:57:16 +0300
committerEd Tanous <ed@tanous.net>2021-06-03 21:18:02 +0300
commit7e860f1550c8686eec42f7a75bc5f2ef51e756ad (patch)
tree989da47a8427bc1a60119f480e2523151b1433aa /redfish-core/lib/pcie.hpp
parenteb75770c6c4369984cb150ded4f5ace410ed24a9 (diff)
downloadbmcweb-7e860f1550c8686eec42f7a75bc5f2ef51e756ad.tar.xz
Remove Redfish Node class
Reduces the total number of lines and will allow for easier testing of the redfish responses. A main purpose of the node class was to set app.routeDynamic(). However now app.routeDynamic can handle the complexity that was once in critical to node. The macro app.routeDynamic() provides a shorter cleaner interface to the unerlying app.routeDyanic call. The old pattern set permissions for 6 interfaces (get, head, patch, put, delete_, and post) even if only one interface is created. That pattern creates unneeded code that can be safely removed with no effect. Unit test for the responses would have to mock the node the class in order to fully test responses. see https://github.com/openbmc/bmcweb/issues/181 The following files still need node to be extracted. virtual_media.hpp account_service.hpp redfish_sessions.hpp ethernet.hpp The files above use a pattern that is not trivial to address. Often their responses call an async lambda capturing the inherited class. ie (https://github.com/openbmc/bmcweb/blob/ffed87b5ad1797ca966d030e7f979770 28d258fa/redfish-core/lib/account_service.hpp#L1393) At a later point I plan to remove node from the files above. Tested: I ran the docker unit test with the following command. WORKSPACE=$(pwd) UNIT_TEST_PKG=bmcweb ./openbmc-build-scripts/run-unit-test-docker.sh I ran the validator and this change did not create any issues. python3 RedfishServiceValidator.py -c config.ini Signed-off-by: John Edward Broadbent <jebr@google.com> Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I147a0289c52cb4198345b1ad9bfe6fdddf57f3df
Diffstat (limited to 'redfish-core/lib/pcie.hpp')
-rw-r--r--redfish-core/lib/pcie.hpp562
1 files changed, 257 insertions, 305 deletions
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 35d20a573f..15b2280e6f 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -16,8 +16,7 @@
#pragma once
-#include "node.hpp"
-
+#include <app.hpp>
#include <boost/system/linux_error.hpp>
namespace redfish
@@ -70,168 +69,201 @@ static inline void
std::string(pciePath) + "/", 1, std::array<std::string, 0>());
}
-class SystemPCIeDeviceCollection : public Node
+inline void requestRoutesSystemPCIeDeviceCollection(App& app)
{
- public:
- SystemPCIeDeviceCollection(App& app) :
- Node(app, "/redfish/v1/Systems/system/PCIeDevices/")
- {
- entityPrivileges = {
- {boost::beast::http::verb::get, {{"Login"}}},
- {boost::beast::http::verb::head, {{"Login"}}},
- {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
- {boost::beast::http::verb::put, {{"ConfigureManager"}}},
- {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
- {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
- }
-
- private:
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&, const std::vector<std::string>&) override
- {
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeDeviceCollection.PCIeDeviceCollection"},
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices"},
- {"Name", "PCIe Device Collection"},
- {"Description", "Collection of PCIe Devices"},
- {"Members", nlohmann::json::array()},
- {"Members@odata.count", 0}};
- getPCIeDeviceList(asyncResp, "Members");
- }
-};
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/PCIeDevices/")
+ .privileges({"Login"})
+ .methods(boost::beast::http::verb::get)(
+ [](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
-class SystemPCIeDevice : public Node
-{
- public:
- SystemPCIeDevice(App& app) :
- Node(app, "/redfish/v1/Systems/system/PCIeDevices/<str>/",
- std::string())
- {
- entityPrivileges = {
- {boost::beast::http::verb::get, {{"Login"}}},
- {boost::beast::http::verb::head, {{"Login"}}},
- {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
- {boost::beast::http::verb::put, {{"ConfigureManager"}}},
- {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
- {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
- }
+ {
+ asyncResp->res.jsonValue = {
+ {"@odata.type",
+ "#PCIeDeviceCollection.PCIeDeviceCollection"},
+ {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices"},
+ {"Name", "PCIe Device Collection"},
+ {"Description", "Collection of PCIe Devices"},
+ {"Members", nlohmann::json::array()},
+ {"Members@odata.count", 0}};
+ getPCIeDeviceList(asyncResp, "Members");
+ });
+}
- private:
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&,
- const std::vector<std::string>& params) override
- {
- if (params.size() != 1)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- const std::string& device = params[0];
+inline void requestRoutesSystemPCIeDevice(App& app)
+{
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/PCIeDevices/<str>/")
+ .privileges({"Login"})
+ .methods(boost::beast::http::verb::get)(
+ [](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& device)
- auto getPCIeDeviceCallback =
- [asyncResp,
- device](const boost::system::error_code ec,
- boost::container::flat_map<std::string,
- std::variant<std::string>>&
- pcieDevProperties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: "
- << ec.value() << ": " << ec.message();
- if (ec.value() ==
- boost::system::linux_error::bad_request_descriptor)
- {
- messages::resourceNotFound(asyncResp->res, "PCIeDevice",
- device);
- }
- else
+ {
+ auto getPCIeDeviceCallback = [asyncResp, device](
+ const boost::system::error_code
+ ec,
+ boost::container::flat_map<
+ std::string,
+ std::variant<std::string>>&
+ pcieDevProperties) {
+ if (ec)
{
- messages::internalError(asyncResp->res);
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() ==
+ boost::system::linux_error::bad_request_descriptor)
+ {
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
+ return;
}
- return;
- }
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
- {"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" + device},
- {"Name", "PCIe Device"},
- {"Id", device}};
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"},
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" + device},
+ {"Name", "PCIe Device"},
+ {"Id", device}};
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Manufacturer"]);
- property)
- {
- asyncResp->res.jsonValue["Manufacturer"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Manufacturer"]);
+ property)
+ {
+ asyncResp->res.jsonValue["Manufacturer"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["DeviceType"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceType"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["DeviceType"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceType"] = *property;
+ }
- asyncResp->res.jsonValue["PCIeFunctions"] = {
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions"}};
- };
- std::string escapedPath = std::string(pciePath) + "/" + device;
- dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
- }
-};
+ asyncResp->res.jsonValue["PCIeFunctions"] = {
+ {"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" + device +
+ "/PCIeFunctions"}};
+ };
+ std::string escapedPath = std::string(pciePath) + "/" + device;
+ dbus::utility::escapePathForDbus(escapedPath);
+ crow::connections::systemBus->async_method_call(
+ std::move(getPCIeDeviceCallback), pcieService, escapedPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ pcieDeviceInterface);
+ });
+}
-class SystemPCIeFunctionCollection : public Node
+inline void requestRoutesSystemPCIeFunctionCollection(App& app)
{
- public:
- SystemPCIeFunctionCollection(App& app) :
- Node(app, "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/",
- std::string())
- {
- entityPrivileges = {
- {boost::beast::http::verb::get, {{"Login"}}},
- {boost::beast::http::verb::head, {{"Login"}}},
- {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
- {boost::beast::http::verb::put, {{"ConfigureManager"}}},
- {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
- {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
- }
-
- private:
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&,
- const std::vector<std::string>& params) override
- {
- if (params.size() != 1)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- const std::string& device = params[0];
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeFunctionCollection.PCIeFunctionCollection"},
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" + device +
- "/PCIeFunctions"},
- {"Name", "PCIe Function Collection"},
- {"Description",
- "Collection of PCIe Functions for PCIe Device " + device}};
+ BMCWEB_ROUTE(app,
+ "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/")
+ .privileges({"Login"})
+ .methods(boost::beast::http::verb::get)(
+ [](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& device)
- auto getPCIeDeviceCallback =
- [asyncResp,
- device](const boost::system::error_code ec,
- boost::container::flat_map<std::string,
- std::variant<std::string>>&
- pcieDevProperties) {
+ {
+ asyncResp->res.jsonValue = {
+ {"@odata.type",
+ "#PCIeFunctionCollection.PCIeFunctionCollection"},
+ {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions"},
+ {"Name", "PCIe Function Collection"},
+ {"Description",
+ "Collection of PCIe Functions for PCIe Device " + device}};
+
+ auto getPCIeDeviceCallback = [asyncResp, device](
+ const boost::system::error_code
+ ec,
+ boost::container::flat_map<
+ std::string,
+ std::variant<std::string>>&
+ pcieDevProperties) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG
+ << "failed to get PCIe Device properties ec: "
+ << ec.value() << ": " << ec.message();
+ if (ec.value() ==
+ boost::system::linux_error::bad_request_descriptor)
+ {
+ messages::resourceNotFound(asyncResp->res,
+ "PCIeDevice", device);
+ }
+ else
+ {
+ messages::internalError(asyncResp->res);
+ }
+ return;
+ }
+
+ nlohmann::json& pcieFunctionList =
+ asyncResp->res.jsonValue["Members"];
+ pcieFunctionList = nlohmann::json::array();
+ static constexpr const int maxPciFunctionNum = 8;
+ for (int functionNum = 0; functionNum < maxPciFunctionNum;
+ functionNum++)
+ {
+ // Check if this function exists by looking for a device
+ // ID
+ std::string devIDProperty =
+ "Function" + std::to_string(functionNum) +
+ "DeviceId";
+ std::string* property = std::get_if<std::string>(
+ &pcieDevProperties[devIDProperty]);
+ if (property && !property->empty())
+ {
+ pcieFunctionList.push_back(
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions/" +
+ std::to_string(functionNum)}});
+ }
+ }
+ asyncResp->res.jsonValue["PCIeFunctions@odata.count"] =
+ pcieFunctionList.size();
+ };
+ std::string escapedPath = std::string(pciePath) + "/" + device;
+ dbus::utility::escapePathForDbus(escapedPath);
+ crow::connections::systemBus->async_method_call(
+ std::move(getPCIeDeviceCallback), pcieService, escapedPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ pcieDeviceInterface);
+ });
+}
+
+inline void requestRoutesSystemPCIeFunction(App& app)
+{
+ BMCWEB_ROUTE(
+ app,
+ "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/<str>/")
+ .privileges({"Login"})
+ .methods(
+ boost::beast::http::verb::get)([](const crow::Request&,
+ const std::shared_ptr<
+ bmcweb::AsyncResp>& asyncResp,
+ const std::string& device,
+ const std::string& function) {
+ auto getPCIeDeviceCallback = [asyncResp, device, function](
+ const boost::system::error_code ec,
+ boost::container::flat_map<
+ std::string,
+ std::variant<std::string>>&
+ pcieDevProperties) {
if (ec)
{
BMCWEB_LOG_DEBUG
@@ -250,179 +282,99 @@ class SystemPCIeFunctionCollection : public Node
return;
}
- nlohmann::json& pcieFunctionList =
- asyncResp->res.jsonValue["Members"];
- pcieFunctionList = nlohmann::json::array();
- static constexpr const int maxPciFunctionNum = 8;
- for (int functionNum = 0; functionNum < maxPciFunctionNum;
- functionNum++)
- {
- // Check if this function exists by looking for a device ID
- std::string devIDProperty =
- "Function" + std::to_string(functionNum) + "DeviceId";
- std::string* property = std::get_if<std::string>(
+ // Check if this function exists by looking for a device ID
+ std::string devIDProperty = "Function" + function + "DeviceId";
+ if (std::string* property = std::get_if<std::string>(
&pcieDevProperties[devIDProperty]);
- if (property && !property->empty())
- {
- pcieFunctionList.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions/" +
- std::to_string(functionNum)}});
- }
+ property && property->empty())
+ {
+ messages::resourceNotFound(asyncResp->res, "PCIeFunction",
+ function);
+ return;
}
- asyncResp->res.jsonValue["PCIeFunctions@odata.count"] =
- pcieFunctionList.size();
- };
- std::string escapedPath = std::string(pciePath) + "/" + device;
- dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
- }
-};
-
-class SystemPCIeFunction : public Node
-{
- public:
- SystemPCIeFunction(App& app) :
- Node(
- app,
- "/redfish/v1/Systems/system/PCIeDevices/<str>/PCIeFunctions/<str>/",
- std::string(), std::string())
- {
- entityPrivileges = {
- {boost::beast::http::verb::get, {{"Login"}}},
- {boost::beast::http::verb::head, {{"Login"}}},
- {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
- {boost::beast::http::verb::put, {{"ConfigureManager"}}},
- {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
- {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
- }
- private:
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&,
- const std::vector<std::string>& params) override
- {
- if (params.size() != 2)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- const std::string& device = params[0];
- const std::string& function = params[1];
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"},
+ {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
+ device + "/PCIeFunctions/" + function},
+ {"Name", "PCIe Function"},
+ {"Id", function},
+ {"FunctionId", std::stoi(function)},
+ {"Links",
+ {{"PCIeDevice",
+ {{"@odata.id",
+ "/redfish/v1/Systems/system/PCIeDevices/" +
+ device}}}}}};
- auto getPCIeDeviceCallback = [asyncResp, device, function](
- const boost::system::error_code ec,
- boost::container::flat_map<
- std::string,
- std::variant<std::string>>&
- pcieDevProperties) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "failed to get PCIe Device properties ec: " << ec.value()
- << ": " << ec.message();
- if (ec.value() ==
- boost::system::linux_error::bad_request_descriptor)
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function + "DeviceId"]);
+ property)
{
- messages::resourceNotFound(asyncResp->res, "PCIeDevice",
- device);
+ asyncResp->res.jsonValue["DeviceId"] = *property;
}
- else
+
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function + "VendorId"]);
+ property)
{
- messages::internalError(asyncResp->res);
+ asyncResp->res.jsonValue["VendorId"] = *property;
}
- return;
- }
-
- // Check if this function exists by looking for a device ID
- std::string devIDProperty = "Function" + function + "DeviceId";
- if (std::string* property =
- std::get_if<std::string>(&pcieDevProperties[devIDProperty]);
- property && property->empty())
- {
- messages::resourceNotFound(asyncResp->res, "PCIeFunction",
- function);
- return;
- }
-
- asyncResp->res.jsonValue = {
- {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"},
- {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" +
- device + "/PCIeFunctions/" + function},
- {"Name", "PCIe Function"},
- {"Id", function},
- {"FunctionId", std::stoi(function)},
- {"Links",
- {{"PCIeDevice",
- {{"@odata.id",
- "/redfish/v1/Systems/system/PCIeDevices/" + device}}}}}};
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "DeviceId"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceId"] = *property;
- }
-
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "VendorId"]);
- property)
- {
- asyncResp->res.jsonValue["VendorId"] = *property;
- }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "FunctionType"]);
- property)
- {
- asyncResp->res.jsonValue["FunctionType"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "FunctionType"]);
+ property)
+ {
+ asyncResp->res.jsonValue["FunctionType"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "DeviceClass"]);
- property)
- {
- asyncResp->res.jsonValue["DeviceClass"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "DeviceClass"]);
+ property)
+ {
+ asyncResp->res.jsonValue["DeviceClass"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "ClassCode"]);
- property)
- {
- asyncResp->res.jsonValue["ClassCode"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "ClassCode"]);
+ property)
+ {
+ asyncResp->res.jsonValue["ClassCode"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "RevisionId"]);
- property)
- {
- asyncResp->res.jsonValue["RevisionId"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "RevisionId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["RevisionId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function + "SubsystemId"]);
- property)
- {
- asyncResp->res.jsonValue["SubsystemId"] = *property;
- }
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "SubsystemId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["SubsystemId"] = *property;
+ }
- if (std::string* property = std::get_if<std::string>(
- &pcieDevProperties["Function" + function +
- "SubsystemVendorId"]);
- property)
- {
- asyncResp->res.jsonValue["SubsystemVendorId"] = *property;
- }
- };
- std::string escapedPath = std::string(pciePath) + "/" + device;
- dbus::utility::escapePathForDbus(escapedPath);
- crow::connections::systemBus->async_method_call(
- std::move(getPCIeDeviceCallback), pcieService, escapedPath,
- "org.freedesktop.DBus.Properties", "GetAll", pcieDeviceInterface);
- }
-};
+ if (std::string* property = std::get_if<std::string>(
+ &pcieDevProperties["Function" + function +
+ "SubsystemVendorId"]);
+ property)
+ {
+ asyncResp->res.jsonValue["SubsystemVendorId"] = *property;
+ }
+ };
+ std::string escapedPath = std::string(pciePath) + "/" + device;
+ dbus::utility::escapePathForDbus(escapedPath);
+ crow::connections::systemBus->async_method_call(
+ std::move(getPCIeDeviceCallback), pcieService, escapedPath,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ pcieDeviceInterface);
+ });
+}
} // namespace redfish