blob: 2edbca5c07da00f0dbdeff3d692cc2c46896fe5a [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -05003#include <sdbusplus/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05004#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -05005#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Saqib Khan7254f0e2017-04-10 21:45:37 -05006#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
Saqib Khan942df8a2017-06-01 14:09:27 -05007#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
Michael Tritz1793b642017-06-28 18:35:58 -05008#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
Saqib Khanc350c612017-08-13 13:36:44 -05009#include "org/openbmc/Associations/server.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050010
11namespace openpower
12{
13namespace software
14{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050015namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050016{
17
Gunnar Mills3edb84b2017-08-18 15:13:15 -050018using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060019 std::vector<std::tuple<std::string, std::string, std::string>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050020using ActivationInherit = sdbusplus::server::object::object<
Saqib Khan7254f0e2017-04-10 21:45:37 -050021 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050022 sdbusplus::xyz::openbmc_project::Software::server::Activation,
23 sdbusplus::org::openbmc::server::Associations>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050024using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060025 sdbusplus::xyz::openbmc_project::Software::server::
26 ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050027using RedundancyPriorityInherit = sdbusplus::server::object::object<
28 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050029using ActivationProgressInherit = sdbusplus::server::object::object<
30 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050031
Michael Tritz9d25b602017-06-14 14:41:43 -050032namespace sdbusRule = sdbusplus::bus::match::rules;
33
Saqib Khan81bac882017-06-08 12:17:01 -050034class ItemUpdater;
35class Activation;
36class RedundancyPriority;
37
Saqib Khan942df8a2017-06-01 14:09:27 -050038/** @class RedundancyPriority
39 * @brief OpenBMC RedundancyPriority implementation
40 * @details A concrete implementation for
41 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
42 */
43class RedundancyPriority : public RedundancyPriorityInherit
44{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060045 public:
46 /** @brief Constructs RedundancyPriority.
47 *
48 * @param[in] bus - The Dbus bus object
49 * @param[in] path - The Dbus object path
50 * @param[in] parent - Parent object.
51 * @param[in] value - The redundancyPriority value
52 */
53 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
54 Activation& parent, uint8_t value) :
55 RedundancyPriorityInherit(bus, path.c_str(), true),
56 parent(parent), bus(bus), path(path)
57 {
58 // Set Property
59 priority(value);
60 std::vector<std::string> interfaces({interface});
61 bus.emit_interfaces_added(path.c_str(), interfaces);
62 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -050063
Adriana Kobylak70dcb632018-02-27 15:46:52 -060064 ~RedundancyPriority()
65 {
66 std::vector<std::string> interfaces({interface});
67 bus.emit_interfaces_removed(path.c_str(), interfaces);
68 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050069
Adriana Kobylak70dcb632018-02-27 15:46:52 -060070 /** @brief Overloaded Priority property set function
71 *
72 * @param[in] value - uint8_t
73 *
74 * @return Success or exception thrown
75 */
76 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050077
Adriana Kobylak70dcb632018-02-27 15:46:52 -060078 /** @brief Priority property get function
79 *
80 * @returns uint8_t - The Priority value
81 */
82 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -050083
Adriana Kobylak70dcb632018-02-27 15:46:52 -060084 /** @brief Parent Object. */
85 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -050086
Adriana Kobylak70dcb632018-02-27 15:46:52 -060087 private:
88 // TODO Remove once openbmc/openbmc#1975 is resolved
89 static constexpr auto interface =
90 "xyz.openbmc_project.Software.RedundancyPriority";
91 sdbusplus::bus::bus& bus;
92 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -050093};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050094
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050095/** @class ActivationBlocksTransition
96 * @brief OpenBMC ActivationBlocksTransition implementation.
97 * @details A concrete implementation for
98 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
99 */
100class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
101{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600102 public:
103 /** @brief Constructs ActivationBlocksTransition.
104 *
105 * @param[in] bus - The Dbus bus object
106 * @param[in] path - The Dbus object path
107 */
108 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
109 const std::string& path) :
110 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
111 bus(bus), path(path)
112 {
113 std::vector<std::string> interfaces({interface});
114 bus.emit_interfaces_added(path.c_str(), interfaces);
115 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500116
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600117 ~ActivationBlocksTransition()
118 {
119 std::vector<std::string> interfaces({interface});
120 bus.emit_interfaces_removed(path.c_str(), interfaces);
121 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500122
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600123 private:
124 // TODO Remove once openbmc/openbmc#1975 is resolved
125 static constexpr auto interface =
126 "xyz.openbmc_project.Software.ActivationBlocksTransition";
127 sdbusplus::bus::bus& bus;
128 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500129};
130
Michael Tritz1793b642017-06-28 18:35:58 -0500131class ActivationProgress : public ActivationProgressInherit
132{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600133 public:
134 /** @brief Constructs ActivationProgress.
135 *
136 * @param[in] bus - The Dbus bus object
137 * @param[in] path - The Dbus object path
138 */
139 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
140 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
141 {
142 progress(0);
143 std::vector<std::string> interfaces({interface});
144 bus.emit_interfaces_added(path.c_str(), interfaces);
145 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500146
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600147 ~ActivationProgress()
148 {
149 std::vector<std::string> interfaces({interface});
150 bus.emit_interfaces_removed(path.c_str(), interfaces);
151 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500152
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600153 private:
154 // TODO Remove once openbmc/openbmc#1975 is resolved
155 static constexpr auto interface =
156 "xyz.openbmc_project.Software.ActivationProgress";
157 sdbusplus::bus::bus& bus;
158 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500159};
160
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500161/** @class Activation
162 * @brief OpenBMC activation software management implementation.
163 * @details A concrete implementation for
164 * xyz.openbmc_project.Software.Activation DBus API.
165 */
166class Activation : public ActivationInherit
167{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600168 public:
169 /** @brief Constructs Activation Software Manager
170 *
171 * @param[in] bus - The Dbus bus object
172 * @param[in] path - The Dbus object path
173 * @param[in] parent - Parent object.
174 * @param[in] versionId - The software version id
175 * @param[in] extVersion - The extended version
176 * @param[in] activationStatus - The status of Activation
177 * @param[in] assocs - Association objects
178 */
179 Activation(sdbusplus::bus::bus& bus, const std::string& path,
180 ItemUpdater& parent, std::string& versionId,
181 std::string& extVersion,
182 sdbusplus::xyz::openbmc_project::Software::server::Activation::
183 Activations activationStatus,
184 AssociationList& assocs) :
185 ActivationInherit(bus, path.c_str(), true),
186 bus(bus), path(path), parent(parent), versionId(versionId),
187 systemdSignals(
188 bus,
189 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
190 sdbusRule::path("/org/freedesktop/systemd1") +
191 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
192 std::bind(std::mem_fn(&Activation::unitStateChange), this,
193 std::placeholders::_1))
194 {
195 // Enable systemd signals
196 subscribeToSystemdSignals();
197 // Set Properties.
198 extendedVersion(extVersion);
199 activation(activationStatus);
200 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500201
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600202 // Emit deferred signal.
203 emit_object_added();
204 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500205
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600206 /** @brief Activation property get function
207 *
208 * @returns One of Activation::Activations
209 */
210 using ActivationInherit::activation;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500211
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600212 /** @brief Overloaded Activation property setter function
213 *
214 * @param[in] value - One of Activation::Activations
215 *
216 * @return Success or exception thrown
217 */
218 Activations activation(Activations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500219
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600220 /** @brief Overloaded requestedActivation property setter function
221 *
222 * @param[in] value - One of Activation::RequestedActivations
223 *
224 * @return Success or exception thrown
225 */
226 RequestedActivations
227 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500228
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600229 /** @brief Check if systemd state change is relevant to this object
230 *
231 * Instance specific interface to handle the detected systemd state
232 * change
233 *
234 * @param[in] msg - Data associated with subscribed signal
235 *
236 */
237 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritz9d25b602017-06-14 14:41:43 -0500238
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600239 /**
240 * @brief subscribe to the systemd signals
241 *
242 * This object needs to capture when it's systemd targets complete
243 * so it can keep it's state updated
244 *
245 **/
246 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500247
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600248 /**
249 * @brief unsubscribe from the systemd signals
250 *
251 * Once the activation process has completed successfully, we can
252 * safely unsubscribe from systemd signals.
253 *
254 **/
255 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500256
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600257 /** @brief Persistent sdbusplus DBus bus connection */
258 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500259
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600260 /** @brief Persistent DBus object path */
261 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500262
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600263 /** @brief Parent Object. */
264 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500265
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600266 /** @brief Version id */
267 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500268
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600269 /** @brief Persistent ActivationBlocksTransition dbus object */
270 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500271
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600272 /** @brief Persistent ActivationProgress dbus object */
273 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500274
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600275 /** @brief Persistent RedundancyPriority dbus object */
276 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500277
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600278 /** @brief Used to subscribe to dbus systemd signals **/
279 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500280
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600281 /** @brief Tracks whether the read-only & read-write volumes have been
282 *created as part of the activation process. **/
283 bool ubiVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500284
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600285 /** @brief activation status property get function
286 *
287 * @returns Activations - The activation value
288 */
289 using ActivationInherit::activation;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500290
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600291 private:
292 /**
293 * @brief Deletes the version from Image Manager and the
294 * untar image from image upload dir.
295 */
296 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500297
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600298 /** @brief Member function for clarity & brevity at activation start */
299 void startActivation();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500300
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600301 /** @brief Member function for clarity & brevity at activation end */
302 void finishActivation();
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500303};
304
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500305} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500306} // namespace software
307} // namespace openpower