blob: 343458dbef04d887fc86323b0b8b82d32b07a42c [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) :
Albert Zhang7f1967d2020-03-02 14:12:08 +080072 RedundancyPriorityInherit(bus, path.c_str(),
73 action::emit_interface_added),
74 parent(parent)
Adriana Kobylak70dcb632018-02-27 15:46:52 -060075 {
76 // Set Property
77 priority(value);
Adriana Kobylak70dcb632018-02-27 15:46:52 -060078 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050079
Adriana Kobylak70dcb632018-02-27 15:46:52 -060080 /** @brief Overloaded Priority property set function
81 *
82 * @param[in] value - uint8_t
83 *
84 * @return Success or exception thrown
85 */
86 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050087
Adriana Kobylak70dcb632018-02-27 15:46:52 -060088 /** @brief Priority property get function
89 *
90 * @returns uint8_t - The Priority value
91 */
92 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -050093
Adriana Kobylak70dcb632018-02-27 15:46:52 -060094 /** @brief Parent Object. */
95 Activation& parent;
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) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800113 ActivationBlocksTransitionInherit(bus, path.c_str(),
114 action::emit_interface_added)
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500115
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600116 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600117 }
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500118};
119
Michael Tritz1793b642017-06-28 18:35:58 -0500120class ActivationProgress : public ActivationProgressInherit
121{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600122 public:
123 /** @brief Constructs ActivationProgress.
124 *
125 * @param[in] bus - The Dbus bus object
126 * @param[in] path - The Dbus object path
127 */
128 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800129 ActivationProgressInherit(bus, path.c_str(),
130 action::emit_interface_added)
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600131 {
132 progress(0);
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600133 }
Michael Tritz1793b642017-06-28 18:35:58 -0500134};
135
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500136/** @class Activation
137 * @brief OpenBMC activation software management implementation.
138 * @details A concrete implementation for
139 * xyz.openbmc_project.Software.Activation DBus API.
140 */
141class Activation : public ActivationInherit
142{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600143 public:
144 /** @brief Constructs Activation Software Manager
145 *
146 * @param[in] bus - The Dbus bus object
147 * @param[in] path - The Dbus object path
148 * @param[in] parent - Parent object.
149 * @param[in] versionId - The software version id
150 * @param[in] extVersion - The extended version
151 * @param[in] activationStatus - The status of Activation
152 * @param[in] assocs - Association objects
153 */
154 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Lei YUa9ac9272019-02-22 16:38:35 +0800155 ItemUpdater& parent, const std::string& versionId,
156 const std::string& extVersion,
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600157 sdbusplus::xyz::openbmc_project::Software::server::Activation::
158 Activations activationStatus,
159 AssociationList& assocs) :
160 ActivationInherit(bus, path.c_str(), true),
161 bus(bus), path(path), parent(parent), versionId(versionId),
162 systemdSignals(
163 bus,
164 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
165 sdbusRule::path("/org/freedesktop/systemd1") +
166 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
167 std::bind(std::mem_fn(&Activation::unitStateChange), this,
168 std::placeholders::_1))
169 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600170 // Set Properties.
171 extendedVersion(extVersion);
172 activation(activationStatus);
173 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500174
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600175 // Emit deferred signal.
176 emit_object_added();
177 }
Lei YU9b21efc2019-02-21 15:52:53 +0800178 virtual ~Activation() = default;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500179
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600180 /** @brief Activation property get function
181 *
182 * @returns One of Activation::Activations
183 */
184 using ActivationInherit::activation;
Saqib Khan2cbfa032017-08-17 14:52:37 -0500185
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600186 /** @brief Overloaded requestedActivation property setter function
187 *
188 * @param[in] value - One of Activation::RequestedActivations
189 *
190 * @return Success or exception thrown
191 */
192 RequestedActivations
193 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500194
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600195 /**
196 * @brief subscribe to the systemd signals
197 *
198 * This object needs to capture when it's systemd targets complete
199 * so it can keep it's state updated
200 *
201 **/
202 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500203
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600204 /**
205 * @brief unsubscribe from the systemd signals
206 *
207 * Once the activation process has completed successfully, we can
208 * safely unsubscribe from systemd signals.
209 *
210 **/
211 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500212
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600213 /** @brief Persistent sdbusplus DBus bus connection */
214 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500215
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600216 /** @brief Persistent DBus object path */
217 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500218
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600219 /** @brief Parent Object. */
220 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500221
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600222 /** @brief Version id */
223 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500224
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600225 /** @brief Persistent ActivationBlocksTransition dbus object */
226 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500227
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600228 /** @brief Persistent ActivationProgress dbus object */
229 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500230
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600231 /** @brief Persistent RedundancyPriority dbus object */
232 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500233
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600234 /** @brief Used to subscribe to dbus systemd signals **/
235 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500236
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600237 /** @brief activation status property get function
238 *
239 * @returns Activations - The activation value
240 */
241 using ActivationInherit::activation;
Leonel Gonzalez9c8adfa2017-07-12 11:08:40 -0500242
Jayashankar Padath4d3d9122019-07-24 16:46:22 +0530243 /**
244 * @brief Determine the configured image apply time value
245 *
246 * @return true if the image apply time value is immediate
247 **/
248 bool checkApplyTimeImmediate();
249
250 /**
251 * @brief Reboot the Host. Called when ApplyTime is immediate.
252 *
253 * @return none
254 **/
255 void rebootHost();
256
Lei YU9b21efc2019-02-21 15:52:53 +0800257 protected:
258 /** @brief Check if systemd state change is relevant to this object
259 *
260 * Instance specific interface to handle the detected systemd state
261 * change
262 *
263 * @param[in] msg - Data associated with subscribed signal
264 *
265 */
266 virtual void unitStateChange(sdbusplus::message::message& msg) = 0;
267
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600268 /**
269 * @brief Deletes the version from Image Manager and the
270 * untar image from image upload dir.
271 */
272 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500273
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600274 /** @brief Member function for clarity & brevity at activation start */
Lei YU9b21efc2019-02-21 15:52:53 +0800275 virtual void startActivation() = 0;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500276
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600277 /** @brief Member function for clarity & brevity at activation end */
Lei YU9b21efc2019-02-21 15:52:53 +0800278 virtual void finishActivation() = 0;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500279
280#ifdef WANT_SIGNATURE_VERIFY
281 /**
282 * @brief Wrapper function for the signature verify function.
283 * Signature class verify function used for validating
284 * signed image. Also added additional logic to continue
285 * update process in lab environment by checking the
286 * fieldModeEnabled property.
287 *
Lei YU2b2d2292019-03-18 15:22:56 +0800288 * @param[in] pnorFileName - The PNOR filename in image dir
289 *
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500290 * @return true if successful signature validation or field
291 * mode is disabled.
292 * false for unsuccessful signature validation or
293 * any internal failure during the mapper call.
294 */
Lei YU2b2d2292019-03-18 15:22:56 +0800295 bool validateSignature(const std::string& pnorFileName);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500296
297 /**
298 * @brief Gets the fieldModeEnabled property value.
299 *
300 * @return fieldModeEnabled property value
301 * @error InternalFailure exception thrown
302 */
303 bool fieldModeEnabled();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500304#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500305};
306
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500307} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500308} // namespace software
309} // namespace openpower