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