Reliably report the BMC Ready state

A very rare corner case was found when reporting BMC Ready. The D-Bus
matching function needed to be initialized prior to reading the
associated D-Bus property and saving it to a global variable.

There was a small slice of time where the D-Bus entry could be
updated, and the associated update event dropped.

A test script was created to increase the likelihood of landing in the
critical point where the BMC Ready event is dropped.

Tested:
Ran the test script and it failed in under 30 runs.
Ran the same script on this change, which ran for 370+ passes.

Change-Id: Ic4fca745452eee392e8ff5a3f1b5f39200dfc21d
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/appcommands.cpp b/src/appcommands.cpp
index c1089c4..2d4e1a9 100644
--- a/src/appcommands.cpp
+++ b/src/appcommands.cpp
@@ -68,22 +68,6 @@
         return -1;
     }
 
-    std::string bmcState;
-    ec = ipmi::getDbusProperty(ctx, objInfo.second, objInfo.first, bmcStateIntf,
-                               currentBmcStateProp, bmcState);
-    if (ec)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "initBMCDeviceState: Failed to get CurrentBMCState property",
-            phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
-        return -1;
-    }
-
-    bmcDeviceBusy = (bmcState != bmcStateReadyStr);
-
-    phosphor::logging::log<phosphor::logging::level::INFO>(
-        "BMC device state updated");
-
     // BMC state may change runtime while doing firmware udpate.
     // Register for property change signal to update state.
     bmcStateChangedSignal = std::make_unique<sdbusplus::bus::match_t>(
@@ -118,6 +102,22 @@
             }
         });
 
+    std::string bmcState;
+    ec = ipmi::getDbusProperty(ctx, objInfo.second, objInfo.first, bmcStateIntf,
+                               currentBmcStateProp, bmcState);
+    if (ec)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "initBMCDeviceState: Failed to get CurrentBMCState property",
+            phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
+        return -1;
+    }
+
+    bmcDeviceBusy = (bmcState != bmcStateReadyStr);
+
+    phosphor::logging::log<phosphor::logging::level::INFO>(
+        "BMC device state updated");
+
     return 0;
 }