side-switch: request bmc reboot to switch to new image

The final piece is to issue a BMC reboot so the system can get over to
the image with the highest priority.

Tested:
- Set running firmware priority to 1 and ran the application. Side
  switch detection ran and BMC was rebooted. After the reboot, the
  system automatically powered on and running image was priority 0.

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Iaafea49f75ad7dd959d4c71a4de29e763f593a83
diff --git a/side-switch/side_switch.cpp b/side-switch/side_switch.cpp
index 16fe6a3..d2a2384 100644
--- a/side-switch/side_switch.cpp
+++ b/side-switch/side_switch.cpp
@@ -196,6 +196,26 @@
     return (true);
 }
 
+bool rebootTheBmc(sdbusplus::bus::bus& bus)
+{
+    try
+    {
+        utils::PropertyValue bmcReboot =
+            "xyz.openbmc_project.State.BMC.Transition.Reboot";
+
+        utils::setProperty(bus, "/xyz/openbmc_project/state/bmc0",
+                           "xyz.openbmc_project.State.BMC",
+                           "RequestedBMCTransition", bmcReboot);
+    }
+    catch (const std::exception& e)
+    {
+        error("rebooting the bmc failed: {ERROR}", "ERROR", e);
+        return (false);
+    }
+    info("BMC reboot initiated");
+    return (true);
+}
+
 int main()
 {
     info("Checking for side switch reboot");
@@ -221,5 +241,13 @@
         // switch to new firmware image so continue
     }
 
-    // TODO - Future commits in series to fill in rest of logic
+    if (!rebootTheBmc(bus))
+    {
+        error("unable to reboot the BMC");
+        // Return invalid rc to trigger systemd target recovery and appropriate
+        // error logging
+        return -1;
+    }
+
+    return 0;
 }