diff options
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 95 | ||||
-rw-r--r-- | redfish-core/lib/ut/log_services_dump_test.cpp | 117 |
3 files changed, 130 insertions, 83 deletions
diff --git a/meson.build b/meson.build index c293e00e3f..b3425beb85 100644 --- a/meson.build +++ b/meson.build @@ -400,6 +400,7 @@ srcfiles_unittest = [ 'include/ut/multipart_test.cpp', 'include/ut/openbmc_dbus_rest_test.cpp', 'redfish-core/include/utils/query_param_test.cpp', + 'redfish-core/lib/ut/log_services_dump_test.cpp', 'redfish-core/lib/ut/service_root_test.cpp', 'redfish-core/lib/ut/thermal_subsystem_test.cpp', 'redfish-core/lib/chassis_test.cpp', diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 2a26ab9e66..ffab320cec 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -2557,56 +2557,17 @@ inline void requestRoutesSystemDumpService(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/") .privileges(redfish::privileges::getLogService) - .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - asyncResp->res.jsonValue["@odata.id"] = - "/redfish/v1/Systems/system/LogServices/Dump"; - asyncResp->res.jsonValue["@odata.type"] = - "#LogService.v1_2_0.LogService"; - asyncResp->res.jsonValue["Name"] = "Dump LogService"; - asyncResp->res.jsonValue["Description"] = "System Dump LogService"; - asyncResp->res.jsonValue["Id"] = "Dump"; - asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; - - std::pair<std::string, std::string> redfishDateTimeOffset = - redfish::time_utils::getDateTimeOffsetNow(); - asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; - asyncResp->res.jsonValue["DateTimeLocalOffset"] = - redfishDateTimeOffset.second; - - asyncResp->res.jsonValue["Entries"]["@odata.id"] = - "/redfish/v1/Systems/system/LogServices/Dump/Entries"; - asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"]["target"] = - "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"; - - asyncResp->res.jsonValue["Actions"]["#LogService.CollectDiagnosticData"] - ["target"] = - "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"; - }); + .methods(boost::beast::http::verb::get)(std::bind_front( + handleLogServicesDumpServiceGet, std::ref(app), "System")); } inline void requestRoutesSystemDumpEntryCollection(App& app) { - - /** - * Functions triggers appropriate requests on DBus - */ BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") .privileges(redfish::privileges::getLogEntryCollection) .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - getDumpEntryCollection(asyncResp, "System"); - }); + std::bind_front(handleLogServicesDumpEntriesCollectionGet, + std::ref(app), "System")); } inline void requestRoutesSystemDumpEntry(App& app) @@ -2614,31 +2575,14 @@ inline void requestRoutesSystemDumpEntry(App& app) BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") .privileges(redfish::privileges::getLogEntry) - - .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& param) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - getDumpEntryById(asyncResp, param, "System"); - }); + .methods(boost::beast::http::verb::get)(std::bind_front( + handleLogServicesDumpEntryGet, std::ref(app), "System")); BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/") .privileges(redfish::privileges::deleteLogEntry) - .methods(boost::beast::http::verb::delete_)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& param) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - deleteDumpEntry(asyncResp, param, "system"); - }); + .methods(boost::beast::http::verb::delete_)(std::bind_front( + handleLogServicesDumpEntryDelete, std::ref(app), "System")); } inline void requestRoutesSystemDumpCreate(App& app) @@ -2648,14 +2592,8 @@ inline void requestRoutesSystemDumpCreate(App& app) "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData/") .privileges(redfish::privileges::postLogService) .methods(boost::beast::http::verb::post)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - createDump(asyncResp, req, "System"); - }); + std::bind_front(handleLogServicesDumpCollectDiagnosticDataPost, + std::ref(app), "System")); } inline void requestRoutesSystemDumpClear(App& app) @@ -2664,17 +2602,8 @@ inline void requestRoutesSystemDumpClear(App& app) app, "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog/") .privileges(redfish::privileges::postLogService) - .methods(boost::beast::http::verb::post)( - [&app](const crow::Request& req, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) - - { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - clearDump(asyncResp, "System"); - }); + .methods(boost::beast::http::verb::post)(std::bind_front( + handleLogServicesDumpClearLogPost, std::ref(app), "System")); } inline void requestRoutesCrashdumpService(App& app) diff --git a/redfish-core/lib/ut/log_services_dump_test.cpp b/redfish-core/lib/ut/log_services_dump_test.cpp new file mode 100644 index 0000000000..192b79dc8d --- /dev/null +++ b/redfish-core/lib/ut/log_services_dump_test.cpp @@ -0,0 +1,117 @@ +#include "app.hpp" +#include "event_service_manager.hpp" +#include "include/async_resp.hpp" +#include "redfish-core/lib/health.hpp" +#include "redfish-core/lib/log_services.hpp" + +#include <nlohmann/json.hpp> + +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +namespace redfish +{ +namespace +{ + +void assertLogServicesDumpServiceGet(crow::Response& res) +{ + nlohmann::json& json = res.jsonValue; + EXPECT_EQ(json["@odata.type"], "#LogService.v1_2_0.LogService"); + EXPECT_EQ(json["Name"], "Dump LogService"); +} + +void assertLogServicesBMCDumpServiceGet(crow::Response& res) +{ + assertLogServicesDumpServiceGet(res); + + nlohmann::json& json = res.jsonValue; + EXPECT_EQ(json["@odata.id"], "/redfish/v1/Managers/bmc/LogServices/Dump"); + EXPECT_EQ( + json["Actions"]["#LogService.ClearLog"]["target"], + "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog"); + EXPECT_EQ( + json["Actions"]["#LogService.CollectDiagnosticData"]["target"], + "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"); + EXPECT_EQ(json["Description"], "BMC Dump LogService"); + EXPECT_EQ(json["Entries"]["@odata.id"], + "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"); + EXPECT_EQ(json["Id"], "Dump"); + EXPECT_EQ(json["OverWritePolicy"], "WrapsWhenFull"); +} + +void assertLogServicesFaultLogDumpServiceGet(crow::Response& res) +{ + assertLogServicesDumpServiceGet(res); + + nlohmann::json& json = res.jsonValue; + EXPECT_EQ(json["@odata.id"], + "/redfish/v1/Managers/bmc/LogServices/FaultLog"); + EXPECT_EQ( + json["Actions"]["#LogService.ClearLog"]["target"], + "/redfish/v1/Managers/bmc/LogServices/FaultLog/Actions/LogService.ClearLog"); + EXPECT_EQ(json["Actions"]["#LogService.CollectDiagnosticData"]["target"], + nlohmann::detail::value_t::null); + EXPECT_EQ(json["Description"], "FaultLog Dump LogService"); + EXPECT_EQ(json["Entries"]["@odata.id"], + "/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries"); + EXPECT_EQ(json["Id"], "FaultLog"); + EXPECT_EQ(json["OverWritePolicy"], "Unknown"); +} + +void assertLogServicesSystemDumpServiceGet(crow::Response& res) +{ + assertLogServicesDumpServiceGet(res); + + nlohmann::json& json = res.jsonValue; + EXPECT_EQ(json["@odata.id"], "/redfish/v1/Systems/system/LogServices/Dump"); + EXPECT_EQ( + json["Actions"]["#LogService.ClearLog"]["target"], + "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.ClearLog"); + EXPECT_EQ( + json["Actions"]["#LogService.CollectDiagnosticData"]["target"], + "/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData"); + EXPECT_EQ(json["Description"], "System Dump LogService"); + EXPECT_EQ(json["Entries"]["@odata.id"], + "/redfish/v1/Systems/system/LogServices/Dump/Entries"); + EXPECT_EQ(json["Id"], "Dump"); + EXPECT_EQ(json["OverWritePolicy"], "WrapsWhenFull"); +} + +TEST(LogServicesDumpServiceTest, + LogServicesBMCDumpServiceStaticAttributesAreExpected) +{ + auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); + shareAsyncResp->res.setCompleteRequestHandler( + assertLogServicesBMCDumpServiceGet); + getDumpServiceInfo(shareAsyncResp, "BMC"); +} + +TEST(LogServicesDumpServiceTest, + LogServicesFaultLogDumpServiceStaticAttributesAreExpected) +{ + auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); + shareAsyncResp->res.setCompleteRequestHandler( + assertLogServicesFaultLogDumpServiceGet); + getDumpServiceInfo(shareAsyncResp, "FaultLog"); +} + +TEST(LogServicesDumpServiceTest, + LogServicesSystemDumpServiceStaticAttributesAreExpected) +{ + auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); + shareAsyncResp->res.setCompleteRequestHandler( + assertLogServicesSystemDumpServiceGet); + getDumpServiceInfo(shareAsyncResp, "System"); +} + +TEST(LogServicesDumpServiceTest, LogServicesInvalidDumpServiceGetReturnsError) +{ + auto shareAsyncResp = std::make_shared<bmcweb::AsyncResp>(); + getDumpServiceInfo(shareAsyncResp, "Invalid"); + EXPECT_EQ(shareAsyncResp->res.result(), + boost::beast::http::status::internal_server_error); +} + +} // namespace +} // namespace redfish |