bmc: add mode json option for verification systemd

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ibe5764c4e2ad7dd938177c813c8c6706886258a2
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp
index 60575db..0be61be 100644
--- a/bmc/buildjson.cpp
+++ b/bmc/buildjson.cpp
@@ -91,9 +91,17 @@
             {
                 const auto& path = verify.at("path");
                 const auto& unit = verify.at("unit");
-                const std::string mode = "replace";
+
+                /* the mode parameter is optional. */
+                std::string systemdMode = "replace";
+                const auto& mode = verify.find("mode");
+                if (mode != verify.end())
+                {
+                    systemdMode = verify.at("mode").get<std::string>();
+                }
+
                 pack->verification = SystemdVerification::CreateVerification(
-                    sdbusplus::bus::new_default(), path, unit, mode);
+                    sdbusplus::bus::new_default(), path, unit, systemdMode);
             }
             else
             {
diff --git a/bmc/test/firmware_json_unittest.cpp b/bmc/test/firmware_json_unittest.cpp
index 8b4f130..70676bf 100644
--- a/bmc/test/firmware_json_unittest.cpp
+++ b/bmc/test/firmware_json_unittest.cpp
@@ -433,7 +433,7 @@
     EXPECT_THAT(updater->getMode(), "replace");
 }
 
-TEST(FirmwareJsonTest, VerifyValidUpdateWithMode)
+TEST(FirmwareJsonTest, VerifyValidWithModes)
 {
     auto j2 = R"(
         [{
@@ -450,7 +450,8 @@
                 "verification" : {
                     "type" : "fileSystemdVerify",
                     "unit" : "phosphor-ipmi-flash-bmc-verify.target",
-                    "path" : "/tmp/bmc.verify"
+                    "path" : "/tmp/bmc.verify",
+                    "mode" : "replace-nope"
                 },
                 "update" : {
                     "type" : "systemd",
@@ -467,6 +468,9 @@
     EXPECT_FALSE(h[0].actions == nullptr);
     EXPECT_FALSE(h[0].actions->preparation == nullptr);
     EXPECT_FALSE(h[0].actions->verification == nullptr);
+    auto verifier = reinterpret_cast<SystemdVerification*>(
+        h[0].actions->verification.get());
+    EXPECT_THAT(verifier->getMode(), "replace-nope");
     EXPECT_FALSE(h[0].actions->update == nullptr);
     auto updater =
         reinterpret_cast<SystemdUpdateMechanism*>(h[0].actions->update.get());