PEL: Use the real system names property

There is now a 'Names' property on the new
xyz.openbmc_project.Configuration.IBMCompatibleSystem interface that the
DataInterface::getSystemNames function will read.  The existing code was
mostly a placeholder until the actual interface showed up on D-Bus.

Since the path that holds the interface is system specific, and the PEL
code should only rarely need this, the code was changed to read it on
demand instead of at caching it startup.

Since getSystemNames() no longer returns a cached value, the signature
was changed slightly to remove the reference from the returned
std::vector<std::string> value.

The UserHeader constructor used to make a call to getSystemNames every
time, and that was changed to only call it when actually necessary,
which is when there is a severity value defined in the message registry
that depends on the system name.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1d4f307ef38287b631f94dae2b8929307d129029
diff --git a/extensions/openpower-pels/user_header.cpp b/extensions/openpower-pels/user_header.cpp
index a687c55..276c506 100644
--- a/extensions/openpower-pels/user_header.cpp
+++ b/extensions/openpower-pels/user_header.cpp
@@ -69,24 +69,19 @@
     else
     {
         // Find the severity possibly dependent on the system type.
-        auto sev =
-            getSeverity(entry.severity.value(), dataIface.getSystemNames());
+        auto sev = getSeverity(entry.severity.value(), dataIface);
         if (sev)
         {
             _eventSeverity = *sev;
         }
         else
         {
-            // Someone screwed up the message registry.
+            // Either someone  screwed up the message registry
+            // or getSystemNames failed.
             std::string types;
-            const auto& compatibles = dataIface.getSystemNames();
-            std::for_each(compatibles.begin(), compatibles.end(),
-                          [&types](const auto& t) { types += t + '|'; });
-
             log<level::ERR>(
-                "No severity entry found for this error and system name",
-                phosphor::logging::entry("ERROR=%s", entry.name.c_str()),
-                phosphor::logging::entry("SYSTEMNAMES=%s", types.c_str()));
+                "Failed finding the severity in the message registry",
+                phosphor::logging::entry("ERROR=%s", entry.name.c_str()));
 
             // Have to choose something, just use informational.
             _eventSeverity = 0;
@@ -199,9 +194,27 @@
 
 std::optional<uint8_t> UserHeader::getSeverity(
     const std::vector<message::RegistrySeverity>& severities,
-    const std::vector<std::string>& systemNames) const
+    const DataInterfaceBase& dataIface) const
 {
     const uint8_t* s = nullptr;
+    std::vector<std::string> systemNames;
+
+    // getSystemNames makes D-Bus calls, so only call it if we
+    // know we'll need it because there is a system name in the sev list
+    if (std::any_of(severities.begin(), severities.end(),
+                    [](const auto& sev) { return !sev.system.empty(); }))
+    {
+        try
+        {
+            systemNames = dataIface.getSystemNames();
+        }
+        catch (const std::exception& e)
+        {
+            log<level::ERR>("Failed trying to look up system names on D-Bus",
+                            entry("ERROR=%s", e.what()));
+            return std::nullopt;
+        }
+    }
 
     // Find the severity to use for this system type, or use the default
     // entry (where no system type is specified).