| #include "app.hpp" |
| #include "async_resp.hpp" |
| #include "dbus_utility.hpp" |
| #include "http_request.hpp" |
| #include "http_response.hpp" |
| #include "pcie_slots.hpp" |
| #include "snapshot_fixture.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| #include <nlohmann/json.hpp> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| namespace redfish |
| { |
| namespace |
| { |
| |
| using ::dbus::utility::DBusPropertiesMap; |
| using ::dbus::utility::DbusVariantType; |
| using ::dbus::utility::MapperGetSubTreeResponse; |
| using ::dbus::utility::MapperServiceMap; |
| using ::managedStore::KeyType; |
| using ::managedStore::ManagedType; |
| using ::managedStore::ValueType; |
| using ::testing::Contains; |
| |
| std::shared_ptr<ValueType> CreateMockSubtreeResponse() |
| { |
| MapperGetSubTreeResponse mockSubtreeResponse{{std::make_pair( |
| "/xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot9", |
| MapperServiceMap{{std::make_pair( |
| "xyz.openbmc_project.Smbios.MDR_V2", |
| std::vector<std::string>{ |
| "xyz.openbmc_project.Inventory.Item.PCIeSlot", |
| "xyz.openbmc_project.Inventory.Connector.Embedded", |
| "xyz.openbmc_project.Inventory.Decorator.LocationCode", |
| "xyz.openbmc_project.Inventory.Item", |
| "xyz.openbmc_project.Association.Definitions"})}})}}; |
| return managedStore::MockManagedStoreTest::CreateValueType( |
| std::move(mockSubtreeResponse)); |
| } |
| |
| std::shared_ptr<ValueType> CreateAssociatedSubtreeResponse() |
| { |
| MapperGetSubTreeResponse mockSubtreeResponse{{std::make_pair( |
| "/xyz/openbmc_project/inventory/system/board/platform1", |
| MapperServiceMap{{std::make_pair( |
| "xyz.openbmc_project.EntityManager", |
| std::vector<std::string>{ |
| "xyz.openbmc_project.Inventory.Decorator.Asset", |
| "xyz.openbmc_project.EntityManager", |
| "xyz.openbmc_project.Inventory.Item.System", |
| "xyz.openbmc_project.Inventory.Item.Board.Motherboard", |
| "xyz.openbmc_project.Inventory.Item", |
| "xyz.openbmc_project.Inventory.Item.Board"})}})}}; |
| return managedStore::MockManagedStoreTest::CreateValueType( |
| std::move(mockSubtreeResponse)); |
| } |
| |
| DBusPropertiesMap CreateSlotTypeDBusPropertiesMap() |
| { |
| return DBusPropertiesMap({std::make_pair( |
| "SlotType", |
| DbusVariantType( |
| "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.M_2"))}); |
| } |
| |
| TEST_F(SnapshotFixture, GetPCIeSlotsReturnsCorrectResponse) |
| { |
| std::string chassisId = "platform1"; |
| std::string path = |
| "/xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot9"; |
| // Looking for Key: |
| // kManagedSubtree|/xyz/openbmc_project/inventory|0|xyz.openbmc_project.Inventory.Item.PCIeSlot |
| KeyType key(ManagedType::kManagedSubtree, "/xyz/openbmc_project/inventory", |
| 0, {"xyz.openbmc_project.Inventory.Item.PCIeSlot"}); |
| |
| ASSERT_TRUE( |
| managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(key, CreateMockSubtreeResponse()) |
| .ok()); |
| |
| KeyType associationkey(ManagedType::kManagedProperty, |
| "xyz.openbmc_project.ObjectMapper", |
| sdbusplus::message::object_path(path + "/chassis"), |
| "xyz.openbmc_project.Association", "endpoints"); |
| std::shared_ptr<ValueType> mockAssociationEndpoint = |
| managedStore::MockManagedStoreTest::CreateValueType< |
| dbus::utility::DbusVariantType>(std::move(std::vector<std::string>( |
| {"/xyz/openbmc_project/inventory/system/board/platform1"}))); |
| ASSERT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(associationkey, |
| mockAssociationEndpoint) |
| .ok()); |
| |
| std::string locationCode = "M2_0"; |
| KeyType locationkey( |
| ManagedType::kManagedProperty, "xyz.openbmc_project.Smbios.MDR_V2", |
| sdbusplus::message::object_path(path), |
| "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode"); |
| std::shared_ptr<ValueType> mockLocationCode = |
| managedStore::MockManagedStoreTest::CreateValueType(locationCode); |
| ASSERT_TRUE( |
| managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(locationkey, mockLocationCode) |
| .ok()); |
| |
| bool present = true; |
| KeyType presencekey(ManagedType::kManagedProperty, |
| "xyz.openbmc_project.Smbios.MDR_V2", |
| sdbusplus::message::object_path(path), |
| "xyz.openbmc_project.Inventory.Item", "Present"); |
| std::shared_ptr<ValueType> mockPresence = |
| managedStore::MockManagedStoreTest::CreateValueType(present); |
| ASSERT_TRUE( |
| managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(presencekey, mockPresence) |
| .ok()); |
| |
| KeyType keySlot(ManagedType::kManagedPropertyMap, |
| "xyz.openbmc_project.Smbios.MDR_V2", |
| sdbusplus::message::object_path(path), |
| "xyz.openbmc_project.Inventory.Item.PCIeSlot", "SlotType"); |
| std::shared_ptr<ValueType> slotType = |
| CreateValueType(CreateSlotTypeDBusPropertiesMap()); |
| EXPECT_TRUE(managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore(keySlot, slotType) |
| .ok()); |
| |
| KeyType getAssociatedSubTreeKey( |
| ManagedType::kManagedAssociatedSubtree, path + "/chassis", |
| "/xyz/openbmc_project/inventory", 0, |
| {"xyz.openbmc_project.Inventory.Item.Board", |
| "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| ASSERT_TRUE( |
| managedStore::GetManagedObjectStore() |
| ->upsertMockObjectIntoManagedStore( |
| getAssociatedSubTreeKey, CreateAssociatedSubtreeResponse()) |
| .ok()); |
| |
| handlePCIeSlotCollectionGet(app_, CreateRequest(), share_async_resp_, |
| chassisId); |
| |
| RunIoUntilDone(); |
| |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.id"], |
| "/redfish/v1/Chassis/" + chassisId + "/PCIeSlots"); |
| EXPECT_EQ(json["@odata.type"], "#PCIeSlots.v1_4_1.PCIeSlots"); |
| EXPECT_EQ(json["Name"], "PCIe Slot Information"); |
| EXPECT_EQ(json["Id"], "1"); |
| EXPECT_TRUE(json["Slots"].is_array()); |
| EXPECT_EQ(json["Slots"][0]["Status"]["State"], "Enabled"); |
| EXPECT_EQ(json["Slots"][0]["Location"]["PartLocation"]["ServiceLabel"], |
| "M2_0"); |
| } |
| |
| } // namespace |
| } // namespace redfish |