psu-ng: Call setPowerSupplyError method for fault

If/when a fault occurs, and the PSU manager is going to create an error,
also call the setPowerSupplyError D-Bus method to let the power
control/sequencer app known that a power supply error has occurred. If
an associated pgood fault also occurs, the power control/sequencer app
can make a determination of whether it is due to the power supply error.

Call setPowerSupplyError method with null string during clearing of
faults.

Tested:
    Simulated power supply faults followed by pgood fault.
        Verified power supply fault used for source of pgood fault.
    After PSU & pgood fault, poweron, try just pgood fault.
        Verified pgood fault logged.
    Real Rainier 2S2U normally fault free operation during poweron.
    Real Rainier 2S2U VIN_UV fault works as expected.
    Real Rainier 2S2U AC loss fault.
    Real Rainier 2S2U injected pgood fault (no PSU error).

Change-Id: Ia5c7c4fdcbd3b86c5184cb5bc6d93a9628747f18
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index a1b9476..3ad94cc 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -377,6 +377,31 @@
     }
 }
 
+void PSUManager::setPowerSupplyError(const std::string& psuErrorString)
+{
+    using namespace sdbusplus::xyz::openbmc_project;
+    constexpr auto service = "org.openbmc.control.Power";
+    constexpr auto objPath = "/org/openbmc/control/power0";
+    constexpr auto interface = "org.openbmc.control.Power";
+    constexpr auto method = "setPowerSupplyError";
+
+    try
+    {
+        // Call D-Bus method to inform pseq of PSU error
+        auto methodMsg =
+            bus.new_method_call(service, objPath, interface, method);
+        methodMsg.append(psuErrorString);
+        auto callReply = bus.call(methodMsg);
+    }
+    catch (const std::exception& e)
+    {
+        log<level::INFO>(
+            fmt::format("Failed calling setPowerSupplyError due to error {}",
+                        e.what())
+                .c_str());
+    }
+}
+
 void PSUManager::createError(const std::string& faultName,
                              std::map<std::string, std::string>& additionalData)
 {
@@ -405,6 +430,7 @@
         method.append(faultName, level, additionalData);
 
         auto reply = bus.call(method);
+        setPowerSupplyError(faultName);
     }
     catch (const std::exception& e)
     {