diff options
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/lib/task.hpp | 52 | ||||
-rw-r--r-- | redfish-core/lib/update_service.hpp | 123 |
2 files changed, 116 insertions, 59 deletions
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index cbae67b109..a746239a35 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -168,28 +168,8 @@ struct TaskData : std::enable_shared_from_this<TaskData> std::chrono::system_clock::now()); } - void startTimer(const std::chrono::seconds &timeout) + void extendTimer(const std::chrono::seconds &timeout) { - match = std::make_unique<sdbusplus::bus::match::match>( - static_cast<sdbusplus::bus::bus &>(*crow::connections::systemBus), - matchStr, - [self = shared_from_this()](sdbusplus::message::message &message) { - boost::system::error_code ec; - - // callback to return True if callback is done, callback needs - // to update status itself if needed - if (self->callback(ec, message, self) == task::completed) - { - self->timer.cancel(); - self->finishTask(); - - // reset the match after the callback was successful - boost::asio::post( - crow::connections::systemBus->get_io_context(), - [self] { self->match.reset(); }); - return; - } - }); timer.expires_after(timeout); timer.async_wait( [self = shared_from_this()](boost::system::error_code ec) { @@ -211,6 +191,36 @@ struct TaskData : std::enable_shared_from_this<TaskData> messages::taskAborted(std::to_string(self->index))); self->callback(ec, msg, self); }); + } + + void startTimer(const std::chrono::seconds &timeout) + { + if (match) + { + return; + } + match = std::make_unique<sdbusplus::bus::match::match>( + static_cast<sdbusplus::bus::bus &>(*crow::connections::systemBus), + matchStr, + [self = shared_from_this()](sdbusplus::message::message &message) { + boost::system::error_code ec; + + // callback to return True if callback is done, callback needs + // to update status itself if needed + if (self->callback(ec, message, self) == task::completed) + { + self->timer.cancel(); + self->finishTask(); + + // reset the match after the callback was successful + boost::asio::post( + crow::connections::systemBus->get_io_context(), + [self] { self->match.reset(); }); + return; + } + }); + + extendTimer(timeout); messages.emplace_back(messages::taskStarted(std::to_string(index))); } diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index 60d6673fd6..9dacbcd922 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -131,51 +131,99 @@ static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp, std::string iface; boost::container::flat_map< - std::string, std::variant<std::string>> + std::string, + std::variant<std::string, uint8_t>> 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; - } std::string index = std::to_string(taskData->index); + msg.read(iface, values); - if (boost::ends_with(*state, "Invalid") || - boost::ends_with(*state, "Failed")) - { - taskData->state = "Exception"; - taskData->status = "Warning"; - taskData->messages.emplace_back( - messages::taskAborted(index)); - return task::completed; - } - - if (boost::ends_with(*state, "Staged")) + if (iface == "xyz.openbmc_project.Software." + "Activation") { - taskData->state = "Pending"; - return !task::completed; + 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::taskAborted(index)); + return task::completed; + } + + if (boost::ends_with(*state, "Staged")) + { + taskData->state = "Stopping"; + taskData->messages.emplace_back( + messages::taskPaused(index)); + + // its staged, set a long timer to + // allow them time to complete the + // update (probably cycle the + // system) if this expires then + // task will be cancelled + taskData->extendTimer( + std::chrono::hours(5)); + return !task::completed; + } + + if (boost::ends_with(*state, "Active")) + { + taskData->messages.emplace_back( + messages::taskCompletedOK( + index)); + taskData->state = "Completed"; + return task::completed; + } } - - if (boost::ends_with(*state, "Active")) + else if (iface == + "xyz.openbmc_project.Software." + "ActivationProgress") { + auto findProgress = + values.find("Progress"); + if (findProgress == values.end()) + { + return !task::completed; + } + uint8_t *progress = + std::get_if<uint8_t>( + &(findProgress->second)); + + if (progress == nullptr) + { + taskData->messages.emplace_back( + messages::internalError()); + return task::completed; + } taskData->messages.emplace_back( - messages::taskCompletedOK(index)); - taskData->state = "Completed"; - return task::completed; + messages::taskProgressChanged( + index, static_cast<size_t>( + *progress))); + + // if we're getting status updates it's + // still alive, update timer + taskData->extendTimer( + std::chrono::minutes(5)); } // as firmware update often results in a @@ -186,8 +234,7 @@ static void softwareInterfaceAdded(std::shared_ptr<AsyncResp> asyncResp, }, "type='signal',interface='org.freedesktop.DBus." "Properties'," - "member='PropertiesChanged',arg0='xyz.openbmc_" - "project.Software.Activation',path='" + + "member='PropertiesChanged',path='" + objPath.str + "'"); task->startTimer(std::chrono::minutes(5)); task->populateResp(asyncResp->res); |