psu-ng: Check if mismatched PSU is supported

The function that checks that all PSUs have the same model currently
calls out the first mismatched PSU. If the mismatched PSU is listed in
the supported configurations and the base model is not, the error log
may cause confusion because it would indicate in the callout data to
replace the PSU that it is supposed to be supported instead of the one
that it is not supported on that system.

Therefore check the supported configurations to determine which PSU to
callout in case of a mismatch.

Tested: On p10bmc with ps0 model 2B1D (no supported) and ps1 model 2B1E
(supported):
- Before change:
    "ACTUAL_MODEL": "2B1E",
    "CALLOUT_INVENTORY_PATH":
"/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1",
    "EXPECTED_MODEL": "2B1D",
- After change:
    "ACTUAL_MODEL": "2B1D",
    "CALLOUT_INVENTORY_PATH":
"/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0",
    "EXPECTED_MODEL": "2B1E",

Change-Id: I0b2d487e12f55e08a93e77b6c569726dde9d4e68
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/phosphor-power-supply/psu_manager.cpp b/phosphor-power-supply/psu_manager.cpp
index ac0901b..085f059 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -720,8 +720,10 @@
 {
     // Check that all PSUs have the same model name. Initialize the model
     // variable with the first PSU name found, then use it as a base to compare
-    // against the rest of the PSUs.
+    // against the rest of the PSUs and get its inventory path to use as callout
+    // if needed.
     model.clear();
+    std::string modelInventoryPath{};
     for (const auto& psu : psus)
     {
         auto psuModel = psu->getModelName();
@@ -732,13 +734,38 @@
         if (model.empty())
         {
             model = psuModel;
+            modelInventoryPath = psu->getInventoryPath();
             continue;
         }
         if (psuModel != model)
         {
-            additionalData["EXPECTED_MODEL"] = model;
-            additionalData["ACTUAL_MODEL"] = psuModel;
-            additionalData["CALLOUT_INVENTORY_PATH"] = psu->getInventoryPath();
+            if (supportedConfigs.find(model) != supportedConfigs.end())
+            {
+                // The base model is supported, callout the mismatched PSU. The
+                // mismatched PSU may or may not be supported.
+                additionalData["EXPECTED_MODEL"] = model;
+                additionalData["ACTUAL_MODEL"] = psuModel;
+                additionalData["CALLOUT_INVENTORY_PATH"] =
+                    psu->getInventoryPath();
+            }
+            else if (supportedConfigs.find(psuModel) != supportedConfigs.end())
+            {
+                // The base model is not supported, but the mismatched PSU is,
+                // callout the base PSU.
+                additionalData["EXPECTED_MODEL"] = psuModel;
+                additionalData["ACTUAL_MODEL"] = model;
+                additionalData["CALLOUT_INVENTORY_PATH"] = modelInventoryPath;
+            }
+            else
+            {
+                // The base model and the mismatched PSU are not supported or
+                // could not be found in the supported configuration, callout
+                // the mismatched PSU.
+                additionalData["EXPECTED_MODEL"] = model;
+                additionalData["ACTUAL_MODEL"] = psuModel;
+                additionalData["CALLOUT_INVENTORY_PATH"] =
+                    psu->getInventoryPath();
+            }
             model.clear();
             return false;
         }