pseq: Modify JSON parsing for entire file

Modify functions that parse the entire JSON configuration file for the
phosphor-power-sequencer application. Parse the new top level JSON
properties.

Tested:
* Ran automated tests

Change-Id: I08f20fc09aa4eff5bc819398834afac61054f8db
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-power-sequencer/src/config_file_parser.cpp b/phosphor-power-sequencer/src/config_file_parser.cpp
index 9e4a18d..44c7877 100644
--- a/phosphor-power-sequencer/src/config_file_parser.cpp
+++ b/phosphor-power-sequencer/src/config_file_parser.cpp
@@ -74,7 +74,8 @@
     return pathName;
 }
 
-std::vector<std::unique_ptr<Rail>> parse(const std::filesystem::path& pathName)
+std::vector<std::unique_ptr<Chassis>> parse(
+    const std::filesystem::path& pathName, Services& services)
 {
     try
     {
@@ -83,7 +84,7 @@
         json rootElement = json::parse(file);
 
         // Parse tree of JSON elements and return corresponding C++ objects
-        return internal::parseRoot(rootElement);
+        return internal::parseRoot(rootElement, services);
     }
     catch (const std::exception& e)
     {
@@ -482,23 +483,37 @@
     return rails;
 }
 
-std::vector<std::unique_ptr<Rail>> parseRoot(const json& element)
+std::vector<std::unique_ptr<Chassis>> parseRoot(const json& element,
+                                                Services& services)
 {
-    std::map<std::string, std::string> variables{};
-
     verifyIsObject(element);
     unsigned int propertyCount{0};
 
-    // Required rails property
-    const json& railsElement = getRequiredProperty(element, "rails");
-    std::vector<std::unique_ptr<Rail>> rails =
-        parseRailArray(railsElement, variables);
+    // Optional comments property; value not stored
+    if (element.contains("comments"))
+    {
+        ++propertyCount;
+    }
+
+    // Optional chassis_templates property
+    std::map<std::string, JSONRefWrapper> chassisTemplates{};
+    auto chassisTemplatesIt = element.find("chassis_templates");
+    if (chassisTemplatesIt != element.end())
+    {
+        chassisTemplates = parseChassisTemplateArray(*chassisTemplatesIt);
+        ++propertyCount;
+    }
+
+    // Required chassis property
+    const json& chassisElement = getRequiredProperty(element, "chassis");
+    std::vector<std::unique_ptr<Chassis>> chassis =
+        parseChassisArray(chassisElement, chassisTemplates, services);
     ++propertyCount;
 
     // Verify no invalid properties exist
     verifyPropertyCount(element, propertyCount);
 
-    return rails;
+    return chassis;
 }
 
 std::map<std::string, std::string> parseVariables(const json& element)
diff --git a/phosphor-power-sequencer/src/config_file_parser.hpp b/phosphor-power-sequencer/src/config_file_parser.hpp
index f43ad0e..b5b54fb 100644
--- a/phosphor-power-sequencer/src/config_file_parser.hpp
+++ b/phosphor-power-sequencer/src/config_file_parser.hpp
@@ -69,14 +69,16 @@
 /**
  * Parses the specified JSON configuration file.
  *
- * Returns the corresponding C++ Rail objects.
+ * Returns the corresponding C++ Chassis objects.
  *
  * Throws a ConfigFileParserError if an error occurs.
  *
  * @param pathName configuration file path name
- * @return vector of Rail objects
+ * @param services system services like hardware presence and the journal
+ * @return vector of Chassis objects
  */
-std::vector<std::unique_ptr<Rail>> parse(const std::filesystem::path& pathName);
+std::vector<std::unique_ptr<Chassis>> parse(
+    const std::filesystem::path& pathName, Services& services);
 
 /*
  * Internal implementation details for parse()
@@ -270,14 +272,16 @@
 /**
  * Parses the JSON root element of the entire configuration file.
  *
- * Returns the corresponding C++ Rail objects.
+ * Returns the corresponding C++ Chassis objects.
  *
  * Throws an exception if parsing fails.
  *
  * @param element JSON element
- * @return vector of Rail objects
+ * @param services system services like hardware presence and the journal
+ * @return vector of Chassis objects
  */
-std::vector<std::unique_ptr<Rail>> parseRoot(const json& element);
+std::vector<std::unique_ptr<Chassis>> parseRoot(const json& element,
+                                                Services& services);
 
 /**
  * Parses a JSON element containing an object with variable names and values.
diff --git a/phosphor-power-sequencer/src/power_control.cpp b/phosphor-power-sequencer/src/power_control.cpp
index fa43ff9..4b8315c 100644
--- a/phosphor-power-sequencer/src/power_control.cpp
+++ b/phosphor-power-sequencer/src/power_control.cpp
@@ -371,14 +371,14 @@
 }
 
 bool PowerControl::parseConfigFile(const std::filesystem::path& configFile,
-                                   std::vector<std::unique_ptr<Rail>>& rails)
+                                   std::vector<std::unique_ptr<Rail>>&)
 {
     // Parse JSON configuration file
     bool wasParsed{false};
     try
     {
-        rails = config_file_parser::parse(configFile);
-        wasParsed = true;
+        config_file_parser::parse(configFile, services);
+        // wasParsed = true;
     }
     catch (const std::exception& e)
     {