blob: c236c9bf749e0664b8235786f6afb58fda61c704 [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>
Andrew Geisslerab139ce2020-05-16 13:22:09 -050011#include <string>
John Wangd05d4722019-09-11 15:18:15 +080012#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013#include <xyz/openbmc_project/Software/Activation/server.hpp>
Adriana Kobylakea9626f2017-04-05 15:37:40 -050014#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050015
16namespace openpower
17{
18namespace software
19{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050020namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050021{
22
Gunnar Mills3edb84b2017-08-18 15:13:15 -050023using AssociationList =
Adriana Kobylak70dcb632018-02-27 15:46:52 -060024 std::vector<std::tuple<std::string, std::string, std::string>>;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050025using ActivationInherit = sdbusplus::server::object::object<
Saqib Khan7254f0e2017-04-10 21:45:37 -050026 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Saqib Khanc350c612017-08-13 13:36:44 -050027 sdbusplus::xyz::openbmc_project::Software::server::Activation,
John Wangd05d4722019-09-11 15:18:15 +080028 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Adriana Kobylakea9626f2017-04-05 15:37:40 -050029using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
Adriana Kobylak70dcb632018-02-27 15:46:52 -060030 sdbusplus::xyz::openbmc_project::Software::server::
31 ActivationBlocksTransition>;
Saqib Khan942df8a2017-06-01 14:09:27 -050032using RedundancyPriorityInherit = sdbusplus::server::object::object<
33 sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
Michael Tritz1793b642017-06-28 18:35:58 -050034using ActivationProgressInherit = sdbusplus::server::object::object<
35 sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
Saqib Khan942df8a2017-06-01 14:09:27 -050036
Jayashankar Padath4d3d9122019-07-24 16:46:22 +053037constexpr auto applyTimeImmediate =
38 "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
39constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
40constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
41constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
42constexpr auto applyTimeProp = "RequestedApplyTime";
43
44constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
45constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
46constexpr auto hostStateRebootProp = "RequestedHostTransition";
47constexpr auto hostStateRebootVal =
48 "xyz.openbmc_project.State.Host.Transition.Reboot";
49
Michael Tritz9d25b602017-06-14 14:41:43 -050050namespace sdbusRule = sdbusplus::bus::match::rules;
51
Saqib Khan81bac882017-06-08 12:17:01 -050052class ItemUpdater;
53class Activation;
54class RedundancyPriority;
55
Saqib Khan942df8a2017-06-01 14:09:27 -050056/** @class RedundancyPriority
57 * @brief OpenBMC RedundancyPriority implementation
58 * @details A concrete implementation for
59 * xyz.openbmc_project.Software.RedundancyPriority DBus API.
60 */
61class RedundancyPriority : public RedundancyPriorityInherit
62{
Adriana Kobylak70dcb632018-02-27 15:46:52 -060063 public:
64 /** @brief Constructs RedundancyPriority.
65 *
66 * @param[in] bus - The Dbus bus object
67 * @param[in] path - The Dbus object path
68 * @param[in] parent - Parent object.
69 * @param[in] value - The redundancyPriority value
70 */
71 RedundancyPriority(sdbusplus::bus::bus& bus, const std::string& path,
72 Activation& parent, uint8_t value) :
Albert Zhang7f1967d2020-03-02 14:12:08 +080073 RedundancyPriorityInherit(bus, path.c_str(),
74 action::emit_interface_added),
75 parent(parent)
Adriana Kobylak70dcb632018-02-27 15:46:52 -060076 {
77 // Set Property
78 priority(value);
Adriana Kobylak70dcb632018-02-27 15:46:52 -060079 }
Saqib Khan2021b4c2017-06-07 14:37:36 -050080
Adriana Kobylak70dcb632018-02-27 15:46:52 -060081 /** @brief Overloaded Priority property set function
82 *
83 * @param[in] value - uint8_t
84 *
85 * @return Success or exception thrown
86 */
87 uint8_t priority(uint8_t value) override;
Saqib Khan81bac882017-06-08 12:17:01 -050088
Adriana Kobylak70dcb632018-02-27 15:46:52 -060089 /** @brief Priority property get function
90 *
91 * @returns uint8_t - The Priority value
92 */
93 using RedundancyPriorityInherit::priority;
Saqib Khan81bac882017-06-08 12:17:01 -050094
Adriana Kobylak70dcb632018-02-27 15:46:52 -060095 /** @brief Parent Object. */
96 Activation& parent;
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{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600106 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) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800114 ActivationBlocksTransitionInherit(bus, path.c_str(),
115 action::emit_interface_added)
Adriana Kobylaka8eda562017-07-17 15:24:29 -0500116
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600117 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600118 }
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500119};
120
Michael Tritz1793b642017-06-28 18:35:58 -0500121class ActivationProgress : public ActivationProgressInherit
122{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600123 public:
124 /** @brief Constructs ActivationProgress.
125 *
126 * @param[in] bus - The Dbus bus object
127 * @param[in] path - The Dbus object path
128 */
129 ActivationProgress(sdbusplus::bus::bus& bus, const std::string& path) :
Albert Zhang7f1967d2020-03-02 14:12:08 +0800130 ActivationProgressInherit(bus, path.c_str(),
131 action::emit_interface_added)
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600132 {
133 progress(0);
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600134 }
Michael Tritz1793b642017-06-28 18:35:58 -0500135};
136
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500137/** @class Activation
138 * @brief OpenBMC activation software management implementation.
139 * @details A concrete implementation for
140 * xyz.openbmc_project.Software.Activation DBus API.
141 */
142class Activation : public ActivationInherit
143{
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600144 public:
145 /** @brief Constructs Activation Software Manager
146 *
147 * @param[in] bus - The Dbus bus object
148 * @param[in] path - The Dbus object path
149 * @param[in] parent - Parent object.
150 * @param[in] versionId - The software version id
151 * @param[in] extVersion - The extended version
152 * @param[in] activationStatus - The status of Activation
153 * @param[in] assocs - Association objects
154 */
155 Activation(sdbusplus::bus::bus& bus, const std::string& path,
Lei YUa9ac9272019-02-22 16:38:35 +0800156 ItemUpdater& parent, const std::string& versionId,
157 const std::string& extVersion,
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600158 sdbusplus::xyz::openbmc_project::Software::server::Activation::
159 Activations activationStatus,
160 AssociationList& assocs) :
161 ActivationInherit(bus, path.c_str(), true),
162 bus(bus), path(path), parent(parent), versionId(versionId),
163 systemdSignals(
164 bus,
165 sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
166 sdbusRule::path("/org/freedesktop/systemd1") +
167 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
168 std::bind(std::mem_fn(&Activation::unitStateChange), this,
169 std::placeholders::_1))
170 {
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600171 // Set Properties.
172 extendedVersion(extVersion);
173 activation(activationStatus);
174 associations(assocs);
Gunnar Mills3edb84b2017-08-18 15:13:15 -0500175
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600176 // Emit deferred signal.
177 emit_object_added();
178 }
Lei YU9b21efc2019-02-21 15:52:53 +0800179 virtual ~Activation() = default;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500180
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600181 /** @brief Overloaded requestedActivation property setter function
182 *
183 * @param[in] value - One of Activation::RequestedActivations
184 *
185 * @return Success or exception thrown
186 */
187 RequestedActivations
188 requestedActivation(RequestedActivations value) override;
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500189
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600190 /**
191 * @brief subscribe to the systemd signals
192 *
193 * This object needs to capture when it's systemd targets complete
194 * so it can keep it's state updated
195 *
196 **/
197 void subscribeToSystemdSignals();
Michael Tritz9d25b602017-06-14 14:41:43 -0500198
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600199 /**
200 * @brief unsubscribe from the systemd signals
201 *
202 * Once the activation process has completed successfully, we can
203 * safely unsubscribe from systemd signals.
204 *
205 **/
206 void unsubscribeFromSystemdSignals();
Michael Tritz1cb127f2017-07-26 15:40:38 -0500207
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600208 /** @brief Persistent sdbusplus DBus bus connection */
209 sdbusplus::bus::bus& bus;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500210
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600211 /** @brief Persistent DBus object path */
212 std::string path;
Adriana Kobylak99c8c0e2017-04-17 13:39:11 -0500213
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600214 /** @brief Parent Object. */
215 ItemUpdater& parent;
Saqib Khan81bac882017-06-08 12:17:01 -0500216
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600217 /** @brief Version id */
218 std::string versionId;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500219
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600220 /** @brief Persistent ActivationBlocksTransition dbus object */
221 std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
Saqib Khan942df8a2017-06-01 14:09:27 -0500222
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600223 /** @brief Persistent ActivationProgress dbus object */
224 std::unique_ptr<ActivationProgress> activationProgress;
Michael Tritz1793b642017-06-28 18:35:58 -0500225
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600226 /** @brief Persistent RedundancyPriority dbus object */
227 std::unique_ptr<RedundancyPriority> redundancyPriority;
Michael Tritz9d25b602017-06-14 14:41:43 -0500228
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600229 /** @brief Used to subscribe to dbus systemd signals **/
230 sdbusplus::bus::match_t systemdSignals;
Michael Tritz9d25b602017-06-14 14:41:43 -0500231
Jayashankar Padath4d3d9122019-07-24 16:46:22 +0530232 /**
233 * @brief Determine the configured image apply time value
234 *
235 * @return true if the image apply time value is immediate
236 **/
237 bool checkApplyTimeImmediate();
238
239 /**
240 * @brief Reboot the Host. Called when ApplyTime is immediate.
241 *
242 * @return none
243 **/
244 void rebootHost();
245
Lei YU9b21efc2019-02-21 15:52:53 +0800246 protected:
247 /** @brief Check if systemd state change is relevant to this object
248 *
249 * Instance specific interface to handle the detected systemd state
250 * change
251 *
252 * @param[in] msg - Data associated with subscribed signal
253 *
254 */
255 virtual void unitStateChange(sdbusplus::message::message& msg) = 0;
256
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600257 /**
258 * @brief Deletes the version from Image Manager and the
259 * untar image from image upload dir.
260 */
261 void deleteImageManagerObject();
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500262
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600263 /** @brief Member function for clarity & brevity at activation start */
Lei YU9b21efc2019-02-21 15:52:53 +0800264 virtual void startActivation() = 0;
Saqib Khan7f80e0b2017-10-22 11:29:07 -0500265
Adriana Kobylak70dcb632018-02-27 15:46:52 -0600266 /** @brief Member function for clarity & brevity at activation end */
Lei YU9b21efc2019-02-21 15:52:53 +0800267 virtual void finishActivation() = 0;
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500268
269#ifdef WANT_SIGNATURE_VERIFY
270 /**
271 * @brief Wrapper function for the signature verify function.
272 * Signature class verify function used for validating
273 * signed image. Also added additional logic to continue
274 * update process in lab environment by checking the
275 * fieldModeEnabled property.
276 *
Lei YU2b2d2292019-03-18 15:22:56 +0800277 * @param[in] pnorFileName - The PNOR filename in image dir
278 *
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500279 * @return true if successful signature validation or field
280 * mode is disabled.
281 * false for unsuccessful signature validation or
282 * any internal failure during the mapper call.
283 */
Lei YU2b2d2292019-03-18 15:22:56 +0800284 bool validateSignature(const std::string& pnorFileName);
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500285
286 /**
287 * @brief Gets the fieldModeEnabled property value.
288 *
289 * @return fieldModeEnabled property value
290 * @error InternalFailure exception thrown
291 */
292 bool fieldModeEnabled();
Jayanth Othayoth11271fb2018-03-29 10:25:50 -0500293#endif
Adriana Kobylakea9626f2017-04-05 15:37:40 -0500294};
295
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -0500296} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500297} // namespace software
298} // namespace openpower