summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-05-31 18:59:27 +0300
committerEd Tanous <ed@tanous.net>2022-06-01 19:10:35 +0300
commit002d39b4a7a5ed7166e2acad84e0943c3def9492 (patch)
tree4307dd5161ec9779d59308a9b933e408cc2c6ca7 /redfish-core/include
parent62c416fb0d2f62e09d7f60754ff359ac2389e749 (diff)
downloadbmcweb-002d39b4a7a5ed7166e2acad84e0943c3def9492.tar.xz
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
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/event_service_manager.hpp142
-rw-r--r--redfish-core/include/query.hpp4
-rw-r--r--redfish-core/include/redfish_aggregator.hpp46
-rw-r--r--redfish-core/include/server_sent_events.hpp68
-rw-r--r--redfish-core/include/utils/collection.hpp70
-rw-r--r--redfish-core/include/utils/fw_utils.hpp389
-rw-r--r--redfish-core/include/utils/json_utils.hpp27
7 files changed, 363 insertions, 383 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 52db9fb384..6747575c33 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -96,8 +96,8 @@ static const Message*
std::span<const MessageEntry>::iterator messageIt =
std::find_if(registry.begin(), registry.end(),
[&messageKey](const MessageEntry& messageEntry) {
- return messageKey == messageEntry.first;
- });
+ return messageKey == messageEntry.first;
+ });
if (messageIt != registry.end())
{
return &messageIt->second;
@@ -1183,91 +1183,89 @@ class EventServiceManager
static std::array<char, 1024> readBuffer;
- inotifyConn->async_read_some(
- boost::asio::buffer(readBuffer),
- [&](const boost::system::error_code& ec,
- const std::size_t& bytesTransferred) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "Callback Error: " << ec.message();
- return;
- }
- std::size_t index = 0;
- while ((index + iEventSize) <= bytesTransferred)
+ inotifyConn->async_read_some(boost::asio::buffer(readBuffer),
+ [&](const boost::system::error_code& ec,
+ const std::size_t& bytesTransferred) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "Callback Error: " << ec.message();
+ return;
+ }
+ std::size_t index = 0;
+ while ((index + iEventSize) <= bytesTransferred)
+ {
+ struct inotify_event event
+ {};
+ std::memcpy(&event, &readBuffer[index], iEventSize);
+ if (event.wd == dirWatchDesc)
{
- struct inotify_event event
- {};
- std::memcpy(&event, &readBuffer[index], iEventSize);
- if (event.wd == dirWatchDesc)
+ if ((event.len == 0) ||
+ (index + iEventSize + event.len > bytesTransferred))
{
- if ((event.len == 0) ||
- (index + iEventSize + event.len > bytesTransferred))
- {
- index += (iEventSize + event.len);
- continue;
- }
+ index += (iEventSize + event.len);
+ continue;
+ }
- std::string fileName(&readBuffer[index + iEventSize]);
- if (fileName != "redfish")
- {
- index += (iEventSize + event.len);
- continue;
- }
+ std::string fileName(&readBuffer[index + iEventSize]);
+ if (fileName != "redfish")
+ {
+ index += (iEventSize + event.len);
+ continue;
+ }
- BMCWEB_LOG_DEBUG
- << "Redfish log file created/deleted. event.name: "
- << fileName;
- if (event.mask == IN_CREATE)
+ BMCWEB_LOG_DEBUG
+ << "Redfish log file created/deleted. event.name: "
+ << fileName;
+ if (event.mask == IN_CREATE)
+ {
+ if (fileWatchDesc != -1)
{
- if (fileWatchDesc != -1)
- {
- BMCWEB_LOG_DEBUG
- << "Remove and Add inotify watcher on "
- "redfish event log file";
- // Remove existing inotify watcher and add
- // with new redfish event log file.
- inotify_rm_watch(inotifyFd, fileWatchDesc);
- fileWatchDesc = -1;
- }
-
- fileWatchDesc = inotify_add_watch(
- inotifyFd, redfishEventLogFile, IN_MODIFY);
- if (fileWatchDesc == -1)
- {
- BMCWEB_LOG_ERROR
- << "inotify_add_watch failed for "
- "redfish log file.";
- return;
- }
-
- EventServiceManager::getInstance()
- .resetRedfishFilePosition();
- EventServiceManager::getInstance()
- .readEventLogsFromFile();
+ BMCWEB_LOG_DEBUG
+ << "Remove and Add inotify watcher on "
+ "redfish event log file";
+ // Remove existing inotify watcher and add
+ // with new redfish event log file.
+ inotify_rm_watch(inotifyFd, fileWatchDesc);
+ fileWatchDesc = -1;
}
- else if ((event.mask == IN_DELETE) ||
- (event.mask == IN_MOVED_TO))
+
+ fileWatchDesc = inotify_add_watch(
+ inotifyFd, redfishEventLogFile, IN_MODIFY);
+ if (fileWatchDesc == -1)
{
- if (fileWatchDesc != -1)
- {
- inotify_rm_watch(inotifyFd, fileWatchDesc);
- fileWatchDesc = -1;
- }
+ BMCWEB_LOG_ERROR << "inotify_add_watch failed for "
+ "redfish log file.";
+ return;
}
+
+ EventServiceManager::getInstance()
+ .resetRedfishFilePosition();
+ EventServiceManager::getInstance()
+ .readEventLogsFromFile();
}
- else if (event.wd == fileWatchDesc)
+ else if ((event.mask == IN_DELETE) ||
+ (event.mask == IN_MOVED_TO))
{
- if (event.mask == IN_MODIFY)
+ if (fileWatchDesc != -1)
{
- EventServiceManager::getInstance()
- .readEventLogsFromFile();
+ inotify_rm_watch(inotifyFd, fileWatchDesc);
+ fileWatchDesc = -1;
}
}
- index += (iEventSize + event.len);
}
+ else if (event.wd == fileWatchDesc)
+ {
+ if (event.mask == IN_MODIFY)
+ {
+ EventServiceManager::getInstance()
+ .readEventLogsFromFile();
+ }
+ }
+ index += (iEventSize + event.len);
+ }
- watchRedfishEventLogFile();
- });
+ watchRedfishEventLogFile();
+ });
}
static int startEventLogMonitor(boost::asio::io_context& ioc)
diff --git a/redfish-core/include/query.hpp b/redfish-core/include/query.hpp
index 88859e11be..1f7774f729 100644
--- a/redfish-core/include/query.hpp
+++ b/redfish-core/include/query.hpp
@@ -50,8 +50,8 @@ namespace redfish
res.setCompleteRequestHandler(
[&app, handler(std::move(handler)),
query{*queryOpt}](crow::Response& res) mutable {
- processAllParams(app, query, handler, res);
- });
+ processAllParams(app, query, handler, res);
+ });
return true;
}
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index d076c6c1ea..67ed929cb5 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -33,32 +33,32 @@ class RedfishAggregator
crow::connections::systemBus->async_method_call(
[handler](const boost::system::error_code ec,
const dbus::utility::ManagedObjectType& objects) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "DBUS response error " << ec.value()
- << ", " << ec.message();
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec.value() << ", "
+ << ec.message();
+ return;
+ }
- // Maps a chosen alias representing a satellite BMC to a url
- // containing the information required to create a http
- // connection to the satellite
- std::unordered_map<std::string, boost::urls::url> satelliteInfo;
+ // Maps a chosen alias representing a satellite BMC to a url
+ // containing the information required to create a http
+ // connection to the satellite
+ std::unordered_map<std::string, boost::urls::url> satelliteInfo;
- findSatelliteConfigs(objects, satelliteInfo);
+ findSatelliteConfigs(objects, satelliteInfo);
- if (!satelliteInfo.empty())
- {
- BMCWEB_LOG_DEBUG << "Redfish Aggregation enabled with "
- << std::to_string(satelliteInfo.size())
- << " satellite BMCs";
- }
- else
- {
- BMCWEB_LOG_DEBUG
- << "No satellite BMCs detected. Redfish Aggregation not enabled";
- }
- handler(satelliteInfo);
+ if (!satelliteInfo.empty())
+ {
+ BMCWEB_LOG_DEBUG << "Redfish Aggregation enabled with "
+ << std::to_string(satelliteInfo.size())
+ << " satellite BMCs";
+ }
+ else
+ {
+ BMCWEB_LOG_DEBUG
+ << "No satellite BMCs detected. Redfish Aggregation not enabled";
+ }
+ handler(satelliteInfo);
},
"xyz.openbmc_project.EntityManager", "/",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
diff --git a/redfish-core/include/server_sent_events.hpp b/redfish-core/include/server_sent_events.hpp
index 13840d3d1e..6663f66c61 100644
--- a/redfish-core/include/server_sent_events.hpp
+++ b/redfish-core/include/server_sent_events.hpp
@@ -109,30 +109,30 @@ class ServerSentEvents : public std::enable_shared_from_this<ServerSentEvents>
[self(shared_from_this())](
boost::beast::error_code ec,
[[maybe_unused]] const std::size_t& bytesTransferred) {
- self->outBuffer.erase(0, bytesTransferred);
-
- if (ec == boost::asio::error::eof)
- {
- // Send is successful, Lets remove data from queue
- // check for next request data in queue.
- self->requestDataQueue.pop();
- self->state = SseConnState::idle;
- self->checkQueue();
- return;
- }
-
- if (ec)
- {
- BMCWEB_LOG_ERROR << "async_write_some() failed: "
- << ec.message();
- self->state = SseConnState::sendFailed;
- self->checkQueue();
- return;
- }
- BMCWEB_LOG_DEBUG << "async_write_some() bytes transferred: "
- << bytesTransferred;
-
- self->doWrite();
+ self->outBuffer.erase(0, bytesTransferred);
+
+ if (ec == boost::asio::error::eof)
+ {
+ // Send is successful, Lets remove data from queue
+ // check for next request data in queue.
+ self->requestDataQueue.pop();
+ self->state = SseConnState::idle;
+ self->checkQueue();
+ return;
+ }
+
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "async_write_some() failed: "
+ << ec.message();
+ self->state = SseConnState::sendFailed;
+ self->checkQueue();
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "async_write_some() bytes transferred: "
+ << bytesTransferred;
+
+ self->doWrite();
});
}
@@ -166,17 +166,17 @@ class ServerSentEvents : public std::enable_shared_from_this<ServerSentEvents>
[this, response,
serializer](const boost::beast::error_code& ec,
[[maybe_unused]] const std::size_t& bytesTransferred) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "Error sending header" << ec;
- state = SseConnState::initFailed;
- checkQueue();
- return;
- }
-
- BMCWEB_LOG_DEBUG << "startSSE Header sent.";
- state = SseConnState::initialized;
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "Error sending header" << ec;
+ state = SseConnState::initFailed;
checkQueue();
+ return;
+ }
+
+ BMCWEB_LOG_DEBUG << "startSSE Header sent.";
+ state = SseConnState::initialized;
+ checkQueue();
});
}
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index f4e37b5284..7a845d1e38 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -33,46 +33,46 @@ inline void
[collectionPath, aResp{std::move(aResp)}](
const boost::system::error_code ec,
const dbus::utility::MapperGetSubTreePathsResponse& objects) {
- if (ec == boost::system::errc::io_error)
- {
- aResp->res.jsonValue["Members"] = nlohmann::json::array();
- aResp->res.jsonValue["Members@odata.count"] = 0;
- return;
- }
+ if (ec == boost::system::errc::io_error)
+ {
+ aResp->res.jsonValue["Members"] = nlohmann::json::array();
+ aResp->res.jsonValue["Members@odata.count"] = 0;
+ return;
+ }
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec.value();
- messages::internalError(aResp->res);
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec.value();
+ messages::internalError(aResp->res);
+ return;
+ }
- std::vector<std::string> pathNames;
- for (const auto& object : objects)
+ std::vector<std::string> pathNames;
+ for (const auto& object : objects)
+ {
+ sdbusplus::message::object_path path(object);
+ std::string leaf = path.filename();
+ if (leaf.empty())
{
- sdbusplus::message::object_path path(object);
- std::string leaf = path.filename();
- if (leaf.empty())
- {
- continue;
- }
- pathNames.push_back(leaf);
+ continue;
}
- std::sort(pathNames.begin(), pathNames.end(),
- AlphanumLess<std::string>());
+ pathNames.push_back(leaf);
+ }
+ std::sort(pathNames.begin(), pathNames.end(),
+ AlphanumLess<std::string>());
- nlohmann::json& members = aResp->res.jsonValue["Members"];
- members = nlohmann::json::array();
- for (const std::string& leaf : pathNames)
- {
- std::string newPath = collectionPath;
- newPath += '/';
- newPath += leaf;
- nlohmann::json::object_t member;
- member["@odata.id"] = std::move(newPath);
- members.push_back(std::move(member));
- }
- aResp->res.jsonValue["Members@odata.count"] = members.size();
+ nlohmann::json& members = aResp->res.jsonValue["Members"];
+ members = nlohmann::json::array();
+ for (const std::string& leaf : pathNames)
+ {
+ std::string newPath = collectionPath;
+ newPath += '/';
+ newPath += leaf;
+ nlohmann::json::object_t member;
+ member["@odata.id"] = std::move(newPath);
+ members.push_back(std::move(member));
+ }
+ aResp->res.jsonValue["Members@odata.count"] = members.size();
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp
index d80ce71f2e..c4c323d3e0 100644
--- a/redfish-core/include/utils/fw_utils.hpp
+++ b/redfish-core/include/utils/fw_utils.hpp
@@ -46,199 +46,183 @@ inline void
[aResp, fwVersionPurpose, activeVersionPropName,
populateLinkToImages](const boost::system::error_code ec,
const std::vector<std::string>& functionalFw) {
- BMCWEB_LOG_DEBUG << "populateFirmwareInformation enter";
- if (ec)
+ BMCWEB_LOG_DEBUG << "populateFirmwareInformation enter";
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "error_code = " << ec;
+ BMCWEB_LOG_ERROR << "error msg = " << ec.message();
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ if (functionalFw.empty())
+ {
+ // Could keep going and try to populate SoftwareImages but
+ // something is seriously wrong, so just fail
+ BMCWEB_LOG_ERROR << "Zero functional software in system";
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ std::vector<std::string> functionalFwIds;
+ // example functionalFw:
+ // v as 2 "/xyz/openbmc_project/software/ace821ef"
+ // "/xyz/openbmc_project/software/230fb078"
+ for (const auto& fw : functionalFw)
+ {
+ sdbusplus::message::object_path path(fw);
+ std::string leaf = path.filename();
+ if (leaf.empty())
{
- BMCWEB_LOG_ERROR << "error_code = " << ec;
- BMCWEB_LOG_ERROR << "error msg = " << ec.message();
- messages::internalError(aResp->res);
- return;
+ continue;
}
- if (functionalFw.empty())
+ functionalFwIds.push_back(leaf);
+ }
+
+ crow::connections::systemBus->async_method_call(
+ [aResp, fwVersionPurpose, activeVersionPropName,
+ populateLinkToImages, functionalFwIds](
+ const boost::system::error_code ec2,
+ const dbus::utility::MapperGetSubTreeResponse& subtree) {
+ if (ec2)
{
- // Could keep going and try to populate SoftwareImages but
- // something is seriously wrong, so just fail
- BMCWEB_LOG_ERROR << "Zero functional software in system";
+ BMCWEB_LOG_ERROR << "error_code = " << ec2;
+ BMCWEB_LOG_ERROR << "error msg = " << ec2.message();
messages::internalError(aResp->res);
return;
}
- std::vector<std::string> functionalFwIds;
- // example functionalFw:
- // v as 2 "/xyz/openbmc_project/software/ace821ef"
- // "/xyz/openbmc_project/software/230fb078"
- for (const auto& fw : functionalFw)
+ BMCWEB_LOG_DEBUG << "Found " << subtree.size() << " images";
+
+ for (const std::pair<std::string,
+ std::vector<std::pair<
+ std::string, std::vector<std::string>>>>&
+ obj : subtree)
{
- sdbusplus::message::object_path path(fw);
- std::string leaf = path.filename();
- if (leaf.empty())
+
+ sdbusplus::message::object_path path(obj.first);
+ std::string swId = path.filename();
+ if (swId.empty())
{
- continue;
+ messages::internalError(aResp->res);
+ BMCWEB_LOG_ERROR << "Invalid firmware ID";
+
+ return;
}
- functionalFwIds.push_back(leaf);
- }
+ bool runningImage = false;
+ // Look at Ids from
+ // /xyz/openbmc_project/software/functional
+ // to determine if this is a running image
+ if (std::find(functionalFwIds.begin(), functionalFwIds.end(),
+ swId) != functionalFwIds.end())
+ {
+ runningImage = true;
+ }
- crow::connections::systemBus->async_method_call(
- [aResp, fwVersionPurpose, activeVersionPropName,
- populateLinkToImages, functionalFwIds](
- const boost::system::error_code ec2,
- const dbus::utility::MapperGetSubTreeResponse& subtree) {
- if (ec2)
+ // Now grab its version info
+ crow::connections::systemBus->async_method_call(
+ [aResp, swId, runningImage, fwVersionPurpose,
+ activeVersionPropName, populateLinkToImages](
+ const boost::system::error_code ec3,
+ const dbus::utility::DBusPropertiesMap&
+ propertiesList) {
+ if (ec3)
{
- BMCWEB_LOG_ERROR << "error_code = " << ec2;
- BMCWEB_LOG_ERROR << "error msg = " << ec2.message();
+ BMCWEB_LOG_ERROR << "error_code = " << ec3;
+ BMCWEB_LOG_ERROR << "error msg = " << ec3.message();
messages::internalError(aResp->res);
return;
}
-
- BMCWEB_LOG_DEBUG << "Found " << subtree.size() << " images";
-
- for (const std::pair<
- std::string,
- std::vector<std::pair<
- std::string, std::vector<std::string>>>>& obj :
- subtree)
+ // example propertiesList
+ // a{sv} 2 "Version" s
+ // "IBM-witherspoon-OP9-v2.0.10-2.22" "Purpose"
+ // s
+ // "xyz.openbmc_project.Software.Version.VersionPurpose.Host"
+ std::string version;
+ std::string swInvPurpose;
+ for (const auto& propertyPair : propertiesList)
{
-
- sdbusplus::message::object_path path(obj.first);
- std::string swId = path.filename();
- if (swId.empty())
+ if (propertyPair.first == "Purpose")
{
- messages::internalError(aResp->res);
- BMCWEB_LOG_ERROR << "Invalid firmware ID";
-
- return;
+ const std::string* purpose =
+ std::get_if<std::string>(&propertyPair.second);
+ if (purpose == nullptr)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+ swInvPurpose = *purpose;
}
-
- bool runningImage = false;
- // Look at Ids from
- // /xyz/openbmc_project/software/functional
- // to determine if this is a running image
- if (std::find(functionalFwIds.begin(),
- functionalFwIds.end(),
- swId) != functionalFwIds.end())
+ if (propertyPair.first == "Version")
{
- runningImage = true;
+ const std::string* versionPtr =
+ std::get_if<std::string>(&propertyPair.second);
+ if (versionPtr == nullptr)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+ version = *versionPtr;
}
+ }
- // Now grab its version info
- crow::connections::systemBus->async_method_call(
- [aResp, swId, runningImage, fwVersionPurpose,
- activeVersionPropName, populateLinkToImages](
- const boost::system::error_code ec3,
- const dbus::utility::DBusPropertiesMap&
- propertiesList) {
- if (ec3)
- {
- BMCWEB_LOG_ERROR << "error_code = " << ec3;
- BMCWEB_LOG_ERROR << "error msg = "
- << ec3.message();
- messages::internalError(aResp->res);
- return;
- }
- // example propertiesList
- // a{sv} 2 "Version" s
- // "IBM-witherspoon-OP9-v2.0.10-2.22" "Purpose"
- // s
- // "xyz.openbmc_project.Software.Version.VersionPurpose.Host"
- std::string version;
- std::string swInvPurpose;
- for (const auto& propertyPair : propertiesList)
- {
- if (propertyPair.first == "Purpose")
- {
- const std::string* purpose =
- std::get_if<std::string>(
- &propertyPair.second);
- if (purpose == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- swInvPurpose = *purpose;
- }
- if (propertyPair.first == "Version")
- {
- const std::string* versionPtr =
- std::get_if<std::string>(
- &propertyPair.second);
- if (versionPtr == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- version = *versionPtr;
- }
- }
-
- BMCWEB_LOG_DEBUG << "Image ID: " << swId;
- BMCWEB_LOG_DEBUG << "Image purpose: "
- << swInvPurpose;
- BMCWEB_LOG_DEBUG << "Running image: "
- << runningImage;
+ BMCWEB_LOG_DEBUG << "Image ID: " << swId;
+ BMCWEB_LOG_DEBUG << "Image purpose: " << swInvPurpose;
+ BMCWEB_LOG_DEBUG << "Running image: " << runningImage;
- if (version.empty())
- {
- messages::internalError(aResp->res);
- return;
- }
- if (swInvPurpose != fwVersionPurpose)
- {
- // Not purpose we're looking for
- return;
- }
+ if (version.empty())
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+ if (swInvPurpose != fwVersionPurpose)
+ {
+ // Not purpose we're looking for
+ return;
+ }
- if (populateLinkToImages)
- {
- nlohmann::json& softwareImageMembers =
- aResp->res.jsonValue["Links"]
- ["SoftwareImages"];
- // Firmware images are at
- // /redfish/v1/UpdateService/FirmwareInventory/<Id>
- // e.g. .../FirmwareInventory/82d3ec86
- softwareImageMembers.push_back(
- {{"@odata.id",
- "/redfish/v1/UpdateService/"
- "FirmwareInventory/" +
- swId}});
- aResp->res.jsonValue
- ["Links"]
- ["SoftwareImages@odata.count"] =
- softwareImageMembers.size();
+ if (populateLinkToImages)
+ {
+ nlohmann::json& softwareImageMembers =
+ aResp->res.jsonValue["Links"]["SoftwareImages"];
+ // Firmware images are at
+ // /redfish/v1/UpdateService/FirmwareInventory/<Id>
+ // e.g. .../FirmwareInventory/82d3ec86
+ softwareImageMembers.push_back(
+ {{"@odata.id", "/redfish/v1/UpdateService/"
+ "FirmwareInventory/" +
+ swId}});
+ aResp->res
+ .jsonValue["Links"]["SoftwareImages@odata.count"] =
+ softwareImageMembers.size();
- if (runningImage)
- {
- // Create the link to the running image
- aResp->res
- .jsonValue["Links"]
- ["ActiveSoftwareImage"] =
- {{"@odata.id",
- "/redfish/v1/UpdateService/"
+ if (runningImage)
+ {
+ // Create the link to the running image
+ aResp->res
+ .jsonValue["Links"]["ActiveSoftwareImage"] = {
+ {"@odata.id", "/redfish/v1/UpdateService/"
"FirmwareInventory/" +
swId}};
- }
- }
- if (!activeVersionPropName.empty() &&
- runningImage)
- {
- aResp->res
- .jsonValue[activeVersionPropName] =
- version;
- }
- },
- obj.second[0].first, obj.first,
- "org.freedesktop.DBus.Properties", "GetAll",
- "xyz.openbmc_project.Software.Version");
+ }
}
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/software", static_cast<int32_t>(0),
- std::array<const char*, 1>{
- "xyz.openbmc_project.Software.Version"});
+ if (!activeVersionPropName.empty() && runningImage)
+ {
+ aResp->res.jsonValue[activeVersionPropName] = version;
+ }
+ },
+ obj.second[0].first, obj.first,
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Software.Version");
+ }
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/software", static_cast<int32_t>(0),
+ std::array<const char*, 1>{"xyz.openbmc_project.Software.Version"});
});
}
@@ -317,33 +301,32 @@ inline void getFwStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
[asyncResp,
swId](const boost::system::error_code errorCode,
const dbus::utility::DBusPropertiesMap& propertiesList) {
- if (errorCode)
- {
- // not all fwtypes are updateable, this is ok
- asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
- return;
- }
- const std::string* swInvActivation = nullptr;
- for (const auto& property : propertiesList)
+ if (errorCode)
+ {
+ // not all fwtypes are updateable, this is ok
+ asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
+ return;
+ }
+ const std::string* swInvActivation = nullptr;
+ for (const auto& property : propertiesList)
+ {
+ if (property.first == "Activation")
{
- if (property.first == "Activation")
- {
- swInvActivation =
- std::get_if<std::string>(&property.second);
- }
+ swInvActivation = std::get_if<std::string>(&property.second);
}
+ }
- if (swInvActivation == nullptr)
- {
- BMCWEB_LOG_DEBUG << "wrong types for property\"Activation\"!";
- messages::internalError(asyncResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "getFwStatus: Activation " << *swInvActivation;
- asyncResp->res.jsonValue["Status"]["State"] =
- getRedfishFWState(*swInvActivation);
- asyncResp->res.jsonValue["Status"]["Health"] =
- getRedfishFWHealth(*swInvActivation);
+ if (swInvActivation == nullptr)
+ {
+ BMCWEB_LOG_DEBUG << "wrong types for property\"Activation\"!";
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ BMCWEB_LOG_DEBUG << "getFwStatus: Activation " << *swInvActivation;
+ asyncResp->res.jsonValue["Status"]["State"] =
+ getRedfishFWState(*swInvActivation);
+ asyncResp->res.jsonValue["Status"]["Health"] =
+ getRedfishFWHealth(*swInvActivation);
},
dbusSvc, "/xyz/openbmc_project/software/" + *swId,
"org.freedesktop.DBus.Properties", "GetAll",
@@ -370,22 +353,22 @@ inline void
"xyz.openbmc_project.Association", "endpoints",
[asyncResp, fwId](const boost::system::error_code ec,
const std::vector<std::string>& objPaths) {
- if (ec)
- {
- BMCWEB_LOG_DEBUG << " error_code = " << ec
- << " error msg = " << ec.message();
- // System can exist with no updateable firmware,
- // so don't throw error here.
- return;
- }
- std::string reqFwObjPath = "/xyz/openbmc_project/software/" + *fwId;
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << " error_code = " << ec
+ << " error msg = " << ec.message();
+ // System can exist with no updateable firmware,
+ // so don't throw error here.
+ return;
+ }
+ std::string reqFwObjPath = "/xyz/openbmc_project/software/" + *fwId;
- if (std::find(objPaths.begin(), objPaths.end(), reqFwObjPath) !=
- objPaths.end())
- {
- asyncResp->res.jsonValue["Updateable"] = true;
- return;
- }
+ if (std::find(objPaths.begin(), objPaths.end(), reqFwObjPath) !=
+ objPaths.end())
+ {
+ asyncResp->res.jsonValue["Updateable"] = true;
+ return;
+ }
});
}
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 317cf11614..de608dfb93 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -451,15 +451,14 @@ inline bool readJsonHelper(nlohmann::json& jsonRequest, crow::Response& res,
break;
}
- result =
- std::visit(
- [&item, &unpackSpec, &res](auto&& val) {
- using ContainedT =
- std::remove_pointer_t<std::decay_t<decltype(val)>>;
- return details::unpackValue<ContainedT>(
- item.value(), unpackSpec.key, res, *val);
- },
- unpackSpec.value) &&
+ result = std::visit(
+ [&item, &unpackSpec, &res](auto&& val) {
+ using ContainedT =
+ std::remove_pointer_t<std::decay_t<decltype(val)>>;
+ return details::unpackValue<ContainedT>(
+ item.value(), unpackSpec.key, res, *val);
+ },
+ unpackSpec.value) &&
result;
unpackSpec.complete = true;
@@ -479,9 +478,9 @@ inline bool readJsonHelper(nlohmann::json& jsonRequest, crow::Response& res,
{
bool isOptional = std::visit(
[](auto&& val) {
- using ContainedType =
- std::remove_pointer_t<std::decay_t<decltype(val)>>;
- return details::IsOptional<ContainedType>::value;
+ using ContainedType =
+ std::remove_pointer_t<std::decay_t<decltype(val)>>;
+ return details::IsOptional<ContainedType>::value;
},
perUnpack.value);
if (isOptional)
@@ -541,8 +540,8 @@ inline std::optional<nlohmann::json>
}
std::erase_if(*object,
[](const std::pair<std::string, nlohmann::json>& item) {
- return item.first.starts_with("@odata.");
- });
+ return item.first.starts_with("@odata.");
+ });
if (object->empty())
{
// If the update request only contains OData annotations, the service