OpenPOWER: Allow initiating mp reboot dump in quiesced state

When system dumps are disabled, a system dump collection
request will end up in quiesced state.  A memory preserving
reboot from that state can get the failed data from the host.
So enabling the mp reboot dump collection from quiesced state.

Test:
Disable dump
Inject error in host to move to quiesced state
Start mp reboot
Dump should be generated

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I9f444752b321f1ab47b99e5b8ac32c79182d6453
diff --git a/dump_utils.cpp b/dump_utils.cpp
index 830cce5..45f4153 100644
--- a/dump_utils.cpp
+++ b/dump_utils.cpp
@@ -55,19 +55,37 @@
         "xyz.openbmc_project.State.Boot.Progress";
     // TODO Need to change host instance if multiple instead "0"
     constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
+    auto value =
+        getStateValue(bootProgressInterface, hostStateObjPath, "BootProgress");
+    return sdbusplus::xyz::openbmc_project::State::Boot::server::Progress::
+        convertProgressStagesFromString(value);
+}
 
-    BootProgress bootProgessStage;
+HostState getHostState()
+{
+    constexpr auto hostStateInterface = "xyz.openbmc_project.State.Host";
+    // TODO Need to change host instance if multiple instead "0"
+    constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
+    auto value =
+        getStateValue(hostStateInterface, hostStateObjPath, "CurrentHostState");
+    return sdbusplus::xyz::openbmc_project::State::server::Host::
+        convertHostStateFromString(value);
+}
 
+std::string getStateValue(const std::string& intf, const std::string& objPath,
+                          const std::string& state)
+{
+    std::string stateVal;
     try
     {
         auto bus = sdbusplus::bus::new_default();
-        auto service = getService(bus, hostStateObjPath, bootProgressInterface);
+        auto service = getService(bus, objPath, intf);
 
         auto method =
-            bus.new_method_call(service.c_str(), hostStateObjPath,
+            bus.new_method_call(service.c_str(), objPath.c_str(),
                                 "org.freedesktop.DBus.Properties", "Get");
 
-        method.append(bootProgressInterface, "BootProgress");
+        method.append(intf, state);
 
         auto reply = bus.call(method);
 
@@ -78,32 +96,27 @@
 
         reply.read(propertyVal);
 
-        // BootProgress property type is string
-        std::string bootPgs(std::get<std::string>(propertyVal));
-
-        bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot::
-            server::Progress::convertProgressStagesFromString(bootPgs);
+        stateVal = std::get<std::string>(propertyVal);
     }
     catch (const sdbusplus::exception_t& e)
     {
         log<level::ERR>(fmt::format("D-Bus call exception, OBJPATH({}), "
-                                    "INTERFACE({}), EXCEPTION({})",
-                                    hostStateObjPath, bootProgressInterface,
-                                    e.what())
+                                    "INTERFACE({}), PROPERTY({}) EXCEPTION({})",
+                                    objPath, intf, state, e.what())
                             .c_str());
-        throw std::runtime_error("Failed to get BootProgress stage");
+        throw std::runtime_error("Failed to get state property");
     }
     catch (const std::bad_variant_access& e)
     {
         log<level::ERR>(
-            fmt::format("Exception raised while read BootProgress property "
+            fmt::format("Exception raised while read host state({}) property "
                         "value,  OBJPATH({}), INTERFACE({}), EXCEPTION({})",
-                        hostStateObjPath, bootProgressInterface, e.what())
+                        state, objPath, intf, e.what())
                 .c_str());
-        throw std::runtime_error("Failed to get BootProgress stage");
+        throw std::runtime_error("Failed to get host state property");
     }
 
-    return bootProgessStage;
+    return stateVal;
 }
 
 bool isHostRunning()
@@ -121,5 +134,10 @@
     }
     return false;
 }
+
+bool isHostQuiesced()
+{
+    return (phosphor::dump::getHostState() == HostState::Quiesced);
+}
 } // namespace dump
 } // namespace phosphor