blob: 792e5d53f5cf12aa5b1a89285b01dd98492424dd [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
Jayashankar Padath4d3d9122019-07-24 16:46:22 +05305#include "utils.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -05006#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>
John Wangd05d4722019-09-11 15:18:15 +080011#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050012#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -050013#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050014
15namespace openpower
16{
17namespace software
18{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050019namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050020{
21
Gunnar Mills3edb84b2017-08-18 15:13:15 -050022using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060023 std::vector<std::tuple<std::string, std::string, std::string>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050024using ActivationInherit = sdbusplus::server::object::object<
Saqib Khan7254f0e2017-04-10 21:45:37 -050025 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050026 sdbusplus::xyz::openbmc_project::Software::server::Activation,
John Wangd05d4722019-09-11 15:18:15 +080027 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050028using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060029 sdbusplus::xyz::openbmc_project::Software::server::
30 ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050031using RedundancyPriorityInherit = sdbusplus::server::object::object<
32 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050033using ActivationProgressInherit = sdbusplus::server::object::object<
34 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050035
Jayashankar Padath4d3d9122019-07-24 16:46:22 +053036constexpr auto applyTimeImmediate =
37 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
38constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
39constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
40constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
41constexpr auto applyTimeProp = "RequestedApplyTime";
42
43constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
44constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
45constexpr auto hostStateRebootProp = "RequestedHostTransition";
46constexpr auto hostStateRebootVal =
47 "xyz.openbmc_project.State.Host.Transition.Reboot";
48
Michael Tritz9d25b602017-06-14 14:41:43 -050049namespace sdbusRule = sdbusplus::bus::match::rules;
50
Saqib Khan81bac882017-06-08 12:17:01 -050051class ItemUpdater;
52class Activation;
53class RedundancyPriority;
54
Saqib Khan942df8a2017-06-01 14:09:27 -050055/** @class RedundancyPriority
56 * @brief OpenBMC RedundancyPriority implementation
57 * @details A concrete implementation for
58 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
59 */
60class RedundancyPriority : public RedundancyPriorityInherit
61{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060062 public:
63 /** @brief Constructs RedundancyPriority.
64 *
65 * @param[in] bus - The Dbus bus object
66 * @param[in] path - The Dbus object path
67 * @param[in] parent - Parent object.
68 * @param[in] value - The redundancyPriority value
69 */
70 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
71 Activation& parent, uint8_t value) :
72 RedundancyPriorityInherit(bus, path.c_str(), true),
73 parent(parent), bus(bus), path(path)
74 {
75 // Set Property
76 priority(value);
77 std::vector<std::string> interfaces({interface});
78 bus.emit_interfaces_added(path.c_str(), interfaces);
79 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -050080
Lei YU9b21efc2019-02-21 15:52:53 +080081 virtual ~RedundancyPriority()
Adriana Kobylak70dcb632018-02-27 15:46:52 -060082 {
83 std::vector<std::string> interfaces({interface});
84 bus.emit_interfaces_removed(path.c_str(), interfaces);
85 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050086
Adriana Kobylak70dcb632018-02-27 15:46:52 -060087 /** @brief Overloaded Priority property set function
88 *
89 * @param[in] value - uint8_t
90 *
91 * @return Success or exception thrown
92 */
93 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050094
Adriana Kobylak70dcb632018-02-27 15:46:52 -060095 /** @brief Priority property get function
96 *
97 * @returns uint8_t - The Priority value
98 */
99 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -0500100
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600101 /** @brief Parent Object. */
102 Activation& parent;
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500103
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600104 private:
105 // TODO Remove once openbmc/openbmc#1975 is resolved
106 static constexpr auto interface =
107 "xyz.openbmc_project.Software.RedundancyPriority";
108 sdbusplus::bus::bus& bus;
109 std::string path;
Saqib Khan942df8a2017-06-01 14:09:27 -0500110};
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500111
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500112/** @class ActivationBlocksTransition
113 * @brief OpenBMC ActivationBlocksTransition implementation.
114 * @details A concrete implementation for
115 * xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
116 */
117class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
118{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600119 public:
120 /** @brief Constructs ActivationBlocksTransition.
121 *
122 * @param[in] bus - The Dbus bus object
123 * @param[in] path - The Dbus object path
124 */
125 ActivationBlocksTransition(sdbusplus::bus::bus& bus,
126 const std::string& path) :
127 ActivationBlocksTransitionInherit(bus, path.c_str(), true),
128 bus(bus), path(path)
129 {
130 std::vector<std::string> interfaces({interface});
131 bus.emit_interfaces_added(path.c_str(), interfaces);
132 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500133
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 ~ActivationBlocksTransition()
135 {
136 std::vector<std::string> interfaces({interface});
137 bus.emit_interfaces_removed(path.c_str(), interfaces);
138 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500139
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600140 private:
141 // TODO Remove once openbmc/openbmc#1975 is resolved
142 static constexpr auto interface =
143 "xyz.openbmc_project.Software.ActivationBlocksTransition";
144 sdbusplus::bus::bus& bus;
145 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500146};
147
Michael Tritz1793b642017-06-28 18:35:58 -0500148class ActivationProgress : public ActivationProgressInherit
149{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600150 public:
151 /** @brief Constructs ActivationProgress.
152 *
153 * @param[in] bus - The Dbus bus object
154 * @param[in] path - The Dbus object path
155 */
156 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
157 ActivationProgressInherit(bus, path.c_str(), true), bus(bus), path(path)
158 {
159 progress(0);
160 std::vector<std::string> interfaces({interface});
161 bus.emit_interfaces_added(path.c_str(), interfaces);
162 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500163
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600164 ~ActivationProgress()
165 {
166 std::vector<std::string> interfaces({interface});
167 bus.emit_interfaces_removed(path.c_str(), interfaces);
168 }
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500169
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600170 private:
171 // TODO Remove once openbmc/openbmc#1975 is resolved
172 static constexpr auto interface =
173 "xyz.openbmc_project.Software.ActivationProgress";
174 sdbusplus::bus::bus& bus;
175 std::string path;
Michael Tritz1793b642017-06-28 18:35:58 -0500176};
177
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500178/** @class Activation
179 * @brief OpenBMC activation software management implementation.
180 * @details A concrete implementation for
181 * xyz.openbmc_project.Software.Activation DBus API.
182 */
183class Activation : public ActivationInherit
184{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600185 public:
186 /** @brief Constructs Activation Software Manager
187 *
188 * @param[in] bus - The Dbus bus object
189 * @param[in] path - The Dbus object path
190 * @param[in] parent - Parent object.
191 * @param[in] versionId - The software version id
192 * @param[in] extVersion - The extended version
193 * @param[in] activationStatus - The status of Activation
194 * @param[in] assocs - Association objects
195 */
196 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Lei YUa9ac9272019-02-22 16:38:35 +0800197 ItemUpdater& parent, const std::string& versionId,
198 const std::string& extVersion,
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600199 sdbusplus::xyz::openbmc_project::Software::server::Activation::
200 Activations activationStatus,
201 AssociationList& assocs) :
202 ActivationInherit(bus, path.c_str(), true),
203 bus(bus), path(path), parent(parent), versionId(versionId),
204 systemdSignals(
205 bus,
206 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
207 sdbusRule::path("/org/freedesktop/systemd1") +
208 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
209 std::bind(std::mem_fn(&Activation::unitStateChange), this,
210 std::placeholders::_1))
211 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600212 // Set Properties.
213 extendedVersion(extVersion);
214 activation(activationStatus);
215 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500216
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600217 // Emit deferred signal.
218 emit_object_added();
219 }
Lei YU9b21efc2019-02-21 15:52:53 +0800220 virtual ~Activation() = default;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500221
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600222 /** @brief Activation property get function
223 *
224 * @returns One of Activation::Activations
225 */
226 using ActivationInherit::activation;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500227
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600228 /** @brief Overloaded requestedActivation property setter function
229 *
230 * @param[in] value - One of Activation::RequestedActivations
231 *
232 * @return Success or exception thrown
233 */
234 RequestedActivations
235 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500236
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600237 /**
238 * @brief subscribe to the systemd signals
239 *
240 * This object needs to capture when it's systemd targets complete
241 * so it can keep it's state updated
242 *
243 **/
244 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500245
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600246 /**
247 * @brief unsubscribe from the systemd signals
248 *
249 * Once the activation process has completed successfully, we can
250 * safely unsubscribe from systemd signals.
251 *
252 **/
253 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500254
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600255 /** @brief Persistent sdbusplus DBus bus connection */
256 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500257
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600258 /** @brief Persistent DBus object path */
259 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500260
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600261 /** @brief Parent Object. */
262 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500263
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600264 /** @brief Version id */
265 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500266
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600267 /** @brief Persistent ActivationBlocksTransition dbus object */
268 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500269
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600270 /** @brief Persistent ActivationProgress dbus object */
271 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500272
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600273 /** @brief Persistent RedundancyPriority dbus object */
274 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500275
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600276 /** @brief Used to subscribe to dbus systemd signals **/
277 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500278
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600279 /** @brief activation status property get function
280 *
281 * @returns Activations - The activation value
282 */
283 using ActivationInherit::activation;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500284
Jayashankar Padath4d3d9122019-07-24 16:46:22 +0530285 /**
286 * @brief Determine the configured image apply time value
287 *
288 * @return true if the image apply time value is immediate
289 **/
290 bool checkApplyTimeImmediate();
291
292 /**
293 * @brief Reboot the Host. Called when ApplyTime is immediate.
294 *
295 * @return none
296 **/
297 void rebootHost();
298
Lei YU9b21efc2019-02-21 15:52:53 +0800299 protected:
300 /** @brief Check if systemd state change is relevant to this object
301 *
302 * Instance specific interface to handle the detected systemd state
303 * change
304 *
305 * @param[in] msg - Data associated with subscribed signal
306 *
307 */
308 virtual void unitStateChange(sdbusplus::message::message& msg) = 0;
309
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600310 /**
311 * @brief Deletes the version from Image Manager and the
312 * untar image from image upload dir.
313 */
314 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500315
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600316 /** @brief Member function for clarity & brevity at activation start */
Lei YU9b21efc2019-02-21 15:52:53 +0800317 virtual void startActivation() = 0;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500318
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600319 /** @brief Member function for clarity & brevity at activation end */
Lei YU9b21efc2019-02-21 15:52:53 +0800320 virtual void finishActivation() = 0;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500321
322#ifdef WANT_SIGNATURE_VERIFY
323 /**
324 * @brief Wrapper function for the signature verify function.
325 * Signature class verify function used for validating
326 * signed image. Also added additional logic to continue
327 * update process in lab environment by checking the
328 * fieldModeEnabled property.
329 *
Lei YU2b2d2292019-03-18 15:22:56 +0800330 * @param[in] pnorFileName - The PNOR filename in image dir
331 *
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500332 * @return true if successful signature validation or field
333 * mode is disabled.
334 * false for unsuccessful signature validation or
335 * any internal failure during the mapper call.
336 */
Lei YU2b2d2292019-03-18 15:22:56 +0800337 bool validateSignature(const std::string& pnorFileName);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500338
339 /**
340 * @brief Gets the fieldModeEnabled property value.
341 *
342 * @return fieldModeEnabled property value
343 * @error InternalFailure exception thrown
344 */
345 bool fieldModeEnabled();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500346#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500347};
348
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500349} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500350} // namespace software
351} // namespace openpower