[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / ice_validator / tests / test_env_parameters_defined_in_template.py
 #
 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
 #
-
-from tests import cached_yaml as yaml
 import pytest
-from .utils.nested_iterables import find_all_get_resource_in_yml
 
+from .helpers import validates, get_environment_pair
+
+
+@validates("R-599443")
+def test_env_params_are_defined_in_template(heat_template):
+    """Test that each paraemter defined in an environment file
+    is also defined in the paired heat template"""
 
-def test_volume_templates_outputs_match_resources(volume_template):
-    '''
-    Check that all referenced resources in the outputs of a volume
-    template actually exists
-    '''
-    with open(volume_template) as fh:
-        yml = yaml.load(fh)
+    bad = []
+    template_pair = get_environment_pair(heat_template)
 
-    # skip if resources are not defined
-    if "resources" not in yml:
-        pytest.skip("No resources specified in the volume template")
+    if not template_pair:
+        pytest.skip("No yaml/env pair could be determined")
 
-    # skip if outputs are not defined
-    if "outputs" not in yml:
-        pytest.skip("No outputs specified in the volume template")
+    template = template_pair.get("yyml").get("parameters", {})
+    environment = template_pair.get("eyml").get("parameters", {})
 
-    referenced_resources = find_all_get_resource_in_yml(yml['outputs'])
+    if not isinstance(template, dict) or not isinstance(environment, dict):
+        pytest.skip("No parameters defined in environment or template")
 
-    invalid_get_attr = []
-    for k, v in yml['outputs'].items():
-        if 'value' not in v:
-            continue
-        if 'get_attr' not in v['value']:
-            continue
-        if not isinstance(v['value']['get_attr'], list):
-            continue
+    template = template.keys()
+    environment = environment.keys()
 
-        for v1 in v['value']['get_attr']:
-            if v1 in yml['resources']:
-                break
-        else:
-            invalid_get_attr.append(k)
+    for parameter in environment:
+        if parameter not in template:
+            bad.append(
+                (
+                    "{} is defined in the environment file but not in "
+                    + "the template file "
+                ).format(parameter)
+            )
+    msg = (
+        "All parameters defined in an environment file must "
+        + "be defined in the template file. "
+        + ". ".join(bad)
+    )
 
-    assert (set(referenced_resources) <= set(yml["resources"]) and
-            not invalid_get_attr)
+    assert not bad, msg