blob: 669686e35491a5bd269cb33b3edde65547839f12 [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
Lei YU7f2a2152019-09-16 16:50:18 +08005#include "association_interface.hpp"
Lei YU91029442019-08-01 15:57:31 +08006#include "types.hpp"
Lei YU9edb7332019-09-19 14:46:19 +08007#include "version.hpp"
Lei YU91029442019-08-01 15:57:31 +08008
Lei YUff83c2a2019-09-12 13:55:18 +08009#include <queue>
Lei YU01539e72019-07-31 10:57:38 +080010#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU99301372019-09-29 16:27:12 +080012#include <xyz/openbmc_project/Common/FilePath/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080013#include <xyz/openbmc_project/Software/Activation/server.hpp>
Lei YU81c67722019-09-11 16:47:29 +080014#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Lei YU90c8a8b2019-09-11 17:20:03 +080015#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +080016#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
17
Lei YUff83c2a2019-09-12 13:55:18 +080018class TestActivation;
19
Lei YU01539e72019-07-31 10:57:38 +080020namespace phosphor
21{
22namespace software
23{
24namespace updater
25{
26
Lei YU12c9f4c2019-09-11 15:08:15 +080027namespace sdbusRule = sdbusplus::bus::match::rules;
28
Lei YU81c67722019-09-11 16:47:29 +080029using 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 */
38class 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 YU90c8a8b2019-09-11 17:20:03 +080069using ActivationProgressInherit = sdbusplus::server::object::object<
70 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
71
72class 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 YU01539e72019-07-31 10:57:38 +0800102using ActivationInherit = sdbusplus::server::object::object<
103 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +0800104 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Lei YU99301372019-09-29 16:27:12 +0800105 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
106 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Lei YU01539e72019-07-31 10:57:38 +0800107
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 */
113class Activation : public ActivationInherit
114{
115 public:
Lei YUff83c2a2019-09-12 13:55:18 +0800116 friend class ::TestActivation;
Lei YU12c9f4c2019-09-11 15:08:15 +0800117 using Status = Activations;
Lei YUff83c2a2019-09-12 13:55:18 +0800118
Lei YU01539e72019-07-31 10:57:38 +0800119 /** @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 YU91029442019-08-01 15:57:31 +0800126 * @param[in] assocs - Association objects
Lei YU99301372019-09-29 16:27:12 +0800127 * @param[in] filePath - The image filesystem path
Lei YU01539e72019-07-31 10:57:38 +0800128 */
Lei YU99301372019-09-29 16:27:12 +0800129 Activation(sdbusplus::bus::bus& bus, const std::string& objPath,
Lei YU01539e72019-07-31 10:57:38 +0800130 const std::string& versionId, const std::string& extVersion,
Lei YU7f2a2152019-09-16 16:50:18 +0800131 Status activationStatus, const AssociationList& assocs,
Lei YU99301372019-09-29 16:27:12 +0800132 AssociationInterface* associationInterface,
133 const std::string& filePath) :
134 ActivationInherit(bus, objPath.c_str(), true),
135 bus(bus), objPath(objPath), versionId(versionId),
Lei YU12c9f4c2019-09-11 15:08:15 +0800136 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 YU7f2a2152019-09-16 16:50:18 +0800142 std::placeholders::_1)),
143 associationInterface(associationInterface)
Lei YU01539e72019-07-31 10:57:38 +0800144 {
145 // Set Properties.
146 extendedVersion(extVersion);
147 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800148 associations(assocs);
Lei YU99301372019-09-29 16:27:12 +0800149 path(filePath);
Lei YU01539e72019-07-31 10:57:38 +0800150
Lei YU9edb7332019-09-19 14:46:19 +0800151 auto info = Version::getExtVersionInfo(extVersion);
152 manufacturer = info["manufacturer"];
153 model = info["model"];
154
Lei YU01539e72019-07-31 10:57:38 +0800155 // 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 YUff83c2a2019-09-12 13:55:18 +0800165 Status activation(Status value) override;
Lei YU01539e72019-07-31 10:57:38 +0800166
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 YU63f9e712019-10-12 15:16:55 +0800179 /** @brief Get the object path */
180 const std::string& getObjectPath() const
181 {
182 return objPath;
183 }
184
Lei YUa5c47bb2019-09-29 11:28:53 +0800185 /** @brief Get the version ID */
186 const std::string& getVersionId() const
187 {
188 return versionId;
189 }
Lei YU12c9f4c2019-09-11 15:08:15 +0800190
191 private:
192 /** @brief Check if systemd state change is relevant to this object
193 *
194 * Instance specific interface to handle the detected systemd state
195 * change
196 *
197 * @param[in] msg - Data associated with subscribed signal
198 *
199 */
200 void unitStateChange(sdbusplus::message::message& msg);
201
Lei YUd0bbfa92019-09-11 16:10:54 +0800202 /**
203 * @brief Delete the version from Image Manager and the
204 * untar image from image upload dir.
205 */
206 void deleteImageManagerObject();
207
Lei YUff83c2a2019-09-12 13:55:18 +0800208 /** @brief Invoke the update service for the PSU
209 *
210 * @param[in] psuInventoryPath - The PSU inventory to be updated.
211 *
212 * @return true if the update starts, and false if it fails.
213 */
214 bool doUpdate(const std::string& psuInventoryPath);
215
216 /** @brief Do PSU update one-by-one
217 *
218 * @return true if the update starts, and false if it fails.
219 */
220 bool doUpdate();
221
222 /** @brief Handle an update done event */
223 void onUpdateDone();
224
225 /** @brief Handle an update failure event */
226 void onUpdateFailed();
227
Lei YU12c9f4c2019-09-11 15:08:15 +0800228 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800229 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800230
231 /** @brief Finish PSU update */
232 void finishActivation();
233
Lei YU9edb7332019-09-19 14:46:19 +0800234 /** @brief Check if the PSU is comaptible with this software*/
235 bool isCompatible(const std::string& psuInventoryPath);
236
Lei YU2e0e2de2019-09-26 16:42:23 +0800237 /** @brief Store the updated PSU image to persistent dir */
238 void storeImage();
239
Lei YUe8945ea2019-09-29 17:25:31 +0800240 /** @brief Construct the systemd service name
241 *
242 * @param[in] psuInventoryPath - The PSU inventory to be updated.
243 *
244 * @return The escaped string of systemd unit to do the PSU update.
245 */
246 std::string getUpdateService(const std::string& psuInventoryPath);
247
Lei YU01539e72019-07-31 10:57:38 +0800248 /** @brief Persistent sdbusplus DBus bus connection */
249 sdbusplus::bus::bus& bus;
250
251 /** @brief Persistent DBus object path */
Lei YU99301372019-09-29 16:27:12 +0800252 std::string objPath;
Lei YU01539e72019-07-31 10:57:38 +0800253
Lei YUa5c47bb2019-09-29 11:28:53 +0800254 /** @brief Version id */
255 std::string versionId;
256
Lei YU12c9f4c2019-09-11 15:08:15 +0800257 /** @brief Used to subscribe to dbus systemd signals */
258 sdbusplus::bus::match_t systemdSignals;
259
Lei YUff83c2a2019-09-12 13:55:18 +0800260 /** @brief The queue of psu objects to be updated */
261 std::queue<std::string> psuQueue;
262
263 /** @brief The progress step for each PSU update is done */
264 uint32_t progressStep;
265
Lei YU12c9f4c2019-09-11 15:08:15 +0800266 /** @brief The PSU update systemd unit */
267 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800268
Lei YU7f2a2152019-09-16 16:50:18 +0800269 /** @brief The PSU Inventory path of the current updating PSU */
270 std::string currentUpdatingPsu;
271
Lei YU81c67722019-09-11 16:47:29 +0800272 /** @brief Persistent ActivationBlocksTransition dbus object */
273 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800274
275 /** @brief Persistent ActivationProgress dbus object */
276 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800277
278 /** @brief The AssociationInterface pointer */
279 AssociationInterface* associationInterface;
Lei YU9edb7332019-09-19 14:46:19 +0800280
281 /** @brief The PSU manufacturer of the software */
282 std::string manufacturer;
283
284 /** @brief The PSU model of the software */
285 std::string model;
Lei YU01539e72019-07-31 10:57:38 +0800286};
287
288} // namespace updater
289} // namespace software
290} // namespace phosphor