Redfish: Fixed incorrect firmware ID strings
Fixes: https://github.com/openbmc/bmcweb/issues/4
It was probably caused by incorrect merging, and that messed up the
logic of the code. Fixed it so the Firmware Collection and Firmware
response reflects correct information.
Signed-off-by: Jennifer Lee <jennifer1.lee@intel.com>
Change-Id: I749a0af804cfa3e5cce89d1b8e11ec09d00d818d
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index df8473f..c2f76f9 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -235,6 +235,20 @@
std::pair<std::string, std::vector<std::string>>>
&connections = obj.second;
+ // if can't parse fw id then return
+ std::size_t idPos = obj.first.rfind("/");
+ if (idPos == std::string::npos ||
+ idPos + 1 == obj.first.size())
+ {
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ asyncResp->res.jsonValue = messages::internalError();
+ BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
+ return;
+ }
+
+ std::string swId = obj.first.substr(idPos + 1);
+
for (auto &conn : connections)
{
const std::string &connectionName = conn.first;
@@ -243,9 +257,9 @@
BMCWEB_LOG_DEBUG << "obj.first = " << obj.first;
crow::connections::systemBus->async_method_call(
- [asyncResp](
- const boost::system::error_code error_code,
- const VariantType &activation) {
+ [asyncResp,
+ swId](const boost::system::error_code error_code,
+ const VariantType &activation) {
BMCWEB_LOG_DEBUG
<< "safe returned in lambda function";
if (error_code)
@@ -256,31 +270,33 @@
return;
}
- const std::string *swInvPurpose =
+ const std::string *swActivationStatus =
mapbox::getPtr<const std::string>(
activation);
- if (swInvPurpose == nullptr)
+ if (swActivationStatus == nullptr)
{
asyncResp->res.result(
boost::beast::http::status::
internal_server_error);
return;
}
- std::size_t last_pos = swInvPurpose->rfind(".");
- if (last_pos == std::string::npos)
+ if (swActivationStatus != nullptr &&
+ *swActivationStatus !=
+ "xyz.openbmc_project.Software."
+ "Activation."
+ "Activations.Active")
{
- asyncResp->res.result(
- boost::beast::http::status::
- internal_server_error);
+ // The activation status of this software is
+ // not currently active, so does not need to
+ // be listed in the response
return;
}
nlohmann::json &members =
asyncResp->res.jsonValue["Members"];
members.push_back(
- {{"@odata.id",
- "/redfish/v1/UpdateService/"
- "FirmwareInventory/" +
- swInvPurpose->substr(last_pos + 1)}});
+ {{"@odata.id", "/redfish/v1/UpdateService/"
+ "FirmwareInventory/" +
+ swId}});
asyncResp->res
.jsonValue["Members@odata.count"] =
members.size();
@@ -374,7 +390,7 @@
continue;
}
- if (obj.second.size() <= 1)
+ if (obj.second.size() < 1)
{
continue;
}
@@ -417,35 +433,33 @@
BMCWEB_LOG_DEBUG << "swInvPurpose = "
<< *swInvPurpose;
- if (boost::ends_with(*swInvPurpose, "." + *swId))
+ it = propertiesList.find("Version");
+ if (it == propertiesList.end())
{
- it = propertiesList.find("Version");
- if (it == propertiesList.end())
- {
- BMCWEB_LOG_DEBUG
- << "Can't find property \"Version\"!";
- asyncResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
-
- const std::string *version =
- mapbox::getPtr<const std::string>(
- it->second);
-
- if (version != nullptr)
- {
- BMCWEB_LOG_DEBUG
- << "Can't find property \"Version\"!";
- asyncResp->res.result(
- boost::beast::http::status::
- internal_server_error);
- return;
- }
- asyncResp->res.jsonValue["Version"] = *version;
- asyncResp->res.jsonValue["Id"] = *swId;
+ BMCWEB_LOG_DEBUG
+ << "Can't find property \"Version\"!";
+ asyncResp->res.result(
+ boost::beast::http::status::
+ internal_server_error);
+ return;
}
+
+ BMCWEB_LOG_DEBUG << "Version found!";
+
+ const std::string *version =
+ mapbox::getPtr<const std::string>(it->second);
+
+ if (version == nullptr)
+ {
+ BMCWEB_LOG_DEBUG
+ << "Can't find property \"Version\"!";
+ asyncResp->res.result(
+ boost::beast::http::status::
+ internal_server_error);
+ return;
+ }
+ asyncResp->res.jsonValue["Version"] = *version;
+ asyncResp->res.jsonValue["Id"] = *swId;
},
obj.second[0].first, obj.first,
"org.freedesktop.DBus.Properties", "GetAll",