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
diff --git a/redfish-core/lib/service_root.hpp b/redfish-core/lib/service_root.hpp
index 06f9c84..df3e8d5 100644
--- a/redfish-core/lib/service_root.hpp
+++ b/redfish-core/lib/service_root.hpp
@@ -15,71 +15,57 @@
*/
#pragma once
-#include "node.hpp"
-
+#include <app.hpp>
#include <utils/systemd_utils.hpp>
namespace redfish
{
-class ServiceRoot : public Node
+inline void requestRoutesServiceRoot(App& app)
{
- public:
- ServiceRoot(App& app) : Node(app, "/redfish/v1/")
- {
- uuid = persistent_data::getConfig().systemUuid;
- entityPrivileges = {
- {boost::beast::http::verb::get, {}},
- {boost::beast::http::verb::head, {}},
- {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
- {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
- {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
- {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
- }
+ std::string uuid = persistent_data::getConfig().systemUuid;
+ BMCWEB_ROUTE(app, "/redfish/v1/")
+ .privileges({})
+ .methods(boost::beast::http::verb::get)(
+ [uuid](const crow::Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ServiceRoot.v1_5_0.ServiceRoot";
+ asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
+ asyncResp->res.jsonValue["Id"] = "RootService";
+ asyncResp->res.jsonValue["Name"] = "Root Service";
+ asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
+ asyncResp->res.jsonValue["Links"]["Sessions"] = {
+ {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
+ asyncResp->res.jsonValue["AccountService"] = {
+ {"@odata.id", "/redfish/v1/AccountService"}};
+ asyncResp->res.jsonValue["Chassis"] = {
+ {"@odata.id", "/redfish/v1/Chassis"}};
+ asyncResp->res.jsonValue["JsonSchemas"] = {
+ {"@odata.id", "/redfish/v1/JsonSchemas"}};
+ asyncResp->res.jsonValue["Managers"] = {
+ {"@odata.id", "/redfish/v1/Managers"}};
+ asyncResp->res.jsonValue["SessionService"] = {
+ {"@odata.id", "/redfish/v1/SessionService"}};
+ asyncResp->res.jsonValue["Managers"] = {
+ {"@odata.id", "/redfish/v1/Managers"}};
+ asyncResp->res.jsonValue["Systems"] = {
+ {"@odata.id", "/redfish/v1/Systems"}};
+ asyncResp->res.jsonValue["Registries"] = {
+ {"@odata.id", "/redfish/v1/Registries"}};
- private:
- void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const crow::Request&, const std::vector<std::string>&) override
- {
- asyncResp->res.jsonValue["@odata.type"] =
- "#ServiceRoot.v1_5_0.ServiceRoot";
- asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1";
- asyncResp->res.jsonValue["Id"] = "RootService";
- asyncResp->res.jsonValue["Name"] = "Root Service";
- asyncResp->res.jsonValue["RedfishVersion"] = "1.9.0";
- asyncResp->res.jsonValue["Links"]["Sessions"] = {
- {"@odata.id", "/redfish/v1/SessionService/Sessions"}};
- asyncResp->res.jsonValue["AccountService"] = {
- {"@odata.id", "/redfish/v1/AccountService"}};
- asyncResp->res.jsonValue["Chassis"] = {
- {"@odata.id", "/redfish/v1/Chassis"}};
- asyncResp->res.jsonValue["JsonSchemas"] = {
- {"@odata.id", "/redfish/v1/JsonSchemas"}};
- asyncResp->res.jsonValue["Managers"] = {
- {"@odata.id", "/redfish/v1/Managers"}};
- asyncResp->res.jsonValue["SessionService"] = {
- {"@odata.id", "/redfish/v1/SessionService"}};
- asyncResp->res.jsonValue["Managers"] = {
- {"@odata.id", "/redfish/v1/Managers"}};
- asyncResp->res.jsonValue["Systems"] = {
- {"@odata.id", "/redfish/v1/Systems"}};
- asyncResp->res.jsonValue["Registries"] = {
- {"@odata.id", "/redfish/v1/Registries"}};
-
- asyncResp->res.jsonValue["UpdateService"] = {
- {"@odata.id", "/redfish/v1/UpdateService"}};
- asyncResp->res.jsonValue["UUID"] = uuid;
- asyncResp->res.jsonValue["CertificateService"] = {
- {"@odata.id", "/redfish/v1/CertificateService"}};
- asyncResp->res.jsonValue["Tasks"] = {
- {"@odata.id", "/redfish/v1/TaskService"}};
- asyncResp->res.jsonValue["EventService"] = {
- {"@odata.id", "/redfish/v1/EventService"}};
- asyncResp->res.jsonValue["TelemetryService"] = {
- {"@odata.id", "/redfish/v1/TelemetryService"}};
- }
-
- std::string uuid;
-};
+ asyncResp->res.jsonValue["UpdateService"] = {
+ {"@odata.id", "/redfish/v1/UpdateService"}};
+ asyncResp->res.jsonValue["UUID"] = uuid;
+ asyncResp->res.jsonValue["CertificateService"] = {
+ {"@odata.id", "/redfish/v1/CertificateService"}};
+ asyncResp->res.jsonValue["Tasks"] = {
+ {"@odata.id", "/redfish/v1/TaskService"}};
+ asyncResp->res.jsonValue["EventService"] = {
+ {"@odata.id", "/redfish/v1/EventService"}};
+ asyncResp->res.jsonValue["TelemetryService"] = {
+ {"@odata.id", "/redfish/v1/TelemetryService"}};
+ });
+}
} // namespace redfish