2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
28 # https://creativecommons.org/licenses/by/4.0/
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
36 # ============LICENSE_END============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
44 from tests import cached_yaml as yaml
46 from .helpers import validates
49 class VolumePairModule:
50 def __init__(self, volume_path):
51 self.volume_path = volume_path
54 def path_options(self):
55 expected_path, _ = self.volume_path.rsplit("_volume", maxsplit=1)
56 return (expected_path + ".yaml", expected_path + ".yml")
60 return any(os.path.exists(option) for option in self.path_options)
62 def get_module_path(self):
64 Return the path of the volume module's pair if it exists,
67 for option in self.path_options:
68 if os.path.exists(option):
74 def test_volume_module_name_matches_incremental_or_base_module(volume_template):
75 pair_module = VolumePairModule(volume_template)
76 assert pair_module.exists, (
77 "Could not find a corresponding module ({}) for " + "volume module ({})"
78 ).format(" or ".join(pair_module.path_options), volume_template)
81 @validates("R-11200", "R-07443")
82 def test_volume_outputs_consumed(template_dir, volume_template):
84 Check that all outputs in a volume template is consumed
85 by the corresponding heat template
87 pair_module = VolumePairModule(volume_template)
88 if not pair_module.exists:
89 pytest.skip("No pair module found for volume template")
90 with open(volume_template, "r") as f:
92 with open(pair_module.get_module_path(), "r") as f:
94 outputs = set(volume.get("outputs", {}).keys())
95 parameters = set(pair.get("parameters", {}).keys())
96 missing_output_parameters = outputs.difference(parameters)
97 assert not missing_output_parameters, (
98 "The output parameters ({}) in {} were not all "
99 "used by the expected module {}".format(
100 ",".join(missing_output_parameters), volume_template, pair_module
104 # Now make sure that none of the output parameters appear in any other
106 template_files = set(glob.glob("*.yaml")).union(glob.glob(".yml"))
108 for template_path in template_files:
109 if template_path in (pair_module, volume_template):
110 continue # Skip these files since we already checked this pair
111 with open(template_path, "r") as f:
112 template = yaml.load(f)
113 parameters = set(template.get("parameters", {}).keys())
114 misused_outputs = outputs.intersection(parameters)
116 errors[template_path] = misused_outputs
118 "{} ({})".format(path, ", ".join(params)) for path, params in errors.items()
121 "Volume output parameters detected in unexpected modules: " + message