regulators: Add check_rule_id_exists function.

Add check_rule_id_exists function to the config file validation tool.
It checks if a rule_id property specifies a rule ID that does not
exist.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I960a1b27a74b89b3bfb89ec18ad54dbd25c9388e
diff --git a/phosphor-regulators/tools/validate-regulators-config.py b/phosphor-regulators/tools/validate-regulators-config.py
old mode 100644
new mode 100755
index 77313e7..a9ebb0d
--- a/phosphor-regulators/tools/validate-regulators-config.py
+++ b/phosphor-regulators/tools/validate-regulators-config.py
@@ -58,6 +58,21 @@
             device_ids.append(device['id'])
     return device_ids
 
+def check_rule_id_exists(config_json):
+    r"""
+    Check if a rule_id property specifies a rule ID that does not exist.
+    config_json: Configuration file JSON
+    """
+
+    rule_ids = get_values(config_json, 'rule_id')
+    valid_rule_ids = get_rule_ids(config_json)
+    for rule_id in rule_ids:
+        if rule_id not in valid_rule_ids:
+            sys.stderr.write("Error: Rule ID does not exist.\n"+\
+            "Found rule_id value that specifies invalid rule ID "+\
+            rule_id+'\n')
+            handle_validation_error()
+
 def check_set_device_value_exists(config_json):
     r"""
     Check if a set_device action specifies a device ID that does not exist.
@@ -269,3 +284,5 @@
     check_run_rule_value_exists(config_json)
 
     check_set_device_value_exists(config_json)
+
+    check_rule_id_exists(config_json)