| #include <cstdint> | |
| #include <iostream> | |
| #include <memory> | |
| #include <optional> | |
| #include <string> | |
| #include <utility> | |
| #include <vector> | |
| #include <gtest/gtest.h> | |
| #include "absl/cleanup/cleanup.h" | |
| #include "absl/status/statusor.h" | |
| #include "dbus_utility.hpp" | |
| #include "systems.hpp" | |
| #include "test/redfish-core/lib/snapshot_fixture.hpp" | |
| #include <nlohmann/json.hpp> | |
| #include "managed_store.hpp" | |
| #include "managed_store_types.hpp" | |
| #include "test/g3/mock_managed_store.hpp" | |
| #include "test/g3/mock_managed_store_test.hpp" | |
| #include "sdbusplus/message/native_types.hpp" | |
| namespace redfish { | |
| namespace { | |
| using ::dbus::utility::DbusVariantType; | |
| using ::managedStore::KeyType; | |
| using ::managedStore::ManagedType; | |
| using ::managedStore::ValueType; | |
| std::shared_ptr<ValueType> CreateBadMockAssociatedSubtreeForMultiSystem() { | |
| dbus::utility::MapperGetSubTreeResponse mockAssociatedSubtree = { | |
| std::make_pair( | |
| "/xyz/openbmc_project/state/chassis1", | |
| dbus::utility::MapperServiceMap{ | |
| {std::make_pair("xyz.openbmc_project.Chassis.Buttons1", | |
| std::vector<std::string>{ | |
| "org.freedesktop.DBus.Introspectable", | |
| "org.freedesktop.DBus.Peer", | |
| "org.freedesktop.DBus.Properties", | |
| "xyz.openbmc_project.State.Chassis", | |
| }), | |
| std::make_pair("xyz.openbmc_project.Control.Host.RestartCause1", | |
| std::vector<std::string>{ | |
| "org.freedesktop.DBus.Introspectable", | |
| "org.freedesktop.DBus.Peer", | |
| "org.freedesktop.DBus.Properties", | |
| "xyz.openbmc_project.State.Chassis", | |
| })}}), | |
| std::make_pair( | |
| "/xyz/openbmc_project/state/chassis2", | |
| dbus::utility::MapperServiceMap{ | |
| {std::make_pair("xyz.openbmc_project.Chassis.Buttons1", | |
| std::vector<std::string>{ | |
| "org.freedesktop.DBus.Introspectable", | |
| "org.freedesktop.DBus.Peer", | |
| "org.freedesktop.DBus.Properties", | |
| "xyz.openbmc_project.State.Chassis", | |
| }), | |
| std::make_pair("xyz.openbmc_project.Control.Host.RestartCause1", | |
| std::vector<std::string>{ | |
| "org.freedesktop.DBus.Introspectable", | |
| "org.freedesktop.DBus.Peer", | |
| "org.freedesktop.DBus.Properties", | |
| "xyz.openbmc_project.State.Chassis", | |
| })}}), | |
| }; | |
| return managedStore::MockManagedStoreTest::CreateValueType( | |
| std::move(mockAssociatedSubtree)); | |
| } | |
| TEST_F(SnapshotFixture_Platform23, | |
| GetSystemHostPowerAssociatedSubTreeHasMoreThanOneObjectsForMultiSystem) { | |
| // Looking for | |
| // kManagedAssociatedSubtree|/xyz/openbmc_project/state|0|xyz.openbmc_project.State.Chassis|/xyz/openbmc_project/inventory/system/board/platform23/system1/chassis_power | |
| KeyType key(ManagedType::kManagedAssociatedSubtree, | |
| "/xyz/openbmc_project/inventory/system/board/platform23/system1/" | |
| "chassis_power", | |
| "/xyz/openbmc_project/state", 0, | |
| {"xyz.openbmc_project.State.Chassis"}); | |
| absl::StatusOr<std::shared_ptr<ValueType>> | |
| chassisPowerAssociatedSubtreeStatusOr = | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->getMockObjectFromManagedStore(key); | |
| ASSERT_TRUE(chassisPowerAssociatedSubtreeStatusOr.ok()); | |
| // TODO(b/416746677): Uncomment after the bug is fixed | |
| // ASSERT_EQ(systemObjectsPathsStatusOr.value()->managedType, | |
| // ManagedType::kManagedSubtreePaths); | |
| std::optional<dbus::utility::MapperGetSubTreeResponse> | |
| originalAssociatedSubtree = | |
| chassisPowerAssociatedSubtreeStatusOr.value()->managedSubtree; | |
| ASSERT_TRUE(originalAssociatedSubtree.has_value()); | |
| ASSERT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| key, CreateBadMockAssociatedSubtreeForMultiSystem()) | |
| .ok()); | |
| absl::Cleanup mockManagedStoreResetter = [key, originalAssociatedSubtree]() { | |
| ASSERT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| key, managedStore::MockManagedStoreTest::CreateValueType( | |
| originalAssociatedSubtree.value())) | |
| .ok()); | |
| }; | |
| handleComputerSystem( | |
| share_async_resp_, | |
| "/xyz/openbmc_project/inventory/system/board/platform23/system1", | |
| "system1", true); | |
| RunIoUntilDone(); | |
| EXPECT_EQ(share_async_resp_->res.result(), | |
| boost::beast::http::status::internal_server_error); | |
| } | |
| TEST_F(SnapshotFixture_Platform23, GetSystemHostPowerAssociatedSubTreeSuccess) { | |
| std::cerr << "Hao: start \n"; | |
| handleComputerSystem( | |
| share_async_resp_, | |
| "/xyz/openbmc_project/inventory/system/board/platform23/system1", | |
| "system1", true); | |
| RunIoUntilDone(); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| std::cerr << "Hao: Done \n"; | |
| } | |
| TEST_F(SnapshotFixture_Platform23, MultiHostPlatformIncludesBios) { | |
| handleComputerSystem(share_async_resp_, "", "system1", false); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_TRUE(json.contains("Bios")); | |
| EXPECT_EQ(json["Bios"]["@odata.id"], "/redfish/v1/Systems/system1/Bios"); | |
| } | |
| TEST_F(SnapshotFixture_Platform23, HandleGetBootNumber) { | |
| KeyType key( | |
| ManagedType::kManagedProperty, "xyz.openbmc_project.Smbios.MDR_V2", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/system/board/platform23/system1/" | |
| "chassis/motherboard/bios"), | |
| "xyz.openbmc_project.State.Host", "BootCount"); | |
| uint32_t num = 1000; | |
| std::shared_ptr<ValueType> bootCountValue = | |
| managedStore::MockManagedStoreTest::CreateValueType(std::move(num)); | |
| ASSERT_TRUE(dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(key, bootCountValue) | |
| .ok()); | |
| handleGetBootNumber(app_, CreateRequest(""), share_async_resp_, "system1"); | |
| RunIoUntilDone(); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Systems/system1/Oem/Google/BootNumber"); | |
| EXPECT_EQ(json["@odata.type"], "#GoogleBootNumber.v1_0_0.GoogleBootNumber"); | |
| EXPECT_TRUE(json.contains("BootNumber")); | |
| EXPECT_EQ(json["BootNumber"], 1000); | |
| } | |
| } // namespace | |
| } // namespace redfish |