summaryrefslogtreecommitdiffstats
path: root/bmc
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2019-08-05 09:58:27 -0700
committerPatrick Venture <venture@google.com>2019-08-05 10:33:45 -0700
commit0caec99f7851fc72bb262627dfbac587f64709a2 (patch)
tree5608247b586e21818a381379760ecb4c526d3972 /bmc
parentec105dda9ce4e764f28cfa91a34e2d9fa9730eaf (diff)
downloadphosphor-ipmi-flash-0caec99f7851fc72bb262627dfbac587f64709a2.tar.gz
phosphor-ipmi-flash-0caec99f7851fc72bb262627dfbac587f64709a2.zip
bmc: json configuration: update: add mode parameter
Add the mode parameter as an optional configuration option for the update systemd approach. Previously this was hard-coded as "replace" but now the user can specify something else. Signed-off-by: Patrick Venture <venture@google.com> Change-Id: I2bcb61bd9ac5733df6da70f901516d26bd31e2a9
Diffstat (limited to 'bmc')
-rw-r--r--bmc/buildjson.cpp11
-rw-r--r--bmc/test/firmware_json_unittest.cpp44
-rw-r--r--bmc/update_systemd.cpp5
-rw-r--r--bmc/update_systemd.hpp2
4 files changed, 61 insertions, 1 deletions
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp
index aec9a09..d8a9ea1 100644
--- a/bmc/buildjson.cpp
+++ b/bmc/buildjson.cpp
@@ -112,8 +112,17 @@ std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data)
else if (updateType == "systemd")
{
const auto& unit = update.at("unit");
+
+ /* the mode parameter is optional. */
+ std::string systemdMode = "replace";
+ const auto& mode = update.find("mode");
+ if (mode != update.end())
+ {
+ systemdMode = update.at("mode").get<std::string>();
+ }
+
pack->update = SystemdUpdateMechanism::CreateSystemdUpdate(
- sdbusplus::bus::new_default(), unit, "replace");
+ sdbusplus::bus::new_default(), unit, systemdMode);
}
else
{
diff --git a/bmc/test/firmware_json_unittest.cpp b/bmc/test/firmware_json_unittest.cpp
index 704243b..04c0f09 100644
--- a/bmc/test/firmware_json_unittest.cpp
+++ b/bmc/test/firmware_json_unittest.cpp
@@ -1,4 +1,5 @@
#include "buildjson.hpp"
+#include "update_systemd.hpp"
#include <nlohmann/json.hpp>
@@ -423,6 +424,49 @@ TEST(FirmwareJsonTest, VerifyValidSingleNonReboot)
EXPECT_FALSE(h[0].actions->preparation == nullptr);
EXPECT_FALSE(h[0].actions->verification == nullptr);
EXPECT_FALSE(h[0].actions->update == nullptr);
+ auto updater =
+ reinterpret_cast<SystemdUpdateMechanism*>(h[0].actions->update.get());
+ EXPECT_THAT(updater->getMode(), "replace");
+}
+
+TEST(FirmwareJsonTest, VerifyValidUpdateWithMode)
+{
+ auto j2 = R"(
+ [{
+ "blob" : "/flash/image",
+ "handler" : {
+ "type" : "file",
+ "path" : "/run/initramfs/bmc-image"
+ },
+ "actions" : {
+ "preparation" : {
+ "type" : "systemd",
+ "unit" : "phosphor-ipmi-flash-bmc-prepare.target"
+ },
+ "verification" : {
+ "type" : "fileSystemdVerify",
+ "unit" : "phosphor-ipmi-flash-bmc-verify.target",
+ "path" : "/tmp/bmc.verify"
+ },
+ "update" : {
+ "type" : "systemd",
+ "mode" : "replace-fake",
+ "unit" : "phosphor-ipmi-flash-bmc-update.target"
+ }
+ }
+ }]
+ )"_json;
+
+ auto h = buildHandlerFromJson(j2);
+ EXPECT_EQ(h[0].blobId, "/flash/image");
+ EXPECT_FALSE(h[0].handler == nullptr);
+ EXPECT_FALSE(h[0].actions == nullptr);
+ EXPECT_FALSE(h[0].actions->preparation == nullptr);
+ EXPECT_FALSE(h[0].actions->verification == nullptr);
+ EXPECT_FALSE(h[0].actions->update == nullptr);
+ auto updater =
+ reinterpret_cast<SystemdUpdateMechanism*>(h[0].actions->update.get());
+ EXPECT_THAT(updater->getMode(), "replace-fake");
}
} // namespace
diff --git a/bmc/update_systemd.cpp b/bmc/update_systemd.cpp
index 92c97c8..afd4316 100644
--- a/bmc/update_systemd.cpp
+++ b/bmc/update_systemd.cpp
@@ -69,4 +69,9 @@ ActionStatus SystemdUpdateMechanism::status()
return ActionStatus::running;
}
+const std::string SystemdUpdateMechanism::getMode() const
+{
+ return mode;
+}
+
} // namespace ipmi_flash
diff --git a/bmc/update_systemd.hpp b/bmc/update_systemd.hpp
index fe0ab33..a8dd8fc 100644
--- a/bmc/update_systemd.hpp
+++ b/bmc/update_systemd.hpp
@@ -36,6 +36,8 @@ class SystemdUpdateMechanism : public TriggerableActionInterface
void abort() override;
ActionStatus status() override;
+ const std::string getMode() const;
+
private:
sdbusplus::bus::bus bus;
const std::string target;
OpenPOWER on IntegriCloud