bmc: add mode to systemd preparation action

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: If29311cfa9eddecdd81781867598a73789225bc5
diff --git a/bmc/buildjson.cpp b/bmc/buildjson.cpp
index f817603..9de4b87 100644
--- a/bmc/buildjson.cpp
+++ b/bmc/buildjson.cpp
@@ -104,8 +104,17 @@
             if (prepareType == "systemd")
             {
                 const auto& unit = prep.at("unit");
+
+                /* the mode parameter is optional. */
+                std::string systemdMode = "replace";
+                const auto& mode = prep.find("mode");
+                if (mode != prep.end())
+                {
+                    systemdMode = prep.at("mode").get<std::string>();
+                }
+
                 pack->preparation = SystemdPreparation::CreatePreparation(
-                    sdbusplus::bus::new_default(), unit);
+                    sdbusplus::bus::new_default(), unit, systemdMode);
             }
             else
             {
diff --git a/bmc/prepare_systemd.cpp b/bmc/prepare_systemd.cpp
index b16bc99..c08fdd1 100644
--- a/bmc/prepare_systemd.cpp
+++ b/bmc/prepare_systemd.cpp
@@ -25,9 +25,10 @@
 
 std::unique_ptr<TriggerableActionInterface>
     SystemdPreparation::CreatePreparation(sdbusplus::bus::bus&& bus,
-                                          const std::string& service)
+                                          const std::string& service,
+                                          const std::string& mode)
 {
-    return std::make_unique<SystemdPreparation>(std::move(bus), service);
+    return std::make_unique<SystemdPreparation>(std::move(bus), service, mode);
 }
 
 bool SystemdPreparation::trigger()
@@ -39,7 +40,7 @@
     auto method = bus.new_method_call(systemdService, systemdRoot,
                                       systemdInterface, "StartUnit");
     method.append(triggerService);
-    method.append("replace");
+    method.append(mode);
 
     try
     {
diff --git a/bmc/prepare_systemd.hpp b/bmc/prepare_systemd.hpp
index af8e065..b8fe605 100644
--- a/bmc/prepare_systemd.hpp
+++ b/bmc/prepare_systemd.hpp
@@ -13,11 +13,13 @@
 {
   public:
     static std::unique_ptr<TriggerableActionInterface>
-        CreatePreparation(sdbusplus::bus::bus&& bus,
-                          const std::string& service);
+        CreatePreparation(sdbusplus::bus::bus&& bus, const std::string& service,
+                          const std::string& mode);
 
-    SystemdPreparation(sdbusplus::bus::bus&& bus, const std::string& service) :
-        bus(std::move(bus)), triggerService(service)
+    SystemdPreparation(sdbusplus::bus::bus&& bus, const std::string& service,
+                       const std::string& mode) :
+        bus(std::move(bus)),
+        triggerService(service), mode(mode)
     {
     }
 
@@ -34,6 +36,7 @@
   private:
     sdbusplus::bus::bus bus;
     const std::string triggerService;
+    const std::string mode;
     ActionStatus state = ActionStatus::unknown;
 };