| #include "app.hpp" |
| #include "async_resp.hpp" |
| #include "chassis.hpp" |
| #include "http_request.hpp" |
| #include "http_response.hpp" |
| #include "snapshot_fixture.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| #include <boost/beast/core/string_type.hpp> |
| #include <boost/beast/http/message.hpp> |
| #include <nlohmann/json.hpp> |
| |
| #include <system_error> |
| #include <unordered_set> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| namespace redfish |
| { |
| namespace |
| { |
| |
| using ::testing::Contains; |
| using ::testing::NotNull; |
| |
| constexpr std::string fakeChassis = "fakeChassis"; |
| |
| TEST(HandleChassisResetActionInfoGet, StaticAttributesAreExpected) |
| { |
| auto response = std::make_shared<bmcweb::AsyncResp>(); |
| std::error_code err; |
| |
| validateChassisResetActionInfoHandler(response, fakeChassis, err, "RackMount"); |
| |
| nlohmann::json& json = response->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.type"], "#ActionInfo.v1_1_2.ActionInfo"); |
| EXPECT_EQ(json["@odata.id"], |
| "/redfish/v1/Chassis/" + fakeChassis + "/ResetActionInfo"); |
| EXPECT_EQ(json["Name"], "Reset Action Info"); |
| |
| EXPECT_EQ(json["Id"], "ResetActionInfo"); |
| |
| nlohmann::json::array_t parameters; |
| nlohmann::json::object_t delayParameter; |
| delayParameter["Name"] = "Delay"; |
| delayParameter["Required"] = false; |
| delayParameter["DataType"] = "Number"; |
| |
| nlohmann::json::object_t parameter; |
| parameter["Name"] = "ResetType"; |
| parameter["Required"] = true; |
| parameter["DataType"] = "String"; |
| |
| nlohmann::json::array_t allowed; |
| allowed.push_back("PowerCycle"); |
| parameter["AllowableValues"] = std::move(allowed); |
| parameters.push_back(std::move(parameter)); |
| parameters.push_back(std::move(delayParameter)); |
| |
| EXPECT_EQ(json["Parameters"], parameters); |
| } |
| |
| TEST_F(SnapshotFixture, ChassisTypeTestReturnsCorrectResponse) |
| { |
| auto response = std::make_shared<bmcweb::AsyncResp>(); |
| nlohmann::json& json = response->res.jsonValue; |
| |
| json["ChassisType"] = "RackMount"; |
| |
| addChassisReset(response, fakeChassis, "UnsupportedType"); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(json["ChassisType"], "UnsupportedType"); |
| } |
| |
| TEST_F(SnapshotFixture, GetChassisCollectionTestReturnsCorrectResposne){ |
| handleChassisCollectionGet(app_, CreateRequest(), share_async_resp_); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_EQ(json["@odata.id"], "/redfish/v1/Chassis"); |
| EXPECT_EQ(json["@odata.type"], "#ChassisCollection.ChassisCollection"); |
| EXPECT_EQ(json["Name"], "Chassis Collection"); |
| EXPECT_EQ(json["Members@odata.count"], json["Members"].size()); |
| |
| std::unordered_set<std::string> chassis_set{{ |
| "/redfish/v1/Chassis/Bigchassis2_1", |
| "/redfish/v1/Chassis/chassis1V2ND", |
| "/redfish/v1/Chassis/chassis3_1", |
| "/redfish/v1/Chassis/chassis4_1", |
| "/redfish/v1/Chassis/coin_battery", |
| "/redfish/v1/Chassis/i2cool_0", |
| "/redfish/v1/Chassis/i2cool_1", |
| "/redfish/v1/Chassis/i2cool_2", |
| "/redfish/v1/Chassis/ioadapter_x16_1", |
| "/redfish/v1/Chassis/platform1" |
| }}; |
| |
| EXPECT_EQ(json["Members"].size(), chassis_set.size()); |
| for (const auto& member : json["Members"]) |
| { |
| ASSERT_TRUE(member.contains("@odata.id")); |
| const std::string* chassis = member["@odata.id"].get_ptr<const std::string*>(); |
| ASSERT_THAT(chassis, NotNull()); |
| EXPECT_THAT(chassis_set, Contains(*chassis)); |
| } |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); |
| } |
| |
| TEST_F(SnapshotFixture, GetChassisTestReturnsCorrectResposne){ |
| handleChassisGet(app_, CreateRequest(), share_async_resp_, "platform1"); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| EXPECT_EQ(json["@odata.id"], "/redfish/v1/Chassis/platform1"); |
| EXPECT_EQ(json["@odata.type"], "#Chassis.v1_17_0.Chassis"); |
| EXPECT_EQ(json["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"], "/redfish/v1/Chassis/platform1/ResetActionInfo"); |
| EXPECT_EQ(json["Actions"]["#Chassis.Reset"]["target"], "/redfish/v1/Chassis/platform1/Actions/Chassis.Reset"); |
| EXPECT_EQ(json["Assembly"]["@odata.id"], "/redfish/v1/Chassis/platform1/Assembly"); |
| EXPECT_EQ(json["Certificates"]["@odata.id"], "/redfish/v1/Chassis/platform1/Certificates"); |
| EXPECT_EQ(json["ChassisType"], "RackMount"); |
| EXPECT_EQ(json["Drives"]["@odata.id"], "/redfish/v1/Chassis/platform1/Drives"); |
| EXPECT_EQ(json["EnvironmentMetrics"]["@odata.id"], "/redfish/v1/Chassis/platform1/EnvironmentMetrics"); |
| EXPECT_EQ(json["Id"], "platform1"); |
| EXPECT_EQ(json["Links"]["Cables"].size(), json["Links"]["Cables@odata.count"]); |
| EXPECT_EQ(json["Links"]["Cables"][0]["@odata.id"], "/redfish/v1/Cables/NcsiCable"); |
| EXPECT_EQ(json["Links"]["ComputerSystems"].size(), 1); |
| EXPECT_EQ(json["Links"]["ComputerSystems"][0]["@odata.id"], "/redfish/v1/Systems/system"); |
| EXPECT_EQ(json["Links"]["ManagedBy"].size(), 1); |
| EXPECT_EQ(json["Links"]["ManagedBy"][0]["@odata.id"], "/redfish/v1/Managers/bmc"); |
| EXPECT_EQ(json["Links"]["Processors"].size(), json["Links"]["Processors@odata.count"]); |
| EXPECT_EQ(json["Links"]["Processors"][0]["@odata.id"], "/redfish/v1/Systems/system/Processors/cpu0"); |
| EXPECT_EQ(json["Links"]["Processors"][1]["@odata.id"], "/redfish/v1/Systems/system/Processors/cpu1"); |
| EXPECT_EQ(json["Manufacturer"], "Manufacturer"); |
| EXPECT_EQ(json["Memory"]["@odata.id"], "/redfish/v1/Systems/system/Memory"); |
| EXPECT_EQ(json["Model"], "Model"); |
| EXPECT_EQ(json["Name"], "platform1"); |
| EXPECT_EQ(json["PCIeDevices"]["@odata.id"], "/redfish/v1/Systems/system/PCIeDevices"); |
| EXPECT_EQ(json["PCIeSlots"]["@odata.id"], "/redfish/v1/Chassis/platform1/PCIeSlots"); |
| EXPECT_EQ(json["PartNumber"], "PartNumber"); |
| EXPECT_EQ(json["Power"]["@odata.id"], "/redfish/v1/Chassis/platform1/Power"); |
| EXPECT_EQ(json["PowerSubsystem"]["@odata.id"], "/redfish/v1/Chassis/platform1/PowerSubsystem"); |
| EXPECT_EQ(json["Sensors"]["@odata.id"], "/redfish/v1/Chassis/platform1/Sensors"); |
| EXPECT_EQ(json["SerialNumber"], "SerialNumber"); |
| EXPECT_EQ(json["Status"]["State"], "Enabled"); |
| EXPECT_EQ(json["Thermal"]["@odata.id"], "/redfish/v1/Chassis/platform1/Thermal"); |
| EXPECT_EQ(json["ThermalSubsystem"]["@odata.id"], "/redfish/v1/Chassis/platform1/ThermalSubsystem"); |
| EXPECT_EQ(json["TrustedComponents"]["@odata.id"], "/redfish/v1/Chassis/platform1/TrustedComponents"); |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); |
| } |
| |
| TEST_F(SnapshotFixture, PostChassisCycleDelayGood){ |
| handleChassisResetActionInfoPost(app_, CreateRequest("{\"ResetType\":\"PowerCycle\", \"Delay\":1} "), share_async_resp_, "platform1"); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(),boost::beast::http::status::ok); |
| |
| EXPECT_EQ(share_async_resp_->res.jsonValue["ResetString"], |
| "systemd-run --on-active=1 --timer-property=AccuracySec=100ms -- systemctl start gbmc-psu-hardreset.target"); |
| } |
| |
| TEST_F(SnapshotFixture, PostChassisCycleDelayBadResetType){ |
| handleChassisResetActionInfoPost(app_, CreateRequest("{\"ResetType\":\"PleaseReset\", \"Delay\":1} "), share_async_resp_, "platform1"); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(),boost::beast::http::status::bad_request); |
| } |
| |
| TEST_F(SnapshotFixture, PostChassisCycleDelayBadTime){ |
| handleChassisResetActionInfoPost(app_, CreateRequest("{\"ResetType\":\"PowerCycle\", \"Delay\":3601} "), share_async_resp_, "platform1"); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(),boost::beast::http::status::bad_request); |
| } |
| |
| TEST_F(SnapshotFixture, PostChassisCycleInvalidParam){ |
| handleChassisResetActionInfoPost(app_, CreateRequest("{\"ResetType\":\"PowerCycle\", \"UnknownParm_foo\":30} "), share_async_resp_, "platform1"); |
| |
| RunIoUntilDone(); |
| |
| EXPECT_EQ(share_async_resp_->res.result(),boost::beast::http::status::bad_request); |
| } |
| |
| } // namespace |
| } // namespace redfish |