blob: 0b6d4c2ad336efc91f28873ca9afdf5e66b6bf53 [file] [log] [blame]
#include "app.hpp"
#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include "managed_store_types.hpp"
#include "manager_diagnostic_data.hpp"
#include "snapshot_fixture.hpp"
#include <boost/beast/core/string_type.hpp>
#include <boost/beast/http/message.hpp>
#include <nlohmann/json.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
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;
using ::testing::Contains;
using ::testing::NotNull;
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(
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(
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["TopProcess"])
{
EXPECT_TRUE(process.contains(json["CommandLine"]));
EXPECT_TRUE(process.contains(json["KernelTimeSeconds"]));
EXPECT_TRUE(process.contains(json["NFileDescriptors"]));
EXPECT_TRUE(process.contains(json["ResidentalSetSizeBytes"]));
EXPECT_TRUE(process.contains(json["RestartCount"]));
EXPECT_TRUE(process.contains(json["UptimeSeconds"]));
EXPECT_TRUE(process.contains(json["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(
commandLine.find("phosphor-ipmi-host.service") != std::string::npos);
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