Activation: add BMC reboot guard

BMC shall not reboot during PSU update, otherwise it has the risk of
putting the PSU in a bad state.
So add BMC reboot guard in ActivationBlocksTransition to enable reboot
guard when PSU update is started, and disable it when it's finished or
failed.

During test, it's found that the ActivationBlocksTransition is created
too early before checking the PSU compatibility, it is fixed by
constructing ActivationBlocksTransition after the check.

Tested: Verify the BMC guard is enabled and disabled during PSU update.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I405fe640929aa91ecbcb3d48e19309d38b6849e5
diff --git a/src/activation.cpp b/src/activation.cpp
index af56f28..37610c0 100644
--- a/src/activation.cpp
+++ b/src/activation.cpp
@@ -154,15 +154,6 @@
                             entry("VERSION_ID=%s", versionId.c_str()));
         return activation(); // Return the previous activation status
     }
-    if (!activationProgress)
-    {
-        activationProgress = std::make_unique<ActivationProgress>(bus, objPath);
-    }
-    if (!activationBlocksTransition)
-    {
-        activationBlocksTransition =
-            std::make_unique<ActivationBlocksTransition>(bus, objPath);
-    }
 
     auto psuPaths = utils::getPSUInventoryPath(bus);
     if (psuPaths.empty())
@@ -196,6 +187,16 @@
         return activation(); // Return the previous activation status
     }
 
+    if (!activationProgress)
+    {
+        activationProgress = std::make_unique<ActivationProgress>(bus, objPath);
+    }
+    if (!activationBlocksTransition)
+    {
+        activationBlocksTransition =
+            std::make_unique<ActivationBlocksTransition>(bus, objPath);
+    }
+
     // The progress to be increased for each successful update of PSU
     // E.g. in case we have 4 PSUs:
     //   1. Initial progrss is 10
@@ -336,6 +337,26 @@
     return service;
 }
 
+void ActivationBlocksTransition::enableRebootGuard()
+{
+    log<level::INFO>("PSU image activating - BMC reboots are disabled.");
+
+    auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+                                      SYSTEMD_INTERFACE, "StartUnit");
+    method.append("reboot-guard-enable.service", "replace");
+    bus.call_noreply_noerror(method);
+}
+
+void ActivationBlocksTransition::disableRebootGuard()
+{
+    log<level::INFO>("PSU activation has ended - BMC reboots are re-enabled.");
+
+    auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+                                      SYSTEMD_INTERFACE, "StartUnit");
+    method.append("reboot-guard-disable.service", "replace");
+    bus.call_noreply_noerror(method);
+}
+
 } // namespace updater
 } // namespace software
 } // namespace phosphor