blob: f6d087008da5e941b4dc7d407161d81c74177ae1 [file]
#include "manager_diagnostic_data.hpp"
#include <boost/beast/core/string_type.hpp>
#include <boost/beast/http/message.hpp>
#include <memory>
#include <utility>
#include <gtest/gtest.h>
#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "http_response.hpp"
#include "dbus_utility.hpp"
#include "query.hpp"
#include "snapshot_fixture.hpp"
#include <nlohmann/json.hpp>
#include "managed_store.hpp"
#include "managed_store_types.hpp"
#include "test/g3/mock_managed_store_test.hpp"
#include "sdbusplus/message/native_types.hpp"
namespace redfish
{
namespace
{
using ::dbus::utility::DBusInteracesMap;
using ::dbus::utility::DBusPropertiesMap;
using ::dbus::utility::DbusVariantType;
using ::dbus::utility::ManagedObjectType;
using ::managedStore::KeyType;
using ::managedStore::ManagedType;
using ::managedStore::ValueType;
std::shared_ptr<ValueType> CreateMockRWFSMetric()
{
double value = 1.0;
dbus::utility::DbusVariantType mockFSMetric{value};
return managedStore::MockManagedStoreTest::CreateValueType(
std::move(mockFSMetric));
}
std::shared_ptr<ValueType> CreateMockTMPFSMetric()
{
double value = 1.0;
dbus::utility::DbusVariantType mockFSMetric{value};
return managedStore::MockManagedStoreTest::CreateValueType(
std::move(mockFSMetric));
}
TEST_F(SnapshotFixture, GetManagerDiagnosisDataTestReturnsCorrectResponse)
{
// Looking for Key:
// kManagedObject|xyz.openbmc_project.HealthMon|/xyz/openbmc_project/metric/bmc/storage/rw|xyz.openbmc_project.Metric.Value|Value
KeyType keyRWFS(ManagedType::kManagedProperty,
"xyz.openbmc_project.HealthMon",
sdbusplus::message::object_path(
"/xyz/openbmc_project/metric/bmc/storage/rw"),
"xyz.openbmc_project.Metric.Value", "Value");
ASSERT_TRUE(
dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyRWFS, CreateMockRWFSMetric())
.ok());
KeyType keyTMPFS(ManagedType::kManagedProperty,
"xyz.openbmc_project.HealthMon",
sdbusplus::message::object_path(
"/xyz/openbmc_project/metric/bmc/storage/tmp"),
"xyz.openbmc_project.Metric.Value", "Value");
ASSERT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>(
managedStore::GetManagedObjectStore())
->upsertMockObjectIntoManagedStore(keyTMPFS,
CreateMockTMPFSMetric())
.ok());
handleManagerDiagnosticDataGet(app_, CreateRequest(), share_async_resp_);
RunIoUntilDone();
LOG(INFO) << share_async_resp_->res.jsonValue.dump(2);
nlohmann::json& json = share_async_resp_->res.jsonValue;
EXPECT_EQ(json["@odata.id"],
"/redfish/v1/Managers/bmc/ManagerDiagnosticData");
EXPECT_EQ(json["@odata.type"],
"#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData");
EXPECT_EQ(json["Id"], "ManagerDiagnosticData");
EXPECT_EQ(json["Name"], "Manager Diagnostic Data");
EXPECT_EQ(
json["Oem"]["Google"]["GoogleManagedObjectStoreMetrics"]["@odata.id"],
"/redfish/v1/Managers/bmc/ManagerDiagnosticData/Oem/Google"
"/GoogleManagedObjectStoreMetrics");
EXPECT_EQ(json["ProcessorStatistics"]["KernelPercent"], 13.785863586358635);
EXPECT_EQ(json["ProcessorStatistics"]["UserPercent"], 44.61052869992882);
EXPECT_EQ(json["MemoryStatistics"]["AvailableBytes"], 739622912);
EXPECT_EQ(json["Oem"]["Google"]["Latency"], 1.873677);
EXPECT_EQ(json["Oem"]["Google"]["RWStorageSpaceUsageBytes"], 1.0);
EXPECT_EQ(json["Oem"]["Google"]["TMPStorageSpaceUsageBytes"], 1.0);
EXPECT_EQ(json["BootInfo"]["BootCount"], 10);
EXPECT_EQ(json["BootInfo"]["CrashCount"], 0);
EXPECT_EQ(json["BootTimeStatistics"]["FirmwareTimeSeconds"], 0.0);
EXPECT_EQ(json["BootTimeStatistics"]["LoaderTimeSeconds"], 0.0);
EXPECT_EQ(json["BootTimeStatistics"]["KernelTimeSeconds"], 35.523635);
EXPECT_EQ(json["BootTimeStatistics"]["InitrdTimeSeconds"], 0.0);
EXPECT_EQ(json["BootTimeStatistics"]["UserSpaceTimeSeconds"], 359.321182);
for (const auto& process : json["TopProcesses"]) {
EXPECT_TRUE(process.contains("CommandLine"));
EXPECT_TRUE(process.contains("KernelTimeSeconds"));
EXPECT_TRUE(process.contains("NFileDescriptors"));
EXPECT_TRUE(process.contains("ResidentSetSizeBytes"));
EXPECT_TRUE(process.contains("RestartCount"));
EXPECT_TRUE(process.contains("UptimeSeconds"));
EXPECT_TRUE(process.contains("UserTimeSeconds"));
}
}
TEST_F(SnapshotFixture, GetManagerDiagnosisDataTopProcessFilter)
{
query_param::Query delegatedQuery;
delegatedQuery.filter = "TopProcesses.CommandLine eq phosphor-ipmi-host";
getDaemonInfo(share_async_resp_, delegatedQuery);
RunIoUntilDone();
nlohmann::json& json = share_async_resp_->res.jsonValue;
const auto& topProcesses = json["TopProcesses"];
ASSERT_EQ(topProcesses.size(), 1);
const auto& ipmiService = topProcesses[0];
EXPECT_TRUE(ipmiService.contains("CommandLine"));
std::string commandLine = ipmiService["CommandLine"].get<std::string>();
EXPECT_TRUE(absl::StrContains(commandLine, "phosphor-ipmi-host.service"));
EXPECT_TRUE(ipmiService.contains("KernelTimeSeconds"));
EXPECT_TRUE(ipmiService.contains("NFileDescriptors"));
EXPECT_TRUE(ipmiService.contains("ResidentSetSizeBytes"));
EXPECT_TRUE(ipmiService.contains("RestartCount"));
EXPECT_TRUE(ipmiService.contains("UptimeSeconds"));
EXPECT_TRUE(ipmiService.contains("UserTimeSeconds"));
}
TEST_F(SnapshotFixture, GetManagerDiagnosisDataTopProcessInvalidFilter)
{
query_param::Query delegatedQuery;
delegatedQuery.filter = "TopProcessesCommandLine eq phosphor-ipmi-host";
getDaemonInfo(share_async_resp_, delegatedQuery);
RunIoUntilDone();
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::not_implemented);
delegatedQuery.filter = "TopProcessesCommandLine eq";
getDaemonInfo(share_async_resp_, delegatedQuery);
RunIoUntilDone();
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::not_implemented);
delegatedQuery.filter = "TopProcesses.CommandLine phosphor-ipmi-host";
getDaemonInfo(share_async_resp_, delegatedQuery);
RunIoUntilDone();
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::not_implemented);
delegatedQuery.filter = "TopProcesses.CommandLine neq phosphor-ipmi-host";
getDaemonInfo(share_async_resp_, delegatedQuery);
RunIoUntilDone();
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::not_implemented);
}
} // namespace
} // namespace redfish