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>
+++ /dev/null
-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
--- /dev/null
+# -*- 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
--- /dev/null
+# -*- 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
+++ /dev/null
-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
--- /dev/null
+# -*- 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 }
--- /dev/null
+# -*- 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 }
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"
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
):
# ============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
}
-@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")
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)
# ============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"
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
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
"""
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"
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
--- /dev/null
+# -*- 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)]
"""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
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