1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "app.hpp"
#include "async_resp.hpp"
#include "chassis.hpp"
#include "dbus_utility.hpp"
#include "generated/enums/chassis.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include <boost/beast/core/string_type.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/beast/http/verb.hpp>
#include <nlohmann/json.hpp>
#include <functional>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
#include <gtest/gtest.h>
namespace redfish
{
namespace
{
void assertChassisResetActionInfoGet(const std::string& chassisId,
crow::Response& res)
{
EXPECT_EQ(res.jsonValue["@odata.type"], "#ActionInfo.v1_1_2.ActionInfo");
EXPECT_EQ(res.jsonValue["@odata.id"],
"/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo");
EXPECT_EQ(res.jsonValue["Name"], "Reset Action Info");
EXPECT_EQ(res.jsonValue["Id"], "ResetActionInfo");
nlohmann::json::array_t parameters;
nlohmann::json::object_t parameter;
parameter["Name"] = "ResetType";
parameter["Required"] = true;
parameter["DataType"] = "String";
nlohmann::json::array_t allowed;
allowed.emplace_back("PowerCycle");
parameter["AllowableValues"] = std::move(allowed);
parameters.emplace_back(std::move(parameter));
EXPECT_EQ(res.jsonValue["Parameters"], parameters);
}
TEST(HandleChassisResetActionInfoGet, StaticAttributesAreExpected)
{
auto response = std::make_shared<bmcweb::AsyncResp>();
std::error_code err;
crow::Request request{{boost::beast::http::verb::get, "/whatever", 11},
err};
std::string fakeChassis = "fakeChassis";
response->res.setCompleteRequestHandler(
std::bind_front(assertChassisResetActionInfoGet, fakeChassis));
crow::App app;
handleChassisResetActionInfoGet(app, request, response, fakeChassis);
}
TEST(TranslateChassisTypeToRedfish, TranslationsAreExpected)
{
ASSERT_EQ(
chassis::ChassisType::Blade,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Blade"));
ASSERT_EQ(
chassis::ChassisType::Component,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Component"));
ASSERT_EQ(
chassis::ChassisType::Enclosure,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Enclosure"));
ASSERT_EQ(
chassis::ChassisType::Module,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Module"));
ASSERT_EQ(
chassis::ChassisType::RackMount,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.RackMount"));
ASSERT_EQ(
chassis::ChassisType::StandAlone,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StandAlone"));
ASSERT_EQ(
chassis::ChassisType::StorageEnclosure,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StorageEnclosure"));
ASSERT_EQ(
chassis::ChassisType::Zone,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Zone"));
ASSERT_EQ(
chassis::ChassisType::Invalid,
translateChassisTypeToRedfish(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Unknown"));
}
TEST(HandleChassisProperties, TypeFound)
{
auto response = std::make_shared<bmcweb::AsyncResp>();
auto properties = dbus::utility::DBusPropertiesMap();
properties.emplace_back(
std::string("Type"),
dbus::utility::DbusVariantType(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.RackMount"));
handleChassisProperties(response, properties);
ASSERT_EQ("RackMount", response->res.jsonValue["ChassisType"]);
response = std::make_shared<bmcweb::AsyncResp>();
properties.clear();
properties.emplace_back(
std::string("Type"),
dbus::utility::DbusVariantType(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StandAlone"));
handleChassisProperties(response, properties);
ASSERT_EQ("StandAlone", response->res.jsonValue["ChassisType"]);
}
TEST(HandleChassisProperties, BadTypeFound)
{
auto response = std::make_shared<bmcweb::AsyncResp>();
auto properties = dbus::utility::DBusPropertiesMap();
properties.emplace_back(
std::string("Type"),
dbus::utility::DbusVariantType(
"xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Unknown"));
handleChassisProperties(response, properties);
// We fall back to RackMount
ASSERT_EQ("RackMount", response->res.jsonValue["ChassisType"]);
}
TEST(HandleChassisProperties, FailToGetProperty)
{
auto response = std::make_shared<bmcweb::AsyncResp>();
auto properties = dbus::utility::DBusPropertiesMap();
properties.emplace_back(std::string("Type"),
dbus::utility::DbusVariantType(123));
handleChassisProperties(response, properties);
ASSERT_EQ(boost::beast::http::status::internal_server_error,
response->res.result());
}
TEST(HandleChassisProperties, TypeNotFound)
{
auto response = std::make_shared<bmcweb::AsyncResp>();
auto properties = dbus::utility::DBusPropertiesMap();
handleChassisProperties(response, properties);
ASSERT_EQ("RackMount", response->res.jsonValue["ChassisType"]);
}
} // namespace
} // namespace redfish
|