From f5edc06be0d8bedeb0904b348ba5e3e67c74f186 Mon Sep 17 00:00:00 2001 From: "Lovett, Trevor (tl2972)" Date: Wed, 22 Aug 2018 11:13:45 -0500 Subject: [VVP] Added new three new reports Resolves VVP-81 by introducing three new reports to the validation script output. Each report is written to the output directory under ice_validator. * mapping_errors.csv - each row represents an issue where a test is mapped to a requirement that does not exist in the requirement.json file * traceability.csv - Shows a mapping between all test cases and requirements. Rows will also be shown where a requirement does not have a tests, and where tests are not mapped to a requirement * report.{html|csv|xlsx} - Formatted error report that shows each failure that was detected and maps it to a the file name, requirement(s) violated if known, possible resolution steps, error message, and raw output from pytest. The report can be written in html, csv, or Excel format Other minor changes: * Replaced smart quotes with regular quotes to resolve issues with py3 * Updated copyright of modified files * Fixed Flake-8 errors Issue-ID: VVP-81 Change-Id: I659836cb20262ae44652c03639281a817dd051ae Signed-off-by: Lovett, Trevor (tl2972) --- ice_validator/tests/__init__.py | 6 +- ice_validator/tests/conftest.py | 539 +++++++++++++++++++-- .../fail/mismatch_get_resource.yaml | 4 +- .../fail/mismatch_get_resource_volume.yaml | 4 +- .../fail/mismatch_resource_id.yaml | 4 +- .../fail/mismatch_resource_id_volume.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../pass/valid_template_volume.yaml | 4 +- .../invalid_naming_for_allowed_address_pairs.yaml | 4 +- .../fail/single_ip_format_used_in_array.yaml | 4 +- .../fail/wrong_network_role.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- ...al_network_network_role_wrong_in_parameter.yaml | 4 +- ...xternal_network_vm_type_wrong_in_parameter.yaml | 4 +- ...al_network_network_role_wrong_in_parameter.yaml | 4 +- ...nternal_network_vm_type_wrong_in_parameter.yaml | 4 +- .../fail/mismatch_vm_type_exernal_nova_server.yaml | 4 +- .../mismatch_vm_type_internal_nova_server.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../fail/missing_increment.yaml | 4 +- .../fail/not_starting_with_availability_zone.yaml | 4 +- .../fail/using_list_instead_of_get_param.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/not_using_get_param.yaml | 4 +- .../fail/only_specifying_param.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/failing_directory/check_cant_fail.yaml | 36 +- .../pass/base_well_named_1/base_well_named.yaml | 36 +- .../pass/base_well_named_2/well_base_named.yaml | 36 +- .../pass/base_well_named_3/well_named_base.yaml | 36 +- .../fail/base_template.yaml | 4 +- ...dule_1_template_missing_output_consumption.yaml | 4 +- .../fail/module_2_child_1_template.yaml | 4 +- ...dule_2_template_missing_output_consumption.yaml | 4 +- .../pass/base_template.yaml | 4 +- .../pass/module_1_template.yaml | 4 +- .../pass/module_2_child_1_template.yaml | 4 +- .../pass/module_2_template.yaml | 4 +- .../match_environment_filename_slightly_lon.yaml | 10 +- .../match_environment_filename_slightly_long.env | 10 +- .../match_environment_filename_slightly_shor.env | 10 +- .../match_environment_filename_slightly_short.yaml | 10 +- .../no_match/no_match_environment_filename.env | 10 +- .../pass/good_matches/good_yaml_eg.env | 10 +- .../pass/good_matches/good_yaml_eg.yaml | 10 +- .../fail/base_template.yaml | 4 +- .../fail/base_template_env.yaml | 4 +- .../test_env_files_provided/pass/base_template.env | 4 +- .../pass/base_template.yaml | 4 +- .../fail/non_environment_invalid_key.env | 4 +- .../fail/non_environment_no_keys.env | 10 +- .../pass/environment.env | 4 +- .../fail/invalid_naming_for_fixed_ips.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/get_param_not_used_for_fixed_ips.yaml | 4 +- .../fail/get_resource_used_for_fixed_ips.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../external_mismatch_vm_type_nova_server.yaml | 4 +- .../fail/external_wrong_network_role_param.yaml | 4 +- .../fail/external_wrong_vm_type_param.yaml | 4 +- .../internal_mismatch_vm_type_nova_server.yaml | 4 +- .../fail/internal_wrong_network_role_param.yaml | 4 +- .../fail/internal_wrong_vm_type_param.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../fail/personality_contains_http.yaml | 4 +- .../fail/user_data_contains_ftp.yaml | 4 +- .../fail/user_data_contains_http.yaml | 4 +- .../pass/valid_template.yaml | 4 +- ...arameter_numeric_value_missing_constraints.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/env_missing_yaml.env | 4 +- .../fail/misnamed_pair.yaml | 4 +- .../fail/misnamed_pairr.env | 4 +- .../fail/yaml_missing_env.yaml | 4 +- .../test_heat_pairs_provided/pass/good_yaml_eg.env | 4 +- .../pass/good_yaml_eg.yaml | 4 +- .../pass/good_yaml_eg_volume.env | 4 +- .../pass/good_yaml_eg_volume.yaml | 4 +- .../fail/parameter_default_value_specified.yaml | 4 +- .../fail/parameter_invalid_keys.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/environment.yaml | 4 +- .../fail/valid_heat_template.env | 4 +- .../pass/environment.env | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../pass/valid_heat_template.yml | 4 +- .../fail/template_missing_description.yaml | 4 +- .../fail/template_missing_type.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../fail/non_heat_template_invalid_keys.yaml | 4 +- .../fail/non_heat_template_invalid_keys.yml | 4 +- .../fail/non_heat_template_no_valid_keys.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../pass/valid_heat_template.yml | 4 +- .../pass/valid_heat_template_minimal_sections.yaml | 4 +- .../fail/base_template.env | 4 +- .../fail/base_template.template | 4 +- .../pass/base_template.env | 4 +- .../pass/base_template.yaml | 4 +- .../fail/heat_template_missing_nested_files.yaml | 4 +- .../pass/nested_template_1.yaml | 4 +- .../pass/nested_template_2.yaml | 4 +- .../pass/valid_nested_heat_template.yaml | 4 +- .../fail/heat_template_invalid_nesting.yaml | 4 +- .../pass/nested_template_1.yaml | 4 +- .../pass/nested_template_2.yaml | 4 +- .../pass/valid_nested_heat_template.yaml | 4 +- .../pass/valid_non_nested_template.yaml | 4 +- .../fail/invalid_naming_used_for_network.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/get_param_not_used_for_network.yaml | 4 +- .../get_resource_used_for_external_network.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/unused_param.env | 14 +- .../fail/unused_param.yaml | 56 +-- .../pass/no_unused_param.env | 12 +- .../pass/no_unused_param.yaml | 52 +- .../fail/not_supported_policies.yml | 4 +- .../pass/with_supported_policies.yml | 4 +- .../fail/wrong_type_for_parameters.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/mismatch_vm_type_key_properties.yaml | 4 +- .../mismatch_vm_type_key_properties_uppercase.yaml | 4 +- .../fail/mismatch_vm_type_resource_id.yaml | 4 +- .../mismatch_vm_type_resource_id_uppercase.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/inconsistent_vm_type.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/missing_get_param.yaml | 4 +- .../using_str_replace_instead_of_get_param.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/bad_yaml_less_indent_on_value.yaml | 28 +- .../test_parse_yaml/fail/bad_yaml_multierror.yaml | 30 +- .../test_parse_yaml/fail/bad_yaml_tab.yaml | 28 +- .../fail/bad_yaml_value_and_keys.yaml | 28 +- .../test_parse_yaml/pass/good_yaml_eg.yaml | 26 +- .../mismatch_vm_type_port_id_get_resource.yaml | 4 +- ..._port_attached_to_nova_server_get_resource.yaml | 4 +- ...ched_to_nova_server_get_resource_uppercase.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../fail/missing_param_definition_1.yaml | 4 +- .../fail/missing_param_definition_2.yaml | 4 +- .../fail/missing_param_reference_1.yaml | 4 +- ...ms_referenced_are_defined_and_vice_versa_1.yaml | 4 +- ...ms_referenced_are_defined_and_vice_versa_2.yaml | 4 +- ...plate_required_parameters_with_constraints.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../missing_required_parameters_in_env_file.env | 4 +- .../missing_required_parameters_in_env_file.yaml | 4 +- .../pass/required_parameters_specified.env | 4 +- .../pass/required_parameters_specified.yaml | 4 +- .../required_parameters_specified_not_needed.env | 4 +- .../required_parameters_specified_not_needed.yaml | 4 +- .../missing_required_parameters_in_template.yaml | 4 +- .../pass/required_parameters_specified.yaml | 4 +- .../required_parameters_specified_not_needed.yaml | 4 +- .../invalid_characters_in_resource_id_template.yml | 4 +- .../valid_characters_in_resource_id_template.yml | 4 +- ...template_missing_specified_vf_module_index.yaml | 4 +- .../template_missing_specified_vf_module_name.yaml | 4 +- ...te_missing_specified_vf_module_name_in_rsg.yaml | 4 +- .../pass/valid_heat_template_1.yaml | 4 +- .../pass/valid_heat_template_2.yaml | 4 +- .../pass/valid_heat_template_3.yaml | 4 +- .../pass/valid_heat_template_4.yaml | 4 +- .../fail/missing_vf_module_id.yaml | 4 +- .../fail/missing_vnf_id.yaml | 4 +- .../fail/missing_vnf_name.yaml | 4 +- .../pass/has_required_metadata.yaml | 4 +- .../fail/missing_metadata_section.yaml | 4 +- .../fail/missing_properties_section.yaml | 4 +- .../fail/not_using_get_param.yaml | 4 +- .../pass/has_required_metadata.yaml | 4 +- .../invalid_naming_used_for_get_param_subnet.yaml | 4 +- ...nvalid_naming_used_for_get_resource_subnet.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/get_param_not_used_for_subnet.yaml | 4 +- .../get_resource_used_for_external_network.yaml | 4 +- .../pass/valid_heat_template.yaml | 4 +- .../fail/heat_template_1.yaml | 4 +- ...at_template_2_identical_to_heat_template_2.yaml | 4 +- .../pass/unique_resource_template_1.yml | 4 +- .../pass/unique_resource_template_2.yml | 4 +- ...ource_stack_name_without_vnf_name_or_module.yml | 4 +- .../pass/unique_resource_template.yml | 4 +- ...ource_stack_name_without_vnf_name_or_module.yml | 4 +- .../pass/unique_resource_template.yml | 4 +- .../fail/duplicate_resource_template.yml | 4 +- .../fail/unique_resource_template.yml | 4 +- .../pass/unique_resource_template_1.yml | 4 +- .../pass/unique_resource_template_2.yml | 4 +- .../fail/duplicate_resource_template.yml | 4 +- .../pass/unique_resource_template.yml | 4 +- .../fail/no_value_volume.yaml | 4 +- .../fail/use_get_param_volume.yml | 4 +- .../pass/valid_template_volume.yml | 4 +- .../fail/more_outputs_than_parameters.yaml | 4 +- .../fail/more_outputs_than_parameters_volume.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../pass/valid_template_volume.yaml | 4 +- ...ch_vm_type_instance_uuid_volume_attachment.yaml | 4 +- .../mismatch_vm_type_volume_id_nova_server_id.yaml | 4 +- .../fail/mismatch_vm_type_volume_id_param.yaml | 4 +- .../fail/mismatch_vm_type_volume_id_resource.yaml | 4 +- ...smatch_vm_type_volume_id_volume_attachment.yaml | 4 +- ...type_volume_id_volume_attachment_uppercase.yaml | 4 +- .../pass/valid_template.yaml | 4 +- .../fail/badly_named_volume_1.yaml | 4 +- .../fail/missing_keyword.yaml | 4 +- .../fail/only_nova_severs_in_volume.yaml | 4 +- .../pass/well_named_volume.yaml | 4 +- .../fail/missing_outputs_volume.yaml | 4 +- .../pass/well_named_volume.yaml | 4 +- ...smatch_resource_keys_outputs_keys_1_volume.yaml | 4 +- ...smatch_resource_keys_outputs_keys_2_volume.yaml | 4 +- ...smatch_resource_keys_outputs_keys_3_volume.yaml | 4 +- .../fail/more_outputs_than_resources_volume.yaml | 4 +- .../fail/more_resources_than_outputs_volume.yaml | 4 +- .../pass/valid_template_volume.yaml | 4 +- ice_validator/tests/parametrizers.py | 445 ++++++++--------- ice_validator/tests/structures.py | 31 +- .../tests/test_all_referenced_resources_exists.py | 18 +- .../tests/test_allowed_address_pair_format.py | 136 ++++-- ...d_address_pairs_include_vm_type_network_role.py | 24 +- ice_validator/tests/test_availability_zone.py | 20 +- .../tests/test_availability_zone_get_param.py | 6 +- ice_validator/tests/test_base_template_names.py | 6 +- .../tests/test_base_template_outputs_consumed.py | 29 +- .../tests/test_cloud_config_resource_id.py | 32 +- ice_validator/tests/test_env_and_yaml_same_name.py | 24 +- .../tests/test_env_no_resource_registry.py | 19 +- .../tests/test_environment_file_structure.py | 64 ++- ice_validator/tests/test_fixed_ips_format.py | 43 +- .../tests/test_fixed_ips_format_use_get_param.py | 10 +- .../test_fixed_ips_include_vm_type_network_role.py | 6 +- .../test_get_file_only_reference_local_files.py | 6 +- .../tests/test_heat_numeric_parameters.py | 6 +- ice_validator/tests/test_heat_pairs_provided.py | 6 +- ice_validator/tests/test_heat_parameter_section.py | 38 +- .../test_heat_template_and_env_file_extension.py | 6 +- ..._template_parameters_contain_required_fields.py | 6 +- .../tests/test_heat_template_structure.py | 32 +- .../tests/test_heat_templates_provided.py | 6 +- .../tests/test_multipart_mime_resource_id.py | 32 +- ice_validator/tests/test_nested_templates.py | 24 +- .../tests/test_nested_templates_invalid_nesting.py | 12 +- ice_validator/tests/test_network_format.py | 9 +- ...network_format_use_get_param_or_get_resource.py | 6 +- ..._unused_parameters_between_env_and_templates.py | 6 +- .../tests/test_nova_servergroup_policies.py | 6 +- .../test_nova_servers_correct_parameter_types.py | 24 +- ice_validator/tests/test_nova_servers_index.py | 38 +- .../tests/test_nova_servers_resource_ids.py | 14 +- ice_validator/tests/test_nova_servers_vm_types.py | 6 +- .../test_nova_servers_vm_types_use_get_param.py | 6 +- ice_validator/tests/test_parse_yaml.py | 6 +- ice_validator/tests/test_port_resource_ids.py | 80 +-- ...test_referenced_and_defined_parameters_match.py | 6 +- .../test_required_parameters_no_constraints.py | 6 +- ...t_required_parameters_specified_in_env_files.py | 6 +- ...uired_parameters_specified_in_heat_templates.py | 6 +- .../tests/test_reserve_port_fixed_ips_format.py | 18 +- .../tests/test_resource_ids_alphanumeric_only.py | 6 +- .../tests/test_servers_have_optional_metadata.py | 6 +- .../tests/test_servers_have_required_metadata.py | 6 +- .../tests/test_servers_metadata_use_get_param.py | 6 +- ice_validator/tests/test_subnet_format.py | 33 +- ..._subnet_format_use_get_param_or_get_resource.py | 6 +- ice_validator/tests/test_unique_name_resources.py | 6 +- ...t_unique_name_str_replace_use_params_in_tmpl.py | 6 +- .../test_unique_name_str_replace_use_req_params.py | 6 +- .../test_unique_resources_across_all_templates.py | 6 +- .../tests/test_unique_resources_across_template.py | 6 +- ice_validator/tests/test_vm_type_resource_id.py | 5 +- ice_validator/tests/test_volume_format_outputs.py | 6 +- .../tests/test_volume_outputs_consumed.py | 6 +- ice_validator/tests/test_volume_resource_ids.py | 63 ++- ice_validator/tests/test_volume_templates.py | 6 +- .../tests/test_volume_templates_outputs.py | 6 +- .../test_volume_templates_outputs_resources.py | 6 +- ice_validator/tests/utils/__init__.py | 6 +- ice_validator/tests/utils/nested_files.py | 50 +- ice_validator/tests/utils/network_roles.py | 82 ++-- ice_validator/tests/utils/ports.py | 176 ++++--- ice_validator/tests/utils/vm_types.py | 34 +- 285 files changed, 2083 insertions(+), 1613 deletions(-) (limited to 'ice_validator/tests') diff --git a/ice_validator/tests/__init__.py b/ice_validator/tests/__init__.py index e8f24cd..ec11176 100644 --- a/ice_validator/tests/__init__.py +++ b/ice_validator/tests/__init__.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/conftest.py b/ice_validator/tests/conftest.py index 84429cf..09baa9a 100644 --- a/ice_validator/tests/conftest.py +++ b/ice_validator/tests/conftest.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -34,29 +34,377 @@ # limitations under the License. # # ============LICENSE_END============================================ -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# +import collections +import csv +import datetime +import hashlib +import io +import json import os +import sys +import time +import docutils.core +import pytest +from more_itertools import partition +from six import string_types +import xlsxwriter __path__ = [os.path.dirname(os.path.abspath(__file__))] +resolution_steps_file = "resolution_steps.json" +requirements_file = "requirements.json" + +FAILURE_DATA = {} + +report_columns = [ + ("Input File", "file"), + ("Test", "test_file"), + ("Requirements", "req_description"), + ("Resolution Steps", "resolution_steps"), + ("Error Message", "message"), + ("Raw Test Output", "raw_output"), +] +report = collections.OrderedDict(report_columns) + + +def extract_error_msg(rep): + msg = str(rep.longrepr.reprcrash) + if "AssertionError:" in msg: + return msg.split("AssertionError:")[1] + else: + return msg + + +@pytest.hookimpl(tryfirst=True, hookwrapper=True) +def pytest_runtest_makereport(item, call): + + outcome = yield + rep = outcome.get_result() + + output_dir = "{}/../output".format(__path__[0]) + if rep.outcome == "failed": + if not os.path.exists(output_dir): + os.mkdir(output_dir) + + if hasattr(item.function, "requirement_ids"): + requirement_ids = item.function.requirement_ids + else: + requirement_ids = "" + + if "environment_pair" in item.fixturenames: + resolved_pair = "{} environment pair".format( + item.funcargs["environment_pair"]["name"] + ) + elif "heat_volume_pair" in item.fixturenames: + resolved_pair = "{} volume pair".format( + item.funcargs["heat_volume_pair"]["name"] + ) + elif "heat_templates" in item.fixturenames: + resolved_pair = item.funcargs["heat_templates"] + elif "yaml_files" in item.fixturenames: + resolved_pair = item.funcargs["yaml_files"] + else: + resolved_pair = rep.nodeid.split("[")[1][:-1] + + FAILURE_DATA[len(FAILURE_DATA)] = { + "file": resolved_pair, + "vnfrqts": requirement_ids, + "test": item.function.__name__, + "test_file": item.function.__module__.split(".")[-1], + "raw_output": str(rep.longrepr), + "message": extract_error_msg(rep), + } + + with open("{}/failures".format(output_dir), "w") as f: + json.dump(FAILURE_DATA, f, indent=4) + + +def make_timestamp(): + timezone = time.tzname[time.localtime().tm_isdst] + return "{} {}".format(str(datetime.datetime.now()), timezone) + + +def pytest_sessionfinish(session, exitstatus): + if not session.config.option.template_dir: + return + template_path = os.path.abspath(session.config.option.template_dir[0]) + profile_name = session.config.option.validation_profile_name + generate_report( + "{}/../output".format(__path__[0]), + template_path, + profile_name, + session.config.option.report_format, + ) + + +def pytest_runtest_setup(item): + profile = item.session.config.option.validation_profile + markers = set(m.name for m in item.iter_markers()) + if not profile and markers: + pytest.skip("No validation profile selected. Skipping tests with marks.") + if profile and markers and profile not in markers: + pytest.skip("Doesn't match selection validation profile") + + +def make_href(path): + paths = [path] if isinstance(path, string_types) else path + links = [] + for p in paths: + abs_path = os.path.abspath(p) + filename = os.path.split(abs_path)[1] + links.append( + "{filename}".format( + abs_path=abs_path, filename=filename + ) + ) + return "
".join(links) + + +def generate_report(outpath, template_path, profile_name, output_format): + failures = "{}/failures".format(outpath) + faildata = None + rdata = None + hdata = None + + if os.path.exists(failures): + with open(failures, "r") as f: + faildata = json.loads(f.read()) + else: + faildata = {} + + resolution_steps = "{}/../{}".format(__path__[0], resolution_steps_file) + if os.path.exists(resolution_steps): + with open(resolution_steps, "r") as f: + rdata = json.loads(f.read()) + + heat_requirements = "{}/../{}".format(__path__[0], requirements_file) + if os.path.exists(heat_requirements): + with open(heat_requirements, "r") as f: + hdata = json.loads(f.read()) + + # point requirements at the most recent version + current_version = hdata["current_version"] + hdata = hdata["versions"][current_version]["needs"] + # mapping requirement IDs from failures to requirement descriptions + for k, v in faildata.items(): + req_text = "" + if v["vnfrqts"] != "": + for req in v["vnfrqts"]: + if req in hdata: + req_text += "\n\n{}: \n{}".format(req, hdata[req]["description"]) + faildata[k]["req_description"] = req_text + + # mapping resolution steps to module and test name + for k, v in faildata.items(): + faildata[k]["resolution_steps"] = "" + for rs in rdata: + if v["test_file"] == rs["module"] and v["test"] == rs["function"]: + faildata[k]["resolution_steps"] = "\n{}: \n{}".format( + rs["header"], rs["resolution_steps"] + ) + output_format = output_format.lower().strip() if output_format else "html" + if output_format == "html": + generate_html_report(outpath, profile_name, template_path, faildata) + elif output_format == "excel": + generate_excel_report(outpath, profile_name, template_path, faildata) + elif output_format == "csv": + generate_csv_report(outpath, profile_name, template_path, faildata) + else: + raise ValueError("Unsupported output format: " + output_format) + + +def generate_csv_report(output_dir, profile_name, template_path, faildata): + rows = [] + rows.append(["Validation Failures"]) + headers = [ + ("Profile Selected:", profile_name), + ("Report Generated At:", make_timestamp()), + ("Directory Validated:", template_path), + ("Checksum:", hash_directory(template_path)), + ("Total Errors:", len(faildata)), + ] + + rows.append([]) + for header in headers: + rows.append(header) + rows.append([]) + + # table header + rows.append([col for col, _ in report_columns]) + + # table content + for data in faildata.values(): + rows.append( + [ + data.get("file", ""), + data.get("test_file", ""), + data.get("req_description", ""), + data.get("resolution_steps", ""), + data.get("message", ""), + data.get("raw_output", ""), + ] + ) + + output_path = os.path.join(output_dir, "report.csv") + with open(output_path, "w", newline="") as f: + writer = csv.writer(f) + for row in rows: + writer.writerow(row) + + +def generate_excel_report(output_dir, profile_name, template_path, faildata): + output_path = os.path.join(output_dir, "report.xlsx") + workbook = xlsxwriter.Workbook(output_path) + bold = workbook.add_format({"bold": True}) + code = workbook.add_format(({"font_name": "Courier", "text_wrap": True})) + normal = workbook.add_format({"text_wrap": True}) + heading = workbook.add_format({"bold": True, "font_size": 18}) + worksheet = workbook.add_worksheet("failures") + worksheet.write(0, 0, "Validation Failures", heading) + + headers = [ + ("Profile Selected:", profile_name), + ("Report Generated At:", make_timestamp()), + ("Directory Validated:", template_path), + ("Checksum:", hash_directory(template_path)), + ("Total Errors:", len(faildata)), + ] + for row, (header, value) in enumerate(headers, start=2): + worksheet.write(row, 0, header, bold) + worksheet.write(row, 1, value) + + worksheet.set_column(0, len(headers) - 1, 40) + worksheet.set_column(len(headers), len(headers), 80) + + # table header + start_error_table_row = 2 + len(headers) + 2 + for col_num, (col_name, _) in enumerate(report_columns): + worksheet.write(start_error_table_row, col_num, col_name, bold) + + # table content + for row, data in enumerate(faildata.values(), start=start_error_table_row + 1): + for col, key in enumerate(report.values()): + if key == "file": + paths = ( + [data[key]] if isinstance(data[key], string_types) else data[key] + ) + contents = "\n".join(paths) + worksheet.write(row, col, contents, normal) + elif key == "raw_output": + worksheet.write_string(row, col, data[key], code) + else: + worksheet.write(row, col, data[key], normal) + + workbook.close() + + +def generate_html_report(outpath, profile_name, template_path, faildata): + with open("{}/report.html".format(outpath), "w") as of: + body_begin = """ + +

