diff options
author | James Feist <james.feist@linux.intel.com> | 2020-03-11 02:16:52 +0300 |
---|---|---|
committer | James Feist <james.feist@linux.intel.com> | 2020-03-12 19:03:48 +0300 |
commit | 32898cea816973f50f1db1f415c73bb4791d1ef0 (patch) | |
tree | e14b573d93c4be50d68a3f3102d3edabd8584b55 /redfish-core | |
parent | 8f52ee52148edea2fbd8d538e6fc93985fb04d36 (diff) | |
download | bmcweb-32898cea816973f50f1db1f415c73bb4791d1ef0.tar.xz |
task: add fwupdate support
This adds firmware update task service support. It adds
a match and updates the task value when the interface
changes.
Tested: On successful fwupdate task was created and
updated correctly. On failed fwupdate the status went
to failed.
Change-Id: Id12cc5d5270e8e45498b665e78601c5c30775323
Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/lib/log_services.hpp | 3 | ||||
-rw-r--r-- | redfish-core/lib/task.hpp | 12 | ||||
-rw-r--r-- | redfish-core/lib/update_service.hpp | 72 |
3 files changed, 76 insertions, 11 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 09602fb963..ca9604b63d 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -1878,8 +1878,9 @@ class OnDemandCrashdump : public Node if (!err) { taskData->messages.emplace_back(messages::success()); + taskData->status = "Completed"; } - return true; + return task::completed; }, "type='signal',interface='org.freedesktop.DBus.Properties'," "member='PropertiesChanged',arg0namespace='com.intel." diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index 12425c1c08..e95eb2e4b7 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -30,6 +30,8 @@ constexpr size_t maxTaskCount = 100; // arbitrary limit static std::deque<std::shared_ptr<struct TaskData>> tasks; +constexpr bool completed = true; + struct TaskData : std::enable_shared_from_this<TaskData> { private: @@ -120,13 +122,9 @@ struct TaskData : std::enable_shared_from_this<TaskData> [self = shared_from_this()](sdbusplus::message::message &message) { boost::system::error_code ec; - // set to complete before callback incase user wants a different - // status - self->state = "Completed"; - // callback to return True if callback is done, callback needs // to update status itself if needed - if (self->callback(ec, message, self)) + if (self->callback(ec, message, self) == task::completed) { self->timer.cancel(); self->finishTask(); @@ -136,10 +134,6 @@ struct TaskData : std::enable_shared_from_this<TaskData> [self] { self->match.reset(); }); return; } - - // set back to running if callback returns false to keep - // callback alive - self->state = "Running"; }); timer.expires_after(timeout); timer.async_wait( diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index a47aca2c10..3ca7721cbd 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -117,7 +117,77 @@ static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp, activateImage(objPath.str, objInfo[0].first); if (asyncResp) { - redfish::messages::success(asyncResp->res); + std::shared_ptr<task::TaskData> task = + task::TaskData::createTask( + [](boost::system::error_code ec, + sdbusplus::message::message &msg, + const std::shared_ptr<task::TaskData> + &taskData) { + if (ec) + { + return task::completed; + } + + std::string iface; + boost::container::flat_map< + std::string, std::variant<std::string>> + values; + msg.read(iface, values); + auto findActivation = + values.find("Activation"); + if (findActivation == values.end()) + { + return !task::completed; + } + std::string *state = + std::get_if<std::string>( + &(findActivation->second)); + + if (state == nullptr) + { + taskData->messages.emplace_back( + messages::internalError()); + return task::completed; + } + + if (boost::ends_with(*state, "Invalid") || + boost::ends_with(*state, "Failed")) + { + taskData->state = "Exception"; + taskData->status = "Warning"; + taskData->messages.emplace_back( + messages::invalidObject( + "/redfish/v1/UpdateService/")); + return task::completed; + } + + if (boost::ends_with(*state, "Staged")) + { + taskData->state = "Pending"; + return !task::completed; + } + + if (boost::ends_with(*state, "Active")) + { + taskData->messages.emplace_back( + messages::success()); + taskData->state = "Completed"; + return task::completed; + } + + // as firmware update often results in a + // reboot, the task may never "complete" + // unless it is an error + + return !task::completed; + }, + "type='signal',interface='org.freedesktop.DBus." + "Properties'," + "member='PropertiesChanged',arg0='xyz.openbmc_" + "project.Software.Activation',path='" + + objPath.str + "'"); + task->startTimer(std::chrono::minutes(5)); + task->populateResp(asyncResp->res); } fwUpdateInProgress = false; }, |