diff options
Diffstat (limited to 'ice_validator/tests')
15 files changed, 441 insertions, 134 deletions
diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail.yaml deleted file mode 100644 index d7770d7..0000000 --- a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail.yaml +++ /dev/null @@ -1,42 +0,0 @@ -heat_template_version: 2015-04-30 - -description: fdsafsfsa - -parameters: - - TESTDB_int_priav_ips: - type: comma_delimited_list - description: asnfjl - - TESTDB_private_ips: - type: string - description: asnfjl - - priv_subnet_id: - type: string - description: asnfjl - - privte_v6_subnet_id: - type: string - description: asnfjl - -resources: - - TESTDB_0_int_priv_vmi_0_IP_0: - type: OS::ContrailV2::InstanceIp - properties: - virtual_machine_interface_refs: { get_resource: TESTDB_0_priv_vmi_0 } - virtual_network_refs: [{ get_resource: int_priv_network }] - instance_ip_address: { get_param: [TESTDB_int_priav_ips, 0] } - subnet_uuid: { get_param: priv_subnet_id } - - TESTDB_0_private_vmi_1_IP_0: - type: OS::ContrailV2::InstanceIp - properties: - virtual_machine_interface_refs: { get_resource: TESTDB_1_priv_vmi_0 } - virtual_network_refs: [{ get_param: priv_net_fqdn }] - instance_ip_address: { get_param: [TESTDB_private_ips, 1] } - subnet_uuid: { get_param: privte_v6_subnet_id } - - #testnlksadf: - # type: http://www.google.com diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_base.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_base.yaml new file mode 100644 index 0000000..7043cda --- /dev/null +++ b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_base.yaml @@ -0,0 +1,79 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ + +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + TESTDB_int_priav_ips: + type: comma_delimited_list + description: asnfjl + + TESTDB_private_ips: + type: string + description: asnfjl + + priv_subnet_id: + type: string + description: asnfjl + + privte_v6_subnet_id: + type: string + description: asnfjl + +resources: + + TESTDB_0_int_priv_vmi_0_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_0_priv_vmi_0 } + virtual_network_refs: [{ get_resource: int_priv_network }] + instance_ip_address: { get_param: [TESTDB_int_priav_ips, 0] } + subnet_uuid: { get_param: priv_subnet_id } + + TESTDB_0_private_vmi_1_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_1_priv_vmi_0 } + virtual_network_refs: [{ get_param: priv_net_fqdn }] + instance_ip_address: { get_param: [TESTDB_private_ips, 1] } + subnet_uuid: { get_param: privte_v6_subnet_id } + + #testnlksadf: + # type: http://www.google.com diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_module.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_module.yaml new file mode 100644 index 0000000..66dd13d --- /dev/null +++ b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_module.yaml @@ -0,0 +1,82 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ + +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + TESTDB_int_priav_ips: + type: comma_delimited_list + description: asnfjl + + TESTDB_private_ips: + type: string + description: asnfjl + + priv_subnet_id: + type: string + description: asnfjl + + privte_v6_subnet_id: + type: string + description: asnfjl + +resources: + + TESTDB_0_int_priv_vmi_0_IP_1: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_0_priv_vmi_0 } + virtual_network_refs: [{ get_resource: int_priv_network }] + instance_ip_address: { get_param: [TESTDB_int_priav_ips, 0] } + subnet_uuid: { get_param: priv_subnet_id } + + TESTDB_0_private_vmi_1_IP_1: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_1_priv_vmi_0 } + virtual_network_refs: [{ get_param: priv_net_fqdn }] + instance_ip_address: { get_param: [TESTDB_private_ips, 1] } + subnet_uuid: { get_param: privte_v6_subnet_id } + + other_0_int_priv_vmi_0_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + instance_ip_address: { get_param: [other_int_priv_ips, 0] } + subnet_uuid: { get_param: int_priv_subnet_id }
\ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass.yaml deleted file mode 100644 index 8645348..0000000 --- a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass.yaml +++ /dev/null @@ -1,42 +0,0 @@ -heat_template_version: 2015-04-30 - -description: fdsafsfsa - -parameters: - - TESTDB_int_priv_ips: - type: comma_delimited_list - description: asnfjl - - TESTDB_private_ips: - type: comma_delimited_list - description: asnfjl - - int_priv_subnet_id: - type: string - description: asnfjl - - private_v6_subnet_id: - type: string - description: asnfjl - -resources: - - TESTDB_0_int_priv_vmi_0_IP_0: - type: OS::ContrailV2::InstanceIp - properties: - virtual_machine_interface_refs: { get_resource: TESTDB_0_priv_vmi_0 } - virtual_network_refs: [{ get_resource: int_priv_network }] - instance_ip_address: { get_param: [TESTDB_int_priv_ips, 0] } - subnet_uuid: { get_param: int_priv_subnet_id } - - TESTDB_0_private_vmi_1_IP_0: - type: OS::ContrailV2::InstanceIp - properties: - virtual_machine_interface_refs: { get_resource: TESTDB_1_priv_vmi_0 } - virtual_network_refs: [{ get_param: priv_net_fqdn }] - instance_ip_address: { get_param: [TESTDB_private_ips, 1] } - subnet_uuid: { get_param: private_v6_subnet_id } - - #testnlksadf: - # type: http://www.google.com diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_base.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_base.yaml new file mode 100644 index 0000000..5afee32 --- /dev/null +++ b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_base.yaml @@ -0,0 +1,83 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ + +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + TESTDB_int_priv_ips: + type: comma_delimited_list + description: asnfjl + + TESTDB_private_ips: + type: comma_delimited_list + description: asnfjl + + int_priv_subnet_id: + type: string + description: asnfjl + + private_v6_subnet_id: + type: string + description: asnfjl + +resources: + + TESTDB_0_int_priv_vmi_0_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_0_priv_vmi_0 } + virtual_network_refs: [{ get_resource: int_priv_network }] + instance_ip_address: { get_param: [TESTDB_int_priv_ips, 0] } + subnet_uuid: { get_param: int_priv_subnet_id } + + TESTDB_0_private_vmi_1_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + virtual_machine_interface_refs: { get_resource: TESTDB_1_priv_vmi_0 } + virtual_network_refs: [{ get_param: priv_net_fqdn }] + instance_ip_address: { get_param: [TESTDB_private_ips, 1] } + subnet_uuid: { get_param: private_v6_subnet_id } + + a_subnet: + type: OS::Neutron::Subnet + +outputs: + int_priv_subnet_id: + value: { get_resource: a_subnet } diff --git a/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_module.yaml b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_module.yaml new file mode 100644 index 0000000..d6bd540 --- /dev/null +++ b/ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_module.yaml @@ -0,0 +1,58 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ + +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + other_int_priv_ips: + type: comma_delimited_list + + int_priv_subnet_id: + type: string + subnet_uuid: int_priv_subnet_id + + +resources: + + other_0_int_priv_vmi_0_IP_0: + type: OS::ContrailV2::InstanceIp + properties: + instance_ip_address: { get_param: [other_int_priv_ips, 0] } + subnet_uuid: { get_param: int_priv_subnet_id } diff --git a/ice_validator/tests/parametrizers.py b/ice_validator/tests/parametrizers.py index 38a93db..35cf6e0 100644 --- a/ice_validator/tests/parametrizers.py +++ b/ice_validator/tests/parametrizers.py @@ -44,8 +44,8 @@ from os import path, listdir import re from tests import cached_yaml as yaml import pytest -from .helpers import get_parsed_yml_for_yaml_files, check_basename_ending -from .utils.nested_files import get_list_of_nested_files +from tests.helpers import get_parsed_yml_for_yaml_files, check_basename_ending +from tests.utils.nested_files import get_nested_files VERSION = "1.0.0" @@ -68,37 +68,6 @@ def get_template_dir(metafunc): return metafunc.config.getoption("template_dir")[0] -def file_is_a_nested_template(file): - directory = path.dirname(file) - nested_files = [] - for filename in listdir(directory): - if filename.endswith(".yaml") or filename.endswith(".yml"): - filename = "{}/{}".format(directory, filename) - try: - with open(filename) as fh: - yml = yaml.load(fh) - if "resources" not in yml: - continue - nested_files.extend( - get_list_of_nested_files(yml["resources"], path.dirname(filename)) - ) - except yaml.YAMLError as e: - print(e) # pylint: disable=superfluous-parens - continue - return file in nested_files - - -def get_nested_files(filenames): - """ - returns all the nested files for a set of filenames - """ - nested_files = [] - for filename in filenames: - if file_is_a_nested_template(filename): - nested_files.append(filename) - return nested_files - - def list_filenames_in_template_dir( metafunc, extensions, template_type="", sub_dirs=None ): diff --git a/ice_validator/tests/test_contrail_instance_ip_parameters.py b/ice_validator/tests/test_contrail_instance_ip_parameters.py index a708a58..312c8e9 100644 --- a/ice_validator/tests/test_contrail_instance_ip_parameters.py +++ b/ice_validator/tests/test_contrail_instance_ip_parameters.py @@ -36,10 +36,14 @@ # ============LICENSE_END============================================ # # +import os import re -from tests.structures import ContrailV2InstanceIpProcessor -from tests.helpers import validates +import pytest + +from tests.structures import ContrailV2InstanceIpProcessor, Heat +from tests.helpers import validates, get_base_template_from_yaml_files, get_param +from tests.utils.incrementals import get_incremental_modules from tests.utils.ports import check_parameter_format RE_EXTERNAL_PARAM_IIP = re.compile( # match pattern @@ -108,12 +112,12 @@ sid_regx_dict = { } -@validates("R-100000", "R-100010", "R-100030", "R-100150", "R-100070") +@validates("R-100000", "R-100010", "R-100030", "R-100050", "R-100070") def test_contrail_external_instance_ip_address_parameter(yaml_file): check_parameter_format(yaml_file, iip_regx_dict, "external", ContrailV2InstanceIpProcessor, "instance_ip_address") -@validates("R-100000", "R-100090", "R-100110", "R-100130", "R-100180") +@validates("R-100000", "R-100090", "R-100110", "R-100130", "R-100150") def test_contrail_internal_instance_ip_address_parameter(yaml_file): check_parameter_format(yaml_file, iip_regx_dict, "internal", ContrailV2InstanceIpProcessor, "instance_ip_address") @@ -128,6 +132,28 @@ def test_contrail_internal_instance_subnet_id_parameter(yaml_file): check_parameter_format(yaml_file, sid_regx_dict, "internal", ContrailV2InstanceIpProcessor, "subnet_uuid") - - - +@validates("R-100240", "R-100260") +def test_contrail_incremental_module_internal_subnet_usage(yaml_files): + base_path = get_base_template_from_yaml_files(yaml_files) + if not base_path: + pytest.skip("No base module detected to check") + base_outputs = Heat(filepath=base_path).outputs + incremental_modules = get_incremental_modules(yaml_files) + errors = [] + for module in incremental_modules: + heat = Heat(filepath=module) + ips = heat.get_resource_by_type(ContrailV2InstanceIpProcessor.resource_type) + internal_ips = ((r_id, props) for r_id, props in ips.items() if "_int_" in r_id) + for r_id, ip in internal_ips: + subnet_uuid = (ip.get("properties") or {}).get("subnet_uuid") + subnet_param = get_param(subnet_uuid) + if not subnet_param: + continue + if subnet_param not in base_outputs: + errors.append(( + "Resource ({}) is designated as an internal IP, but its " + "subnet_uuid parameter ({}) does not refer to subnet in " + "this template nor is it defined in the output section " + "of the base module ({})" + ).format(r_id, subnet_param, os.path.basename(base_path))) + assert not errors, ". ".join(errors) diff --git a/ice_validator/tests/test_filename_is_vmtype_dot_yaml.py b/ice_validator/tests/test_filename_is_vmtype_dot_yaml.py index 5343bcc..2ec4481 100644 --- a/ice_validator/tests/test_filename_is_vmtype_dot_yaml.py +++ b/ice_validator/tests/test_filename_is_vmtype_dot_yaml.py @@ -36,9 +36,9 @@ # ============LICENSE_END============================================ # import os -from .helpers import validates +from tests.helpers import validates +from tests.utils.nested_files import get_nested_files from .utils.vm_types import get_all_vm_types -from .parametrizers import get_nested_files VERSION = "1.0.0" diff --git a/ice_validator/tests/test_neutron_port_fixed_ips_subnet.py b/ice_validator/tests/test_neutron_port_fixed_ips_subnet.py index a07225b..ccabf5e 100644 --- a/ice_validator/tests/test_neutron_port_fixed_ips_subnet.py +++ b/ice_validator/tests/test_neutron_port_fixed_ips_subnet.py @@ -39,10 +39,10 @@ import re from tests.utils.network_roles import get_network_type_from_port -from tests.parametrizers import get_nested_files -from .structures import Heat -from .helpers import validates, load_yaml, get_base_template_from_yaml_files +from tests.structures import Heat +from tests.helpers import validates, load_yaml, get_base_template_from_yaml_files +from tests.utils.nested_files import get_nested_files from .utils.ports import check_parameter_format from tests.structures import NeutronPortProcessor diff --git a/ice_validator/tests/test_neutron_port_network_attachment.py b/ice_validator/tests/test_neutron_port_network_attachment.py index 0e0d8e6..61b127e 100644 --- a/ice_validator/tests/test_neutron_port_network_attachment.py +++ b/ice_validator/tests/test_neutron_port_network_attachment.py @@ -4,7 +4,7 @@ import re import pytest from tests.helpers import validates, get_base_template_from_yaml_files, get_param -from tests.parametrizers import get_nested_files +from tests.utils.nested_files import get_nested_files from tests.structures import Heat diff --git a/ice_validator/tests/test_server_parameters.py b/ice_validator/tests/test_server_parameters.py index 46aa7bf..b1adce2 100644 --- a/ice_validator/tests/test_server_parameters.py +++ b/ice_validator/tests/test_server_parameters.py @@ -40,9 +40,9 @@ """ import pytest from tests import cached_yaml as yaml -from tests.parametrizers import file_is_a_nested_template -from .helpers import validates +from tests.helpers import validates +from tests.utils.nested_files import file_is_a_nested_template VERSION = "1.1.0" diff --git a/ice_validator/tests/test_volume_module_naming.py b/ice_validator/tests/test_volume_module_naming.py index 68c2158..fdd4894 100644 --- a/ice_validator/tests/test_volume_module_naming.py +++ b/ice_validator/tests/test_volume_module_naming.py @@ -37,7 +37,7 @@ import os from tests.helpers import validates -from tests.parametrizers import get_nested_files +from tests.utils.nested_files import get_nested_files from tests.structures import Heat, Resource diff --git a/ice_validator/tests/utils/incrementals.py b/ice_validator/tests/utils/incrementals.py new file mode 100644 index 0000000..2728d3b --- /dev/null +++ b/ice_validator/tests/utils/incrementals.py @@ -0,0 +1,63 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# +import os + +from tests.helpers import get_base_template_from_yaml_files +from tests.utils.nested_files import get_nested_files + + +def is_incremental_module(yaml_file, yaml_files): + """ + Returns true if the file is not a base module, volume module, or nested module. + """ + base_template = get_base_template_from_yaml_files(yaml_files) + nested_templates = get_nested_files(yaml_files) + is_volume_module = os.path.splitext(yaml_file)[0].endswith("_volume") + return ( + yaml_file != base_template + and yaml_file not in nested_templates + and not is_volume_module + ) + + +def get_incremental_modules(yaml_files): + """ + Returns the a list of file paths for the incremental modules in yaml_files + """ + return [f for f in yaml_files if is_incremental_module(f, yaml_files)] diff --git a/ice_validator/tests/utils/nested_files.py b/ice_validator/tests/utils/nested_files.py index 5f1f174..c7a5601 100644 --- a/ice_validator/tests/utils/nested_files.py +++ b/ice_validator/tests/utils/nested_files.py @@ -40,7 +40,7 @@ """nested files """ -from os import path +from os import path, listdir import re from tests import cached_yaml as yaml from tests.structures import Heat @@ -258,3 +258,34 @@ def get_type_nested_files(yml, dirpath): if path.exists(filepath): nested_files[rid] = nested_file return nested_files + + +def get_nested_files(filenames): + """ + returns all the nested files for a set of filenames + """ + nested_files = [] + for filename in filenames: + if file_is_a_nested_template(filename): + nested_files.append(filename) + return nested_files + + +def file_is_a_nested_template(file): + directory = path.dirname(file) + nested_files = [] + for filename in listdir(directory): + if filename.endswith(".yaml") or filename.endswith(".yml"): + filename = "{}/{}".format(directory, filename) + try: + with open(filename) as fh: + yml = yaml.load(fh) + if "resources" not in yml: + continue + nested_files.extend( + get_list_of_nested_files(yml["resources"], path.dirname(filename)) + ) + except yaml.YAMLError as e: + print(e) # pylint: disable=superfluous-parens + continue + return file in nested_files |