side-switch: ensure both host and chassis off

Ran into an issue where the BMC reboot occurs so early in the boot that
the chassis power never changed from Off to On, so the BMC reboot was
instant. This caused an unwanted failure in a host-start service which
led to a BMC dump being generated on the subsequent BMC reboot.

Enhance the code to look for both the chassis and host to be off before
initiating the BMC reboot.

Tested:
- Verified on p10bmc hardware that the unwanted service failure no
  longer occurs and side-switch waits for both host and chassis to be
  off prior to rebooting the BMC

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Ifb5e71aeaa4dbfff7ea21fa0bdce01642a3bec37
diff --git a/side-switch/side_switch.cpp b/side-switch/side_switch.cpp
index 45b1c73..9eedae5 100644
--- a/side-switch/side_switch.cpp
+++ b/side-switch/side_switch.cpp
@@ -141,7 +141,7 @@
         return (false);
     }
 
-    // Now just wait for power to turn off
+    // Now just wait for host and power to turn off
     // Worst case is a systemd service hangs in power off for 2 minutes so
     // take that and double it to avoid any timing issues. The user has
     // requested we switch to the other side, so a lengthy delay is warranted
@@ -151,6 +151,22 @@
         std::this_thread::sleep_for(std::chrono::milliseconds(1000));
         try
         {
+            // First wait for host to be off
+            auto currentHostState = utils::getProperty<std::string>(
+                bus, "/xyz/openbmc_project/state/host0",
+                "xyz.openbmc_project.State.Host", "CurrentHostState");
+
+            if (currentHostState ==
+                "xyz.openbmc_project.State.Host.HostState.Off")
+            {
+                info("host is off");
+            }
+            else
+            {
+                continue;
+            }
+
+            // Then verify chassis power is off
             auto currentPwrState = utils::getProperty<std::string>(
                 bus, "/xyz/openbmc_project/state/chassis0",
                 "xyz.openbmc_project.State.Chassis", "CurrentPowerState");
@@ -161,6 +177,10 @@
                 info("chassis power is off");
                 return (true);
             }
+            else
+            {
+                continue;
+            }
         }
         catch (const std::exception& e)
         {