Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 5 | #include "association_interface.hpp" |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 6 | #include "types.hpp" |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 7 | #include "version.hpp" |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 8 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 9 | #include <queue> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 10 | #include <sdbusplus/server.hpp> |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 12 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 13 | #include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp> |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 14 | #include <xyz/openbmc_project/Software/ActivationProgress/server.hpp> |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 15 | #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp> |
| 16 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 17 | class TestActivation; |
| 18 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 19 | namespace phosphor |
| 20 | { |
| 21 | namespace software |
| 22 | { |
| 23 | namespace updater |
| 24 | { |
| 25 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 26 | namespace sdbusRule = sdbusplus::bus::match::rules; |
| 27 | |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 28 | using ActivationBlocksTransitionInherit = sdbusplus::server::object::object< |
| 29 | sdbusplus::xyz::openbmc_project::Software::server:: |
| 30 | ActivationBlocksTransition>; |
| 31 | |
| 32 | /** @class ActivationBlocksTransition |
| 33 | * @brief OpenBMC ActivationBlocksTransition implementation. |
| 34 | * @details A concrete implementation for |
| 35 | * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API. |
| 36 | */ |
| 37 | class ActivationBlocksTransition : public ActivationBlocksTransitionInherit |
| 38 | { |
| 39 | public: |
| 40 | /** @brief Constructs ActivationBlocksTransition. |
| 41 | * |
| 42 | * @param[in] bus - The Dbus bus object |
| 43 | * @param[in] path - The Dbus object path |
| 44 | */ |
| 45 | ActivationBlocksTransition(sdbusplus::bus::bus& bus, |
| 46 | const std::string& path) : |
| 47 | ActivationBlocksTransitionInherit(bus, path.c_str(), true), |
| 48 | bus(bus), path(path) |
| 49 | { |
| 50 | std::vector<std::string> interfaces({interface}); |
| 51 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 52 | } |
| 53 | |
| 54 | ~ActivationBlocksTransition() |
| 55 | { |
| 56 | std::vector<std::string> interfaces({interface}); |
| 57 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 62 | static constexpr auto interface = |
| 63 | "xyz.openbmc_project.Software.ActivationBlocksTransition"; |
| 64 | sdbusplus::bus::bus& bus; |
| 65 | std::string path; |
| 66 | }; |
| 67 | |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 68 | using ActivationProgressInherit = sdbusplus::server::object::object< |
| 69 | sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>; |
| 70 | |
| 71 | class ActivationProgress : public ActivationProgressInherit |
| 72 | { |
| 73 | public: |
| 74 | /** @brief Constructs ActivationProgress. |
| 75 | * |
| 76 | * @param[in] bus - The Dbus bus object |
| 77 | * @param[in] path - The Dbus object path |
| 78 | */ |
| 79 | ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) : |
| 80 | ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path) |
| 81 | { |
| 82 | progress(0); |
| 83 | std::vector<std::string> interfaces({interface}); |
| 84 | bus.emit_interfaces_added(path.c_str(), interfaces); |
| 85 | } |
| 86 | |
| 87 | ~ActivationProgress() |
| 88 | { |
| 89 | std::vector<std::string> interfaces({interface}); |
| 90 | bus.emit_interfaces_removed(path.c_str(), interfaces); |
| 91 | } |
| 92 | |
| 93 | private: |
| 94 | // TODO Remove once openbmc/openbmc#1975 is resolved |
| 95 | static constexpr auto interface = |
| 96 | "xyz.openbmc_project.Software.ActivationProgress"; |
| 97 | sdbusplus::bus::bus& bus; |
| 98 | std::string path; |
| 99 | }; |
| 100 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 101 | using ActivationInherit = sdbusplus::server::object::object< |
| 102 | sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion, |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 103 | sdbusplus::xyz::openbmc_project::Software::server::Activation, |
| 104 | sdbusplus::xyz::openbmc_project::Association::server::Definitions>; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 105 | |
| 106 | /** @class Activation |
| 107 | * @brief OpenBMC activation software management implementation. |
| 108 | * @details A concrete implementation for |
| 109 | * xyz.openbmc_project.Software.Activation DBus API. |
| 110 | */ |
| 111 | class Activation : public ActivationInherit |
| 112 | { |
| 113 | public: |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 114 | friend class ::TestActivation; |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 115 | using Status = Activations; |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 116 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 117 | /** @brief Constructs Activation Software Manager |
| 118 | * |
| 119 | * @param[in] bus - The Dbus bus object |
| 120 | * @param[in] path - The Dbus object path |
| 121 | * @param[in] versionId - The software version id |
| 122 | * @param[in] extVersion - The extended version |
| 123 | * @param[in] activationStatus - The status of Activation |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 124 | * @param[in] assocs - Association objects |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 125 | */ |
| 126 | Activation(sdbusplus::bus::bus& bus, const std::string& path, |
| 127 | const std::string& versionId, const std::string& extVersion, |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 128 | Status activationStatus, const AssociationList& assocs, |
| 129 | AssociationInterface* associationInterface) : |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 130 | ActivationInherit(bus, path.c_str(), true), |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame^] | 131 | bus(bus), path(path), versionId(versionId), |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 132 | systemdSignals( |
| 133 | bus, |
| 134 | sdbusRule::type::signal() + sdbusRule::member("JobRemoved") + |
| 135 | sdbusRule::path("/org/freedesktop/systemd1") + |
| 136 | sdbusRule::interface("org.freedesktop.systemd1.Manager"), |
| 137 | std::bind(&Activation::unitStateChange, this, |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 138 | std::placeholders::_1)), |
| 139 | associationInterface(associationInterface) |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 140 | { |
| 141 | // Set Properties. |
| 142 | extendedVersion(extVersion); |
| 143 | activation(activationStatus); |
Lei YU | 9102944 | 2019-08-01 15:57:31 +0800 | [diff] [blame] | 144 | associations(assocs); |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 145 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 146 | auto info = Version::getExtVersionInfo(extVersion); |
| 147 | manufacturer = info["manufacturer"]; |
| 148 | model = info["model"]; |
| 149 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 150 | // Emit deferred signal. |
| 151 | emit_object_added(); |
| 152 | } |
| 153 | |
| 154 | /** @brief Overloaded Activation property setter function |
| 155 | * |
| 156 | * @param[in] value - One of Activation::Activations |
| 157 | * |
| 158 | * @return Success or exception thrown |
| 159 | */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 160 | Status activation(Status value) override; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 161 | |
| 162 | /** @brief Activation */ |
| 163 | using ActivationInherit::activation; |
| 164 | |
| 165 | /** @brief Overloaded requestedActivation property setter function |
| 166 | * |
| 167 | * @param[in] value - One of Activation::RequestedActivations |
| 168 | * |
| 169 | * @return Success or exception thrown |
| 170 | */ |
| 171 | RequestedActivations |
| 172 | requestedActivation(RequestedActivations value) override; |
| 173 | |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame^] | 174 | /** @brief Get the version ID */ |
| 175 | const std::string& getVersionId() const |
| 176 | { |
| 177 | return versionId; |
| 178 | } |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 179 | |
| 180 | private: |
| 181 | /** @brief Check if systemd state change is relevant to this object |
| 182 | * |
| 183 | * Instance specific interface to handle the detected systemd state |
| 184 | * change |
| 185 | * |
| 186 | * @param[in] msg - Data associated with subscribed signal |
| 187 | * |
| 188 | */ |
| 189 | void unitStateChange(sdbusplus::message::message& msg); |
| 190 | |
Lei YU | d0bbfa9 | 2019-09-11 16:10:54 +0800 | [diff] [blame] | 191 | /** |
| 192 | * @brief Delete the version from Image Manager and the |
| 193 | * untar image from image upload dir. |
| 194 | */ |
| 195 | void deleteImageManagerObject(); |
| 196 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 197 | /** @brief Invoke the update service for the PSU |
| 198 | * |
| 199 | * @param[in] psuInventoryPath - The PSU inventory to be updated. |
| 200 | * |
| 201 | * @return true if the update starts, and false if it fails. |
| 202 | */ |
| 203 | bool doUpdate(const std::string& psuInventoryPath); |
| 204 | |
| 205 | /** @brief Do PSU update one-by-one |
| 206 | * |
| 207 | * @return true if the update starts, and false if it fails. |
| 208 | */ |
| 209 | bool doUpdate(); |
| 210 | |
| 211 | /** @brief Handle an update done event */ |
| 212 | void onUpdateDone(); |
| 213 | |
| 214 | /** @brief Handle an update failure event */ |
| 215 | void onUpdateFailed(); |
| 216 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 217 | /** @brief Start PSU update */ |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 218 | Status startActivation(); |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 219 | |
| 220 | /** @brief Finish PSU update */ |
| 221 | void finishActivation(); |
| 222 | |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 223 | /** @brief Check if the PSU is comaptible with this software*/ |
| 224 | bool isCompatible(const std::string& psuInventoryPath); |
| 225 | |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 226 | /** @brief Persistent sdbusplus DBus bus connection */ |
| 227 | sdbusplus::bus::bus& bus; |
| 228 | |
| 229 | /** @brief Persistent DBus object path */ |
| 230 | std::string path; |
| 231 | |
Lei YU | a5c47bb | 2019-09-29 11:28:53 +0800 | [diff] [blame^] | 232 | /** @brief Version id */ |
| 233 | std::string versionId; |
| 234 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 235 | /** @brief Used to subscribe to dbus systemd signals */ |
| 236 | sdbusplus::bus::match_t systemdSignals; |
| 237 | |
Lei YU | ff83c2a | 2019-09-12 13:55:18 +0800 | [diff] [blame] | 238 | /** @brief The queue of psu objects to be updated */ |
| 239 | std::queue<std::string> psuQueue; |
| 240 | |
| 241 | /** @brief The progress step for each PSU update is done */ |
| 242 | uint32_t progressStep; |
| 243 | |
Lei YU | 12c9f4c | 2019-09-11 15:08:15 +0800 | [diff] [blame] | 244 | /** @brief The PSU update systemd unit */ |
| 245 | std::string psuUpdateUnit; |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 246 | |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 247 | /** @brief The PSU Inventory path of the current updating PSU */ |
| 248 | std::string currentUpdatingPsu; |
| 249 | |
Lei YU | 81c6772 | 2019-09-11 16:47:29 +0800 | [diff] [blame] | 250 | /** @brief Persistent ActivationBlocksTransition dbus object */ |
| 251 | std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition; |
Lei YU | 90c8a8b | 2019-09-11 17:20:03 +0800 | [diff] [blame] | 252 | |
| 253 | /** @brief Persistent ActivationProgress dbus object */ |
| 254 | std::unique_ptr<ActivationProgress> activationProgress; |
Lei YU | 7f2a215 | 2019-09-16 16:50:18 +0800 | [diff] [blame] | 255 | |
| 256 | /** @brief The AssociationInterface pointer */ |
| 257 | AssociationInterface* associationInterface; |
Lei YU | 9edb733 | 2019-09-19 14:46:19 +0800 | [diff] [blame] | 258 | |
| 259 | /** @brief The PSU manufacturer of the software */ |
| 260 | std::string manufacturer; |
| 261 | |
| 262 | /** @brief The PSU model of the software */ |
| 263 | std::string model; |
Lei YU | 01539e7 | 2019-07-31 10:57:38 +0800 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | } // namespace updater |
| 267 | } // namespace software |
| 268 | } // namespace phosphor |