diff options
author | Jayashankar Padath <jayashankar.padath@in.ibm.com> | 2019-07-24 16:46:22 +0530 |
---|---|---|
committer | Adriana Kobylak <anoo@linux.ibm.com> | 2019-08-09 20:45:06 +0000 |
commit | 4d3d91262bcaf1afc2eee54145052106644410be (patch) | |
tree | a38b42c90db405f19b742fd08dc513451d187346 | |
parent | abe862aae4527b4df569f9c664898202a073dabc (diff) | |
download | openpower-pnor-code-mgmt-4d3d91262bcaf1afc2eee54145052106644410be.tar.gz openpower-pnor-code-mgmt-4d3d91262bcaf1afc2eee54145052106644410be.zip |
Code Update: Host ApplyTime support
Get the requested image apply time value provided through the
UpdateService redfish schema. If the apply time value is Immediate, then
host reboot will be triggered just after the new pnor image activation. The
default apply time value is OnReset in which the new image remains at
Active state and user has to manualy reboot the host for applying the new
image.
Tested: Verified that host is getting rebooted while doing a pnor code update
if the apply time value is Immediate. Tested this use case at server power Off
and Running scenarios. OnReset scenario was also tested in which new image
remained at Active state as pnor code update application did not trigger the
host reboot.
Note: This change is applicable to ubi based systems (Witherspoon)
Signed-off-by: Jayashankar Padath <jayashankar.padath@in.ibm.com>
Change-Id: I74f73172626919b225efef43d9baacd64eadbf60
-rw-r--r-- | activation.cpp | 80 | ||||
-rw-r--r-- | activation.hpp | 28 | ||||
-rw-r--r-- | ubi/activation_ubi.cpp | 8 |
3 files changed, 109 insertions, 7 deletions
diff --git a/activation.cpp b/activation.cpp index dd52fb681..48baf6d59 100644 --- a/activation.cpp +++ b/activation.cpp @@ -5,16 +5,15 @@ #include "item_updater.hpp" #include <experimental/filesystem> +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> #include <phosphor-logging/log.hpp> #include <sdbusplus/exception.hpp> +#include <sdbusplus/server.hpp> +#include <xyz/openbmc_project/Common/error.hpp> #ifdef WANT_SIGNATURE_VERIFY #include "image_verify.hpp" - -#include <phosphor-logging/elog-errors.hpp> -#include <phosphor-logging/elog.hpp> -#include <sdbusplus/server.hpp> -#include <xyz/openbmc_project/Common/error.hpp> #endif namespace openpower @@ -29,11 +28,10 @@ namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; using namespace phosphor::logging; using sdbusplus::exception::SdBusError; - -#ifdef WANT_SIGNATURE_VERIFY using InternalFailure = sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; +#ifdef WANT_SIGNATURE_VERIFY // Field mode path and interface. constexpr auto FIELDMODE_PATH("/xyz/openbmc_project/software"); constexpr auto FIELDMODE_INTERFACE("xyz.openbmc_project.Control.FieldMode"); @@ -166,6 +164,74 @@ void Activation::deleteImageManagerObject() } } +bool Activation::checkApplyTimeImmediate() +{ + auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf); + if (service.empty()) + { + log<level::INFO>("Error getting the service name for Host image " + "ApplyTime. The Host needs to be manually rebooted to " + "complete the image activation if needed " + "immediately."); + } + else + { + + auto method = bus.new_method_call(service.c_str(), applyTimeObjPath, + dbusPropIntf, "Get"); + method.append(applyTimeIntf, applyTimeProp); + + try + { + auto reply = bus.call(method); + + sdbusplus::message::variant<std::string> result; + reply.read(result); + auto applyTime = + sdbusplus::message::variant_ns::get<std::string>(result); + if (applyTime == applyTimeImmediate) + { + return true; + } + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in getting ApplyTime", + entry("ERROR=%s", e.what())); + } + } + return false; +} + +void Activation::rebootHost() +{ + auto service = utils::getService(bus, hostStateObjPath, hostStateIntf); + if (service.empty()) + { + log<level::ALERT>("Error in getting the service name to reboot the " + "Host. The Host needs to be manually rebooted to " + "complete the image activation."); + } + + auto method = bus.new_method_call(service.c_str(), hostStateObjPath, + dbusPropIntf, "Set"); + sdbusplus::message::variant<std::string> hostReboot = hostStateRebootVal; + method.append(hostStateIntf, hostStateRebootProp, hostReboot); + + try + { + auto reply = bus.call(method); + } + catch (const SdBusError& e) + { + log<level::ALERT>("Error in trying to reboot the Host. " + "The Host needs to be manually rebooted to complete " + "the image activation.", + entry("ERROR=%s", e.what())); + report<InternalFailure>(); + } +} + uint8_t RedundancyPriority::priority(uint8_t value) { parent.parent.freePriority(value, parent.versionId); diff --git a/activation.hpp b/activation.hpp index a9fb34712..e3cff64bf 100644 --- a/activation.hpp +++ b/activation.hpp @@ -3,6 +3,7 @@ #include "config.h" #include "org/openbmc/Associations/server.hpp" +#include "utils.hpp" #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp" #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp" #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp" @@ -32,6 +33,19 @@ using RedundancyPriorityInherit = sdbusplus::server::object::object< using ActivationProgressInherit = sdbusplus::server::object::object< sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; +constexpr auto applyTimeImmediate = + "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate"; +constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime"; +constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties"; +constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time"; +constexpr auto applyTimeProp = "RequestedApplyTime"; + +constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; +constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; +constexpr auto hostStateRebootProp = "RequestedHostTransition"; +constexpr auto hostStateRebootVal = + "xyz.openbmc_project.State.Host.Transition.Reboot"; + namespace sdbusRule = sdbusplus::bus::match::rules; class ItemUpdater; @@ -268,6 +282,20 @@ class Activation : public ActivationInherit */ using ActivationInherit::activation; + /** + * @brief Determine the configured image apply time value + * + * @return true if the image apply time value is immediate + **/ + bool checkApplyTimeImmediate(); + + /** + * @brief Reboot the Host. Called when ApplyTime is immediate. + * + * @return none + **/ + void rebootHost(); + protected: /** @brief Check if systemd state change is relevant to this object * diff --git a/ubi/activation_ubi.cpp b/ubi/activation_ubi.cpp index 5c57c4b56..4575a610c 100644 --- a/ubi/activation_ubi.cpp +++ b/ubi/activation_ubi.cpp @@ -4,6 +4,7 @@ #include "serialize.hpp" #include <experimental/filesystem> +#include <phosphor-logging/log.hpp> namespace openpower { @@ -13,6 +14,7 @@ namespace updater { namespace fs = std::experimental::filesystem; namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server; +using namespace phosphor::logging; uint8_t RedundancyPriorityUbi::priority(uint8_t value) { @@ -65,6 +67,12 @@ auto ActivationUbi::activation(Activations value) -> Activations (fs::is_directory(PNOR_RO_PREFIX + versionId))) { finishActivation(); + if (Activation::checkApplyTimeImmediate()) + { + log<level::INFO>("Image Active. ApplyTime is immediate, " + "rebooting Host."); + Activation::rebootHost(); + } return softwareServer::Activation::activation( softwareServer::Activation::Activations::Active); } |