blob: ed077ae37da16316455502f1197acdc921c63738 [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 =
19 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<
25 sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050026using RedundancyPriorityInherit = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050028using ActivationProgressInherit = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050030
Michael Tritz9d25b602017-06-14 14:41:43 -050031namespace sdbusRule = sdbusplus::bus::match::rules;
32
Saqib Khan81bac882017-06-08 12:17:01 -050033class ItemUpdater;
34class Activation;
35class RedundancyPriority;
36
Saqib Khan942df8a2017-06-01 14:09:27 -050037/** @class RedundancyPriority
38 * @brief OpenBMC RedundancyPriority implementation
39 * @details A concrete implementation for
40 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
41 */
42class RedundancyPriority : public RedundancyPriorityInherit
43{
44 public:
45 /** @brief Constructs RedundancyPriority.
46 *
47 * @param[in] bus - The Dbus bus object
48 * @param[in] path - The Dbus object path
Saqib Khan81bac882017-06-08 12:17:01 -050049 * @param[in] parent - Parent object.
50 * @param[in] value - The redundancyPriority value
Saqib Khan942df8a2017-06-01 14:09:27 -050051 */
52 RedundancyPriority(sdbusplus::bus::bus& bus,
Saqib Khan81bac882017-06-08 12:17:01 -050053 const std::string& path,
54 Activation& parent,
55 uint8_t value) :
Saqib Khan942df8a2017-06-01 14:09:27 -050056 RedundancyPriorityInherit(bus,
Saqib Khan81bac882017-06-08 12:17:01 -050057 path.c_str(), true),
Adriana Kobylaka8eda562017-07-17 15:24:29 -050058 parent(parent),
59 bus(bus),
60 path(path)
Saqib Khan942df8a2017-06-01 14:09:27 -050061 {
62 // Set Property
Saqib Khan81bac882017-06-08 12:17:01 -050063 priority(value);
Adriana Kobylaka8eda562017-07-17 15:24:29 -050064 std::vector<std::string> interfaces({interface});
65 bus.emit_interfaces_added(path.c_str(), interfaces);
66 }
67
68 ~RedundancyPriority()
69 {
70 std::vector<std::string> interfaces({interface});
71 bus.emit_interfaces_removed(path.c_str(), interfaces);
Saqib Khan942df8a2017-06-01 14:09:27 -050072 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050073
74 /** @brief Overloaded Priority property set function
75 *
76 * @param[in] value - uint8_t
77 *
78 * @return Success or exception thrown
79 */
80 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050081
82 /** @brief Priority property get function
83 *
84 * @returns uint8_t - The Priority value
85 */
86 using RedundancyPriorityInherit::priority;
87
88 /** @brief Parent Object. */
89 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -050090
91 private:
92 // TODO Remove once openbmc/openbmc#1975 is resolved
93 static constexpr auto interface =
94 "xyz.openbmc_project.Software.RedundancyPriority";
95 sdbusplus::bus::bus& bus;
96 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -050097};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050098
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050099/** @class ActivationBlocksTransition
100 * @brief OpenBMC ActivationBlocksTransition implementation.
101 * @details A concrete implementation for
102 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
103 */
104class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
105{
106 public:
107 /** @brief Constructs ActivationBlocksTransition.
108 *
109 * @param[in] bus - The Dbus bus object
110 * @param[in] path - The Dbus object path
111 */
112 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
113 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500114 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
115 bus(bus),
116 path(path)
117 {
118 std::vector<std::string> interfaces({interface});
119 bus.emit_interfaces_added(path.c_str(), interfaces);
120 }
121
122 ~ActivationBlocksTransition()
123 {
124 std::vector<std::string> interfaces({interface});
125 bus.emit_interfaces_removed(path.c_str(), interfaces);
126 }
127
128 private:
129 // TODO Remove once openbmc/openbmc#1975 is resolved
130 static constexpr auto interface =
131 "xyz.openbmc_project.Software.ActivationBlocksTransition";
132 sdbusplus::bus::bus& bus;
133 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500134};
135
Michael Tritz1793b642017-06-28 18:35:58 -0500136class ActivationProgress : public ActivationProgressInherit
137{
138 public:
139 /** @brief Constructs ActivationProgress.
140 *
141 * @param[in] bus - The Dbus bus object
142 * @param[in] path - The Dbus object path
143 */
144 ActivationProgress(sdbusplus::bus::bus& bus,
145 const std::string& path) :
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500146 ActivationProgressInherit(bus, path.c_str(), true),
147 bus(bus),
148 path(path)
Michael Tritz1793b642017-06-28 18:35:58 -0500149 {
150 progress(0);
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500151 std::vector<std::string> interfaces({interface});
152 bus.emit_interfaces_added(path.c_str(), interfaces);
Michael Tritz1793b642017-06-28 18:35:58 -0500153 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500154
155 ~ActivationProgress()
156 {
157 std::vector<std::string> interfaces({interface});
158 bus.emit_interfaces_removed(path.c_str(), interfaces);
159 }
160
161 private:
162 // TODO Remove once openbmc/openbmc#1975 is resolved
163 static constexpr auto interface =
164 "xyz.openbmc_project.Software.ActivationProgress";
165 sdbusplus::bus::bus& bus;
166 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500167};
168
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500169/** @class Activation
170 * @brief OpenBMC activation software management implementation.
171 * @details A concrete implementation for
172 * xyz.openbmc_project.Software.Activation DBus API.
173 */
174class Activation : public ActivationInherit
175{
176 public:
177 /** @brief Constructs Activation Software Manager
178 *
179 * @param[in] bus - The Dbus bus object
180 * @param[in] path - The Dbus object path
Saqib Khan81bac882017-06-08 12:17:01 -0500181 * @param[in] parent - Parent object.
Saqib Khan7254f0e2017-04-10 21:45:37 -0500182 * @param[in] versionId - The software version id
183 * @param[in] extVersion - The extended version
Saqib Khana8ade7e2017-04-12 10:27:56 -0500184 * @param[in] activationStatus - The status of Activation
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500185 * @param[in] assocs - Association objects
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500186 */
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500187 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Saqib Khan81bac882017-06-08 12:17:01 -0500188 ItemUpdater& parent,
Saqib Khan7254f0e2017-04-10 21:45:37 -0500189 std::string& versionId,
Saqib Khana8ade7e2017-04-12 10:27:56 -0500190 std::string& extVersion,
191 sdbusplus::xyz::openbmc_project::Software::
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500192 server::Activation::Activations activationStatus,
193 AssociationList& assocs) :
Saqib Khan7254f0e2017-04-10 21:45:37 -0500194 ActivationInherit(bus, path.c_str(), true),
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500195 bus(bus),
196 path(path),
Saqib Khan81bac882017-06-08 12:17:01 -0500197 parent(parent),
Michael Tritz9d25b602017-06-14 14:41:43 -0500198 versionId(versionId),
199 systemdSignals(
200 bus,
201 sdbusRule::type::signal() +
202 sdbusRule::member("JobRemoved") +
203 sdbusRule::path("/org/freedesktop/systemd1") +
204 sdbusRule::interface(
205 "org.freedesktop.systemd1.Manager"),
206 std::bind(std::mem_fn(&Activation::unitStateChange),
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500207 this, std::placeholders::_1))
Saqib Khan7254f0e2017-04-10 21:45:37 -0500208 {
Michael Tritz9d25b602017-06-14 14:41:43 -0500209 // Enable systemd signals
210 subscribeToSystemdSignals();
Saqib Khan7254f0e2017-04-10 21:45:37 -0500211 // Set Properties.
212 extendedVersion(extVersion);
Saqib Khana8ade7e2017-04-12 10:27:56 -0500213 activation(activationStatus);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500214 associations(assocs);
215
Saqib Khan7254f0e2017-04-10 21:45:37 -0500216 // Emit deferred signal.
217 emit_object_added();
218 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500219
Saqib Khan2cbfa032017-08-17 14:52:37 -0500220 /** @brief Activation property get function
221 *
222 * @returns One of Activation::Activations
223 */
224 using ActivationInherit::activation;
225
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500226 /** @brief Overloaded Activation property setter function
227 *
228 * @param[in] value - One of Activation::Activations
229 *
230 * @return Success or exception thrown
231 */
232 Activations activation(Activations value) override;
233
234 /** @brief Overloaded requestedActivation property setter function
235 *
236 * @param[in] value - One of Activation::RequestedActivations
237 *
238 * @return Success or exception thrown
239 */
240 RequestedActivations requestedActivation(RequestedActivations value)
241 override;
242
Michael Tritz9d25b602017-06-14 14:41:43 -0500243 /** @brief Check if systemd state change is relevant to this object
244 *
245 * Instance specific interface to handle the detected systemd state
246 * change
247 *
248 * @param[in] msg - Data associated with subscribed signal
249 *
250 */
251 void unitStateChange(sdbusplus::message::message& msg);
252
253 /**
254 * @brief subscribe to the systemd signals
255 *
256 * This object needs to capture when it's systemd targets complete
257 * so it can keep it's state updated
258 *
259 **/
260 void subscribeToSystemdSignals();
261
Michael Tritz1cb127f2017-07-26 15:40:38 -0500262 /**
263 * @brief unsubscribe from the systemd signals
264 *
265 * Once the activation process has completed successfully, we can
266 * safely unsubscribe from systemd signals.
267 *
268 **/
269 void unsubscribeFromSystemdSignals();
270
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500271 /** @brief Persistent sdbusplus DBus bus connection */
272 sdbusplus::bus::bus& bus;
273
274 /** @brief Persistent DBus object path */
275 std::string path;
276
Saqib Khan81bac882017-06-08 12:17:01 -0500277 /** @brief Parent Object. */
278 ItemUpdater& parent;
279
Adriana Kobylakbc37a4c2017-04-10 09:45:36 -0500280 /** @brief Version id */
281 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500282
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500283 /** @brief Persistent ActivationBlocksTransition dbus object */
284 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500285
Michael Tritz1793b642017-06-28 18:35:58 -0500286 /** @brief Persistent ActivationProgress dbus object */
287 std::unique_ptr<ActivationProgress> activationProgress;
288
Saqib Khan942df8a2017-06-01 14:09:27 -0500289 /** @brief Persistent RedundancyPriority dbus object */
290 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500291
292 /** @brief Used to subscribe to dbus systemd signals **/
293 sdbusplus::bus::match_t systemdSignals;
294
Saqib Khan1e0aa5c2017-08-31 11:04:17 -0500295 /** @brief Tracks whether the read-only & read-write volumes have been
296 *created as part of the activation process. **/
297 bool ubiVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500298
299 /** @brief activation status property get function
300 *
301 * @returns Activations - The activation value
302 */
303 using ActivationInherit::activation;
304
Michael Tritz1cb127f2017-07-26 15:40:38 -0500305 private:
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500306
307 /**
308 * @brief Deletes the version from Image Manager and the
309 * untar image from image upload dir.
310 */
311 void deleteImageManagerObject();
312
Michael Tritz1cb127f2017-07-26 15:40:38 -0500313 /** @brief Member function for clarity & brevity at activation start */
314 void startActivation();
315
316 /** @brief Member function for clarity & brevity at activation end */
317 void finishActivation();
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500318};
319
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500320} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500321} // namespace software
322} // namespace openpower