blob: 2fc08d72ceb9a53a08b02d6c44e88c37644b8723 [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
Gunnar Millsf6ed5892018-09-07 17:08:02 -05003#include "config.h"
4
5#include "org/openbmc/Associations/server.hpp"
6#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
7#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
8#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
9
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050010#include <sdbusplus/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050011#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -050012#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013
14namespace openpower
15{
16namespace software
17{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050018namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019{
20
Gunnar Mills3edb84b2017-08-18 15:13:15 -050021using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060022 std::vector<std::tuple<std::string, std::string, std::string>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050023using ActivationInherit = sdbusplus::server::object::object<
Saqib Khan7254f0e2017-04-10 21:45:37 -050024 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050025 sdbusplus::xyz::openbmc_project::Software::server::Activation,
26 sdbusplus::org::openbmc::server::Associations>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050027using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060028 sdbusplus::xyz::openbmc_project::Software::server::
29 ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050030using RedundancyPriorityInherit = sdbusplus::server::object::object<
31 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050032using ActivationProgressInherit = sdbusplus::server::object::object<
33 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050034
Michael Tritz9d25b602017-06-14 14:41:43 -050035namespace sdbusRule = sdbusplus::bus::match::rules;
36
Saqib Khan81bac882017-06-08 12:17:01 -050037class ItemUpdater;
38class Activation;
39class RedundancyPriority;
40
Saqib Khan942df8a2017-06-01 14:09:27 -050041/** @class RedundancyPriority
42 * @brief OpenBMC RedundancyPriority implementation
43 * @details A concrete implementation for
44 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
45 */
46class RedundancyPriority : public RedundancyPriorityInherit
47{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060048 public:
49 /** @brief Constructs RedundancyPriority.
50 *
51 * @param[in] bus - The Dbus bus object
52 * @param[in] path - The Dbus object path
53 * @param[in] parent - Parent object.
54 * @param[in] value - The redundancyPriority value
55 */
56 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
57 Activation& parent, uint8_t value) :
58 RedundancyPriorityInherit(bus, path.c_str(), true),
59 parent(parent), bus(bus), path(path)
60 {
61 // Set Property
62 priority(value);
63 std::vector<std::string> interfaces({interface});
64 bus.emit_interfaces_added(path.c_str(), interfaces);
65 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -050066
Adriana Kobylak70dcb632018-02-27 15:46:52 -060067 ~RedundancyPriority()
68 {
69 std::vector<std::string> interfaces({interface});
70 bus.emit_interfaces_removed(path.c_str(), interfaces);
71 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050072
Adriana Kobylak70dcb632018-02-27 15:46:52 -060073 /** @brief Overloaded Priority property set function
74 *
75 * @param[in] value - uint8_t
76 *
77 * @return Success or exception thrown
78 */
79 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050080
Adriana Kobylak70dcb632018-02-27 15:46:52 -060081 /** @brief Priority property get function
82 *
83 * @returns uint8_t - The Priority value
84 */
85 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -050086
Adriana Kobylak70dcb632018-02-27 15:46:52 -060087 /** @brief Parent Object. */
88 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -050089
Adriana Kobylak70dcb632018-02-27 15:46:52 -060090 private:
91 // TODO Remove once openbmc/openbmc#1975 is resolved
92 static constexpr auto interface =
93 "xyz.openbmc_project.Software.RedundancyPriority";
94 sdbusplus::bus::bus& bus;
95 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -050096};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050097
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -050098/** @class ActivationBlocksTransition
99 * @brief OpenBMC ActivationBlocksTransition implementation.
100 * @details A concrete implementation for
101 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
102 */
103class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
104{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600105 public:
106 /** @brief Constructs ActivationBlocksTransition.
107 *
108 * @param[in] bus - The Dbus bus object
109 * @param[in] path - The Dbus object path
110 */
111 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
112 const std::string& path) :
113 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
114 bus(bus), path(path)
115 {
116 std::vector<std::string> interfaces({interface});
117 bus.emit_interfaces_added(path.c_str(), interfaces);
118 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500119
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600120 ~ActivationBlocksTransition()
121 {
122 std::vector<std::string> interfaces({interface});
123 bus.emit_interfaces_removed(path.c_str(), interfaces);
124 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500125
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600126 private:
127 // TODO Remove once openbmc/openbmc#1975 is resolved
128 static constexpr auto interface =
129 "xyz.openbmc_project.Software.ActivationBlocksTransition";
130 sdbusplus::bus::bus& bus;
131 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500132};
133
Michael Tritz1793b642017-06-28 18:35:58 -0500134class ActivationProgress : public ActivationProgressInherit
135{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600136 public:
137 /** @brief Constructs ActivationProgress.
138 *
139 * @param[in] bus - The Dbus bus object
140 * @param[in] path - The Dbus object path
141 */
142 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
143 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
144 {
145 progress(0);
146 std::vector<std::string> interfaces({interface});
147 bus.emit_interfaces_added(path.c_str(), interfaces);
148 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500149
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600150 ~ActivationProgress()
151 {
152 std::vector<std::string> interfaces({interface});
153 bus.emit_interfaces_removed(path.c_str(), interfaces);
154 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500155
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600156 private:
157 // TODO Remove once openbmc/openbmc#1975 is resolved
158 static constexpr auto interface =
159 "xyz.openbmc_project.Software.ActivationProgress";
160 sdbusplus::bus::bus& bus;
161 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500162};
163
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500164/** @class Activation
165 * @brief OpenBMC activation software management implementation.
166 * @details A concrete implementation for
167 * xyz.openbmc_project.Software.Activation DBus API.
168 */
169class Activation : public ActivationInherit
170{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 public:
172 /** @brief Constructs Activation Software Manager
173 *
174 * @param[in] bus - The Dbus bus object
175 * @param[in] path - The Dbus object path
176 * @param[in] parent - Parent object.
177 * @param[in] versionId - The software version id
178 * @param[in] extVersion - The extended version
179 * @param[in] activationStatus - The status of Activation
180 * @param[in] assocs - Association objects
181 */
182 Activation(sdbusplus::bus::bus& bus, const std::string& path,
183 ItemUpdater& parent, std::string& versionId,
184 std::string& extVersion,
185 sdbusplus::xyz::openbmc_project::Software::server::Activation::
186 Activations activationStatus,
187 AssociationList& assocs) :
188 ActivationInherit(bus, path.c_str(), true),
189 bus(bus), path(path), parent(parent), versionId(versionId),
190 systemdSignals(
191 bus,
192 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
193 sdbusRule::path("/org/freedesktop/systemd1") +
194 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
195 std::bind(std::mem_fn(&Activation::unitStateChange), this,
196 std::placeholders::_1))
197 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600198 // Set Properties.
199 extendedVersion(extVersion);
200 activation(activationStatus);
201 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500202
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600203 // Emit deferred signal.
204 emit_object_added();
205 }
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500206
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600207 /** @brief Activation property get function
208 *
209 * @returns One of Activation::Activations
210 */
211 using ActivationInherit::activation;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500212
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600213 /** @brief Overloaded Activation property setter function
214 *
215 * @param[in] value - One of Activation::Activations
216 *
217 * @return Success or exception thrown
218 */
219 Activations activation(Activations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500220
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600221 /** @brief Overloaded requestedActivation property setter function
222 *
223 * @param[in] value - One of Activation::RequestedActivations
224 *
225 * @return Success or exception thrown
226 */
227 RequestedActivations
228 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500229
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600230 /** @brief Check if systemd state change is relevant to this object
231 *
232 * Instance specific interface to handle the detected systemd state
233 * change
234 *
235 * @param[in] msg - Data associated with subscribed signal
236 *
237 */
238 void unitStateChange(sdbusplus::message::message& msg);
Michael Tritz9d25b602017-06-14 14:41:43 -0500239
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600240 /**
241 * @brief subscribe to the systemd signals
242 *
243 * This object needs to capture when it's systemd targets complete
244 * so it can keep it's state updated
245 *
246 **/
247 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500248
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600249 /**
250 * @brief unsubscribe from the systemd signals
251 *
252 * Once the activation process has completed successfully, we can
253 * safely unsubscribe from systemd signals.
254 *
255 **/
256 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500257
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600258 /** @brief Persistent sdbusplus DBus bus connection */
259 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500260
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600261 /** @brief Persistent DBus object path */
262 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500263
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600264 /** @brief Parent Object. */
265 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500266
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600267 /** @brief Version id */
268 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500269
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600270 /** @brief Persistent ActivationBlocksTransition dbus object */
271 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500272
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600273 /** @brief Persistent ActivationProgress dbus object */
274 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500275
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600276 /** @brief Persistent RedundancyPriority dbus object */
277 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500278
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600279 /** @brief Used to subscribe to dbus systemd signals **/
280 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500281
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600282 /** @brief Tracks whether the read-only & read-write volumes have been
283 *created as part of the activation process. **/
284 bool ubiVolumesCreated = false;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500285
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600286 /** @brief activation status property get function
287 *
288 * @returns Activations - The activation value
289 */
290 using ActivationInherit::activation;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500291
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600292 private:
293 /**
294 * @brief Deletes the version from Image Manager and the
295 * untar image from image upload dir.
296 */
297 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500298
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600299 /** @brief Member function for clarity & brevity at activation start */
300 void startActivation();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500301
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600302 /** @brief Member function for clarity & brevity at activation end */
303 void finishActivation();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500304
305#ifdef WANT_SIGNATURE_VERIFY
306 /**
307 * @brief Wrapper function for the signature verify function.
308 * Signature class verify function used for validating
309 * signed image. Also added additional logic to continue
310 * update process in lab environment by checking the
311 * fieldModeEnabled property.
312 *
313 * @return true if successful signature validation or field
314 * mode is disabled.
315 * false for unsuccessful signature validation or
316 * any internal failure during the mapper call.
317 */
318 inline bool validateSignature();
319
320 /**
321 * @brief Gets the fieldModeEnabled property value.
322 *
323 * @return fieldModeEnabled property value
324 * @error InternalFailure exception thrown
325 */
326 bool fieldModeEnabled();
327
328 /**
329 * @brief Gets the D-Bus Service name for the input D-Bus path
330 *
331 * @param[in] bus - Bus handler
332 * @param[in] path - Object Path
333 * @param[in] intf - Interface
334 *
335 * @return Service name
336 * @error InternalFailure exception thrown
337 */
338 std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
339 const std::string& intf);
340#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500341};
342
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500343} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500344} // namespace software
345} // namespace openpower