regulators: Enhance config file parser
Enhance JSON config file parser to convert relative inventory paths to
absolute form.
Tested:
Run local CI with -Dlong-tests=enabled to enable tests for
validate-regulators-config.py.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I80237a673f9c5918898db15363847722141388e6
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 6fa34e1..123cb4d 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -236,7 +236,7 @@
// Required fru property
const json& fruElement = getRequiredProperty(element, "fru");
- std::string fru = parseString(fruElement);
+ std::string fru = parseInventoryPath(fruElement);
++propertyCount;
// Required value property
@@ -257,7 +257,7 @@
// Required fru property
const json& fruElement = getRequiredProperty(element, "fru");
- std::string fru = parseString(fruElement);
+ std::string fru = parseInventoryPath(fruElement);
++propertyCount;
// Required keyword property
@@ -331,7 +331,7 @@
// Required fru property
const json& fruElement = getRequiredProperty(element, "fru");
- std::string fru = parseString(fruElement);
+ std::string fru = parseInventoryPath(fruElement);
++propertyCount;
// Required i2c_interface property
@@ -648,6 +648,18 @@
std::move(elseActions));
}
+std::string parseInventoryPath(const json& element)
+{
+ std::string inventoryPath = parseString(element);
+ std::string absPath = "/xyz/openbmc_project/inventory";
+ if (inventoryPath.front() != '/')
+ {
+ absPath += '/';
+ }
+ absPath += inventoryPath;
+ return absPath;
+}
+
std::unique_ptr<NotAction> parseNot(const json& element)
{
// Required action to execute
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index 848ed95..4b39b7e 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -485,6 +485,21 @@
}
/**
+ * Parses a JSON element containing a relative inventory path.
+ *
+ * Returns the corresponding C++ string containing the absolute inventory path.
+ *
+ * Inventory paths in the JSON configuration file are relative. Adds the
+ * necessary prefix to make the path absolute.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return absolute D-Bus inventory path
+ */
+std::string parseInventoryPath(const nlohmann::json& element);
+
+/**
* Parses a JSON element containing a not action.
*
* Returns the corresponding C++ NotAction object.
diff --git a/phosphor-regulators/src/error_logging.cpp b/phosphor-regulators/src/error_logging.cpp
index 309d9b6..bf3467c 100644
--- a/phosphor-regulators/src/error_logging.cpp
+++ b/phosphor-regulators/src/error_logging.cpp
@@ -78,11 +78,8 @@
void DBusErrorLogging::logPMBusError(Entry::Level severity, Journal& journal,
const std::string& inventoryPath)
{
- // Convert relative inventory path to an absolute path
- std::string absInventoryPath = getAbsoluteInventoryPath(inventoryPath);
-
std::map<std::string, std::string> additionalData{};
- additionalData.emplace("CALLOUT_INVENTORY_PATH", absInventoryPath);
+ additionalData.emplace("CALLOUT_INVENTORY_PATH", inventoryPath);
logError("xyz.openbmc_project.Power.Error.PMBus", severity, additionalData,
journal);
}
@@ -90,11 +87,8 @@
void DBusErrorLogging::logWriteVerificationError(
Entry::Level severity, Journal& journal, const std::string& inventoryPath)
{
- // Convert relative inventory path to an absolute path
- std::string absInventoryPath = getAbsoluteInventoryPath(inventoryPath);
-
std::map<std::string, std::string> additionalData{};
- additionalData.emplace("CALLOUT_INVENTORY_PATH", absInventoryPath);
+ additionalData.emplace("CALLOUT_INVENTORY_PATH", inventoryPath);
logError("xyz.openbmc_project.Power.Regulators.Error.WriteVerification",
severity, additionalData, journal);
}
diff --git a/phosphor-regulators/src/error_logging.hpp b/phosphor-regulators/src/error_logging.hpp
index d1a5879..ba95561 100644
--- a/phosphor-regulators/src/error_logging.hpp
+++ b/phosphor-regulators/src/error_logging.hpp
@@ -211,26 +211,6 @@
std::vector<FFDCTuple> createFFDCTuples(std::vector<FFDCFile>& files);
/**
- * Returns the absolute form of the specified inventory path.
- *
- * The inventory paths in the JSON configuration file are relative. Add the
- * the necessary prefix to make the path absolute.
- *
- * @param inventoryPath relative D-Bus inventory path
- * @return absolute D-Bus inventory path
- */
- std::string getAbsoluteInventoryPath(const std::string& inventoryPath)
- {
- std::string absPath = "/xyz/openbmc_project/inventory";
- if ((!inventoryPath.empty()) && (inventoryPath.front() != '/'))
- {
- absPath += '/';
- }
- absPath += inventoryPath;
- return absPath;
- }
-
- /**
* Logs an error using the D-Bus CreateWithFFDCFiles method.
*
* If logging fails, a message is written to the journal but an exception is