regulators: Add inventory_path to JSON chassis obj

Add the property "inventory_path" to the "chassis" object in the JSON
configuration file.

This property will be used to create the required D-Bus association
between a voltage regulator sensor and the chassis that contains it.
This association is required by the Redfish support.

Long term, this new property will be required.  That is how it is
documented in the updated version of chassis.md.

However, it will be temporarily optional in the JSON schema and the C++
configuration file parser.  This temporary measure will be removed once
all known JSON configuration files have been updated to specify the new
property.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I45f5e8ec86be7672a33099c94c35328862ffe11b
diff --git a/phosphor-regulators/config_files/ibm_everest.json b/phosphor-regulators/config_files/ibm_everest.json
index d0fe229..014815a 100644
--- a/phosphor-regulators/config_files/ibm_everest.json
+++ b/phosphor-regulators/config_files/ibm_everest.json
@@ -87,7 +87,8 @@
     {
       "comments": [ "Chassis (drawer) 1",
                     "Note: Devices not defined yet" ],
-      "number": 1
+      "number": 1,
+      "inventory_path": "system/chassis"
     }
   ]
 }
diff --git a/phosphor-regulators/config_files/ibm_rainier.json b/phosphor-regulators/config_files/ibm_rainier.json
index 83f4956..d7ede78 100644
--- a/phosphor-regulators/config_files/ibm_rainier.json
+++ b/phosphor-regulators/config_files/ibm_rainier.json
@@ -60,7 +60,8 @@
     {
       "comments": [ "Chassis (drawer) 1",
                     "Note: Devices not defined yet" ],
-      "number": 1
+      "number": 1,
+      "inventory_path": "system/chassis"
     }
   ]
 }
diff --git a/phosphor-regulators/docs/config_file/chassis.md b/phosphor-regulators/docs/config_file/chassis.md
index e3e52d0..1fb0aa6 100644
--- a/phosphor-regulators/docs/config_file/chassis.md
+++ b/phosphor-regulators/docs/config_file/chassis.md
@@ -15,6 +15,7 @@
 | :--- | :------: | :--- | :---------- |
 | comments | no | array of strings | One or more comment lines describing this chassis. |
 | number | yes | number | Chassis number within the system.  Chassis numbers start at 1 because chassis 0 represents the entire system. |
+| inventory_path | yes | string | Specify the relative D-Bus inventory path of the chassis.  Full inventory paths begin with the root "/xyz/openbmc_project/inventory".  Specify the relative path below the root, such as "system/chassis". |
 | devices | no | array of [devices](device.md) | One or more devices within the chassis.  The array should contain regulator devices and any related devices required to perform regulator operations. |
 
 ## Example
@@ -22,6 +23,7 @@
 {
   "comments": [ "Chassis number 1 containing CPUs and memory" ],
   "number": 1,
+  "inventory_path": "system/chassis",
   "devices": [
     {
       "id": "vdd_regulator",
diff --git a/phosphor-regulators/docs/config_file/config_file.md b/phosphor-regulators/docs/config_file/config_file.md
index dec3ba1..71a7818 100644
--- a/phosphor-regulators/docs/config_file/config_file.md
+++ b/phosphor-regulators/docs/config_file/config_file.md
@@ -27,6 +27,7 @@
   "chassis": [
     {
       "number": 1,
+      "inventory_path": "system/chassis",
       "devices": [
         ... details omitted ...
       ]
diff --git a/phosphor-regulators/examples/config.json b/phosphor-regulators/examples/config.json
index f18237e..711fa74 100644
--- a/phosphor-regulators/examples/config.json
+++ b/phosphor-regulators/examples/config.json
@@ -52,6 +52,7 @@
     {
       "comments": [ "Chassis number 1 containing CPUs and memory" ],
       "number": 1,
+      "inventory_path": "system/chassis",
       "devices": [
         {
           "comments": [ "IR35221 regulator producing the Vdd rail" ],
diff --git a/phosphor-regulators/schema/config_schema.json b/phosphor-regulators/schema/config_schema.json
index 681c66f..c6ef268 100644
--- a/phosphor-regulators/schema/config_schema.json
+++ b/phosphor-regulators/schema/config_schema.json
@@ -136,7 +136,7 @@
             "type": "object",
             "properties":
             {
-                "fru": {"$ref": "#/definitions/fru" },
+                "fru": {"$ref": "#/definitions/inventory_path" },
 
                 "value": {"$ref": "#/definitions/boolean_value" }
             },
@@ -144,7 +144,7 @@
             "additionalProperties": false
         },
 
-        "fru":
+        "inventory_path":
         {
             "type": "string",
             "minLength": 1
@@ -160,7 +160,7 @@
             "type": "object",
             "properties":
             {
-                "fru": {"$ref": "#/definitions/fru" },
+                "fru": {"$ref": "#/definitions/inventory_path" },
 
                 "keyword": {"$ref": "#/definitions/keyword" },
 
@@ -372,6 +372,8 @@
 
                     "number": {"$ref": "#/definitions/number" },
 
+                    "inventory_path": {"$ref": "#/definitions/inventory_path" },
+
                     "devices": {"$ref": "#/definitions/devices" }
                 },
 
@@ -401,7 +403,7 @@
 
                     "is_regulator": {"$ref": "#/definitions/is_regulator" },
 
-                    "fru": {"$ref": "#/definitions/fru" },
+                    "fru": {"$ref": "#/definitions/inventory_path" },
 
                     "i2c_interface": {"$ref": "#/definitions/i2c_interface" },
 
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index fb1a40e..e6b84ec 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -75,6 +75,7 @@
         {
           "comments": [ "Chassis number 1 containing CPUs and memory" ],
           "number": 1,
+          "inventory_path": "system/chassis",
           "devices": [
             {
               "comments": [ "IR35221 regulator producing the Vdd rail" ],
@@ -513,10 +514,11 @@
         json configFile = validConfigFile;
         EXPECT_JSON_VALID(configFile);
     }
-    // Valid: test chassis with required properties.
+    // Valid: test chassis with only required properties.
     {
         json configFile = validConfigFile;
         configFile["chassis"][0].erase("comments");
+        configFile["chassis"][0].erase("inventory_path");
         configFile["chassis"][0].erase("devices");
         EXPECT_JSON_VALID(configFile);
     }
@@ -541,6 +543,13 @@
         EXPECT_JSON_INVALID(configFile, "Validation failed.",
                             "1.3 is not of type 'integer'");
     }
+    // Invalid: test chassis with property inventory_path wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["inventory_path"] = 2;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "2 is not of type 'string'");
+    }
     // Invalid: test chassis with property devices wrong type.
     {
         json configFile = validConfigFile;
@@ -569,6 +578,13 @@
         EXPECT_JSON_INVALID(configFile, "Validation failed.",
                             "0 is less than the minimum of 1");
     }
+    // Invalid: test chassis with property inventory_path empty string.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["inventory_path"] = "";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "'' is too short");
+    }
 }
 TEST(ValidateRegulatorsConfigTest, ComparePresence)
 {