diff options
author | Jagpal Singh Gill <paligill@gmail.com> | 2023-12-21 02:35:41 +0300 |
---|---|---|
committer | Jagpal Singh Gill <paligill@gmail.com> | 2024-02-23 20:39:54 +0300 |
commit | e610b3168321eee167271e4532c37fe1ed9c6f56 (patch) | |
tree | 0dc0f86091d788cb32af73fb4cc9540d33f6e7dc /test | |
parent | 78c9020305038b7974b4737c9b1d0b4afb9740f2 (diff) | |
download | bmcweb-e610b3168321eee167271e4532c37fe1ed9c6f56.tar.xz |
manager_diagnostic_data: add metric get
Add support to fetch MemoryStatistics, FreeStorageSpaceKiB and
ProcessorStatistics for Manager Diagnostic Data.
https://redfish.dmtf.org/schemas/v1/ManagerDiagnosticData.v1_2_1.json
This change is in relation to following design and D-Bus interface -
https://gerrit.openbmc.org/c/openbmc/docs/+/64917
https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/64914
Test:
Redfish query output -
{
"@odata.id": "/redfish/v1/Managers/bmc/ManagerDiagnosticData",
"@odata.type": "#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData",
"FreeStorageSpaceKiB": 3772,
"Id": "ManagerDiagnosticData",
"MemoryStatistics": {
"AvailableBytes": 354224066,
"BuffersAndCacheBytes": 78984633,
"SharedBytes": 11876066,
"TotalBytes": 425516000
},
"Name": "Manager Diagnostic Data",
"ProcessorStatistics": {
"KernelPercent": 13.0234,
"UserPercent": 5.7374
},
"ServiceRootUptimeSeconds": 2255.117
}
Redfish service validator passing -
Elapsed time: 0:03:12
metadataNamespaces: 3726
pass: 5133
passAction: 9
passGet: 205
passRedfishUri: 197
skipNoSchema: 3
skipOptional: 3492
warnDeprecated: 4
warningPresent: 7
Validation has succeeded.
Change-Id: I43758a993eb7f342cb9ac5f5574498b37261c2cc
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/redfish-core/lib/manager_diagnostic_data_test.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/redfish-core/lib/manager_diagnostic_data_test.cpp b/test/redfish-core/lib/manager_diagnostic_data_test.cpp new file mode 100644 index 0000000000..b59842ab57 --- /dev/null +++ b/test/redfish-core/lib/manager_diagnostic_data_test.cpp @@ -0,0 +1,75 @@ +#include "async_resp.hpp" +#include "manager_diagnostic_data.hpp" + +#include <nlohmann/json.hpp> + +#include <memory> + +#include <gtest/gtest.h> + +namespace redfish +{ +namespace +{ + +using json_pointer = nlohmann::json::json_pointer; + +void testDataGetNoError(boost::system::error_code ec) +{ + auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); + + setBytesProperty(asyncResp, + json_pointer("/MemoryStatistics/FreeStorageSpace"), ec, 0); + EXPECT_TRUE(asyncResp->res.jsonValue.is_null()); + EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::ok); +} + +TEST(ManagerDiagnosticDataTest, ManagerDataGetServerUnreachable) +{ + testDataGetNoError(boost::asio::error::basic_errors::host_unreachable); +} + +TEST(ManagerDiagnosticDataTest, ManagerDataGetPathInvalid) +{ + testDataGetNoError(boost::system::linux_error::bad_request_descriptor); +} + +void verifyError(crow::Response& res) +{ + EXPECT_EQ(res.result(), boost::beast::http::status::internal_server_error); + res.clear(); +} + +TEST(ManagerDiagnosticDataTest, ManagerDataGetFailure) +{ + auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); + boost::system::error_code ec = boost::asio::error::operation_aborted; + + setBytesProperty(asyncResp, + json_pointer("/MemoryStatistics/FreeStorageSpace"), ec, 0); + verifyError(asyncResp->res); +} + +TEST(ManagerDiagnosticDataTest, ManagerDataGetNullPtr) +{ + auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); + + setPercentProperty( + asyncResp, + nlohmann::json::json_pointer("/MemoryStatistics/FreeStorageSpace"), {}, + std::numeric_limits<double>::quiet_NaN()); + EXPECT_EQ(asyncResp->res.jsonValue["FreeStorageSpaceKiB"], nullptr); +} + +TEST(ManagerDiagnosticDataTest, ManagerDataGetSuccess) +{ + auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); + + setBytesProperty(asyncResp, json_pointer("/FreeStorageSpaceKiB"), {}, + 204800.0); + EXPECT_EQ(asyncResp->res.jsonValue["FreeStorageSpaceKiB"].get<int64_t>(), + 200); +} + +} // namespace +} // namespace redfish |