-
Notifications
You must be signed in to change notification settings - Fork 10
/
activation.hpp
298 lines (259 loc) · 9.79 KB
/
activation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#pragma once
#include "config.h"
#include "utils.hpp"
#include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
#include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
#include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Association/Definitions/server.hpp>
#include <xyz/openbmc_project/Software/Activation/server.hpp>
#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
#include <string>
namespace openpower
{
namespace software
{
namespace updater
{
using AssociationList =
std::vector<std::tuple<std::string, std::string, std::string>>;
using ActivationInherit = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
sdbusplus::xyz::openbmc_project::Software::server::Activation,
sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
using ActivationBlocksTransitionInherit =
sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::Software::
server::ActivationBlocksTransition>;
using RedundancyPriorityInherit = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
using ActivationProgressInherit = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
constexpr auto applyTimeImmediate =
"xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate";
constexpr auto applyTimeIntf = "xyz.openbmc_project.Software.ApplyTime";
constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
constexpr auto applyTimeObjPath = "/xyz/openbmc_project/software/apply_time";
constexpr auto applyTimeProp = "RequestedApplyTime";
constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host";
constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
constexpr auto hostStateRebootProp = "RequestedHostTransition";
constexpr auto hostStateRebootVal =
"xyz.openbmc_project.State.Host.Transition.Reboot";
namespace sdbusRule = sdbusplus::bus::match::rules;
class ItemUpdater;
class Activation;
class RedundancyPriority;
/** @class RedundancyPriority
* @brief OpenBMC RedundancyPriority implementation
* @details A concrete implementation for
* xyz.openbmc_project.Software.RedundancyPriority DBus API.
*/
class RedundancyPriority : public RedundancyPriorityInherit
{
public:
/** @brief Constructs RedundancyPriority.
*
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
* @param[in] parent - Parent object.
* @param[in] value - The redundancyPriority value
*/
RedundancyPriority(sdbusplus::bus_t& bus, const std::string& path,
Activation& parent, uint8_t value) :
RedundancyPriorityInherit(bus, path.c_str(),
action::emit_interface_added),
parent(parent)
{
// Set Property
priority(value);
}
/** @brief Overloaded Priority property set function
*
* @param[in] value - uint8_t
*
* @return Success or exception thrown
*/
uint8_t priority(uint8_t value) override;
/** @brief Priority property get function
*
* @returns uint8_t - The Priority value
*/
using RedundancyPriorityInherit::priority;
/** @brief Parent Object. */
Activation& parent;
};
/** @class ActivationBlocksTransition
* @brief OpenBMC ActivationBlocksTransition implementation.
* @details A concrete implementation for
* xyz.openbmc_project.Software.ActivationBlocksTransition DBus API.
*/
class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
{
public:
/** @brief Constructs ActivationBlocksTransition.
*
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
*/
ActivationBlocksTransition(sdbusplus::bus_t& bus, const std::string& path) :
ActivationBlocksTransitionInherit(bus, path.c_str(),
action::emit_interface_added)
{}
};
class ActivationProgress : public ActivationProgressInherit
{
public:
/** @brief Constructs ActivationProgress.
*
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
*/
ActivationProgress(sdbusplus::bus_t& bus, const std::string& path) :
ActivationProgressInherit(bus, path.c_str(),
action::emit_interface_added)
{
progress(0);
}
};
/** @class Activation
* @brief OpenBMC activation software management implementation.
* @details A concrete implementation for
* xyz.openbmc_project.Software.Activation DBus API.
*/
class Activation : public ActivationInherit
{
public:
/** @brief Constructs Activation Software Manager
*
* @param[in] bus - The Dbus bus object
* @param[in] path - The Dbus object path
* @param[in] parent - Parent object.
* @param[in] versionId - The software version id
* @param[in] extVersion - The extended version
* @param[in] activationStatus - The status of Activation
* @param[in] assocs - Association objects
*/
Activation(sdbusplus::bus_t& bus, const std::string& path,
ItemUpdater& parent, const std::string& versionId,
const std::string& extVersion,
sdbusplus::xyz::openbmc_project::Software::server::Activation::
Activations activationStatus,
AssociationList& assocs) :
ActivationInherit(bus, path.c_str(),
ActivationInherit::action::defer_emit),
bus(bus), path(path), parent(parent), versionId(versionId),
systemdSignals(
bus,
sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
sdbusRule::path("/org/freedesktop/systemd1") +
sdbusRule::interface("org.freedesktop.systemd1.Manager"),
std::bind(std::mem_fn(&Activation::unitStateChange), this,
std::placeholders::_1))
{
// Set Properties.
extendedVersion(extVersion);
activation(activationStatus);
associations(assocs);
// Emit deferred signal.
emit_object_added();
}
virtual ~Activation() = default;
/** @brief Overloaded requestedActivation property setter function
*
* @param[in] value - One of Activation::RequestedActivations
*
* @return Success or exception thrown
*/
RequestedActivations
requestedActivation(RequestedActivations value) override;
/**
* @brief subscribe to the systemd signals
*
* This object needs to capture when it's systemd targets complete
* so it can keep it's state updated
*
**/
void subscribeToSystemdSignals();
/**
* @brief unsubscribe from the systemd signals
*
* Once the activation process has completed successfully, we can
* safely unsubscribe from systemd signals.
*
**/
void unsubscribeFromSystemdSignals();
/** @brief Persistent sdbusplus DBus bus connection */
sdbusplus::bus_t& bus;
/** @brief Persistent DBus object path */
std::string path;
/** @brief Parent Object. */
ItemUpdater& parent;
/** @brief Version id */
std::string versionId;
/** @brief Persistent ActivationBlocksTransition dbus object */
std::unique_ptr<ActivationBlocksTransition> activationBlocksTransition;
/** @brief Persistent ActivationProgress dbus object */
std::unique_ptr<ActivationProgress> activationProgress;
/** @brief Persistent RedundancyPriority dbus object */
std::unique_ptr<RedundancyPriority> redundancyPriority;
/** @brief Used to subscribe to dbus systemd signals **/
sdbusplus::bus::match_t systemdSignals;
/**
* @brief Determine the configured image apply time value
*
* @return true if the image apply time value is immediate
**/
bool checkApplyTimeImmediate();
/**
* @brief Reboot the Host. Called when ApplyTime is immediate.
*
* @return none
**/
void rebootHost();
protected:
/** @brief Check if systemd state change is relevant to this object
*
* Instance specific interface to handle the detected systemd state
* change
*
* @param[in] msg - Data associated with subscribed signal
*
*/
virtual void unitStateChange(sdbusplus::message_t& msg) = 0;
/**
* @brief Deletes the version from Image Manager and the
* untar image from image upload dir.
*/
void deleteImageManagerObject();
/** @brief Member function for clarity & brevity at activation start */
virtual void startActivation() = 0;
/** @brief Member function for clarity & brevity at activation end */
virtual void finishActivation() = 0;
#ifdef WANT_SIGNATURE_VERIFY
/**
* @brief Wrapper function for the signature verify function.
* Signature class verify function used for validating
* signed image. Also added additional logic to continue
* update process in lab environment by checking the
* fieldModeEnabled property.
*
* @param[in] pnorFileName - The PNOR filename in image dir
*
* @return true if successful signature validation or field
* mode is disabled.
* false for unsuccessful signature validation or
* any internal failure during the mapper call.
*/
bool validateSignature(const std::string& pnorFileName);
/**
* @brief Gets the fieldModeEnabled property value.
*
* @return fieldModeEnabled property value
* @error InternalFailure exception thrown
*/
bool fieldModeEnabled();
#endif
};
} // namespace updater
} // namespace software
} // namespace openpower