summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyung Bae <myungbae@us.ibm.com>2023-08-16 22:18:19 +0300
committerEd Tanous <ed@tanous.net>2023-08-17 18:58:52 +0300
commit8549b951ff911b7a491f08d3e23c61ceeada6f8f (patch)
tree4f2b9bb903fd27d7c3d2589fff390abaed16b3d8
parent2deee1b3cf4c520e966af97ebfe14b71a89afa66 (diff)
downloadbmcweb-8549b951ff911b7a491f08d3e23c61ceeada6f8f.tar.xz
Refactor Update monitorForSoftwareAvailable function
The scope of this code refactor is to limit the function of monitorForSoftwareAvailable() for the coming future code modifications in the area. Tested: - Compiles successfully. - Code update works as before (for success and failure cases) Change-Id: I90fd41caa6b88c97c2a0c47fcf4553d48905b886 Signed-off-by: Myung Bae <myungbae@us.ibm.com>
-rw-r--r--redfish-core/lib/update_service.hpp194
1 files changed, 99 insertions, 95 deletions
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index b538806ec8..da3762567d 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -264,6 +264,102 @@ static void
}
}
+inline void afterAvailbleTimerAsyncWait(
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const boost::system::error_code& ec)
+{
+ cleanUp();
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ // expected, we were canceled before the timer completed.
+ return;
+ }
+ BMCWEB_LOG_ERROR("Timed out waiting for firmware object being created");
+ BMCWEB_LOG_ERROR("FW image may has already been uploaded to server");
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Async_wait failed{}", ec);
+ return;
+ }
+ if (asyncResp)
+ {
+ redfish::messages::internalError(asyncResp->res);
+ }
+}
+
+inline void
+ handleUpdateErrorType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& url, const std::string& type)
+{
+ if (type == "xyz.openbmc_project.Software.Image.Error.UnTarFailure")
+ {
+ redfish::messages::invalidUpload(asyncResp->res, url,
+ "Invalid archive");
+ }
+ else if (type ==
+ "xyz.openbmc_project.Software.Image.Error.ManifestFileFailure")
+ {
+ redfish::messages::invalidUpload(asyncResp->res, url,
+ "Invalid manifest");
+ }
+ else if (type == "xyz.openbmc_project.Software.Image.Error.ImageFailure")
+ {
+ redfish::messages::invalidUpload(asyncResp->res, url,
+ "Invalid image format");
+ }
+ else if (type == "xyz.openbmc_project.Software.Version.Error.AlreadyExists")
+ {
+ redfish::messages::invalidUpload(asyncResp->res, url,
+ "Image version already exists");
+
+ redfish::messages::resourceAlreadyExists(
+ asyncResp->res, "UpdateService", "Version", "uploaded version");
+ }
+ else if (type == "xyz.openbmc_project.Software.Image.Error.BusyFailure")
+ {
+ redfish::messages::resourceExhaustion(asyncResp->res, url);
+ }
+ else
+ {
+ BMCWEB_LOG_ERROR("Unknown Software Image Error type={}", type);
+ redfish::messages::internalError(asyncResp->res);
+ }
+}
+
+inline void
+ afterUpdateErrorMatcher(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& url, sdbusplus::message_t& m)
+{
+ dbus::utility::DBusInteracesMap interfacesProperties;
+ sdbusplus::message::object_path objPath;
+ m.read(objPath, interfacesProperties);
+ BMCWEB_LOG_DEBUG("obj path = {}", objPath.str);
+ for (const std::pair<std::string, dbus::utility::DBusPropertiesMap>&
+ interface : interfacesProperties)
+ {
+ if (interface.first == "xyz.openbmc_project.Logging.Entry")
+ {
+ for (const std::pair<std::string, dbus::utility::DbusVariantType>&
+ value : interface.second)
+ {
+ if (value.first != "Message")
+ {
+ continue;
+ }
+ const std::string* type =
+ std::get_if<std::string>(&value.second);
+ if (type == nullptr)
+ {
+ // if this was our message, timeout will cover it
+ return;
+ }
+ fwAvailableTimer = nullptr;
+ handleUpdateErrorType(asyncResp, url, *type);
+ }
+ }
+ }
+}
+
// Note that asyncResp can be either a valid pointer or nullptr. If nullptr
// then no asyncResp updates will occur
static void monitorForSoftwareAvailable(
@@ -287,25 +383,8 @@ static void monitorForSoftwareAvailable(
fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds));
fwAvailableTimer->async_wait(
- [asyncResp](const boost::system::error_code& ec) {
- cleanUp();
- if (ec == boost::asio::error::operation_aborted)
- {
- // expected, we were canceled before the timer completed.
- return;
- }
- BMCWEB_LOG_ERROR("Timed out waiting for firmware object being created");
- BMCWEB_LOG_ERROR("FW image may has already been uploaded to server");
- if (ec)
- {
- BMCWEB_LOG_ERROR("Async_wait failed{}", ec);
- return;
- }
- if (asyncResp)
- {
- redfish::messages::internalError(asyncResp->res);
- }
- });
+ std::bind_front(afterAvailbleTimerAsyncWait, asyncResp));
+
task::Payload payload(req);
auto callback = [asyncResp, payload](sdbusplus::message_t& m) mutable {
BMCWEB_LOG_DEBUG("Match fired");
@@ -325,82 +404,7 @@ static void monitorForSoftwareAvailable(
"interface='org.freedesktop.DBus.ObjectManager',type='signal',"
"member='InterfacesAdded',"
"path='/xyz/openbmc_project/logging'",
- [asyncResp, url](sdbusplus::message_t& m) {
- std::vector<std::pair<std::string, dbus::utility::DBusPropertiesMap>>
- interfacesProperties;
- sdbusplus::message::object_path objPath;
- m.read(objPath, interfacesProperties);
- BMCWEB_LOG_DEBUG("obj path = {}", objPath.str);
- for (const std::pair<std::string, dbus::utility::DBusPropertiesMap>&
- interface : interfacesProperties)
- {
- if (interface.first == "xyz.openbmc_project.Logging.Entry")
- {
- for (const std::pair<std::string,
- dbus::utility::DbusVariantType>& value :
- interface.second)
- {
- if (value.first != "Message")
- {
- continue;
- }
- const std::string* type =
- std::get_if<std::string>(&value.second);
- if (type == nullptr)
- {
- // if this was our message, timeout will cover it
- return;
- }
- fwAvailableTimer = nullptr;
- if (*type ==
- "xyz.openbmc_project.Software.Image.Error.UnTarFailure")
- {
- redfish::messages::invalidUpload(asyncResp->res, url,
- "Invalid archive");
- }
- else if (*type ==
- "xyz.openbmc_project.Software.Image.Error."
- "ManifestFileFailure")
- {
- redfish::messages::invalidUpload(asyncResp->res, url,
- "Invalid manifest");
- }
- else if (
- *type ==
- "xyz.openbmc_project.Software.Image.Error.ImageFailure")
- {
- redfish::messages::invalidUpload(
- asyncResp->res, url, "Invalid image format");
- }
- else if (
- *type ==
- "xyz.openbmc_project.Software.Version.Error.AlreadyExists")
- {
- redfish::messages::invalidUpload(
- asyncResp->res, url,
- "Image version already exists");
-
- redfish::messages::resourceAlreadyExists(
- asyncResp->res, "UpdateService", "Version",
- "uploaded version");
- }
- else if (
- *type ==
- "xyz.openbmc_project.Software.Image.Error.BusyFailure")
- {
- redfish::messages::resourceExhaustion(asyncResp->res,
- url);
- }
- else
- {
- BMCWEB_LOG_ERROR("Unknown Software Image Error type={}",
- *type);
- redfish::messages::internalError(asyncResp->res);
- }
- }
- }
- }
- });
+ std::bind_front(afterUpdateErrorMatcher, asyncResp, url));
}
/**