regulators: Make inventory_path required property

Make "inventory_path" a required property of the "chassis" object in the
regulators JSON configuration file.

This property is used to create the chassis <-> sensor associations
required by bmcweb for finding regulator sensors.

The property is already documented in the markdown file as being
required.  However, that requirement was not being enforced in the JSON
schema nor in the C++ configuration file parser.

The existing configuration files did not have the property, and
requiring it would have caused errors.

Those configuration files have been updated to include the property, so
the requirement is now being enforced.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: If9af7969f8b92068e66c750681179db70eae489e
diff --git a/phosphor-regulators/test/config_file_parser_tests.cpp b/phosphor-regulators/test/config_file_parser_tests.cpp
index c17703a..38bee22 100644
--- a/phosphor-regulators/test/config_file_parser_tests.cpp
+++ b/phosphor-regulators/test/config_file_parser_tests.cpp
@@ -105,9 +105,9 @@
                 }
               ],
               "chassis": [
-                { "number": 1 },
-                { "number": 2 },
-                { "number": 3 }
+                { "number": 1, "inventory_path": "system/chassis1" },
+                { "number": 2, "inventory_path": "system/chassis2" },
+                { "number": 3, "inventory_path": "system/chassis3" }
               ]
             }
         )"_json;
@@ -126,8 +126,14 @@
 
         EXPECT_EQ(chassis.size(), 3);
         EXPECT_EQ(chassis[0]->getNumber(), 1);
+        EXPECT_EQ(chassis[0]->getInventoryPath(),
+                  "/xyz/openbmc_project/inventory/system/chassis1");
         EXPECT_EQ(chassis[1]->getNumber(), 2);
+        EXPECT_EQ(chassis[1]->getInventoryPath(),
+                  "/xyz/openbmc_project/inventory/system/chassis2");
         EXPECT_EQ(chassis[2]->getNumber(), 3);
+        EXPECT_EQ(chassis[2]->getInventoryPath(),
+                  "/xyz/openbmc_project/inventory/system/chassis3");
     }
 
     // Test where fails: File does not exist
@@ -147,7 +153,9 @@
     {
         const json configFileContents = R"(
             {
-              "chassis": [ { "number": 1 } ]
+              "chassis": [
+                { "number": 1, "inventory_path": "system/chassis1" }
+              ]
             }
         )"_json;
 
@@ -786,13 +794,14 @@
     {
         const json element = R"(
             {
-              "number": 1
+              "number": 1,
+              "inventory_path": "system/chassis1"
             }
         )"_json;
         std::unique_ptr<Chassis> chassis = parseChassis(element);
         EXPECT_EQ(chassis->getNumber(), 1);
         EXPECT_EQ(chassis->getInventoryPath(),
-                  "/xyz/openbmc_project/inventory/system/chassis");
+                  "/xyz/openbmc_project/inventory/system/chassis1");
         EXPECT_EQ(chassis->getDevices().size(), 0);
     }
 
@@ -830,7 +839,8 @@
     {
         const json element = R"(
             {
-              "number": 0.5
+              "number": 0.5,
+              "inventory_path": "system/chassis"
             }
         )"_json;
         parseChassis(element);
@@ -881,6 +891,7 @@
         const json element = R"(
             {
               "number": 1,
+              "inventory_path": "system/chassis",
               "foo": 2
             }
         )"_json;
@@ -897,18 +908,7 @@
     {
         const json element = R"(
             {
-              "devices": [
-                {
-                  "id": "vdd_regulator",
-                  "is_regulator": true,
-                  "fru": "system/chassis/motherboard/regulator2",
-                  "i2c_interface":
-                  {
-                      "bus": 1,
-                      "address": "0x70"
-                  }
-                }
-              ]
+              "inventory_path": "system/chassis"
             }
         )"_json;
         parseChassis(element);
@@ -919,6 +919,22 @@
         EXPECT_STREQ(e.what(), "Required property missing: number");
     }
 
