blob: 7a9e464faa88bcad2e8dde8d48aa929e96304490 [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 YUa5c47bb2019-09-29 11:28:53 +0800179 /** @brief Get the version ID */
180 const std::string& getVersionId() const
181 {
182 return versionId;
183 }
Lei YU12c9f4c2019-09-11 15:08:15 +0800184
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 YUd0bbfa92019-09-11 16:10:54 +0800196 /**
197 * @brief Delete the version from Image Manager and the
198 * untar image from image upload dir.
199 */
200 void deleteImageManagerObject();
201
Lei YUff83c2a2019-09-12 13:55:18 +0800202 /** @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 YU12c9f4c2019-09-11 15:08:15 +0800222 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800223 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800224
225 /** @brief Finish PSU update */
226 void finishActivation();
227
Lei YU9edb7332019-09-19 14:46:19 +0800228 /** @brief Check if the PSU is comaptible with this software*/
229 bool isCompatible(const std::string& psuInventoryPath);
230
Lei YU01539e72019-07-31 10:57:38 +0800231 /** @brief Persistent sdbusplus DBus bus connection */
232 sdbusplus::bus::bus& bus;
233
234 /** @brief Persistent DBus object path */
Lei YU99301372019-09-29 16:27:12 +0800235 std::string objPath;
Lei YU01539e72019-07-31 10:57:38 +0800236
Lei YUa5c47bb2019-09-29 11:28:53 +0800237 /** @brief Version id */
238 std::string versionId;
239
Lei YU12c9f4c2019-09-11 15:08:15 +0800240 /** @brief Used to subscribe to dbus systemd signals */
241 sdbusplus::bus::match_t systemdSignals;
242
Lei YUff83c2a2019-09-12 13:55:18 +0800243 /** @brief The queue of psu objects to be updated */
244 std::queue<std::string> psuQueue;
245
246 /** @brief The progress step for each PSU update is done */
247 uint32_t progressStep;
248
Lei YU12c9f4c2019-09-11 15:08:15 +0800249 /** @brief The PSU update systemd unit */
250 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800251
Lei YU7f2a2152019-09-16 16:50:18 +0800252 /** @brief The PSU Inventory path of the current updating PSU */
253 std::string currentUpdatingPsu;
254
Lei YU81c67722019-09-11 16:47:29 +0800255 /** @brief Persistent ActivationBlocksTransition dbus object */
256 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800257
258 /** @brief Persistent ActivationProgress dbus object */
259 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800260
261 /** @brief The AssociationInterface pointer */
262 AssociationInterface* associationInterface;
Lei YU9edb7332019-09-19 14:46:19 +0800263
264 /** @brief The PSU manufacturer of the software */
265 std::string manufacturer;
266
267 /** @brief The PSU model of the software */
268 std::string model;
Lei YU01539e72019-07-31 10:57:38 +0800269};
270
271} // namespace updater
272} // namespace software
273} // namespace phosphor