regulators: Stop boot if cfg file not found/valid

Stop the boot during a BMC chassison/poweron if the regulators JSON
configuration file cannot be found or is invalid.

During the boot, the regulators application configures the voltage
regulators in the system.  One of the most important voltage regulator
settings that can be changed is the output voltage.

The rules on how to configure the voltage regulators are defined in the
JSON config file.  If this file cannot be found or is invalid, the
voltage regulators cannot be configured.

That would mean that the voltage regulators would be turned on during
the boot using their hardware default settings.  It is common for some
of the hardware defaults to be incorrect, occasionally by a significant
amount.

If the hardware defaults are significantly off, it is possible that
hardware damage could occur.  For example, if the output voltage is too
high, downstream hardware components could be damaged.

For this reason, the boot needs to be stopped.  A critical error is
logged, and the executable run by the systemd service file exits with a
non-zero return code indicating failure.

Note that this behavior will only occur if the phosphor-regulators
application is being used.  The application must be explicitly enabled
using a meson build option.

Tested:
* Verified that boot is stopped if JSON config file not found/valid
  * Verified critical error logged
  * Verified regsctl exits with non-zero value causing config service to
    fail
* Verified that boot continues if JSON config file valid
* Tested with both 'obmcutil chassison' and 'obmcutil poweron'
* For complete test plan see
  https://gist.github.com/smccarney/8801cad1fe1c4ae8913e57d9474bfaac

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I211f19cd9b98daea86645611633f8943c44b0f75
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index 778e4b4..94f1431 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -22,6 +22,8 @@
 #include "rule.hpp"
 #include "utility.hpp"
 
+#include <xyz/openbmc_project/Common/error.hpp>
+
 #include <algorithm>
 #include <chrono>
 #include <exception>
@@ -101,14 +103,18 @@
     }
     else
     {
+        // Write error message to journal
         services.getJournal().logError("Unable to configure regulator devices: "
                                        "Configuration file not loaded");
-        // TODO: Log error
-    }
 
-    // TODO Configuration errors that should halt poweron,
-    // throw InternalFailure exception (or similar) to
-    // fail the call(busctl) to this method
+        // Log critical error since regulators could not be configured.  Could
+        // cause hardware damage if default regulator settings are very wrong.
+        services.getErrorLogging().logConfigFileError(Entry::Level::Critical,
+                                                      services.getJournal());
+
+        // Throw InternalFailure to propogate error status to D-Bus client
+        throw sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure{};
+    }
 }
 
 void Manager::interfacesAddedHandler(sdbusplus::message::message& msg)
@@ -331,7 +337,9 @@
         services.getJournal().logError(exception_utils::getMessages(e));
         services.getJournal().logError("Unable to load configuration file");
 
-        // TODO: Create error log entry
+        // Log error
+        services.getErrorLogging().logConfigFileError(Entry::Level::Error,
+                                                      services.getJournal());
     }
 }