[VVP] Add test for R-100260 and fix mapping 06/87906/1
authorLovett, Trevor (tl2972) <tl2972@att.com>
Thu, 16 May 2019 16:31:07 +0000 (11:31 -0500)
committerLovett, Trevor (tl2972) <tl2972@att.com>
Thu, 16 May 2019 16:31:07 +0000 (11:31 -0500)
Re-arranged some helper and util functions to more logical locations.

Added test to verify than an internal subnet parameter used in an
incremental module is defined in the base module.

Change-Id: I20369396b18820f0e321c0e75bd47446b0a7a39f
Issue-ID: VVP-215
Signed-off-by: Lovett, Trevor (tl2972) <tl2972@att.com>
15 files changed:
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail.yaml [deleted file]
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_base.yaml [new file with mode: 0644]
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/fail/fail_module.yaml [new file with mode: 0644]
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass.yaml [deleted file]
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_base.yaml [new file with mode: 0644]
ice_validator/tests/fixtures/test_contrail_instance_ip_parameters/pass/pass_module.yaml [new file with mode: 0644]
ice_validator/tests/parametrizers.py
ice_validator/tests/test_contrail_instance_ip_parameters.py
ice_validator/tests/test_filename_is_vmtype_dot_yaml.py
ice_validator/tests/test_neutron_port_fixed_ips_subnet.py
ice_validator/tests/test_neutron_port_network_attachment.py
ice_validator/tests/test_server_parameters.py
ice_validator/tests/test_volume_module_naming.py
ice_validator/tests/utils/incrementals.py [new file with mode: 0644]
ice_validator/tests/utils/nested_files.py

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 (file)
index d7770d7..0000000
+++ /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 (file)
index 0000000..7043cda
--- /dev/null
@@ -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 (file)
index 0000000..66dd13d
--- /dev/null
@@ -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 (file)
index 8645348..0000000
+++ /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 (file)
index 0000000..5afee32
--- /dev/null
@@ -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 (file)
index 0000000..d6bd540
--- /dev/null
@@ -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 }
index 38a93db..35cf6e0 100644 (file)
@@ -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
 ):
index a708a58..312c8e9 100644 (file)
 # ============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)
index 5343bcc..2ec4481 100644 (file)
@@ -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"
 
index a07225b..ccabf5e 100644 (file)
 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
 
index 0e0d8e6..61b127e 100644 (file)
@@ -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
 
 
index 46aa7bf..b1adce2 100644 (file)
@@ -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"
 
index 68c2158..fdd4894 100644 (file)
@@ -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 (file)
index 0000000..2728d3b
--- /dev/null
@@ -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)]
index 5f1f174..c7a5601 100644 (file)
@@ -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