regulators: Add check_duplicate_object_id function.

Add the check_duplicate_object_id function to the config file validation tool.
It checks that there aren't any JSON objects with the same 'id' property value.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I1e0d8de50f3687f88509476a5cc81e5577d4c84c
diff --git a/phosphor-regulators/tools/validate-regulators-config.py b/phosphor-regulators/tools/validate-regulators-config.py
index b413c63..0c2e185 100644
--- a/phosphor-regulators/tools/validate-regulators-config.py
+++ b/phosphor-regulators/tools/validate-regulators-config.py
@@ -13,6 +13,24 @@
 def handle_validation_error():
     sys.exit("Validation failed.")
 
+def check_duplicate_object_id(config_json):
+    r"""
+    Check that there aren't any JSON objects with the same 'id' property value.
+    config_json: Configuration file JSON
+    """
+
+    json_ids = check_duplicate_rule_id(config_json)+\
+               check_duplicate_device_id(config_json)+\
+               check_duplicate_rail_id(config_json)
+    unique_ids = set()
+    for id in json_ids:
+        if id in unique_ids:
+           sys.stderr.write("Error: Duplicate ID.\n"+\
+           "Found multiple objects with the ID "+id+'\n')
+           handle_validation_error()
+        else:
+            unique_ids.add(id)
+
 def check_duplicate_rule_id(config_json):
     r"""
     Check that there aren't any "rule" elements with the same 'id' field.
@@ -27,6 +45,7 @@
             handle_validation_error()
         else:
             rule_ids.append(rule_id)
+    return rule_ids
 
 def check_duplicate_chassis_number(config_json):
     r"""
@@ -58,6 +77,7 @@
                 handle_validation_error()
             else:
                 device_ids.append(device_id)
+    return device_ids
 
 def check_duplicate_rail_id(config_json):
     r"""
@@ -75,6 +95,7 @@
                     handle_validation_error()
                 else:
                     rail_ids.append(rail_id)
+    return rail_ids
 
 def check_for_duplicates(config_json):
     r"""
@@ -88,6 +109,8 @@
 
     check_duplicate_rail_id(config_json)
 
+    check_duplicate_object_id(config_json)
+
 def validate_schema(config, schema):
     r"""
     Validates the specified config file using the specified