regulators: Add phase_fault_detection to parser
Enhance the JSON configuration file parser to support the new
phase_fault_detection object.
Add gtest test cases to exercise new code.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I5b987054ef35c8b27d7d984e5e9ec9b4488bf944
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 6527b5f..430d490 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -759,6 +759,38 @@
return std::make_unique<OrAction>(std::move(actions));
}
+std::unique_ptr<PhaseFaultDetection>
+ parsePhaseFaultDetection(const json& element)
+{
+ verifyIsObject(element);
+ unsigned int propertyCount{0};
+
+ // Optional comments property; value not stored
+ if (element.contains("comments"))
+ {
+ ++propertyCount;
+ }
+
+ // Optional device_id property
+ std::string deviceID{};
+ auto deviceIDIt = element.find("device_id");
+ if (deviceIDIt != element.end())
+ {
+ deviceID = parseString(*deviceIDIt);
+ ++propertyCount;
+ }
+
+ // Required rule_id or actions property
+ std::vector<std::unique_ptr<Action>> actions{};
+ actions = parseRuleIDOrActionsProperty(element);
+ ++propertyCount;
+
+ // Verify no invalid properties exist
+ verifyPropertyCount(element, propertyCount);
+
+ return std::make_unique<PhaseFaultDetection>(std::move(actions), deviceID);
+}
+
PhaseFaultType parsePhaseFaultType(const json& element)
{
std::string value = parseString(element);