| #include "absl/cleanup/cleanup.h" |
| #include "bmcweb_config.h" |
| |
| #include "app.hpp" |
| #include "async_resp.hpp" |
| #include "http_response.hpp" |
| #include "nlohmann/json.hpp" |
| #include "snapshot_fixture.hpp" |
| #include "systems.hpp" |
| |
| #include <memory> |
| #include <vector> |
| |
| #include <gmock/gmock.h> // IWYU pragma: keep |
| #include <gtest/gtest.h> // IWYU pragma: keep |
| |
| // IWYU pragma: no_include <gtest/gtest-message.h> |
| // IWYU pragma: no_include <gtest/gtest-test-part.h> |
| // IWYU pragma: no_include "gtest/gtest_pred_impl.h" |
| // IWYU pragma: no_include <gmock/gmock-matchers.h> |
| // IWYU pragma: no_include <gtest/gtest-matchers.h> |
| |
| namespace redfish |
| { |
| namespace |
| { |
| |
| using ::dbus::utility::DbusVariantType; |
| using ::managedStore::KeyType; |
| using ::managedStore::ManagedObjectStoreContext; |
| using ::managedStore::ManagedType; |
| using ::managedStore::SimulateFailedAsyncPostDbusCallThreadSafeAction; |
| using ::managedStore::SimulateSuccessfulAsyncPostDbusCallThreadSafeAction; |
| using ::managedStore::ValueType; |
| using ::testing::_; |
| using ::testing::An; |
| |
| 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 = |
| 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(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore( |
| key, CreateBadMockAssociatedSubtreeForMultiSystem()) |
| .ok()); |
| |
| absl::Cleanup mockManagedStoreResetter = [key, |
| originalAssociatedSubtree]() { |
| ASSERT_TRUE( |
| 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"; |
| } |
| |
| } // namespace |
| } // namespace redfish |