Try to fix the lambda formatting issue
clang-tidy has a setting, LambdaBodyIndentation, which it says:
"For callback-heavy code, it may improve readability to have the
signature indented two levels and to use OuterScope."
bmcweb is very callback heavy code. Try to enable it and see if that
improves things. There are many cases where the length of a lambda call
will change, and reindent the entire lambda function. This is really
bad for code reviews, as it's difficult to see the lines changed. This
commit should resolve it. This does have the downside of reindenting a
lot of functions, which is unfortunate, but probably worth it in the
long run.
All changes except for the .clang-format file were made by the robot.
Tested: Code compiles, whitespace changes only.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 1aa7b40..2961513 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -44,34 +44,33 @@
"xyz.openbmc_project.State.Chassis", "CurrentPowerState",
[aResp{std::move(aResp)}](const boost::system::error_code ec,
const std::string& chassisState) {
- if (ec)
+ if (ec)
+ {
+ if (ec == boost::system::errc::host_unreachable)
{
- if (ec == boost::system::errc::host_unreachable)
- {
- // Service not available, no error, just don't return
- // chassis state info
- BMCWEB_LOG_DEBUG << "Service not available " << ec;
- return;
- }
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
- messages::internalError(aResp->res);
+ // Service not available, no error, just don't return
+ // chassis state info
+ BMCWEB_LOG_DEBUG << "Service not available " << ec;
return;
}
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ messages::internalError(aResp->res);
+ return;
+ }
- BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
- // Verify Chassis State
- if (chassisState ==
- "xyz.openbmc_project.State.Chassis.PowerState.On")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] = "Enabled";
- }
- else if (chassisState ==
- "xyz.openbmc_project.State.Chassis.PowerState.Off")
- {
- aResp->res.jsonValue["PowerState"] = "Off";
- aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
- }
+ BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
+ // Verify Chassis State
+ if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
+ }
+ else if (chassisState ==
+ "xyz.openbmc_project.State.Chassis.PowerState.Off")
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
+ }
});
}
@@ -86,17 +85,16 @@
"xyz.openbmc_project.Chassis.Intrusion", "Status",
[aResp{std::move(aResp)}](const boost::system::error_code ec,
const std::string& value) {
- if (ec)
- {
- // do not add err msg in redfish response, because this is not
- // mandatory property
- BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
- return;
- }
+ if (ec)
+ {
+ // do not add err msg in redfish response, because this is not
+ // mandatory property
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
+ return;
+ }
- aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] =
- 1;
- aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value;
+ aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1;
+ aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value;
});
}
@@ -109,23 +107,22 @@
[aResp{std::move(aResp)}](
const boost::system::error_code ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
- if (ec)
+ if (ec)
+ {
+ // do not add err msg in redfish response, because this is not
+ // mandatory property
+ BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec << "\n";
+ return;
+ }
+ // Iterate over all retrieved ObjectPaths.
+ for (const auto& object : subtree)
+ {
+ for (const auto& service : object.second)
{
- // do not add err msg in redfish response, because this is not
- // mandatory property
- BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec
- << "\n";
+ getIntrusionByService(aResp, service.first, object.first);
return;
}
- // Iterate over all retrieved ObjectPaths.
- for (const auto& object : subtree)
- {
- for (const auto& service : object.second)
- {
- getIntrusionByService(aResp, service.first, object.first);
- return;
- }
- }
+ }
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -145,20 +142,20 @@
.methods(boost::beast::http::verb::get)(
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
- {
- return;
- }
- asyncResp->res.jsonValue["@odata.type"] =
- "#ChassisCollection.ChassisCollection";
- asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
- asyncResp->res.jsonValue["Name"] = "Chassis Collection";
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ChassisCollection.ChassisCollection";
+ asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
+ asyncResp->res.jsonValue["Name"] = "Chassis Collection";
- collection_util::getCollectionMembers(
- asyncResp, "/redfish/v1/Chassis",
- {"xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"});
- });
+ collection_util::getCollectionMembers(
+ asyncResp, "/redfish/v1/Chassis",
+ {"xyz.openbmc_project.Inventory.Item.Board",
+ "xyz.openbmc_project.Inventory.Item.Chassis"});
+ });
}
inline void
@@ -171,16 +168,15 @@
"xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
[asyncResp](const boost::system::error_code ec,
const std::string& property) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error for Location";
- messages::internalError(asyncResp->res);
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error for Location";
+ messages::internalError(asyncResp->res);
+ return;
+ }
- asyncResp->res
- .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
- property;
+ asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
+ property;
});
}
@@ -193,13 +189,13 @@
"xyz.openbmc_project.Common.UUID", "UUID",
[asyncResp](const boost::system::error_code ec,
const std::string& chassisUUID) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["UUID"] = chassisUUID;
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["UUID"] = chassisUUID;
});
}
@@ -211,381 +207,352 @@
{
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
.privileges(redfish::privileges::getChassis)
- .methods(
- boost::beast::http::verb::
- get)([&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& chassisId) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ .methods(boost::beast::http::verb::get)(
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& chassisId) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ const std::array<const char*, 2> interfaces = {
+ "xyz.openbmc_project.Inventory.Item.Board",
+ "xyz.openbmc_project.Inventory.Item.Chassis"};
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, chassisId(std::string(chassisId))](
+ const boost::system::error_code ec,
+ const dbus::utility::MapperGetSubTreeResponse& subtree) {
+ if (ec)
{
+ messages::internalError(asyncResp->res);
return;
}
- const std::array<const char*, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
+ // Iterate over all retrieved ObjectPaths.
+ for (const std::pair<std::string,
+ std::vector<std::pair<
+ std::string, std::vector<std::string>>>>&
+ object : subtree)
+ {
+ const std::string& path = object.first;
+ const std::vector<
+ std::pair<std::string, std::vector<std::string>>>&
+ connectionNames = object.second;
- crow::connections::systemBus->async_method_call(
- [asyncResp, chassisId(std::string(chassisId))](
- const boost::system::error_code ec,
- const dbus::utility::MapperGetSubTreeResponse& subtree) {
- if (ec)
+ sdbusplus::message::object_path objPath(path);
+ if (objPath.filename() != chassisId)
+ {
+ continue;
+ }
+
+ auto health = std::make_shared<HealthPopulate>(asyncResp);
+
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.ObjectMapper", path + "/all_sensors",
+ "xyz.openbmc_project.Association", "endpoints",
+ [health](const boost::system::error_code ec2,
+ const std::vector<std::string>& resp) {
+ if (ec2)
{
- messages::internalError(asyncResp->res);
- return;
+ return; // no sensors = no failures
}
- // Iterate over all retrieved ObjectPaths.
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string,
- std::vector<std::string>>>>&
- object : subtree)
+ health->inventory = resp;
+ });
+
+ health->populate();
+
+ if (connectionNames.empty())
+ {
+ BMCWEB_LOG_ERROR << "Got 0 Connection names";
+ continue;
+ }
+
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#Chassis.v1_16_0.Chassis";
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassisId;
+ asyncResp->res.jsonValue["Name"] = "Chassis Collection";
+ asyncResp->res.jsonValue["ChassisType"] = "RackMount";
+ asyncResp->res
+ .jsonValue["Actions"]["#Chassis.Reset"]["target"] =
+ "/redfish/v1/Chassis/" + chassisId +
+ "/Actions/Chassis.Reset";
+ asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]
+ ["@Redfish.ActionInfo"] =
+ "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo";
+ asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
+ "/redfish/v1/Systems/system/PCIeDevices";
+
+ const std::string& connectionName = connectionNames[0].first;
+
+ const std::vector<std::string>& interfaces2 =
+ connectionNames[0].second;
+ const std::array<const char*, 2> hasIndicatorLed = {
+ "xyz.openbmc_project.Inventory.Item.Panel",
+ "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
+
+ const std::string assetTagInterface =
+ "xyz.openbmc_project.Inventory.Decorator.AssetTag";
+ if (std::find(interfaces2.begin(), interfaces2.end(),
+ assetTagInterface) != interfaces2.end())
+ {
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connectionName, path,
+ assetTagInterface, "AssetTag",
+ [asyncResp, chassisId(std::string(chassisId))](
+ const boost::system::error_code ec,
+ const std::string& property) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG
+ << "DBus response error for AssetTag";
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["AssetTag"] = property;
+ });
+ }
+
+ for (const char* interface : hasIndicatorLed)
+ {
+ if (std::find(interfaces2.begin(), interfaces2.end(),
+ interface) != interfaces2.end())
{
- const std::string& path = object.first;
- const std::vector<
- std::pair<std::string, std::vector<std::string>>>&
- connectionNames = object.second;
+ getIndicatorLedState(asyncResp);
+ getLocationIndicatorActive(asyncResp);
+ break;
+ }
+ }
- sdbusplus::message::object_path objPath(path);
- if (objPath.filename() != chassisId)
- {
- continue;
- }
-
- auto health =
- std::make_shared<HealthPopulate>(asyncResp);
-
- sdbusplus::asio::getProperty<std::vector<std::string>>(
- *crow::connections::systemBus,
- "xyz.openbmc_project.ObjectMapper",
- path + "/all_sensors",
- "xyz.openbmc_project.Association", "endpoints",
- [health](const boost::system::error_code ec2,
- const std::vector<std::string>& resp) {
- if (ec2)
- {
- return; // no sensors = no failures
- }
- health->inventory = resp;
- });
-
- health->populate();
-
- if (connectionNames.empty())
- {
- BMCWEB_LOG_ERROR << "Got 0 Connection names";
- continue;
- }
-
- asyncResp->res.jsonValue["@odata.type"] =
- "#Chassis.v1_16_0.Chassis";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Chassis/" + chassisId;
- asyncResp->res.jsonValue["Name"] = "Chassis Collection";
- asyncResp->res.jsonValue["ChassisType"] = "RackMount";
- asyncResp->res
- .jsonValue["Actions"]["#Chassis.Reset"]["target"] =
- "/redfish/v1/Chassis/" + chassisId +
- "/Actions/Chassis.Reset";
- asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]
- ["@Redfish.ActionInfo"] =
- "/redfish/v1/Chassis/" + chassisId +
- "/ResetActionInfo";
- asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
- "/redfish/v1/Systems/system/PCIeDevices";
-
- const std::string& connectionName =
- connectionNames[0].first;
-
- const std::vector<std::string>& interfaces2 =
- connectionNames[0].second;
- const std::array<const char*, 2> hasIndicatorLed = {
- "xyz.openbmc_project.Inventory.Item.Panel",
- "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
-
- const std::string assetTagInterface =
- "xyz.openbmc_project.Inventory.Decorator.AssetTag";
- if (std::find(interfaces2.begin(), interfaces2.end(),
- assetTagInterface) != interfaces2.end())
- {
- sdbusplus::asio::getProperty<std::string>(
- *crow::connections::systemBus, connectionName,
- path, assetTagInterface, "AssetTag",
- [asyncResp, chassisId(std::string(chassisId))](
- const boost::system::error_code ec,
- const std::string& property) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG
- << "DBus response error for AssetTag";
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["AssetTag"] =
- property;
- });
- }
-
- for (const char* interface : hasIndicatorLed)
- {
- if (std::find(interfaces2.begin(),
- interfaces2.end(),
- interface) != interfaces2.end())
- {
- getIndicatorLedState(asyncResp);
- getLocationIndicatorActive(asyncResp);
- break;
- }
- }
-
- crow::connections::systemBus->async_method_call(
- [asyncResp, chassisId(std::string(chassisId))](
- const boost::system::error_code /*ec2*/,
- const dbus::utility::DBusPropertiesMap&
- propertiesList) {
- for (const std::pair<
- std::string,
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, chassisId(std::string(chassisId))](
+ const boost::system::error_code /*ec2*/,
+ const dbus::utility::DBusPropertiesMap&
+ propertiesList) {
+ for (const std::pair<std::string,
dbus::utility::DbusVariantType>&
- property : propertiesList)
- {
- // Store DBus properties that are also
- // Redfish properties with same name and a
- // string value
- const std::string& propertyName =
- property.first;
- if ((propertyName == "PartNumber") ||
- (propertyName == "SerialNumber") ||
- (propertyName == "Manufacturer") ||
- (propertyName == "Model") ||
- (propertyName == "SparePartNumber"))
- {
- const std::string* value =
- std::get_if<std::string>(
- &property.second);
- if (value == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "Null value returned for "
- << propertyName;
- messages::internalError(
- asyncResp->res);
- return;
- }
- // SparePartNumber is optional on D-Bus
- // so skip if it is empty
- if (propertyName == "SparePartNumber")
- {
- if (value->empty())
- {
- continue;
- }
- }
- asyncResp->res.jsonValue[propertyName] =
- *value;
- }
- }
- asyncResp->res.jsonValue["Name"] = chassisId;
- asyncResp->res.jsonValue["Id"] = chassisId;
-#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
- asyncResp->res
- .jsonValue["Thermal"]["@odata.id"] =
- "/redfish/v1/Chassis/" + chassisId +
- "/Thermal";
- // Power object
- asyncResp->res.jsonValue["Power"]["@odata.id"] =
- "/redfish/v1/Chassis/" + chassisId +
- "/Power";
-#endif
- // SensorCollection
- asyncResp->res
- .jsonValue["Sensors"]["@odata.id"] =
- "/redfish/v1/Chassis/" + chassisId +
- "/Sensors";
- asyncResp->res.jsonValue["Status"]["State"] =
- "Enabled";
-
- nlohmann::json::array_t computerSystems;
- nlohmann::json::object_t system;
- system["@odata.id"] =
- "/redfish/v1/Systems/system";
- computerSystems.push_back(std::move(system));
- asyncResp->res
- .jsonValue["Links"]["ComputerSystems"] =
- std::move(computerSystems);
-
- nlohmann::json::array_t managedBy;
- nlohmann::json::object_t manager;
- manager["@odata.id"] =
- "/redfish/v1/Managers/bmc";
- managedBy.push_back(std::move(manager));
- asyncResp->res.jsonValue["Links"]["ManagedBy"] =
- std::move(managedBy);
- getChassisState(asyncResp);
- },
- connectionName, path,
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Inventory.Decorator.Asset");
-
- for (const auto& interface : interfaces2)
+ property : propertiesList)
+ {
+ // Store DBus properties that are also
+ // Redfish properties with same name and a
+ // string value
+ const std::string& propertyName = property.first;
+ if ((propertyName == "PartNumber") ||
+ (propertyName == "SerialNumber") ||
+ (propertyName == "Manufacturer") ||
+ (propertyName == "Model") ||
+ (propertyName == "SparePartNumber"))
{
- if (interface == "xyz.openbmc_project.Common.UUID")
+ const std::string* value =
+ std::get_if<std::string>(&property.second);
+ if (value == nullptr)
{
- getChassisUUID(asyncResp, connectionName, path);
+ BMCWEB_LOG_ERROR << "Null value returned for "
+ << propertyName;
+ messages::internalError(asyncResp->res);
+ return;
}
- else if (
- interface ==
- "xyz.openbmc_project.Inventory.Decorator.LocationCode")
+ // SparePartNumber is optional on D-Bus
+ // so skip if it is empty
+ if (propertyName == "SparePartNumber")
{
- getChassisLocationCode(asyncResp,
- connectionName, path);
+ if (value->empty())
+ {
+ continue;
+ }
}
+ asyncResp->res.jsonValue[propertyName] = *value;
}
-
- return;
}
+ asyncResp->res.jsonValue["Name"] = chassisId;
+ asyncResp->res.jsonValue["Id"] = chassisId;
+#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
+ asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassisId + "/Thermal";
+ // Power object
+ asyncResp->res.jsonValue["Power"]["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassisId + "/Power";
+#endif
+ // SensorCollection
+ asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassisId + "/Sensors";
+ asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
- // Couldn't find an object with that name. return an error
- messages::resourceNotFound(
- asyncResp->res, "#Chassis.v1_16_0.Chassis", chassisId);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", 0, interfaces);
+ nlohmann::json::array_t computerSystems;
+ nlohmann::json::object_t system;
+ system["@odata.id"] = "/redfish/v1/Systems/system";
+ computerSystems.push_back(std::move(system));
+ asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
+ std::move(computerSystems);
- getPhysicalSecurityData(asyncResp);
+ nlohmann::json::array_t managedBy;
+ nlohmann::json::object_t manager;
+ manager["@odata.id"] = "/redfish/v1/Managers/bmc";
+ managedBy.push_back(std::move(manager));
+ asyncResp->res.jsonValue["Links"]["ManagedBy"] =
+ std::move(managedBy);
+ getChassisState(asyncResp);
+ },
+ connectionName, path, "org.freedesktop.DBus.Properties",
+ "GetAll", "xyz.openbmc_project.Inventory.Decorator.Asset");
+
+ for (const auto& interface : interfaces2)
+ {
+ if (interface == "xyz.openbmc_project.Common.UUID")
+ {
+ getChassisUUID(asyncResp, connectionName, path);
+ }
+ else if (
+ interface ==
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode")
+ {
+ getChassisLocationCode(asyncResp, connectionName, path);
+ }
+ }
+
+ return;
+ }
+
+ // Couldn't find an object with that name. return an error
+ messages::resourceNotFound(asyncResp->res,
+ "#Chassis.v1_16_0.Chassis", chassisId);
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/inventory", 0, interfaces);
+
+ getPhysicalSecurityData(asyncResp);
});
BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
.privileges(redfish::privileges::patchChassis)
- .methods(
- boost::beast::http::verb::
- patch)([&app](
- const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& param) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
- {
- return;
- }
- std::optional<bool> locationIndicatorActive;
- std::optional<std::string> indicatorLed;
+ .methods(boost::beast::http::verb::patch)(
+ [&app](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& param) {
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ std::optional<bool> locationIndicatorActive;
+ std::optional<std::string> indicatorLed;
- if (param.empty())
+ if (param.empty())
+ {
+ return;
+ }
+
+ if (!json_util::readJsonPatch(
+ req, asyncResp->res, "LocationIndicatorActive",
+ locationIndicatorActive, "IndicatorLED", indicatorLed))
+ {
+ return;
+ }
+
+ // TODO (Gunnar): Remove IndicatorLED after enough time has passed
+ if (!locationIndicatorActive && !indicatorLed)
+ {
+ return; // delete this when we support more patch properties
+ }
+ if (indicatorLed)
+ {
+ asyncResp->res.addHeader(
+ boost::beast::http::field::warning,
+ "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
+ }
+
+ const std::array<const char*, 2> interfaces = {
+ "xyz.openbmc_project.Inventory.Item.Board",
+ "xyz.openbmc_project.Inventory.Item.Chassis"};
+
+ const std::string& chassisId = param;
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, chassisId, locationIndicatorActive, indicatorLed](
+ const boost::system::error_code ec,
+ const dbus::utility::MapperGetSubTreeResponse& subtree) {
+ if (ec)
{
+ messages::internalError(asyncResp->res);
return;
}
- if (!json_util::readJsonPatch(
- req, asyncResp->res, "LocationIndicatorActive",
- locationIndicatorActive, "IndicatorLED", indicatorLed))
+ // Iterate over all retrieved ObjectPaths.
+ for (const std::pair<std::string,
+ std::vector<std::pair<
+ std::string, std::vector<std::string>>>>&
+ object : subtree)
{
- return;
- }
+ const std::string& path = object.first;
+ const std::vector<
+ std::pair<std::string, std::vector<std::string>>>&
+ connectionNames = object.second;
- // TODO (Gunnar): Remove IndicatorLED after enough time has passed
- if (!locationIndicatorActive && !indicatorLed)
- {
- return; // delete this when we support more patch properties
- }
- if (indicatorLed)
- {
- asyncResp->res.addHeader(
- boost::beast::http::field::warning,
- "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
- }
+ sdbusplus::message::object_path objPath(path);
+ if (objPath.filename() != chassisId)
+ {
+ continue;
+ }
- const std::array<const char*, 2> interfaces = {
- "xyz.openbmc_project.Inventory.Item.Board",
- "xyz.openbmc_project.Inventory.Item.Chassis"};
+ if (connectionNames.empty())
+ {
+ BMCWEB_LOG_ERROR << "Got 0 Connection names";
+ continue;
+ }
- const std::string& chassisId = param;
+ const std::vector<std::string>& interfaces3 =
+ connectionNames[0].second;
- crow::connections::systemBus->async_method_call(
- [asyncResp, chassisId, locationIndicatorActive, indicatorLed](
- const boost::system::error_code ec,
- const dbus::utility::MapperGetSubTreeResponse& subtree) {
- if (ec)
+ const std::array<const char*, 2> hasIndicatorLed = {
+ "xyz.openbmc_project.Inventory.Item.Panel",
+ "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
+ bool indicatorChassis = false;
+ for (const char* interface : hasIndicatorLed)
+ {
+ if (std::find(interfaces3.begin(), interfaces3.end(),
+ interface) != interfaces3.end())
{
- messages::internalError(asyncResp->res);
- return;
+ indicatorChassis = true;
+ break;
}
-
- // Iterate over all retrieved ObjectPaths.
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string,
- std::vector<std::string>>>>&
- object : subtree)
+ }
+ if (locationIndicatorActive)
+ {
+ if (indicatorChassis)
{
- const std::string& path = object.first;
- const std::vector<
- std::pair<std::string, std::vector<std::string>>>&
- connectionNames = object.second;
-
- sdbusplus::message::object_path objPath(path);
- if (objPath.filename() != chassisId)
- {
- continue;
- }
-
- if (connectionNames.empty())
- {
- BMCWEB_LOG_ERROR << "Got 0 Connection names";
- continue;
- }
-
- const std::vector<std::string>& interfaces3 =
- connectionNames[0].second;
-
- const std::array<const char*, 2> hasIndicatorLed = {
- "xyz.openbmc_project.Inventory.Item.Panel",
- "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
- bool indicatorChassis = false;
- for (const char* interface : hasIndicatorLed)
- {
- if (std::find(interfaces3.begin(),
- interfaces3.end(),
- interface) != interfaces3.end())
- {
- indicatorChassis = true;
- break;
- }
- }
- if (locationIndicatorActive)
- {
- if (indicatorChassis)
- {
- setLocationIndicatorActive(
- asyncResp, *locationIndicatorActive);
- }
- else
- {
- messages::propertyUnknown(
- asyncResp->res, "LocationIndicatorActive");
- }
- }
- if (indicatorLed)
- {
- if (indicatorChassis)
- {
- setIndicatorLedState(asyncResp, *indicatorLed);
- }
- else
- {
- messages::propertyUnknown(asyncResp->res,
- "IndicatorLED");
- }
- }
- return;
+ setLocationIndicatorActive(asyncResp,
+ *locationIndicatorActive);
}
+ else
+ {
+ messages::propertyUnknown(asyncResp->res,
+ "LocationIndicatorActive");
+ }
+ }
+ if (indicatorLed)
+ {
+ if (indicatorChassis)
+ {
+ setIndicatorLedState(asyncResp, *indicatorLed);
+ }
+ else
+ {
+ messages::propertyUnknown(asyncResp->res,
+ "IndicatorLED");
+ }
+ }
+ return;
+ }
- messages::resourceNotFound(
- asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", 0, interfaces);
+ messages::resourceNotFound(asyncResp->res,
+ "#Chassis.v1_14_0.Chassis", chassisId);
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/inventory", 0, interfaces);
});
}
@@ -605,47 +572,45 @@
[asyncResp](
const boost::system::error_code ec,
const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ const char* processName = "xyz.openbmc_project.State.Chassis";
+ const char* interfaceName = "xyz.openbmc_project.State.Chassis";
+ const char* destProperty = "RequestedPowerTransition";
+ const std::string propertyValue =
+ "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
+ std::string objectPath = "/xyz/openbmc_project/state/chassis_system0";
+
+ /* Look for system reset chassis path */
+ if ((std::find(chassisList.begin(), chassisList.end(), objectPath)) ==
+ chassisList.end())
+ {
+ /* We prefer to reset the full chassis_system, but if it doesn't
+ * exist on some platforms, fall back to a host-only power reset
+ */
+ objectPath = "/xyz/openbmc_project/state/chassis0";
+ }
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec) {
+ // Use "Set" method to set the property value.
if (ec)
{
- BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec;
+ BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
messages::internalError(asyncResp->res);
return;
}
- const char* processName = "xyz.openbmc_project.State.Chassis";
- const char* interfaceName = "xyz.openbmc_project.State.Chassis";
- const char* destProperty = "RequestedPowerTransition";
- const std::string propertyValue =
- "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
- std::string objectPath =
- "/xyz/openbmc_project/state/chassis_system0";
-
- /* Look for system reset chassis path */
- if ((std::find(chassisList.begin(), chassisList.end(),
- objectPath)) == chassisList.end())
- {
- /* We prefer to reset the full chassis_system, but if it doesn't
- * exist on some platforms, fall back to a host-only power reset
- */
- objectPath = "/xyz/openbmc_project/state/chassis0";
- }
-
- crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec) {
- // Use "Set" method to set the property value.
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: "
- << ec;
- messages::internalError(asyncResp->res);
- return;
- }
-
- messages::success(asyncResp->res);
- },
- processName, objectPath, "org.freedesktop.DBus.Properties",
- "Set", interfaceName, destProperty,
- dbus::utility::DbusVariantType{propertyValue});
+ messages::success(asyncResp->res);
+ },
+ processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
+ interfaceName, destProperty,
+ dbus::utility::DbusVariantType{propertyValue});
},
busName, path, interface, method, "/", 0, interfaces);
}
@@ -665,31 +630,31 @@
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string&) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
- {
- return;
- }
- BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
- std::string resetType;
+ std::string resetType;
- if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
- resetType))
- {
- return;
- }
+ if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
+ resetType))
+ {
+ return;
+ }
- if (resetType != "PowerCycle")
- {
- BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
- << resetType;
- messages::actionParameterNotSupported(
- asyncResp->res, resetType, "ResetType");
+ if (resetType != "PowerCycle")
+ {
+ BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
+ << resetType;
+ messages::actionParameterNotSupported(asyncResp->res, resetType,
+ "ResetType");
- return;
- }
- doChassisPowerCycle(asyncResp);
- });
+ return;
+ }
+ doChassisPowerCycle(asyncResp);
+ });
}
/**
@@ -704,26 +669,26 @@
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& chassisId) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
- {
- return;
- }
- asyncResp->res.jsonValue["@odata.type"] =
- "#ActionInfo.v1_1_2.ActionInfo";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo";
- asyncResp->res.jsonValue["Name"] = "Reset Action Info";
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+ {
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ActionInfo.v1_1_2.ActionInfo";
+ asyncResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo";
+ asyncResp->res.jsonValue["Name"] = "Reset Action Info";
- asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
- nlohmann::json::object_t parameters;
- parameters["Name"] = "ResetType";
- parameters["Required"] = true;
- parameters["DataType"] = "String";
- nlohmann::json::array_t allowed;
- allowed.push_back("PowerCycle");
- parameters["AllowableValues"] = std::move(allowed);
- asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
- });
+ asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
+ nlohmann::json::object_t parameters;
+ parameters["Name"] = "ResetType";
+ parameters["Required"] = true;
+ parameters["DataType"] = "String";
+ nlohmann::json::array_t allowed;
+ allowed.push_back("PowerCycle");
+ parameters["AllowableValues"] = std::move(allowed);
+ asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
+ });
}
} // namespace redfish