psu-ng: Move model validation to its own function
Move the model validation to a separate function so that it can be used
in a subsequent commit to get the psu count from the supported
configurations map. The supported configurations maps a psu model name
to the expected psu characteristics, so by knowing the model name, it
can be used to get the expected psu information for that system.
Tested: The validation function works as before.
Change-Id: I3494f68721131b4a42af2ad9e1889ad2e340d4e2
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 8e1be6a..e5d4dfb 100644
--- a/phosphor-power-supply/psu_manager.cpp
+++ b/phosphor-power-supply/psu_manager.cpp
@@ -485,29 +485,10 @@
bool PSUManager::hasRequiredPSUs(
std::map<std::string, std::string>& additionalData)
{
- // 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.
std::string model{};
- for (const auto& psu : psus)
+ if (!validateModelName(model, additionalData))
{
- auto psuModel = psu->getModelName();
- if (psuModel.empty())
- {
- continue;
- }
- if (model.empty())
- {
- model = psuModel;
- continue;
- }
- if (psuModel != model)
- {
- additionalData["EXPECTED_MODEL"] = model;
- additionalData["ACTUAL_MODEL"] = psuModel;
- additionalData["CALLOUT_INVENTORY_PATH"] = psu->getInventoryPath();
- return false;
- }
+ return false;
}
auto presentCount =
@@ -578,4 +559,35 @@
return false;
}
+bool PSUManager::validateModelName(
+ std::string& model, std::map<std::string, std::string>& additionalData)
+{
+ // 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.
+ model.clear();
+ for (const auto& psu : psus)
+ {
+ auto psuModel = psu->getModelName();
+ if (psuModel.empty())
+ {
+ continue;
+ }
+ if (model.empty())
+ {
+ model = psuModel;
+ continue;
+ }
+ if (psuModel != model)
+ {
+ additionalData["EXPECTED_MODEL"] = model;
+ additionalData["ACTUAL_MODEL"] = psuModel;
+ additionalData["CALLOUT_INVENTORY_PATH"] = psu->getInventoryPath();
+ model.clear();
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace phosphor::power::manager
diff --git a/phosphor-power-supply/psu_manager.hpp b/phosphor-power-supply/psu_manager.hpp
index 085f11e..e54f536 100644
--- a/phosphor-power-supply/psu_manager.hpp
+++ b/phosphor-power-supply/psu_manager.hpp
@@ -263,6 +263,17 @@
bool hasRequiredPSUs(std::map<std::string, std::string>& additionalData);
/**
+ * @brief Helper function to validate that all PSUs have the same model name
+ *
+ * @param[out] model - The model name. Empty if there is a mismatch.
+ * @param[out] additionalData - If there is a mismatch, it contains debug
+ * information such as the mismatched model name.
+ * @return true if all the PSUs have the same model name, false otherwise.
+ */
+ bool validateModelName(std::string& model,
+ std::map<std::string, std::string>& additionalData);
+
+ /**
* @brief Map of supported PSU configurations that include the model name
* and their properties.
*/