Validation Failures

+ + """.format( + profile=profile_name, + timestamp=make_timestamp(), + checksum=hash_directory(template_path), + template_dir=template_path, + num_failures=len(faildata), + ) + of.write(body_begin) + + if len(faildata) == 0: + of.write("

Success! No validation failures detected.

") + return + + table_begin = '' + of.write(table_begin) + + # table headers + of.write("") + for k, v in report.items(): + of.write(''.format(k)) + of.write("") + + # table content + for k, v in faildata.items(): + of.write("") + for rk, rv in report.items(): + if rv == "file": + value = make_href(v[rv]) + elif rv == "raw_output": + value = "
{}
".format(v[rv]) + elif rv == "req_description": + parts = docutils.core.publish_parts( + writer_name="html", source=v[rv] + ) + value = parts["body"] + else: + value = v[rv].replace("\n", "
") + of.write(" ".format(value)) + of.write("") + + of.write("
{}
{}
") + def pytest_addoption(parser): """ Add needed CLI arguments """ - parser.addoption("--template-directory", - dest="template_dir", - action="append", - help="Directory which holds the templates for validation") + parser.addoption( + "--template-directory", + dest="template_dir", + action="append", + help="Directory which holds the templates for validation", + ) + + parser.addoption( + "--self-test", + dest="self_test", + action="store_true", + help="Test the unit tests against their fixtured data", + ) + + parser.addoption( + "--validation-profile", + dest="validation_profile", + action="store", + help="Runs all unmarked tests plus test with a matching marker", + ) - parser.addoption("--self-test", - dest="self_test", - action='store_true', - help="Test the unit tests against their fixtured data") + parser.addoption( + "--validation-profile-name", + dest="validation_profile_name", + action="store", + help="Friendly name of the validation profile used in reports", + ) + + parser.addoption( + "--report-format", + dest="report_format", + action="store", + help="Format of output report (html, csv, excel)", + ) def pytest_configure(config): @@ -64,12 +412,14 @@ def pytest_configure(config): Ensure that we are receive either `--self-test` or `--template-dir= 1 - and m.group(2) == network_role): + if ( + v4[2] == "internal" and + len(m.groups()) > 1 and + m.group(2) == network_role + ): break - elif (v4[2] == "external" - and len(m.groups()) > 0 - and m.group(1).endswith("_" + network_role)): + elif ( + v4[2] == "external" + and len(m.groups()) > 0 + and m.group(1).endswith("_" + network_role) + ): break else: invalid_allowed_address_pairs.append(param) - assert not set(invalid_allowed_address_pairs), ( - 'invalid_allowed_address_pairs %s' % list( - set(invalid_allowed_address_pairs))) + assert not set( + invalid_allowed_address_pairs + ), "invalid_allowed_address_pairs %s" % list(set(invalid_allowed_address_pairs)) diff --git a/ice_validator/tests/test_allowed_address_pairs_include_vm_type_network_role.py b/ice_validator/tests/test_allowed_address_pairs_include_vm_type_network_role.py index cd2e50f..7ce9c43 100644 --- a/ice_validator/tests/test_allowed_address_pairs_include_vm_type_network_role.py +++ b/ice_validator/tests/test_allowed_address_pairs_include_vm_type_network_role.py @@ -38,9 +38,9 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -''' +""" test_allowed_address_pairs_include_vm_type_network_role -''' +""" import pytest import yaml @@ -48,19 +48,18 @@ import yaml from .helpers import validates from .utils.ports import get_invalid_ip_addresses -VERSION = '1.0.0' +VERSION = "1.0.0" # pylint: disable=invalid-name -@validates('R-41492', - 'R-35735') +@validates("R-41492", "R-35735") def test_allowed_address_pairs_include_vm_type_network_role(heat_template): - ''' + """ Check that all allowed_address_pairs include the {vm_type} of the nova server it is associated to and also contains the {network_role} of the network it is associated with - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) @@ -68,9 +67,10 @@ def test_allowed_address_pairs_include_vm_type_network_role(heat_template): if "resources" not in yml: pytest.skip("No resources specified in the heat template") - invalid_ip_addresses = get_invalid_ip_addresses(yml['resources'], - "allowed_address_pairs") + invalid_ip_addresses = get_invalid_ip_addresses( + yml["resources"], "allowed_address_pairs" + ) - assert not set(invalid_ip_addresses), ( - 'invalid ip addresses allowed address pairs %s' % list( - set(invalid_ip_addresses))) + assert not set( + invalid_ip_addresses + ), "invalid ip addresses allowed address pairs %s" % list(set(invalid_ip_addresses)) diff --git a/ice_validator/tests/test_availability_zone.py b/ice_validator/tests/test_availability_zone.py index 6e0de32..4f250b8 100644 --- a/ice_validator/tests/test_availability_zone.py +++ b/ice_validator/tests/test_availability_zone.py @@ -47,14 +47,14 @@ import yaml from .helpers import validates -VERSION = '1.1.0' +VERSION = "1.1.0" -@validates('R-98450') +@validates("R-98450") def test_availability_zone_naming(heat_template): - ''' + """ Make sure all availability zones are properly formatted - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) @@ -75,13 +75,13 @@ def test_availability_zone_naming(heat_template): if v1["type"] == "OS::Nova::Server": for k2, v2 in v1["properties"].items(): - if k2 != 'availability_zone': + if k2 != "availability_zone": continue - if 'str_replace' in v2: + if "str_replace" in v2: continue - if not re.match(r'availability_zone_\d+', v2["get_param"]): + if not re.match(r"availability_zone_\d+", v2["get_param"]): invalid_availability_zones.add(v2["get_param"]) - assert not invalid_availability_zones, ( - 'invalid availability zones %s' % list( - invalid_availability_zones)) + assert not invalid_availability_zones, "invalid availability zones %s" % list( + invalid_availability_zones + ) diff --git a/ice_validator/tests/test_availability_zone_get_param.py b/ice_validator/tests/test_availability_zone_get_param.py index 088a272..456f74b 100644 --- a/ice_validator/tests/test_availability_zone_get_param.py +++ b/ice_validator/tests/test_availability_zone_get_param.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_base_template_names.py b/ice_validator/tests/test_base_template_names.py index 40452ae..f9196a9 100644 --- a/ice_validator/tests/test_base_template_names.py +++ b/ice_validator/tests/test_base_template_names.py @@ -72,7 +72,5 @@ def test_base_template_names(template_dir): if RE_BASE.search(filename): base_template_count += 1 - assert base_template_count == 1, ( - 'must be 1 "*_base_*" in %s not %d' % ( - filenames, - base_template_count)) + msg = 'must be 1 "*_base_*" in %s not %d' % (filenames, base_template_count) + assert base_template_count == 1, msg diff --git a/ice_validator/tests/test_base_template_outputs_consumed.py b/ice_validator/tests/test_base_template_outputs_consumed.py index fc1edc1..5d5bcd9 100644 --- a/ice_validator/tests/test_base_template_outputs_consumed.py +++ b/ice_validator/tests/test_base_template_outputs_consumed.py @@ -38,9 +38,9 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -''' +""" test_base_template_outputs_consumed -''' +""" from os import path, sep @@ -49,27 +49,29 @@ import yaml from .helpers import validates -VERSION = '1.0.0' +VERSION = "1.0.0" # pylint: disable=invalid-name -@validates('R-52753') +@validates("R-52753") def test_base_template_outputs_consumed(heat_templates): - ''' + """ Check that all outputs in the base template is consumed by another template. The exception is the predefined output parameters. - ''' + """ base_template = "" base_template_yml = "" for heat_template in heat_templates: with open(heat_template) as fh: yml = yaml.load(fh) basename = path.splitext(heat_template)[0].rsplit(sep, 1)[1] - if (basename.endswith("_base") - or basename.startswith("base_") - or basename.find("_base_") > 0): + if ( + basename.endswith("_base") or + basename.startswith("base_") or + basename.find("_base_") > 0 + ): base_template = heat_template base_template_yml = yml @@ -77,8 +79,7 @@ def test_base_template_outputs_consumed(heat_templates): if "outputs" not in base_template_yml: pytest.skip("No outputs specified in the base template") - predefined_outputs = ['oam_management_v4_address', - 'oam_management_v6_address'] + predefined_outputs = ["oam_management_v4_address", "oam_management_v6_address"] base_outputs = set(base_template_yml["outputs"]) - set(predefined_outputs) # get all add-on templates @@ -94,6 +95,6 @@ def test_base_template_outputs_consumed(heat_templates): parameters = yml["parameters"].keys() non_base_parameters.extend(parameters) - assert base_outputs <= set(non_base_parameters), ( - 'unconsumed outputs %s' % list( - base_outputs - set(non_base_parameters))) + assert base_outputs <= set(non_base_parameters), "unconsumed outputs %s" % list( + base_outputs - set(non_base_parameters) + ) diff --git a/ice_validator/tests/test_cloud_config_resource_id.py b/ice_validator/tests/test_cloud_config_resource_id.py index bd04e37..de82fe4 100644 --- a/ice_validator/tests/test_cloud_config_resource_id.py +++ b/ice_validator/tests/test_cloud_config_resource_id.py @@ -38,10 +38,10 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -''' +""" A VNF's Heat Orchestration Template's Resource ``OS::Heat::CloudConfig`` Resource ID **MUST** contain the ``{vm-type}``. -''' +""" import pytest @@ -49,24 +49,24 @@ from .structures import Heat from .helpers import validates from .utils import vm_types -VERSION = '1.0.0' +VERSION = "1.0.0" -@validates('R-04747') +@validates("R-04747") def test_cloud_config(heat_template): - '''validate resource ids - ''' + """validate resource ids + """ h = Heat(filepath=heat_template) if not h.resources: - pytest.skip('No resources in this template') + pytest.skip("No resources in this template") cloud_configs = get_cloud_configs(h) if not cloud_configs: - pytest.skip('No CloudConfig resources in this template') + pytest.skip("No CloudConfig resources in this template") resource_vm_types = vm_types.get_vm_types(h.resources) if not resource_vm_types: - pytest.skip('No resources with {vm-type} in this template') + pytest.skip("No resources with {vm-type} in this template") bad = set() for rid in cloud_configs: @@ -75,13 +75,17 @@ def test_cloud_config(heat_template): break else: bad.add(rid) - assert not bad, 'CloudConfigs %s have {vm-type} not in %s' % ( - list(bad), - list(resource_vm_types)) + assert not bad, "CloudConfigs %s have {vm-type} not in %s" % ( + list(bad), + list(resource_vm_types), + ) def get_cloud_configs(heat): """Return list of resource_id whose type is OS::Heat::CloudConfig. """ - return [rid for rid, resource in heat.resources.items() - if heat.nested_get(resource, 'type') == 'OS::Heat::CloudConfig'] + return [ + rid + for rid, resource in heat.resources.items() + if heat.nested_get(resource, "type") == "OS::Heat::CloudConfig" + ] diff --git a/ice_validator/tests/test_env_and_yaml_same_name.py b/ice_validator/tests/test_env_and_yaml_same_name.py index 865845a..58b0f39 100644 --- a/ice_validator/tests/test_env_and_yaml_same_name.py +++ b/ice_validator/tests/test_env_and_yaml_same_name.py @@ -39,31 +39,27 @@ # from .helpers import validates -'''test_env_and_yaml_same_name -''' +"""test_env_and_yaml_same_name +""" from os import listdir from os import path -VERSION = '1.0.0' +VERSION = "1.0.0" -@validates('R-67205', 'R-35727', 'R-22656') +@validates("R-67205", "R-35727", "R-22656") def test_env_and_yaml_same_name(template_dir): - ''' + """ Check that all environment template filenames are identical to an associated Heat template filenames. Log the result of the check and add the filename of any environment file that is badly named. - ''' + """ files = listdir(template_dir) - env_files = [f for f in files - if path.splitext(f)[-1] == ".env"] - yaml_files = [f for f in files - if path.splitext(f)[-1] in ['.yml', '.yaml']] + env_files = [f for f in files if path.splitext(f)[-1] == ".env"] + yaml_files = [f for f in files if path.splitext(f)[-1] in [".yml", ".yaml"]] unmatched = [] for filename in env_files: basename = path.splitext(filename)[0] - if (basename + '.yaml' not in yaml_files - and basename + '.yml' not in yaml_files): + if basename + ".yaml" not in yaml_files and basename + ".yml" not in yaml_files: unmatched.append(filename) - assert not unmatched, ( - 'files with no corresponding .y[a]ml %s' % unmatched) + assert not unmatched, "files with no corresponding .y[a]ml %s" % unmatched diff --git a/ice_validator/tests/test_env_no_resource_registry.py b/ice_validator/tests/test_env_no_resource_registry.py index 1d03d74..5d6949a 100644 --- a/ice_validator/tests/test_env_no_resource_registry.py +++ b/ice_validator/tests/test_env_no_resource_registry.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -42,17 +42,18 @@ import yaml from .helpers import validates -VERSION = '1.0.0' +VERSION = "1.0.0" -@validates('R-67231') +@validates("R-67231") def test_env_no_resource_registry(env_files): - ''' + """ A VNF's Heat Orchestration template's Environment File's **MUST NOT** contain the "resource_registry:" section. - ''' + """ for filename in env_files: with open(filename) as fi: yml = yaml.load(fi) - assert 'resource_registry' not in yml, ( - '%s contains "resource_registry"' % filename) + assert "resource_registry" not in yml, ( + '%s contains "resource_registry"' % filename + ) diff --git a/ice_validator/tests/test_environment_file_structure.py b/ice_validator/tests/test_environment_file_structure.py index b50629e..34d3b48 100644 --- a/ice_validator/tests/test_environment_file_structure.py +++ b/ice_validator/tests/test_environment_file_structure.py @@ -46,68 +46,64 @@ import pytest from .helpers import validates -VERSION = '1.0.0' +VERSION = "1.0.0" # pylint: disable=invalid-name def test_environment_structure(env_file): - ''' + """ Check that all environments files only have the allowed sections - ''' - key_values = ["parameters", "event_sinks", "encrypted_parameters", - "parameter_merge_strategies"] + """ + key_values = [ + "parameters", + "event_sinks", + "encrypted_parameters", + "parameter_merge_strategies", + ] with open(env_file) as fh: yml = yaml.load(fh) - assert [k for k in key_values if k in yml], ( - '%s missing any of %s' % ( - env_file, - key_values)) + assert [k for k in key_values if k in yml], "%s missing any of %s" % ( + env_file, + key_values, + ) -@validates('R-03324') +@validates("R-03324") def test_environment_file_contains_required_sections(env_file): - ''' + """ Check that all environments files only have the allowed sections - ''' + """ required_keys = ["parameters"] with open(env_file) as fh: yml = yaml.load(fh) missing_keys = [v for v in required_keys if v not in yml] - assert not missing_keys, '%s missing %s' % (env_file, missing_keys) + assert not missing_keys, "%s missing %s" % (env_file, missing_keys) def test_environment_file_sections_have_the_right_format(env_file): - ''' + """ Check that all environment files have sections of the right format. Do note that it only tests for dicts or not dicts currently. - ''' - dict_keys = [ - "parameters", - "encrypted_parameters", - "parameter_merge_strategies"] - not_dict_keys = [ - "event_sinks"] + """ + dict_keys = ["parameters", "encrypted_parameters", "parameter_merge_strategies"] + not_dict_keys = ["event_sinks"] with open(env_file) as fh: yml = yaml.load(fh) if not [k for k in dict_keys + not_dict_keys if k in yml]: - pytest.skip('The fixture is not applicable for this test') - - bad_dict_keys = [k for k in dict_keys - if k in yml - and not isinstance(yml[k], dict)] - bad_not_dict_keys = [k for k in not_dict_keys - if k in yml - and isinstance(yml[k], dict)] + pytest.skip("The fixture is not applicable for this test") + + bad_dict_keys = [k for k in dict_keys if k in yml and not isinstance(yml[k], dict)] + bad_not_dict_keys = [ + k for k in not_dict_keys if k in yml and isinstance(yml[k], dict) + ] errors = [] if bad_dict_keys: - errors.append('must be dict %s' % bad_dict_keys) + errors.append("must be dict %s" % bad_dict_keys) if bad_not_dict_keys: - errors.append('must not be dict %s' % bad_not_dict_keys) - assert not errors, '%s errors:\n %s' % ( - env_file, - '\n '.join(errors)) + errors.append("must not be dict %s" % bad_not_dict_keys) + assert not errors, "%s errors:\n %s" % (env_file, "\n ".join(errors)) diff --git a/ice_validator/tests/test_fixed_ips_format.py b/ice_validator/tests/test_fixed_ips_format.py index 8e159ba..77a515e 100644 --- a/ice_validator/tests/test_fixed_ips_format.py +++ b/ice_validator/tests/test_fixed_ips_format.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -41,8 +41,7 @@ import pytest import yaml from .utils.ports import is_reserved_port -from .utils.network_roles import get_network_role_from_port,\ - property_uses_get_resource +from .utils.network_roles import get_network_role_from_port, property_uses_get_resource import re @@ -52,23 +51,23 @@ def test_fixed_ips_format(heat_template): naming conventions ''' formats = [ - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_ip_\d+')], - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_ip_\d+')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_v6_ip_\d+')], - ["fixed_ips", "comma_delimited_list", "internal", - re.compile(r'(.+?)_int_(.+?)_ips')], - ["fixed_ips", "comma_delimited_list", "internal", - re.compile(r'(.+?)_int_(.+?)_v6_ips')], - ["fixed_ips", "comma_delimited_list", "external", - re.compile(r'(.+?)_ips')], - ["fixed_ips", "comma_delimited_list", "external", - re.compile(r'(.+?)_v6_ips')], - ] + ["fixed_ips", "string", "internal", + re.compile(r'(.+?)_int_(.+?)_ip_\d+')], + ["fixed_ips", "string", "internal", + re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')], + ["fixed_ips", "string", "external", + re.compile(r'(.+?)_ip_\d+')], + ["fixed_ips", "string", "external", + re.compile(r'(.+?)_v6_ip_\d+')], + ["fixed_ips", "comma_delimited_list", "internal", + re.compile(r'(.+?)_int_(.+?)_ips')], + ["fixed_ips", "comma_delimited_list", "internal", + re.compile(r'(.+?)_int_(.+?)_v6_ips')], + ["fixed_ips", "comma_delimited_list", "external", + re.compile(r'(.+?)_ips')], + ["fixed_ips", "comma_delimited_list", "external", + re.compile(r'(.+?)_v6_ips')], + ] with open(heat_template) as fh: yml = yaml.load(fh) diff --git a/ice_validator/tests/test_fixed_ips_format_use_get_param.py b/ice_validator/tests/test_fixed_ips_format_use_get_param.py index 13f028d..df57c01 100644 --- a/ice_validator/tests/test_fixed_ips_format_use_get_param.py +++ b/ice_validator/tests/test_fixed_ips_format_use_get_param.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -44,9 +44,9 @@ from .utils.ports import is_reserved_port def test_fixed_ips_format_use_get_parm(heat_template): - ''' + """ Make sure all fixed_ips properties only use get_param - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) diff --git a/ice_validator/tests/test_fixed_ips_include_vm_type_network_role.py b/ice_validator/tests/test_fixed_ips_include_vm_type_network_role.py index 85c0a4d..53f6453 100644 --- a/ice_validator/tests/test_fixed_ips_include_vm_type_network_role.py +++ b/ice_validator/tests/test_fixed_ips_include_vm_type_network_role.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_get_file_only_reference_local_files.py b/ice_validator/tests/test_get_file_only_reference_local_files.py index 6588a61..65d470c 100644 --- a/ice_validator/tests/test_get_file_only_reference_local_files.py +++ b/ice_validator/tests/test_get_file_only_reference_local_files.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_heat_numeric_parameters.py b/ice_validator/tests/test_heat_numeric_parameters.py index ef29987..3345e4e 100644 --- a/ice_validator/tests/test_heat_numeric_parameters.py +++ b/ice_validator/tests/test_heat_numeric_parameters.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_heat_pairs_provided.py b/ice_validator/tests/test_heat_pairs_provided.py index c89917e..b9c8290 100644 --- a/ice_validator/tests/test_heat_pairs_provided.py +++ b/ice_validator/tests/test_heat_pairs_provided.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_heat_parameter_section.py b/ice_validator/tests/test_heat_parameter_section.py index 2aab7d3..dde4176 100644 --- a/ice_validator/tests/test_heat_parameter_section.py +++ b/ice_validator/tests/test_heat_parameter_section.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -43,16 +43,15 @@ import re import yaml # one or more (alphanumeric or underscore) -RE_VALID_PARAMETER_NAME = re.compile(r'[\w_]+$') +RE_VALID_PARAMETER_NAME = re.compile(r"[\w_]+$") def test_parameter_valid_keys(yaml_file): - ''' + """ Make sure each parameter is a dict and only contain valid keys - ''' - key_values = ["type", "label", "description", - "hidden", "constraints", "immutable"] + """ + key_values = ["type", "label", "description", "hidden", "constraints", "immutable"] with open(yaml_file) as fh: yml = yaml.load(fh) @@ -72,11 +71,11 @@ def test_parameter_valid_keys(yaml_file): assert not set(invalid_params) -@validates('R-90526') +@validates("R-90526") def test_default_values(yaml_file): - ''' + """ Make sure no default values are set for any parameter. - ''' + """ with open(yaml_file) as fh: yml = yaml.load(fh) @@ -88,19 +87,19 @@ def test_default_values(yaml_file): for v1 in yml["parameters"].values(): if not isinstance(v1, dict): continue - if any(k == 'default' for k in v1): + if any(k == "default" for k in v1): invalid_params.append(str(v1)) assert not set(invalid_params) -@validates('R-25877') +@validates("R-25877") def test_parameter_names(yaml_file): - ''' + """ A VNF's Heat Orchestration Template's parameter name (i.e., ) **MUST** contain only alphanumeric characters and underscores ('_'). - ''' + """ with open(yaml_file) as fh: yml = yaml.load(fh) @@ -108,8 +107,7 @@ def test_parameter_names(yaml_file): if "parameters" not in yml: pytest.skip("No parameters specified in the heat template") - for key in yml['parameters']: - assert RE_VALID_PARAMETER_NAME.match(key), ( - '%s parameter "%s" not alphanumeric or underscore' % ( - yaml_file, - key)) + for key in yml["parameters"]: + assert RE_VALID_PARAMETER_NAME.match( + key + ), '%s parameter "%s" not alphanumeric or underscore' % (yaml_file, key) diff --git a/ice_validator/tests/test_heat_template_and_env_file_extension.py b/ice_validator/tests/test_heat_template_and_env_file_extension.py index 8174c20..de83745 100644 --- a/ice_validator/tests/test_heat_template_and_env_file_extension.py +++ b/ice_validator/tests/test_heat_template_and_env_file_extension.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_heat_template_parameters_contain_required_fields.py b/ice_validator/tests/test_heat_template_parameters_contain_required_fields.py index 31684a5..6d9e502 100644 --- a/ice_validator/tests/test_heat_template_parameters_contain_required_fields.py +++ b/ice_validator/tests/test_heat_template_parameters_contain_required_fields.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_heat_template_structure.py b/ice_validator/tests/test_heat_template_structure.py index cc05df9..1e0b8c8 100644 --- a/ice_validator/tests/test_heat_template_structure.py +++ b/ice_validator/tests/test_heat_template_structure.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -101,23 +101,23 @@ def test_heat_template_structure_sections_have_the_right_format(yaml_file): @validates('R-11441') def test_parameter_type(yaml_file): types = [ - 'string', - 'number', - 'json', - 'comma_delimited_list', - 'boolean', - ] + 'string', + 'number', + 'json', + 'comma_delimited_list', + 'boolean', + ] with open(yaml_file) as fh: yml = yaml.load(fh) for key, param in yml.get('parameters', {}).items(): assert isinstance(param, dict), '%s parameter %s is not dict' % ( - yaml_file, - key) + yaml_file, + key) assert 'type' in param, '%s parameter %s has no "type"' % ( - yaml_file, - key) + yaml_file, + key) typ = param['type'] assert typ in types, '%s parameter %s has invalid type "%s"' % ( - yaml_file, - key, - typ) + yaml_file, + key, + typ) diff --git a/ice_validator/tests/test_heat_templates_provided.py b/ice_validator/tests/test_heat_templates_provided.py index 187397f..168dbe0 100644 --- a/ice_validator/tests/test_heat_templates_provided.py +++ b/ice_validator/tests/test_heat_templates_provided.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_multipart_mime_resource_id.py b/ice_validator/tests/test_multipart_mime_resource_id.py index 58023a5..fe6fe47 100644 --- a/ice_validator/tests/test_multipart_mime_resource_id.py +++ b/ice_validator/tests/test_multipart_mime_resource_id.py @@ -38,10 +38,10 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -''' +""" A VNF's Heat Orchestration Template's Resource ``OS::Heat::MultipartMime`` Resource ID **MUST** contain the ``{vm-type}``. -''' +""" import pytest @@ -49,24 +49,24 @@ from .structures import Heat from .helpers import validates from .utils import vm_types -VERSION = '1.0.1' +VERSION = "1.0.1" -@validates('R-30804') +@validates("R-30804") def test_multipart_mime(heat_template): - '''validate resource ids - ''' + """validate resource ids + """ h = Heat(filepath=heat_template) if not h.resources: - pytest.skip('No resources in this template') + pytest.skip("No resources in this template") multipart_mimes = get_multipart_mimes(h) if not multipart_mimes: - pytest.skip('No MultipartMime resources in this template') + pytest.skip("No MultipartMime resources in this template") resource_vm_types = vm_types.get_vm_types(h.resources) if not resource_vm_types: - pytest.skip('No resources with {vm-type} in this template') + pytest.skip("No resources with {vm-type} in this template") bad = set() for rid in multipart_mimes: @@ -75,13 +75,17 @@ def test_multipart_mime(heat_template): break else: bad.add(rid) - assert not bad, 'MultipartMime %s have {vm-type} not in %s' % ( - list(bad), - list(resource_vm_types)) + assert not bad, "MultipartMime %s have {vm-type} not in %s" % ( + list(bad), + list(resource_vm_types), + ) def get_multipart_mimes(heat): """Return list of resource_id whose type is OS::Heat::MultipartMime. """ - return [rid for rid, resource in heat.resources.items() - if heat.nested_get(resource, 'type') == 'OS::Heat::MultipartMime'] + return [ + rid + for rid, resource in heat.resources.items() + if heat.nested_get(resource, "type") == "OS::Heat::MultipartMime" + ] diff --git a/ice_validator/tests/test_nested_templates.py b/ice_validator/tests/test_nested_templates.py index 12f0f34..c9caa19 100644 --- a/ice_validator/tests/test_nested_templates.py +++ b/ice_validator/tests/test_nested_templates.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -44,12 +44,12 @@ from os import path from .utils.nested_files import get_list_of_nested_files -@validates('R-70276') +@validates("R-70276") def test_all_nested_templates_provided(yaml_files): - ''' + """ Check that all templates marked as volume templates are in fact volume templates - ''' + """ nested_yaml_files = [] for yaml_file in yaml_files: @@ -57,13 +57,13 @@ def test_all_nested_templates_provided(yaml_files): yml = yaml.load(fh) if "resources" not in yml: continue - nested_yaml_files.extend(get_list_of_nested_files( - yml["resources"], path.dirname(yaml_file))) + nested_yaml_files.extend( + get_list_of_nested_files(yml["resources"], path.dirname(yaml_file)) + ) # detect all provided nested files - provided_nested_yaml_files = [f1 - for f1 in nested_yaml_files - for f2 in yaml_files - if f1 in f2] + provided_nested_yaml_files = [ + f1 for f1 in nested_yaml_files for f2 in yaml_files if f1 in f2 + ] assert set(provided_nested_yaml_files) == set(nested_yaml_files) diff --git a/ice_validator/tests/test_nested_templates_invalid_nesting.py b/ice_validator/tests/test_nested_templates_invalid_nesting.py index 00d6d25..edd5ca3 100644 --- a/ice_validator/tests/test_nested_templates_invalid_nesting.py +++ b/ice_validator/tests/test_nested_templates_invalid_nesting.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -56,8 +56,8 @@ def test_valid_nesting(yaml_files): if "resources" not in yml: continue invalid_nesting.extend(check_for_invalid_nesting( - yml["resources"], - yaml_file, - path.dirname(yaml_file))) + yml["resources"], + yaml_file, + path.dirname(yaml_file))) assert not set(invalid_nesting) diff --git a/ice_validator/tests/test_network_format.py b/ice_validator/tests/test_network_format.py index 651267e..4bd13ad 100644 --- a/ice_validator/tests/test_network_format.py +++ b/ice_validator/tests/test_network_format.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -41,8 +41,7 @@ from .helpers import validates import pytest import yaml -from .utils.network_roles import get_network_role_from_port,\ - property_uses_get_resource +from .utils.network_roles import get_network_role_from_port, property_uses_get_resource @validates('R-62983', 'R-86182') diff --git a/ice_validator/tests/test_network_format_use_get_param_or_get_resource.py b/ice_validator/tests/test_network_format_use_get_param_or_get_resource.py index e30b344..a1b3b06 100644 --- a/ice_validator/tests/test_network_format_use_get_param_or_get_resource.py +++ b/ice_validator/tests/test_network_format_use_get_param_or_get_resource.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_no_unused_parameters_between_env_and_templates.py b/ice_validator/tests/test_no_unused_parameters_between_env_and_templates.py index 4845751..781f35d 100644 --- a/ice_validator/tests/test_no_unused_parameters_between_env_and_templates.py +++ b/ice_validator/tests/test_no_unused_parameters_between_env_and_templates.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_nova_servergroup_policies.py b/ice_validator/tests/test_nova_servergroup_policies.py index a3bdf5a..6915fd4 100644 --- a/ice_validator/tests/test_nova_servergroup_policies.py +++ b/ice_validator/tests/test_nova_servergroup_policies.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_nova_servers_correct_parameter_types.py b/ice_validator/tests/test_nova_servers_correct_parameter_types.py index a71ee4a..8364d38 100644 --- a/ice_validator/tests/test_nova_servers_correct_parameter_types.py +++ b/ice_validator/tests/test_nova_servers_correct_parameter_types.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -53,15 +53,15 @@ def test_nova_servers_correct_parameter_types(heat_template): ''' key_values = ["name", "flavor", "image"] key_value_formats = [ - ["name", "string", - re.compile(r'(.+?)_name_\d+')], - ["name", "comma_delimited_list", - re.compile(r'(.+?)_names')], - ["flavor", "string", - re.compile(r'(.+?)_flavor_name')], - ["image", "string", - re.compile(r'(.+?)_image_name')], - ] + ["name", "string", + re.compile(r'(.+?)_name_\d+')], + ["name", "comma_delimited_list", + re.compile(r'(.+?)_names')], + ["flavor", "string", + re.compile(r'(.+?)_flavor_name')], + ["image", "string", + re.compile(r'(.+?)_image_name')], + ] with open(heat_template) as fh: yml = yaml.load(fh) diff --git a/ice_validator/tests/test_nova_servers_index.py b/ice_validator/tests/test_nova_servers_index.py index 3ca99a0..85ce335 100644 --- a/ice_validator/tests/test_nova_servers_index.py +++ b/ice_validator/tests/test_nova_servers_index.py @@ -38,11 +38,11 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -''' +""" Ensure that if a resource_id has an {index}, then all resources of the same vm-type have an index, the indices are consecutive and start with 0. -''' +""" import collections import re @@ -53,15 +53,15 @@ from .structures import Heat from .helpers import validates from .utils import vm_types -VERSION = '1.1.0' +VERSION = "1.1.0" -RE_INDEXED_RESOURCE_ID = re.compile(r'\w+_(?P\d+)$') +RE_INDEXED_RESOURCE_ID = re.compile(r"\w+_(?P\d+)$") -@validates('R-11690') +@validates("R-11690") def test_indices(heat_templates): - '''validate indices - ''' + """validate indices + """ indexed_resource_ids = {} resources = {} for heat_template in heat_templates: @@ -70,14 +70,14 @@ def test_indices(heat_templates): indexed_resource_ids.update(get_indexed_resource_ids(h.resources)) resources.update(h.resources) if not resources: - pytest.skip('No resources found') + pytest.skip("No resources found") if not indexed_resource_ids: - pytest.skip('No resources with {index} found') + pytest.skip("No resources with {index} found") types = get_types(resources, indexed_resource_ids) if not types: - pytest.skip('No resources with {vm-type} found') + pytest.skip("No resources with {vm-type} found") indices = collections.defaultdict(list) for resource_id, vm_type in types.items(): @@ -89,10 +89,18 @@ def test_indices(heat_templates): bad[vm_type] = index_list break assert not bad, ( - 'vm-type indices must be consecutive, unique,' - ' and start at 0.\n %s' % ( - '\n '.join(['Resource ID %s: VM Type: %s' % (x, y) - for x, y in types.items() if y in bad]))) + "vm-type indices must be consecutive, unique," + " and start at 0.\n %s" + % ( + "\n ".join( + [ + "Resource ID %s: VM Type: %s" % (x, y) + for x, y in types.items() + if y in bad + ] + ) + ) + ) def get_indexed_resource_ids(resources): @@ -103,7 +111,7 @@ def get_indexed_resource_ids(resources): for resource in resources: match = RE_INDEXED_RESOURCE_ID.match(resource) if match: - indexed_resource_ids[resource] = int(match.groupdict()['index']) + indexed_resource_ids[resource] = int(match.groupdict()["index"]) return indexed_resource_ids diff --git a/ice_validator/tests/test_nova_servers_resource_ids.py b/ice_validator/tests/test_nova_servers_resource_ids.py index 3f588dc..d35fce5 100644 --- a/ice_validator/tests/test_nova_servers_resource_ids.py +++ b/ice_validator/tests/test_nova_servers_resource_ids.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -44,11 +44,11 @@ from .helpers import validates from .utils.vm_types import get_vm_type_for_nova_server -@validates('R-01455', 'R-48067', 'R-00977') +@validates("R-01455", "R-48067", "R-00977") def test_nova_servers_valid_resource_ids(heat_template): - ''' + """ Make sure all nova servers have valid resource ids - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) @@ -71,7 +71,7 @@ def test_nova_servers_valid_resource_ids(heat_template): continue vm_type = vm_type.lower() - if vm_type+"_" not in k1.lower(): + if vm_type + "_" not in k1.lower(): invalid_nova_servers.append(k1) assert not set(invalid_nova_servers) diff --git a/ice_validator/tests/test_nova_servers_vm_types.py b/ice_validator/tests/test_nova_servers_vm_types.py index 9511ecd..48abe04 100644 --- a/ice_validator/tests/test_nova_servers_vm_types.py +++ b/ice_validator/tests/test_nova_servers_vm_types.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py b/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py index 2be7e6f..79bc4b2 100644 --- a/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py +++ b/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_parse_yaml.py b/ice_validator/tests/test_parse_yaml.py index 5246f33..637e93d 100644 --- a/ice_validator/tests/test_parse_yaml.py +++ b/ice_validator/tests/test_parse_yaml.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_port_resource_ids.py b/ice_validator/tests/test_port_resource_ids.py index a6f7093..511af35 100644 --- a/ice_validator/tests/test_port_resource_ids.py +++ b/ice_validator/tests/test_port_resource_ids.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -43,29 +43,33 @@ import pytest import yaml from .helpers import validates from .utils.vm_types import get_vm_type_for_nova_server -from .utils.network_roles import get_network_role_from_port,\ - get_network_type_from_port,\ - property_uses_get_resource - - -@validates('R-29865', - 'R-69014', - 'R-05201', - 'R-68936', - 'R-32025', - 'R-11168', - 'R-84322', - 'R-96983', - 'R-26506', - 'R-20453', - 'R-26351') +from .utils.network_roles import ( + get_network_role_from_port, + get_network_type_from_port, + property_uses_get_resource, +) + + +@validates( + "R-29865", + "R-69014", + "R-05201", + "R-68936", + "R-32025", + "R-11168", + "R-84322", + "R-96983", + "R-26506", + "R-20453", + "R-26351", +) def test_port_resource_ids(heat_template): - ''' + """ Check that all resource ids for ports follow the right naming convention to include the {vm_type} of the nova server it is associated to and also contains the {network_role} of the network it is associated with - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) @@ -74,22 +78,22 @@ def test_port_resource_ids(heat_template): pytest.skip("No resources specified in the heat template") port_patterns = { - 'internal': re.compile(r'(.+?)_\d+_int_(.+?)_port_\d+'), - 'external': re.compile(r'(.+?)_\d+_(.+?)_port_\d+'), - } - resources = yml['resources'] + "internal": re.compile(r"(.+?)_\d+_int_(.+?)_port_\d+"), + "external": re.compile(r"(.+?)_\d+_(.+?)_port_\d+"), + } + resources = yml["resources"] invalid_ports = [] for k, v in resources.items(): if not isinstance(v, dict): continue - if 'type' not in v: + if "type" not in v: continue - if v['type'] not in 'OS::Nova::Server': + if v["type"] not in "OS::Nova::Server": continue - if 'properties' not in v: + if "properties" not in v: continue - if 'networks' not in v['properties']: + if "networks" not in v["properties"]: continue has_vm_type = False @@ -102,18 +106,18 @@ def test_port_resource_ids(heat_template): vm_type = vm_type.lower() # get all ports associated with the nova server - properties = v['properties'] - for v2 in properties['networks']: + properties = v["properties"] + for v2 in properties["networks"]: for k3, v3 in v2.items(): - if k3 != 'port': + if k3 != "port": continue if not isinstance(v3, dict): continue - if 'get_param' in v3: + if "get_param" in v3: continue - elif 'get_resource' in v3: - port_id = v3['get_resource'] + elif "get_resource" in v3: + port_id = v3["get_resource"] if not resources[port_id]: continue port_resource = resources[port_id] @@ -121,7 +125,7 @@ def test_port_resource_ids(heat_template): else: continue - has_vm_type = vm_type+"_" in port_id + has_vm_type = vm_type + "_" in port_id has_network_role = False if port_resource: @@ -141,9 +145,9 @@ def test_port_resource_ids(heat_template): else: # match the assumed naming convention for ports # if the specified port is provided via get_param - network_type = 'external' + network_type = "external" if "int_" in port_id: - network_type = 'internal' + network_type = "internal" if port_patterns[network_type].match(port_id): has_network_role = True diff --git a/ice_validator/tests/test_referenced_and_defined_parameters_match.py b/ice_validator/tests/test_referenced_and_defined_parameters_match.py index d31831f..918d396 100644 --- a/ice_validator/tests/test_referenced_and_defined_parameters_match.py +++ b/ice_validator/tests/test_referenced_and_defined_parameters_match.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_required_parameters_no_constraints.py b/ice_validator/tests/test_required_parameters_no_constraints.py index 247eab6..9e89191 100644 --- a/ice_validator/tests/test_required_parameters_no_constraints.py +++ b/ice_validator/tests/test_required_parameters_no_constraints.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_required_parameters_specified_in_env_files.py b/ice_validator/tests/test_required_parameters_specified_in_env_files.py index f60f8d7..15894c3 100644 --- a/ice_validator/tests/test_required_parameters_specified_in_env_files.py +++ b/ice_validator/tests/test_required_parameters_specified_in_env_files.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py b/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py index d86a22b..bbfcf2d 100644 --- a/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py +++ b/ice_validator/tests/test_required_parameters_specified_in_heat_templates.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_reserve_port_fixed_ips_format.py b/ice_validator/tests/test_reserve_port_fixed_ips_format.py index 42d9a61..5b28d06 100644 --- a/ice_validator/tests/test_reserve_port_fixed_ips_format.py +++ b/ice_validator/tests/test_reserve_port_fixed_ips_format.py @@ -51,15 +51,15 @@ def test_reserve_port_fixed_ips_format(heat_template): follow the allowed naming conventions ''' allowed_formats = [ - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_floating_v6_ip')], - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_floating_ip')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_floating_v6_ip')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_floating_ip')], - ] + ["fixed_ips", "string", "internal", + re.compile(r'(.+?)_int_(.+?)_floating_v6_ip')], + ["fixed_ips", "string", "internal", + re.compile(r'(.+?)_int_(.+?)_floating_ip')], + ["fixed_ips", "string", "external", + re.compile(r'(.+?)_floating_v6_ip')], + ["fixed_ips", "string", "external", + re.compile(r'(.+?)_floating_ip')], + ] with open(heat_template) as fh: yml = yaml.load(fh) diff --git a/ice_validator/tests/test_resource_ids_alphanumeric_only.py b/ice_validator/tests/test_resource_ids_alphanumeric_only.py index c124ea7..8342520 100644 --- a/ice_validator/tests/test_resource_ids_alphanumeric_only.py +++ b/ice_validator/tests/test_resource_ids_alphanumeric_only.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_servers_have_optional_metadata.py b/ice_validator/tests/test_servers_have_optional_metadata.py index 0e72e6c..de40fdf 100644 --- a/ice_validator/tests/test_servers_have_optional_metadata.py +++ b/ice_validator/tests/test_servers_have_optional_metadata.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_servers_have_required_metadata.py b/ice_validator/tests/test_servers_have_required_metadata.py index 9d10fc9..3a12b9d 100644 --- a/ice_validator/tests/test_servers_have_required_metadata.py +++ b/ice_validator/tests/test_servers_have_required_metadata.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_servers_metadata_use_get_param.py b/ice_validator/tests/test_servers_metadata_use_get_param.py index c2d1d54..1b5f869 100644 --- a/ice_validator/tests/test_servers_metadata_use_get_param.py +++ b/ice_validator/tests/test_servers_metadata_use_get_param.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_subnet_format.py b/ice_validator/tests/test_subnet_format.py index e5f28cc..51b513c 100644 --- a/ice_validator/tests/test_subnet_format.py +++ b/ice_validator/tests/test_subnet_format.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -40,26 +40,21 @@ import pytest import yaml -from .utils.network_roles import get_network_role_from_port,\ - property_uses_get_resource +from .utils.network_roles import get_network_role_from_port, property_uses_get_resource import re def test_subnet_format(heat_template): - ''' + """ Make sure all subnet properties follow the allowed naming conventions - ''' + """ formats = [ - ["subnet_id", "string", "internal", - re.compile(r'int_(.+?)_subnet_id')], - ["subnet_id", "string", "internal", - re.compile(r'int_(.+?)_v6_subnet_id')], - ["subnet_id", "string", "external", - re.compile(r'(.+?)_subnet_id')], - ["subnet_id", "string", "external", - re.compile(r'(.+?)_v6_subnet_id')], - ] + ["subnet_id", "string", "internal", re.compile(r"int_(.+?)_subnet_id")], + ["subnet_id", "string", "internal", re.compile(r"int_(.+?)_v6_subnet_id")], + ["subnet_id", "string", "external", re.compile(r"(.+?)_subnet_id")], + ["subnet_id", "string", "external", re.compile(r"(.+?)_v6_subnet_id")], + ] with open(heat_template) as fh: yml = yaml.load(fh) @@ -87,9 +82,9 @@ def test_subnet_format(heat_template): continue # define the network_type - network_type = 'external' - if network_param.startswith('int_'): - network_type = 'internal' + network_type = "external" + if network_param.startswith("int_"): + network_type = "internal" for k2, v2 in v1["properties"].items(): if k2 != "fixed_ips": diff --git a/ice_validator/tests/test_subnet_format_use_get_param_or_get_resource.py b/ice_validator/tests/test_subnet_format_use_get_param_or_get_resource.py index 597dd22..b462ef5 100644 --- a/ice_validator/tests/test_subnet_format_use_get_param_or_get_resource.py +++ b/ice_validator/tests/test_subnet_format_use_get_param_or_get_resource.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_unique_name_resources.py b/ice_validator/tests/test_unique_name_resources.py index a89dd1d..df803dd 100644 --- a/ice_validator/tests/test_unique_name_resources.py +++ b/ice_validator/tests/test_unique_name_resources.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_unique_name_str_replace_use_params_in_tmpl.py b/ice_validator/tests/test_unique_name_str_replace_use_params_in_tmpl.py index 80397b1..fed7e90 100644 --- a/ice_validator/tests/test_unique_name_str_replace_use_params_in_tmpl.py +++ b/ice_validator/tests/test_unique_name_str_replace_use_params_in_tmpl.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_unique_name_str_replace_use_req_params.py b/ice_validator/tests/test_unique_name_str_replace_use_req_params.py index d89d8d9..00df3b5 100644 --- a/ice_validator/tests/test_unique_name_str_replace_use_req_params.py +++ b/ice_validator/tests/test_unique_name_str_replace_use_req_params.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_unique_resources_across_all_templates.py b/ice_validator/tests/test_unique_resources_across_all_templates.py index 2d05147..d8fd066 100644 --- a/ice_validator/tests/test_unique_resources_across_all_templates.py +++ b/ice_validator/tests/test_unique_resources_across_all_templates.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_unique_resources_across_template.py b/ice_validator/tests/test_unique_resources_across_template.py index 9ed8927..6bfc43c 100644 --- a/ice_validator/tests/test_unique_resources_across_template.py +++ b/ice_validator/tests/test_unique_resources_across_template.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_vm_type_resource_id.py b/ice_validator/tests/test_vm_type_resource_id.py index 9a47656..39a11ef 100644 --- a/ice_validator/tests/test_vm_type_resource_id.py +++ b/ice_validator/tests/test_vm_type_resource_id.py @@ -68,7 +68,6 @@ def test_vm_type_resource_id(heat_template): for rid in h.resources: lower_rid = rid.lower() for vm_type, lower_vm_type in vm_types.items(): - if (lower_rid.startswith(lower_vm_type) - and not rid.startswith(vm_type)): - bad[rid] = vm_type + if lower_rid.startswith(lower_vm_type) and not rid.startswith(vm_type): + bad[rid] = vm_type assert not bad, 'resource_id which do not match their vm-type %s' % bad diff --git a/ice_validator/tests/test_volume_format_outputs.py b/ice_validator/tests/test_volume_format_outputs.py index 02ab9c2..3a00275 100644 --- a/ice_validator/tests/test_volume_format_outputs.py +++ b/ice_validator/tests/test_volume_format_outputs.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_volume_outputs_consumed.py b/ice_validator/tests/test_volume_outputs_consumed.py index 648a689..3ee7178 100644 --- a/ice_validator/tests/test_volume_outputs_consumed.py +++ b/ice_validator/tests/test_volume_outputs_consumed.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_volume_resource_ids.py b/ice_validator/tests/test_volume_resource_ids.py index a6a7334..45b05e7 100644 --- a/ice_validator/tests/test_volume_resource_ids.py +++ b/ice_validator/tests/test_volume_resource_ids.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # @@ -45,11 +45,11 @@ from .utils.vm_types import get_vm_type_for_nova_server def test_volume_resource_ids(heat_template): - ''' + """ Check that all resource ids for cinder volumes follow the right naming convention to include the {vm_type} of the nova server it is associated to - ''' + """ with open(heat_template) as fh: yml = yaml.load(fh) @@ -57,25 +57,24 @@ def test_volume_resource_ids(heat_template): if "resources" not in yml: pytest.skip("No resources specified in the heat template") - volume_pattern = re.compile(r'(.+?)_volume_id_\d+') - resources = yml['resources'] + volume_pattern = re.compile(r"(.+?)_volume_id_\d+") + resources = yml["resources"] invalid_volumes = [] for k, v in resources.items(): if not isinstance(v, dict): continue - if 'type' not in v: + if "type" not in v: continue - if v['type'] not in ['OS::Nova::Server', - 'OS::Cinder::VolumeAttachment']: + if v["type"] not in ["OS::Nova::Server", "OS::Cinder::VolumeAttachment"]: continue - if v['type'] == 'OS::Nova::Server': + if v["type"] == "OS::Nova::Server": # check block_device_mapping and make sure the right # {vm_type} is used - if 'properties' not in v: + if "properties" not in v: continue - if 'block_device_mapping' not in v['properties']: + if "block_device_mapping" not in v["properties"]: continue vm_type = get_vm_type_for_nova_server(v) @@ -84,17 +83,15 @@ def test_volume_resource_ids(heat_template): vm_type = vm_type.lower() # get the volume_id from the block_device_mapping - properties = v['properties'] - for v2 in properties['block_device_mapping']: + properties = v["properties"] + for v2 in properties["block_device_mapping"]: for k3, v3 in v2.items(): - if k3 != 'volume_id': + if k3 != "volume_id": continue if not isinstance(v3, dict): continue - volume_id = ( - v3.get('get_param') or - v3.get('get_resource')) + volume_id = v3.get("get_param") or v3.get("get_resource") if not volume_id: continue if isinstance(volume_id, list): @@ -102,30 +99,30 @@ def test_volume_resource_ids(heat_template): else: volume_id = volume_id.lower() - if vm_type+"_" not in volume_id: + if vm_type + "_" not in volume_id: invalid_volumes.append(volume_id) - elif v['type'] == 'OS::Cinder::VolumeAttachment': + elif v["type"] == "OS::Cinder::VolumeAttachment": # check the volume attachment and the {vm_type} # of the corresponding nova server - if 'properties' not in v: + if "properties" not in v: continue - if 'volume_id' not in v['properties']: + if "volume_id" not in v["properties"]: continue - if 'instance_uuid' not in v['properties']: + if "instance_uuid" not in v["properties"]: continue - properties = v['properties'] + properties = v["properties"] # get the instance_uuid and when applicable # the nova server instance instance_uuid = None nova_server = None - if 'get_param' in properties['instance_uuid']: + if "get_param" in properties["instance_uuid"]: continue - elif 'get_resource' in properties['instance_uuid']: - instance_uuid = properties['instance_uuid']['get_resource'] + elif "get_resource" in properties["instance_uuid"]: + instance_uuid = properties["instance_uuid"]["get_resource"] if not resources[instance_uuid]: continue nova_server = resources[instance_uuid] @@ -135,9 +132,9 @@ def test_volume_resource_ids(heat_template): # get the volume_id volume_id = None - volume_id = ( - properties['volume_id'].get('get_param') or - properties['volume_id'].get('get_resource')) + volume_id = properties["volume_id"].get("get_param") or properties[ + "volume_id" + ].get("get_resource") if not volume_id: continue if isinstance(volume_id, list): @@ -155,14 +152,14 @@ def test_volume_resource_ids(heat_template): if not vm_type: continue vm_type = vm_type.lower() - if vm_type+"_" not in volume_id: + if vm_type + "_" not in volume_id: invalid_volumes.append(volume_id) else: # extract the assumed {vm_type} from volume_id m = volume_pattern.match(volume_id) if m: vm_type = m.group(1).lower() - if vm_type+"_" not in instance_uuid: + if vm_type + "_" not in instance_uuid: invalid_volumes.append(volume_id) else: continue diff --git a/ice_validator/tests/test_volume_templates.py b/ice_validator/tests/test_volume_templates.py index d30ee19..191ae9d 100644 --- a/ice_validator/tests/test_volume_templates.py +++ b/ice_validator/tests/test_volume_templates.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_volume_templates_outputs.py b/ice_validator/tests/test_volume_templates_outputs.py index 975afb7..f18f1cd 100644 --- a/ice_validator/tests/test_volume_templates_outputs.py +++ b/ice_validator/tests/test_volume_templates_outputs.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/test_volume_templates_outputs_resources.py b/ice_validator/tests/test_volume_templates_outputs_resources.py index 85a9d02..90096e3 100644 --- a/ice_validator/tests/test_volume_templates_outputs_resources.py +++ b/ice_validator/tests/test_volume_templates_outputs_resources.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/utils/__init__.py b/ice_validator/tests/utils/__init__.py index e8f24cd..ec11176 100644 --- a/ice_validator/tests/utils/__init__.py +++ b/ice_validator/tests/utils/__init__.py @@ -2,11 +2,11 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2018 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”); +# 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 # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# 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 # diff --git a/ice_validator/tests/utils/nested_files.py b/ice_validator/tests/utils/nested_files.py index 39306eb..02f733d 100644 --- a/ice_validator/tests/utils/nested_files.py +++ b/ice_validator/tests/utils/nested_files.py @@ -45,15 +45,15 @@ from os import path import re import yaml -VERSION = '1.0.2' +VERSION = "1.0.2" def get_list_of_nested_files(yml, dirpath): - ''' + """ return a list of all nested files - ''' + """ - if not hasattr(yml, 'items'): + if not hasattr(yml, "items"): return [] nested_files = [] @@ -68,34 +68,29 @@ def get_list_of_nested_files(yml, dirpath): nested_files.append(filepath) nested_files.extend(get_list_of_nested_files(t_yml, dirpath)) elif t == "OS::Heat::ResourceGroup": - rdt = (v.get("properties", {}) - .get("resource_def", {}) - .get("type", None)) + rdt = v.get("properties", {}).get("resource_def", {}).get("type", None) if rdt and (rdt.endswith(".yml") or rdt.endswith(".yaml")): filepath = path.join(dirpath, rdt) with open(filepath) as fh: rdt_yml = yaml.load(fh) nested_files.append(filepath) - nested_files.extend( - get_list_of_nested_files(rdt_yml, dirpath)) + nested_files.extend(get_list_of_nested_files(rdt_yml, dirpath)) if isinstance(v, dict): - nested_files.extend( - get_list_of_nested_files(v, dirpath)) + nested_files.extend(get_list_of_nested_files(v, dirpath)) elif isinstance(v, list): for d in v: - nested_files.extend( - get_list_of_nested_files(d, dirpath)) + nested_files.extend(get_list_of_nested_files(d, dirpath)) return nested_files def check_for_invalid_nesting(yml, yaml_file, dirpath): - ''' + """ return a list of all nested files - ''' - if not hasattr(yml, 'items'): + """ + if not hasattr(yml, "items"): return [] invalid_nesting = [] - p = re.compile('^[A-z]*::[A-z]*::[A-z]*$') + p = re.compile("^[A-z]*::[A-z]*::[A-z]*$") for v in yml.values(): if isinstance(v, dict) and "type" in v: @@ -108,8 +103,8 @@ def check_for_invalid_nesting(yml, yaml_file, dirpath): invalid_nesting.append(yaml_file) continue elif not p.match(rd["type"]) and not ( - rd["type"].endswith(".yml") - or rd["type"].endswith(".yaml")): + rd["type"].endswith(".yml") or rd["type"].endswith(".yaml") + ): filepath = path.join(dirpath, rd["type"]) else: continue @@ -120,20 +115,11 @@ def check_for_invalid_nesting(yml, yaml_file, dirpath): yml = yaml.load(fh) except yaml.YAMLError as e: invalid_nesting.append(filepath) - print(e) # pylint: disable=superfluous-parens - invalid_nesting.extend(check_for_invalid_nesting( - yml, - filepath, - dirpath)) + print(e) # pylint: disable=superfluous-parens + invalid_nesting.extend(check_for_invalid_nesting(yml, filepath, dirpath)) if isinstance(v, dict): - invalid_nesting.extend(check_for_invalid_nesting( - v, - yaml_file, - dirpath)) + invalid_nesting.extend(check_for_invalid_nesting(v, yaml_file, dirpath)) elif isinstance(v, list): for d in v: - invalid_nesting.extend(check_for_invalid_nesting( - d, - yaml_file, - dirpath)) + invalid_nesting.extend(check_for_invalid_nesting(d, yaml_file, dirpath)) return invalid_nesting diff --git a/ice_validator/tests/utils/network_roles.py b/ice_validator/tests/utils/network_roles.py index 3f8d6b8..d4b2cce 100644 --- a/ice_validator/tests/utils/network_roles.py +++ b/ice_validator/tests/utils/network_roles.py @@ -43,37 +43,31 @@ import socket def get_network_role_from_port(resource): - ''' + """ get the network role from a neutron port resource - ''' + """ if not isinstance(resource, dict): return None - if 'type' not in resource: + if "type" not in resource: return None - if resource['type'] != 'OS::Neutron::Port': + if resource["type"] != "OS::Neutron::Port": return None - if 'properties' not in resource: + if "properties" not in resource: return None formats = [ - ["network", "string", "internal", - re.compile(r'int_(.+?)_net_id')], - ["network", "string", "internal", - re.compile(r'int_(.+?)_net_name')], - ["network", "string", "external", - re.compile(r'(.+?)_net_id')], - ["network", "string", "external", - re.compile(r'(.+?)_net_name')], - ] + ["network", "string", "internal", re.compile(r"int_(.+?)_net_id")], + ["network", "string", "internal", re.compile(r"int_(.+?)_net_name")], + ["network", "string", "external", re.compile(r"(.+?)_net_id")], + ["network", "string", "external", re.compile(r"(.+?)_net_name")], + ] for k1, v1 in resource["properties"].items(): - if k1 != 'network': + if k1 != "network": continue # get the network id or name - network = ( - v1.get('get_param') or - v1.get('get_resource')) + network = v1.get("get_param") or v1.get("get_resource") if not network: continue @@ -86,31 +80,27 @@ def get_network_role_from_port(resource): def get_network_type_from_port(resource): - ''' + """ get the network type from a neutron port resource - ''' + """ if not isinstance(resource, dict): return None - if 'type' not in resource: + if "type" not in resource: return None - if resource['type'] != 'OS::Neutron::Port': + if resource["type"] != "OS::Neutron::Port": return None - if 'properties' not in resource: + if "properties" not in resource: return None formats = [ - ["network", "string", "internal", - re.compile(r'int_(.+?)_net_id')], - ["network", "string", "internal", - re.compile(r'int_(.+?)_net_name')], - ["network", "string", "external", - re.compile(r'(.+?)_net_id')], - ["network", "string", "external", - re.compile(r'(.+?)_net_name')], - ] + ["network", "string", "internal", re.compile(r"int_(.+?)_net_id")], + ["network", "string", "internal", re.compile(r"int_(.+?)_net_name")], + ["network", "string", "external", re.compile(r"(.+?)_net_id")], + ["network", "string", "external", re.compile(r"(.+?)_net_name")], + ] for k1, v1 in resource["properties"].items(): - if k1 != 'network': + if k1 != "network": continue if "get_param" not in v1: continue @@ -122,22 +112,22 @@ def get_network_type_from_port(resource): return None -def is_valid_ip_address(ip_address, ip_type='ipv4'): - ''' +def is_valid_ip_address(ip_address, ip_type="ipv4"): + """ check if an ip address is valid - ''' - if ip_type == 'ipv4': + """ + if ip_type == "ipv4": return is_valid_ipv4_address(ip_address) - elif ip_type == 'ipv6': + elif ip_type == "ipv6": return is_valid_ipv6_address(ip_address) return False def is_valid_ipv4_address(ip_address): - ''' + """ check if an ip address of the type ipv4 is valid - ''' + """ try: socket.inet_pton(socket.AF_INET, ip_address) except AttributeError: @@ -145,17 +135,17 @@ def is_valid_ipv4_address(ip_address): socket.inet_aton(ip_address) except (OSError, socket.error): return False - return ip_address.count('.') == 3 + return ip_address.count(".") == 3 except (OSError, socket.error): return False return True def is_valid_ipv6_address(ip_address): - ''' + """ check if an ip address of the type ipv6 is valid - ''' + """ try: socket.inet_pton(socket.AF_INET6, ip_address) except (OSError, socket.error): @@ -164,13 +154,13 @@ def is_valid_ipv6_address(ip_address): def property_uses_get_resource(resource, property_name): - ''' + """ returns true if a port's network property uses the get_resource function - ''' + """ if not isinstance(resource, dict): return False - if 'properties' not in resource: + if "properties" not in resource: return False for k1, v1 in resource["properties"].items(): if k1 != property_name: diff --git a/ice_validator/tests/utils/ports.py b/ice_validator/tests/utils/ports.py index c9d4be9..e479201 100644 --- a/ice_validator/tests/utils/ports.py +++ b/ice_validator/tests/utils/ports.py @@ -44,53 +44,93 @@ import re def is_valid_ip_address(ip_address, vm_type, network_role, port_property): - ''' + """ Check the ip_address to make sure it is properly formatted and also contains {vm_type} and {network_role} - ''' + """ allowed_formats = [ - ["allowed_address_pairs", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_floating_v6_ip')], - ["allowed_address_pairs", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_floating_ip')], - ["allowed_address_pairs", "string", "external", - re.compile(r'(.+?)_floating_v6_ip')], - ["allowed_address_pairs", "string", "external", - re.compile(r'(.+?)_floating_ip')], - ["allowed_address_pairs", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')], - ["allowed_address_pairs", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_ip_\d+')], - ["allowed_address_pairs", "string", "external", - re.compile(r'(.+?)_v6_ip_\d+')], - ["allowed_address_pairs", "string", "external", - re.compile(r'(.+?)_ip_\d+')], - ["allowed_address_pairs", "comma_delimited_list", - "internal", re.compile(r'(.+?)_int_(.+?)_v6_ips')], - ["allowed_address_pairs", "comma_delimited_list", - "internal", re.compile(r'(.+?)_int_(.+?)_ips')], - ["allowed_address_pairs", "comma_delimited_list", - "external", re.compile(r'(.+?)_v6_ips')], - ["allowed_address_pairs", "comma_delimited_list", - "external", re.compile(r'(.+?)_ips')], - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')], - ["fixed_ips", "string", "internal", - re.compile(r'(.+?)_int_(.+?)_ip_\d+')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_v6_ip_\d+')], - ["fixed_ips", "string", "external", - re.compile(r'(.+?)_ip_\d+')], - ["fixed_ips", "comma_delimited_list", "internal", - re.compile(r'(.+?)_int_(.+?)_v6_ips')], - ["fixed_ips", "comma_delimited_list", "internal", - re.compile(r'(.+?)_int_(.+?)_ips')], - ["fixed_ips", "comma_delimited_list", "external", - re.compile(r'(.+?)_v6_ips')], - ["fixed_ips", "comma_delimited_list", "external", - re.compile(r'(.+?)_ips')], - ] + [ + "allowed_address_pairs", + "string", + "internal", + re.compile(r"(.+?)_int_(.+?)_floating_v6_ip"), + ], + [ + "allowed_address_pairs", + "string", + "internal", + re.compile(r"(.+?)_int_(.+?)_floating_ip"), + ], + [ + "allowed_address_pairs", + "string", + "external", + re.compile(r"(.+?)_floating_v6_ip"), + ], + [ + "allowed_address_pairs", + "string", + "external", + re.compile(r"(.+?)_floating_ip"), + ], + [ + "allowed_address_pairs", + "string", + "internal", + re.compile(r"(.+?)_int_(.+?)_v6_ip_\d+"), + ], + [ + "allowed_address_pairs", + "string", + "internal", + re.compile(r"(.+?)_int_(.+?)_ip_\d+"), + ], + ["allowed_address_pairs", "string", "external", re.compile(r"(.+?)_v6_ip_\d+")], + ["allowed_address_pairs", "string", "external", re.compile(r"(.+?)_ip_\d+")], + [ + "allowed_address_pairs", + "comma_delimited_list", + "internal", + re.compile(r"(.+?)_int_(.+?)_v6_ips"), + ], + [ + "allowed_address_pairs", + "comma_delimited_list", + "internal", + re.compile(r"(.+?)_int_(.+?)_ips"), + ], + [ + "allowed_address_pairs", + "comma_delimited_list", + "external", + re.compile(r"(.+?)_v6_ips"), + ], + [ + "allowed_address_pairs", + "comma_delimited_list", + "external", + re.compile(r"(.+?)_ips"), + ], + ["fixed_ips", "string", "internal", re.compile(r"(.+?)_int_(.+?)_v6_ip_\d+")], + ["fixed_ips", "string", "internal", re.compile(r"(.+?)_int_(.+?)_ip_\d+")], + ["fixed_ips", "string", "external", re.compile(r"(.+?)_v6_ip_\d+")], + ["fixed_ips", "string", "external", re.compile(r"(.+?)_ip_\d+")], + [ + "fixed_ips", + "comma_delimited_list", + "internal", + re.compile(r"(.+?)_int_(.+?)_v6_ips"), + ], + [ + "fixed_ips", + "comma_delimited_list", + "internal", + re.compile(r"(.+?)_int_(.+?)_ips"), + ], + ["fixed_ips", "comma_delimited_list", "external", re.compile(r"(.+?)_v6_ips")], + ["fixed_ips", "comma_delimited_list", "external", re.compile(r"(.+?)_ips")], + ] for v3 in allowed_formats: if v3[0] != port_property: @@ -98,33 +138,30 @@ def is_valid_ip_address(ip_address, vm_type, network_role, port_property): # check if pattern matches m = v3[3].match(ip_address) if m: - if (v3[2] == "internal" and - len(m.groups()) > 1): - return m.group(1) == vm_type and\ - m.group(2) == network_role - elif (v3[2] == "external" and - len(m.groups()) > 0): + if v3[2] == "internal" and len(m.groups()) > 1: + return m.group(1) == vm_type and m.group(2) == network_role + elif v3[2] == "external" and len(m.groups()) > 0: return m.group(1) == vm_type + "_" + network_role return False def get_invalid_ip_addresses(resources, port_property): - ''' + """ Get a list of valid ip addresses for a heat resources section - ''' + """ invalid_ip_addresses = [] for k, v in resources.items(): if not isinstance(v, dict): continue - if 'type' not in v: + if "type" not in v: continue - if v['type'] not in 'OS::Nova::Server': + if v["type"] not in "OS::Nova::Server": continue - if 'properties' not in v: + if "properties" not in v: continue - if 'networks' not in v['properties']: + if "networks" not in v["properties"]: continue port_resource = None @@ -134,16 +171,16 @@ def get_invalid_ip_addresses(resources, port_property): continue # get all ports associated with the nova server - properties = v['properties'] - for network in properties['networks']: + properties = v["properties"] + for network in properties["networks"]: for k3, v3 in network.items(): - if k3 != 'port': + if k3 != "port": continue if not isinstance(v3, dict): continue - if 'get_resource' in v3: - port_id = v3['get_resource'] + if "get_resource" in v3: + port_id = v3["get_resource"] if not resources[port_id]: continue port_resource = resources[port_id] @@ -168,10 +205,9 @@ def get_invalid_ip_addresses(resources, port_property): if isinstance(ip_address, list): ip_address = ip_address[0] - valid_ip_address = is_valid_ip_address(ip_address, - vm_type, - network_role, - port_property) + valid_ip_address = is_valid_ip_address( + ip_address, vm_type, network_role, port_property + ) if not valid_ip_address: invalid_ip_addresses.append(ip_address) @@ -180,16 +216,14 @@ def get_invalid_ip_addresses(resources, port_property): def is_reserved_port(port_id): - ''' + """ Checks to see if the resource id for a port follows the reserve port concept - ''' + """ formats = [ - ["port_id", - re.compile(r'reserve_port_(.+?)_floating_ip_\d+')], - ["port_id", - re.compile(r'reserve_port_(.+?)_floating_v6_ip_\d+')], - ] + ["port_id", re.compile(r"reserve_port_(.+?)_floating_ip_\d+")], + ["port_id", re.compile(r"reserve_port_(.+?)_floating_v6_ip_\d+")], + ] for f in formats: m = f[1].match(port_id.lower()) if m and m.group(1): diff --git a/ice_validator/tests/utils/vm_types.py b/ice_validator/tests/utils/vm_types.py index 41da7d9..78006b9 100644 --- a/ice_validator/tests/utils/vm_types.py +++ b/ice_validator/tests/utils/vm_types.py @@ -42,37 +42,33 @@ import re def get_vm_types_for_resource(resource): - ''' + """ Get all unique vm_types for a resource Notes: - Returns set([]) if the resource is not formatted properly, the passed resource is not a nova server - If more than one vm_type is detected all vm_types will be returned - ''' + """ if not isinstance(resource, dict): return set() - if 'type' not in resource: + if "type" not in resource: return set() - if resource['type'] != 'OS::Nova::Server': + if resource["type"] != "OS::Nova::Server": return set() - if 'properties' not in resource: + if "properties" not in resource: return set() key_values = ["name", "flavor", "image"] key_value_formats = [ - ["name", "string", - re.compile(r'(.+?)_name_\d+')], - ["name", "comma_delimited_list", - re.compile(r'(.+?)_names')], - ["flavor", "string", - re.compile(r'(.+?)_flavor_name')], - ["image", "string", - re.compile(r'(.+?)_image_name')], - ] + ["name", "string", re.compile(r"(.+?)_name_\d+")], + ["name", "comma_delimited_list", re.compile(r"(.+?)_names")], + ["flavor", "string", re.compile(r"(.+?)_flavor_name")], + ["image", "string", re.compile(r"(.+?)_image_name")], + ] vm_types = [] - for k2, v2 in resource['properties'].items(): + for k2, v2 in resource["properties"].items(): if k2 not in key_values: continue if "get_param" not in v2: @@ -90,12 +86,12 @@ def get_vm_types_for_resource(resource): def get_vm_type_for_nova_server(resource): - ''' + """ Get the vm_type for a resource Note: Returns None if not exactly one vm_type is detected, if the resource is not formatted properly, or the passed resource is not a nova server - ''' + """ vm_types = get_vm_types_for_resource(resource) # if more than one vm_type was identified, return None @@ -106,10 +102,10 @@ def get_vm_type_for_nova_server(resource): def get_vm_types(resources): - ''' + """ Get all vm_types for a list of heat resources, do note that some of the values retrieved may be invalid - ''' + """ vm_types = [] for v in resources.values(): vm_types.extend(list(get_vm_types_for_resource(v))) -- cgit 1.2.3-korg