+    // Test where fails: Required inventory_path property not specified
+    try
+    {
+        const json element = R"(
+            {
+              "number": 1
+            }
+        )"_json;
+        parseChassis(element);
+        ADD_FAILURE() << "Should not have reached this line.";
+    }
+    catch (const std::invalid_argument& e)
+    {
+        EXPECT_STREQ(e.what(), "Required property missing: inventory_path");
+    }
+
     // Test where fails: Element is not an object
     try
     {
@@ -936,7 +952,8 @@
     {
         const json element = R"(
             {
-              "number": 0
+              "number": 0,
+              "inventory_path": "system/chassis"
             }
         )"_json;
         parseChassis(element);
@@ -953,6 +970,7 @@
         const json element = R"(
             {
               "number": 1,
+              "inventory_path": "system/chassis",
               "devices": 2
             }
         )"_json;
@@ -971,15 +989,19 @@
     {
         const json element = R"(
             [
-              { "number": 1 },
-              { "number": 2 }
+              { "number": 1, "inventory_path": "system/chassis1" },
+              { "number": 2, "inventory_path": "system/chassis2" }
             ]
         )"_json;
         std::vector<std::unique_ptr<Chassis>> chassis =
             parseChassisArray(element);
         EXPECT_EQ(chassis.size(), 2);
         EXPECT_EQ(chassis[0]->getNumber(), 1);
+        EXPECT_EQ(chassis[0]->getInventoryPath(),
+                  "/xyz/openbmc_project/inventory/system/chassis1");
         EXPECT_EQ(chassis[1]->getNumber(), 2);
+        EXPECT_EQ(chassis[1]->getInventoryPath(),
+                  "/xyz/openbmc_project/inventory/system/chassis2");
     }
 
     // Test where fails: Element is not an array
@@ -4404,7 +4426,7 @@
         const json element = R"(
             {
               "chassis": [
-                { "number": 1 }
+                { "number": 1, "inventory_path": "system/chassis" }
               ]
             }
         )"_json;
@@ -4429,8 +4451,8 @@
                 }
               ],
               "chassis": [
-                { "number": 1 },
-                { "number": 3 }
+                { "number": 1, "inventory_path": "system/chassis1" },
+                { "number": 3, "inventory_path": "system/chassis3" }
               ]
             }
         )"_json;
@@ -4483,7 +4505,7 @@
             {
               "remarks": [ "Config file for a FooBar one-chassis system" ],
               "chassis": [
-                { "number": 1 }
+                { "number": 1, "inventory_path": "system/chassis" }
               ]
             }
         )"_json;
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index 18eef6f..f6033d5 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -565,7 +565,6 @@
     {
         json configFile = validConfigFile;
         configFile["chassis"][0].erase("comments");
-        configFile["chassis"][0].erase("inventory_path");
         configFile["chassis"][0].erase("devices");
         EXPECT_JSON_VALID(configFile);
     }
@@ -576,6 +575,13 @@
         EXPECT_JSON_INVALID(configFile, "Validation failed.",
                             "'number' is a required property");
     }
+    // Invalid: test chassis with no inventory_path.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0].erase("inventory_path");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "'inventory_path' is a required property");
+    }
     // Invalid: test chassis with property comments wrong type.
     {
         json configFile = validConfigFile;
@@ -809,6 +815,7 @@
     {
         json configFile;
         configFile["chassis"][0]["number"] = 1;
+        configFile["chassis"][0]["inventory_path"] = "system/chassis";
         EXPECT_JSON_VALID(configFile);
     }
     // Valid: All properties specified
@@ -3084,6 +3091,7 @@
     {
         json configFile = validConfigFile;
         configFile["chassis"][1]["number"] = 1;
+        configFile["chassis"][1]["inventory_path"] = "system/chassis2";
         EXPECT_JSON_INVALID(configFile, "Error: Duplicate chassis number.", "");
     }
 }