blob: fc3282774aa7fb6c7156345a8d592462da6ffcc9 [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
Lei YUffb36532019-10-15 13:55:24 +08005#include "activation_listener.hpp"
Lei YU7f2a2152019-09-16 16:50:18 +08006#include "association_interface.hpp"
Lei YU91029442019-08-01 15:57:31 +08007#include "types.hpp"
Lei YU9edb7332019-09-19 14:46:19 +08008#include "version.hpp"
Lei YU91029442019-08-01 15:57:31 +08009
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
Patrick Williams5670b182023-05-10 07:50:50 -050018#include <queue>
19
Lei YUff83c2a2019-09-12 13:55:18 +080020class TestActivation;
21
Lei YU01539e72019-07-31 10:57:38 +080022namespace phosphor
23{
24namespace software
25{
26namespace updater
27{
28
Lei YU12c9f4c2019-09-11 15:08:15 +080029namespace sdbusRule = sdbusplus::bus::match::rules;
30
Patrick Williams374fae52022-07-22 19:26:55 -050031using ActivationBlocksTransitionInherit =
32 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software::
33 server::ActivationBlocksTransition>;
Lei YU81c67722019-09-11 16:47:29 +080034
35/** @class ActivationBlocksTransition
36 * @brief OpenBMC ActivationBlocksTransition implementation.
37 * @details A concrete implementation for
38 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
39 */
40class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
41{
42 public:
43 /** @brief Constructs ActivationBlocksTransition.
44 *
45 * @param[in] bus - The Dbus bus object
46 * @param[in] path - The Dbus object path
47 */
Patrick Williams374fae52022-07-22 19:26:55 -050048 ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
Albert Zhangf356fdc2020-03-02 09:24:17 +080049 ActivationBlocksTransitionInherit(bus, path.c_str(),
50 action::emit_interface_added),
51 bus(bus)
Lei YU81c67722019-09-11 16:47:29 +080052 {
Lei YU8afeee52019-10-21 15:25:35 +080053 enableRebootGuard();
Lei YU81c67722019-09-11 16:47:29 +080054 }
55
56 ~ActivationBlocksTransition()
57 {
Lei YU8afeee52019-10-21 15:25:35 +080058 disableRebootGuard();
Lei YU81c67722019-09-11 16:47:29 +080059 }
60
61 private:
Patrick Williams374fae52022-07-22 19:26:55 -050062 sdbusplus::bus_t& bus;
Lei YU8afeee52019-10-21 15:25:35 +080063
64 /** @brief Enables a Guard that blocks any BMC reboot commands */
65 void enableRebootGuard();
66
67 /** @brief Disables any guard that was blocking the BMC reboot */
68 void disableRebootGuard();
Lei YU81c67722019-09-11 16:47:29 +080069};
70
Patrick Williams374fae52022-07-22 19:26:55 -050071using ActivationProgressInherit = sdbusplus::server::object_t<
Lei YU90c8a8b2019-09-11 17:20:03 +080072 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
73
74class ActivationProgress : public ActivationProgressInherit
75{
76 public:
77 /** @brief Constructs ActivationProgress.
78 *
79 * @param[in] bus - The Dbus bus object
80 * @param[in] path - The Dbus object path
81 */
Patrick Williams374fae52022-07-22 19:26:55 -050082 ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
Albert Zhangf356fdc2020-03-02 09:24:17 +080083 ActivationProgressInherit(bus, path.c_str(),
84 action::emit_interface_added)
Lei YU90c8a8b2019-09-11 17:20:03 +080085 {
86 progress(0);
Lei YU90c8a8b2019-09-11 17:20:03 +080087 }
Lei YU90c8a8b2019-09-11 17:20:03 +080088};
89
Patrick Williams374fae52022-07-22 19:26:55 -050090using ActivationInherit = sdbusplus::server::object_t<
Lei YU01539e72019-07-31 10:57:38 +080091 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +080092 sdbusplus::xyz::openbmc_project::Software::server::Activation,
Lei YU99301372019-09-29 16:27:12 +080093 sdbusplus::xyz::openbmc_project::Association::server::Definitions,
94 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Lei YU01539e72019-07-31 10:57:38 +080095
96/** @class Activation
97 * @brief OpenBMC activation software management implementation.
98 * @details A concrete implementation for
99 * xyz.openbmc_project.Software.Activation DBus API.
100 */
101class Activation : public ActivationInherit
102{
103 public:
Lei YUff83c2a2019-09-12 13:55:18 +0800104 friend class ::TestActivation;
Lei YU12c9f4c2019-09-11 15:08:15 +0800105 using Status = Activations;
Lei YUff83c2a2019-09-12 13:55:18 +0800106
Lei YU01539e72019-07-31 10:57:38 +0800107 /** @brief Constructs Activation Software Manager
108 *
109 * @param[in] bus - The Dbus bus object
110 * @param[in] path - The Dbus object path
111 * @param[in] versionId - The software version id
112 * @param[in] extVersion - The extended version
113 * @param[in] activationStatus - The status of Activation
Lei YU91029442019-08-01 15:57:31 +0800114 * @param[in] assocs - Association objects
Lei YU99301372019-09-29 16:27:12 +0800115 * @param[in] filePath - The image filesystem path
Lei YU01539e72019-07-31 10:57:38 +0800116 */
Patrick Williams374fae52022-07-22 19:26:55 -0500117 Activation(sdbusplus::bus_t& bus, const std::string& objPath,
Lei YU01539e72019-07-31 10:57:38 +0800118 const std::string& versionId, const std::string& extVersion,
Lei YU7f2a2152019-09-16 16:50:18 +0800119 Status activationStatus, const AssociationList& assocs,
Lei YUffb36532019-10-15 13:55:24 +0800120 const std::string& filePath,
Lei YU99301372019-09-29 16:27:12 +0800121 AssociationInterface* associationInterface,
Lei YUffb36532019-10-15 13:55:24 +0800122 ActivationListener* activationListener) :
Tang Yiwei434ae482022-04-16 13:55:21 +0800123 ActivationInherit(bus, objPath.c_str(),
124 ActivationInherit::action::defer_emit),
Lei YU99301372019-09-29 16:27:12 +0800125 bus(bus), objPath(objPath), versionId(versionId),
Lei YU12c9f4c2019-09-11 15:08:15 +0800126 systemdSignals(
127 bus,
128 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
129 sdbusRule::path("/org/freedesktop/systemd1") +
130 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
131 std::bind(&Activation::unitStateChange, this,
Lei YU7f2a2152019-09-16 16:50:18 +0800132 std::placeholders::_1)),
Lei YUffb36532019-10-15 13:55:24 +0800133 associationInterface(associationInterface),
134 activationListener(activationListener)
Lei YU01539e72019-07-31 10:57:38 +0800135 {
136 // Set Properties.
137 extendedVersion(extVersion);
138 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +0800139 associations(assocs);
Lei YU99301372019-09-29 16:27:12 +0800140 path(filePath);
Lei YU01539e72019-07-31 10:57:38 +0800141
Lei YU9edb7332019-09-19 14:46:19 +0800142 auto info = Version::getExtVersionInfo(extVersion);
143 manufacturer = info["manufacturer"];
144 model = info["model"];
145
Lei YU01539e72019-07-31 10:57:38 +0800146 // Emit deferred signal.
147 emit_object_added();
148 }
149
150 /** @brief Overloaded Activation property setter function
151 *
152 * @param[in] value - One of Activation::Activations
153 *
154 * @return Success or exception thrown
155 */
Lei YUff83c2a2019-09-12 13:55:18 +0800156 Status activation(Status value) override;
Lei YU01539e72019-07-31 10:57:38 +0800157
158 /** @brief Activation */
159 using ActivationInherit::activation;
160
161 /** @brief Overloaded requestedActivation property setter function
162 *
163 * @param[in] value - One of Activation::RequestedActivations
164 *
165 * @return Success or exception thrown
166 */
167 RequestedActivations
168 requestedActivation(RequestedActivations value) override;
169
Lei YU63f9e712019-10-12 15:16:55 +0800170 /** @brief Get the object path */
171 const std::string& getObjectPath() const
172 {
173 return objPath;
174 }
175
Lei YUa5c47bb2019-09-29 11:28:53 +0800176 /** @brief Get the version ID */
177 const std::string& getVersionId() const
178 {
179 return versionId;
180 }
Lei YU12c9f4c2019-09-11 15:08:15 +0800181
182 private:
183 /** @brief Check if systemd state change is relevant to this object
184 *
185 * Instance specific interface to handle the detected systemd state
186 * change
187 *
188 * @param[in] msg - Data associated with subscribed signal
189 *
190 */
Patrick Williams374fae52022-07-22 19:26:55 -0500191 void unitStateChange(sdbusplus::message_t& msg);
Lei YU12c9f4c2019-09-11 15:08:15 +0800192
Lei YUd0bbfa92019-09-11 16:10:54 +0800193 /**
194 * @brief Delete the version from Image Manager and the
195 * untar image from image upload dir.
196 */
197 void deleteImageManagerObject();
198
Lei YUff83c2a2019-09-12 13:55:18 +0800199 /** @brief Invoke the update service for the PSU
200 *
201 * @param[in] psuInventoryPath - The PSU inventory to be updated.
202 *
203 * @return true if the update starts, and false if it fails.
204 */
205 bool doUpdate(const std::string& psuInventoryPath);
206
207 /** @brief Do PSU update one-by-one
208 *
209 * @return true if the update starts, and false if it fails.
210 */
211 bool doUpdate();
212
213 /** @brief Handle an update done event */
214 void onUpdateDone();
215
216 /** @brief Handle an update failure event */
217 void onUpdateFailed();
218
Lei YU12c9f4c2019-09-11 15:08:15 +0800219 /** @brief Start PSU update */
Lei YUff83c2a2019-09-12 13:55:18 +0800220 Status startActivation();
Lei YU12c9f4c2019-09-11 15:08:15 +0800221
222 /** @brief Finish PSU update */
223 void finishActivation();
224
Lei YU9edb7332019-09-19 14:46:19 +0800225 /** @brief Check if the PSU is comaptible with this software*/
226 bool isCompatible(const std::string& psuInventoryPath);
227
Lei YU2e0e2de2019-09-26 16:42:23 +0800228 /** @brief Store the updated PSU image to persistent dir */
229 void storeImage();
230
Lei YUe8945ea2019-09-29 17:25:31 +0800231 /** @brief Construct the systemd service name
232 *
233 * @param[in] psuInventoryPath - The PSU inventory to be updated.
234 *
235 * @return The escaped string of systemd unit to do the PSU update.
236 */
237 std::string getUpdateService(const std::string& psuInventoryPath);
238
Lei YU01539e72019-07-31 10:57:38 +0800239 /** @brief Persistent sdbusplus DBus bus connection */
Patrick Williams374fae52022-07-22 19:26:55 -0500240 sdbusplus::bus_t& bus;
Lei YU01539e72019-07-31 10:57:38 +0800241
242 /** @brief Persistent DBus object path */
Lei YU99301372019-09-29 16:27:12 +0800243 std::string objPath;
Lei YU01539e72019-07-31 10:57:38 +0800244
Lei YUa5c47bb2019-09-29 11:28:53 +0800245 /** @brief Version id */
246 std::string versionId;
247
Lei YU12c9f4c2019-09-11 15:08:15 +0800248 /** @brief Used to subscribe to dbus systemd signals */
249 sdbusplus::bus::match_t systemdSignals;
250
Lei YUff83c2a2019-09-12 13:55:18 +0800251 /** @brief The queue of psu objects to be updated */
252 std::queue<std::string> psuQueue;
253
254 /** @brief The progress step for each PSU update is done */
255 uint32_t progressStep;
256
Lei YU12c9f4c2019-09-11 15:08:15 +0800257 /** @brief The PSU update systemd unit */
258 std::string psuUpdateUnit;
Lei YU81c67722019-09-11 16:47:29 +0800259
Lei YU7f2a2152019-09-16 16:50:18 +0800260 /** @brief The PSU Inventory path of the current updating PSU */
261 std::string currentUpdatingPsu;
262
Lei YU81c67722019-09-11 16:47:29 +0800263 /** @brief Persistent ActivationBlocksTransition dbus object */
264 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Lei YU90c8a8b2019-09-11 17:20:03 +0800265
266 /** @brief Persistent ActivationProgress dbus object */
267 std::unique_ptr<ActivationProgress> activationProgress;
Lei YU7f2a2152019-09-16 16:50:18 +0800268
269 /** @brief The AssociationInterface pointer */
270 AssociationInterface* associationInterface;
Lei YU9edb7332019-09-19 14:46:19 +0800271
Lei YUffb36532019-10-15 13:55:24 +0800272 /** @brief The activationListener pointer */
273 ActivationListener* activationListener;
274
Lei YU9edb7332019-09-19 14:46:19 +0800275 /** @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 YU01539e72019-07-31 10:57:38 +0800280};
281
282} // namespace updater
283} // namespace software
284} // namespace phosphor