Add check for "quiesced" bmc manager state

The bmc now supports the Quiesced state, which is tracked using systemd
targets.  Previously, the bmc startup state was determined by systemd
alone.  The old systemd startup behavior is retained, but if the bmc is
found to be started, this commit also check the quiesced target to
determine if we should set that state as well.  This allows
phosphor-state-manager users to have a state that works for the quiesced
use case, while avoiding race conditions on startup, or having to impose
a hard dependency on phosphor-state-manager, which we know some users
do not use.  The reasons for not using phosphor-state-manager are
outside of the scope of this commit.

In comparison to the alternative:
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/50318

This actually seems to have a smaller diff, so while there's some
concern about adding complexity to bmcweb, this seems like this patch
gets us the same behavior with slightly less code.

Tested: Loaded onto a p10bmc and see this new state.
systemctl start obmc-bmc-service-quiesce@0.target
root@xxx:~# obmcutil state
CurrentBMCState     : xyz.openbmc_project.State.BMC.BMCState.Quiesced

curl -k https://$bmc/redfish/v1/Managers/bmc
...
 "Status": {
    "Health": "Critical",
    "State": "Quiesced"
  },

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I718b8ad0a43327051cb5fdf0da59a1ccfbde9940
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 5904f5d..b08ee51 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1888,6 +1888,29 @@
         dbus::utility::DbusVariantType(us->count()));
 }
 
+inline void
+    checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+{
+    sdbusplus::asio::getProperty<std::string>(
+        *crow::connections::systemBus, "org.freedesktop.systemd1",
+        "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
+        "org.freedesktop.systemd1.Unit", "ActiveState",
+        [asyncResp](const boost::system::error_code& ec,
+                    const std::string& val) {
+        if (!ec)
+        {
+            if (val == "active")
+            {
+                asyncResp->res.jsonValue["Status"]["Health"] = "Critical";
+                asyncResp->res.jsonValue["Status"]["State"] = "Quiesced";
+                return;
+            }
+        }
+        asyncResp->res.jsonValue["Status"]["Health"] = "OK";
+        asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
+        });
+}
+
 inline void requestRoutesManager(App& app)
 {
     std::string uuid = persistent_data::getConfig().systemUuid;
@@ -1908,8 +1931,6 @@
         asyncResp->res.jsonValue["Description"] =
             "Baseboard Management Controller";
         asyncResp->res.jsonValue["PowerState"] = "On";
-        asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
-        asyncResp->res.jsonValue["Status"]["Health"] = "OK";
 
         asyncResp->res.jsonValue["ManagerType"] = "BMC";
         asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
@@ -2030,29 +2051,25 @@
                 chassiUrl;
         });
 
-        static bool started = false;
-
-        if (!started)
-        {
-            sdbusplus::asio::getProperty<double>(
-                *crow::connections::systemBus, "org.freedesktop.systemd1",
-                "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
-                "Progress",
-                [asyncResp](const boost::system::error_code& ec,
-                            const double& val) {
-                if (ec)
-                {
-                    BMCWEB_LOG_ERROR << "Error while getting progress";
-                    messages::internalError(asyncResp->res);
-                    return;
-                }
-                if (val < 1.0)
-                {
-                    asyncResp->res.jsonValue["Status"]["State"] = "Starting";
-                    started = true;
-                }
-                });
-        }
+        sdbusplus::asio::getProperty<double>(
+            *crow::connections::systemBus, "org.freedesktop.systemd1",
+            "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
+            "Progress",
+            [asyncResp](const boost::system::error_code& ec, double val) {
+            if (ec)
+            {
+                BMCWEB_LOG_ERROR << "Error while getting progress";
+                messages::internalError(asyncResp->res);
+                return;
+            }
+            if (val < 1.0)
+            {
+                asyncResp->res.jsonValue["Status"]["Health"] = "OK";
+                asyncResp->res.jsonValue["Status"]["State"] = "Starting";
+                return;
+            }
+            checkForQuiesced(asyncResp);
+            });
 
         constexpr std::array<std::string_view, 1> interfaces = {
             "xyz.openbmc_project.Inventory.Item.Bmc"};