[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / ice_validator / tests / test_all_parameters_used_in_template.py
@@ -1,8 +1,8 @@
 # -*- coding: utf8 -*-
-# ============LICENSE_START=======================================================
+# ============LICENSE_START====================================================
 # org.onap.vvp/validation-scripts
 # ===================================================================
-# Copyright © 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 # ===================================================================
 #
 # Unless otherwise specified, all software contained herein is licensed
@@ -42,37 +42,39 @@ import pytest
 from tests import cached_yaml as yaml
 
 from .helpers import validates
+from .utils.nested_iterables import find_all_get_param_in_yml
 
+VERSION = "1.0.0"
 
-@validates('R-88863')
-def test_numeric_parameter(heat_template):
-    '''
-    Make sure all numeric parameters has either `range` or `allowed_values`
-    specified
-    '''
-    key_values = ["range", "allowed_values"]
-    missing_constraints = []
+# pylint: disable=invalid-name
 
-    with open(heat_template) as fh:
-        yml = yaml.load(fh)
 
-    # skip if parameters are not defined
-    if "parameters" not in yml:
-        pytest.skip("No parameters specified in the heat template")
+@validates("R-90279")
+def test_all_parameters_used_in_template(yaml_file):
 
-    for k1, v1 in yml["parameters"].items():
-        if not isinstance(v1, dict):
-            continue
-        if 'number' not in v1.values():
-            continue
+    invalid_params = []
+    get_params = []
+    skip_params = ["availability_zone"]
 
-        for k2, v2 in v1.items():
-            if k2 == "type" and v2 == "number":
-                if "constraints" not in v1:
-                    missing_constraints.append(k1)
-                    continue
-                for v3 in v1["constraints"]:
-                    if not set(v3) & set(key_values):
-                        missing_constraints.append(k1)
+    with open(yaml_file, "r") as f:
+        yml = yaml.load(f)
 
-    assert not set(missing_constraints)
+        template_parameters = yml.get("parameters")
+        if not template_parameters:
+            pytest.skip("no parameters found in template")
+
+        get_params = find_all_get_param_in_yml(yml)
+        if not get_params:
+            pytest.skip("no get_params found in template")
+
+    template_parameters = list(template_parameters.keys())
+    for param in template_parameters:
+        for sparam in skip_params:
+            if param.find(sparam) != -1:
+                template_parameters.remove(param)
+
+    invalid_params = set(template_parameters) - set(get_params)
+
+    assert not invalid_params, "Unused parameters detected in template {}".format(
+        invalid_params
+    )