From: stark, steven Date: Fri, 14 Sep 2018 14:55:49 +0000 (-0700) Subject: [VVP] udpating scripts for casablanca 2 X-Git-Tag: 5.0.0~93 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vvp%2Fvalidation-scripts.git;a=commitdiff_plain;h=60d5ad7d00eadd6395eca186e6fa76a43df3c6cf [VVP] udpating scripts for casablanca 2 adding scripts updates adding docrators for sections 5.2.6 - end closes out VVP 80 Change-Id: Iecac476949aa3ae3982f8c77671869583eb313d6 Issue-ID: VVP-80 Signed-off-by: stark, steven --- diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_1.yaml b/ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/fail/fail.yaml similarity index 62% rename from ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_1.yaml rename to ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/fail/fail.yaml index 8341ba0..516e57f 100644 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_1.yaml +++ b/ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/fail/fail.yaml @@ -52,17 +52,6 @@ parameters: vnf_name: type: string description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM ex1_vm_names: type: comma_delimited_list description: Name of the VM @@ -73,58 +62,18 @@ parameters: ex1_flavor_name: type: string label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex1_server_index: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } + description: Type of instance (flavor) to be used + #ex1_key: + # type: string + # label: key pair + # description: Name of the key apir the nova server will use resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - user_data: - get_resource: ex_software_config_0 ex1_nova_server_0: type: OS::Nova::Server properties: name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - project_id: { get_param: "OS::project_id" } - image: { get_param: ex1_image_name } - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } metadata: vnf_id: { get_param: vnf_id } vf_module_id: { get_param: vf_module_id } diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_2.yaml b/ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/pass/pass.yaml similarity index 66% rename from ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_2.yaml rename to ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/pass/pass.yaml index 54edcc8..84e9b6d 100644 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_2.yaml +++ b/ice_validator/tests/fixtures/test_all_get_param_have_defined_parameter/pass/pass.yaml @@ -52,21 +52,6 @@ parameters: vnf_name: type: string description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM ex1_vm_names: type: comma_delimited_list description: Name of the VM @@ -84,27 +69,6 @@ parameters: description: Name of the key apir the nova server will use resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - user_data: - get_resource: ex_software_config_0 ex1_nova_server_0: type: OS::Nova::Server @@ -114,19 +78,6 @@ resources: vnf_id: { get_param: vnf_id } vf_module_id: { get_param: vf_module_id } vnf_name: { get_param: vnf_name } - metering.stack: { get_param: "OS::stack_id" } image: { get_param: ex1_image_name} flavor: { get_param: ex1_flavor_name } key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_availability_zone_get_param/fail/not_using_get_param.yaml b/ice_validator/tests/fixtures/test_availability_zone_get_param/fail/not_using_get_param.yaml index fa457b5..4016bb9 100644 --- a/ice_validator/tests/fixtures/test_availability_zone_get_param/fail/not_using_get_param.yaml +++ b/ice_validator/tests/fixtures/test_availability_zone_get_param/fail/not_using_get_param.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,12 +37,15 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- resources: vm_type_b_server_0: type: OS::Nova::Server properties: - availability_zone: { str_replace: availability_zone_0 } + availability_zone: { not_str_replace: availability_zone_0 } name: { get_param: vm_type_b_name_0 } flavor: { get_param: vm_type_b_flavor_name} image: { get_param: vm_type_b_image_name} @@ -51,3 +54,4 @@ resources: vnf_id: { get_param: vnf_id } vf_module_id: { get_param: vf_module_id } key_name: { get_param: vm_type_b_key_name } + diff --git a/ice_validator/tests/fixtures/test_env_no_resource_registry/fail/bad.env b/ice_validator/tests/fixtures/test_env_no_resource_registry/fail/bad.env index 7be0e88..2802d00 100644 --- a/ice_validator/tests/fixtures/test_env_no_resource_registry/fail/bad.env +++ b/ice_validator/tests/fixtures/test_env_no_resource_registry/fail/bad.env @@ -2,11 +2,11 @@ # ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 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/fixtures/test_env_no_resource_registry/pass/good.env b/ice_validator/tests/fixtures/test_env_no_resource_registry/pass/good.env index 44a70dc..559e32d 100644 --- a/ice_validator/tests/fixtures/test_env_no_resource_registry/pass/good.env +++ b/ice_validator/tests/fixtures/test_env_no_resource_registry/pass/good.env @@ -2,11 +2,11 @@ # ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 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/fixtures/test_environment_file_parameters/fail/STARKDB-nested.yaml b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/STARKDB-nested.yaml new file mode 100644 index 0000000..97bc4cf --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/STARKDB-nested.yaml @@ -0,0 +1,22 @@ +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + my_nested_parameter: + type: number + description: sdfnklafd + #constraints: + # - range: { min: 100, max: 400 } + +resources: + + my_nested_resource2: + type: test + properties: + my_nested_parameter: {get_param: my_nested_parameter} + +outputs: + test_value: + value: { get_param: my_nested_parameter } \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.env b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.env new file mode 100644 index 0000000..1ce6cc4 --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.env @@ -0,0 +1,60 @@ +parameters: + + fw_oam_route_prefixes: nsaflj + + myvm_net_fqdn: nasfln + + vnf_id: sadfadf + + vf_module_id: sadfadf + + vf_module_name: sadfadf + + vnf_name: sadfadf + + starkdb_name: bghbhjb + + STARKDB_name: bghbhjb + + #STARKDB_image_name: sadfadf + + #STARKDB_flavor_dvdfg: sadfadf + + TESTDB_name: bghbhjb + + + #TESTDB_image_name: sadfadf + + #TESTDB_flavor_name: sadfadf + + stark_vol1_id: sanfkl + + param_X: sadnfklsadnfl + + priv_net_id: 123214 + + priv_sub2net_id: 123123 + + int_priv_net_id: sndfj + + workload_context: asdfsadfs + + environment_context: asdfsadfs + + availability_zone_0: sadnfjk + + STARKDB_private_v6_ips: ansdfj + + int_priv_subnet_name: safbdjk + + STARKDB_crazy_floating_ip: safd + + crazy_net_id: safd + + crazy_subnet_id: asfd + + STARKDB_crazy_ip_0: sadf + + STARKDB_crazy_ip_1: fsad + + TESTDB_name2: asnjkv diff --git a/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.yaml b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.yaml new file mode 100644 index 0000000..23f4e1a --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/fail/fail.yaml @@ -0,0 +1,325 @@ +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + fw_oam_route_prefixes: + type: string + description: nsjalfdn + + myvm_net_fqdn: + type: string + description: nasfln + + STARKDB_private_v6_ips: + type: comma_delimited_list + description: ndsajlfn + + workload_context: + type: string + description: Unique ID for this VNF instance + + availability_zone_0: + type: json + description: Unique ID for this VNF instance + + environment_context: + type: string + description: Unique ID for this VNF instance + + vnf_id: + type: string + description: Unique ID for this VNF instance + + vf_module_id: + type: json + description: Unique ID for this VNF module instance + + vnf_name: + type: string + description: Unique name for this VNF instance + + starkdb_name: + type: string + description: fdhsfbsakdjnfjdsank + + STARKDB_name: + type: json + description: fdhsfbsakdjnfjdsank + + STARKDB_image_name: + type: string + description: fdhsfbsakdjnfjdsank + + STARKDB_flavor_dvdfg: + type: string + description: fdhsfbsakdjnfjdsank + + + TESTDB_name: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_name2: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_image_name: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_flavor_name: + type: string + description: fdhsfbsakdjnfjdsank + + stark_vol1_id: + type: number + description: myvolume + constraints: + - range: { min: 100, max: 400 } + + param_X: + type: string + description: fdafsda + + priv_net_id: + type: string + description: external network + + #priv_sub2net_id: + # type: json + # description: external subnetwork + + int_priv_subnet_name: + type: string + description: sadnfjls + + int_priv_net_id: + type: string + description: internal network name + + STARKDB_crazy_floating_ip: + type: string + description: asnfjl + + crazy_net_id: + type: string + description: ansfkld + + crazy_subnet_id: + type: string + description: asdfnkal + + STARKDB_crazy_ip_0: + type: string + description: nsalfd + + STARKDB_crazy_ip_1: + type: string + description: nsalfd + + stark_rg_count: + type: string + description: nafs + +resources: + + STARKDB_cinder_attach: + type: OS::Cinder::VolumeAttachment + properties: + server: { get_resource: STARKDB_server_0 } + volume: { get_param: stark_vol1_id } + + STARKDB_server_0: + type: OS::Nova::Server + properties: + image: { get_param: STARKDB_image_name } + flavor: { get_param: STARKDB_flavor_dvdfg } + name: { get_param: starkdb_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: { get_resource: STARKDB_0_int_priv_port_0 } + - port: { get_resource: STARKDB_0_PRIV_port_1} + - port: { get_resource: STARKDB_0_crazy_port_0 } + - network: { get_param: int_priv_net_id } + user_data: { get_file: deep-nested.file } + + + STARKDB_server_1: + type: OS::Nova::Server + properties: + image: { get_param: STARKDB_image_name } + flavor: { get_param: STARKDB_flavor_dvdfg } + name: { get_param: STARKDB_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: STARKDB_1_int_priv_port_0} + - port: {get_resource: STARKDB_1_crazy_port_0} + - network: { get_param: int_priv_net_id } + + TESTDB_server_0: + type: OS::Nova::Server + properties: + image: { get_param: TESTDB_image_name } + flavor: { get_param: TESTDB_flavor_name } + name: { get_param: TESTDB_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: TESTDB_0_int_priv_port_0} + - network: { get_param: int_priv_net_id } + + availability_zone: { get_param: availability_zone_0 } + + TESTDB_server_1: + type: OS::Nova::Server + properties: + image: { get_param: TESTDB_image_name } + flavor: { get_param: TESTDB_flavor_name } + name: { get_param: TESTDB_name2 } + metadata: + test_fqdn: { get_param: myvm_net_fqdn } + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: TESTDB_0_int_priv_port_0} + - network: { get_param: int_priv_net_id } + + vol_attachment: + type: OS::Cinder::VolumeAttachment + properties: + volume_id: { get_param: stark_vol1_id } + server: { get_resource: STARKDB_server_0 } + + int_private_net_id: + type: OS::Neutron::Net + properties: + name: { get_param: int_priv_net_id } + + priv_network: + type: OS::Neutron::Net + properties: + fnsdf: nksldfnkl + + stark_nested_resource: + type: STARKDB-nested.yaml + properties: + my_nested_parame: { get_param: vnf_id } + + int_priv_subnet: + type: OS::Neutron::Subnet + properties: + name: { get_param: int_priv_subnet_name} + network_id: { get_resource: int_private_net_id } + + STARKDB_0_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_resource: int_private_net_id } + fixed_ips: + - subnet_id: { get_resource: int_priv_subnet } + - ip_address: { get_param: STARKDB_private_v6_ips } + + + STARKDB_0_crazy_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: crazy_net_id } + fixed_ips: + - subnet_id: { get_param: crazy_subnet_id } + - ip_address: { get_param: STARKDB_crazy_ip_0 } + allowed_address_pairs: [ { "ip_address": {get_param: + STARKDB_crazy_floating_ip}}] + + + STARKDB_1_crazy_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: crazy_net_id } + fixed_ips: + - subnet_id: { get_param: crazy_subnet_id } + - ip_address: { get_param: STARKDB_crazy_ip_1 } + allowed_address_pairs: [ { "ip_address": {get_param: + STARKDB_crazy_floating_ip}}] + + STARKDB_1_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_resource: int_private_net_id } + + + TESTDB_0_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: int_priv_net_id } + + STARKDB_0_PRIV_port_1: + type: OS::Neutron::Port + properties: + network: { get_param: priv_net_id } + + STARKDB_cloud_config: + type: OS::Heat::CloudConfig + + + myrouteprefix: + type: OS::ContrailV2::InterfaceRouteTable + properties: + name: + str_replace: + template: VNF_NAME_interface_route_table + params: + VNF_NAME: { get_param: vnf_name } + interface_route_table_routes: + interface_route_table_routes_route: { get_param: fw_oam_route_prefixes } + test: safd + + stark_rg: + type: OS::Heat::ResourceGroup + properties: + count: { get_param: stark_rg_count } + resource_def: + type: STARKDB-nested.yaml + properties: + my_nested_parameter: 4 + +outputs: + test_output: + value: { list_join: [',', [ { get_param: param_X }, { get_param: stark_vol1_id } ] ] } + + int_priv_su2bnet_id: + value: { get_resource: int_priv_subnet } + + int_priv_net_id: + value: { get_resource: int_private_net_id } + + STARKDB_crazy_floating_ip: + value: { get_param: STARKDB_crazy_floating_ip } + + crazy_subnet_id: + value: { get_param: crazy_subnet_id } + + crazy_net_id: + value: { get_param: crazy_net_id } diff --git a/ice_validator/tests/fixtures/test_environment_file_parameters/pass/STARKDB-nested.yaml b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/STARKDB-nested.yaml new file mode 100644 index 0000000..97bc4cf --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/STARKDB-nested.yaml @@ -0,0 +1,22 @@ +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + my_nested_parameter: + type: number + description: sdfnklafd + #constraints: + # - range: { min: 100, max: 400 } + +resources: + + my_nested_resource2: + type: test + properties: + my_nested_parameter: {get_param: my_nested_parameter} + +outputs: + test_value: + value: { get_param: my_nested_parameter } \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.env b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.env new file mode 100644 index 0000000..46d2728 --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.env @@ -0,0 +1,63 @@ +parameters: + + #fw_oam_route_prefixes: nsaflj + + #myvm_net_fqdn: nasfln + + #vnf_id: sadfadf + + #vf_module_id: sadfadf + + #vnf_name: sadfadf + + #starkdb_name: bghbhjb + + #STARKDB_name: bghbhjb + + STARKDB_image_name: sadfadf + + STARKDB_flavor_dvdfg: sadfadf + + #TESTDB_name: bghbhjb + + TESTDB_avail_hosts: test + + TESTDB_image_name: sadfadf + + TESTDB_flavor_name: sadfadf + + stark_vol1_id: sanfkl + + param_X: sadnfklsadnfl + + priv_net_id: 123214 + + #priv_sub2net_id: 123123 + + #int_priv_net_id: sndfj + + #workload_context: asdfsadfs + + #environment_context: asdfsadfs + + #availability_zone_0: sadnfjk + + #STARKDB_private_v6_ips: ansdfj + + #int_priv_subnet_name: safbdjk + + #STARKDB_crazy_floating_ip: safd + + crazy_net_id: safd + + #crazy_subnet_id: asfd + + #STARKDB_crazy_ip_0: sadf + + #STARKDB_crazy_ip_1: fsad + + #TESTDB_name2: asnjkv + + stark_rg_count: najsf + + my_nested_parameter: nasjlf \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.yaml b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.yaml new file mode 100644 index 0000000..42f23ee --- /dev/null +++ b/ice_validator/tests/fixtures/test_environment_file_parameters/pass/pass.yaml @@ -0,0 +1,304 @@ +heat_template_version: 2015-04-30 + +description: fdsafsfsa + +parameters: + + fw_oam_route_prefixes: + type: string + description: nsjalfdn + + myvm_net_fqdn: + type: string + description: nasfln + + TESTDB_avail_hosts: + type: string + description: nsfadl + + STARKDB_private_v6_ips: + type: comma_delimited_list + description: ndsajlfn + + workload_context: + type: string + description: Unique ID for this VNF instance + + availability_zone_0: + type: json + description: Unique ID for this VNF instance + + environment_context: + type: string + description: Unique ID for this VNF instance + + vnf_id: + type: string + description: Unique ID for this VNF instance + + vf_module_id: + type: json + description: Unique ID for this VNF module instance + + vnf_name: + type: string + description: Unique name for this VNF instance + + starkdb_name: + type: string + description: fdhsfbsakdjnfjdsank + + STARKDB_name: + type: json + description: fdhsfbsakdjnfjdsank + + STARKDB_image_name: + type: string + description: fdhsfbsakdjnfjdsank + + STARKDB_flavor_dvdfg: + type: string + description: fdhsfbsakdjnfjdsank + + + TESTDB_name: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_name2: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_image_name: + type: string + description: fdhsfbsakdjnfjdsank + + TESTDB_flavor_name: + type: string + description: fdhsfbsakdjnfjdsank + + stark_vol1_id: + type: number + description: myvolume + constraints: + - range: { min: 100, max: 400 } + + param_X: + type: string + description: fdafsda + + priv_net_id: + type: string + description: external network + + #priv_sub2net_id: + # type: json + # description: external subnetwork + + int_priv_subnet_name: + type: string + description: sadnfjls + + int_priv_net_id: + type: string + description: internal network name + + STARKDB_crazy_floating_ip: + type: string + description: asnfjl + + crazy_net_id: + type: string + description: ansfkld + + crazy_subnet_id: + type: string + description: asdfnkal + + STARKDB_crazy_ip_0: + type: string + description: nsalfd + + STARKDB_crazy_ip_1: + type: string + description: nsalfd + + stark_rg_count: + type: string + description: njlasd + + my_nested_parameter: + type: string + description: naskl + +resources: + + STARKDB_cinder_attach: + type: OS::Cinder::VolumeAttachment + properties: + server: { get_resource: STARKDB_server_0 } + volume: { get_param: stark_vol1_id } + + STARKDB_server_0: + type: OS::Nova::Server + properties: + image: { get_param: STARKDB_image_name } + flavor: { get_param: STARKDB_flavor_dvdfg } + name: { get_param: starkdb_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: { get_resource: STARKDB_0_int_priv_port_0 } + - port: { get_resource: STARKDB_0_PRIV_port_1} + - port: { get_resource: STARKDB_0_crazy_port_0 } + + + STARKDB_server_1: + type: OS::Nova::Server + properties: + image: { get_param: STARKDB_image_name } + flavor: { get_param: STARKDB_flavor_dvdfg } + name: { get_param: STARKDB_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: STARKDB_1_int_priv_port_0} + - port: {get_resource: STARKDB_1_crazy_port_0} + + TESTDB_server_0: + type: OS::Nova::Server + properties: + image: { get_param: TESTDB_image_name } + flavor: { get_param: TESTDB_flavor_name } + name: { get_param: TESTDB_name } + metadata: + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: TESTDB_0_int_priv_port_0} + availability_zone: { get_param: availability_zone_0 } + + TESTDB_server_1: + type: OS::Nova::Server + properties: + image: { get_param: TESTDB_image_name } + flavor: { get_param: TESTDB_flavor_name } + name: { get_param: TESTDB_name2 } + metadata: + test_fqdn: { get_param: myvm_net_fqdn } + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + vnf_name: { get_param: vnf_name } + #int_network_id: { get_resource: int_priv_network } + workload_context: { get_param: workload_context } + environment_context: { get_param: environment_context } + networks: + - port: {get_resource: TESTDB_0_int_priv_port_0} + availability_zone: { get_param: [ TESTDB_avail_hosts, 0 ] } + + + vol_attachment: + type: OS::Cinder::VolumeAttachment + properties: + volume_id: { get_param: stark_vol1_id } + server: { get_resource: STARKDB_server_0 } + + int_private_net_id: + type: OS::Neutron::Net + properties: + name: { get_param: int_priv_net_id } + + priv_network: + type: OS::Neutron::Net + properties: + fnsdf: nksldfnkl + + int_priv_subnet: + type: OS::Neutron::Subnet + properties: + name: { get_param: int_priv_subnet_name} + network_id: { get_resource: int_private_net_id } + + STARKDB_0_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_resource: int_private_net_id } + fixed_ips: + - subnet_id: { get_resource: int_priv_subnet } + - ip_address: { get_param: STARKDB_private_v6_ips } + + + STARKDB_0_crazy_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: crazy_net_id } + fixed_ips: + - subnet_id: { get_param: crazy_subnet_id } + - ip_address: { get_param: STARKDB_crazy_ip_0 } + allowed_address_pairs: [ { "ip_address": {get_param: + STARKDB_crazy_floating_ip}}] + + + STARKDB_1_crazy_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: crazy_net_id } + fixed_ips: + - subnet_id: { get_param: crazy_subnet_id } + - ip_address: { get_param: STARKDB_crazy_ip_1 } + allowed_address_pairs: [ { "ip_address": {get_param: + STARKDB_crazy_floating_ip}}] + + STARKDB_1_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_resource: int_private_net_id } + + + TESTDB_0_int_priv_port_0: + type: OS::Neutron::Port + properties: + network: { get_param: int_priv_net_id } + + STARKDB_0_PRIV_port_1: + type: OS::Neutron::Port + properties: + network: { get_param: priv_net_id } + + STARKDB_cloud_config: + type: OS::Heat::CloudConfig + + + myrouteprefix: + type: OS::ContrailV2::InterfaceRouteTable + properties: + name: + str_replace: + template: VNF_NAME_interface_route_table + params: + VNF_NAME: { get_param: vnf_name } + interface_route_table_routes: + interface_route_table_routes_route: { get_param: fw_oam_route_prefixes } + test: safd + + stark_rg: + type: OS::Heat::ResourceGroup + properties: + count: { get_param: stark_rg_count } + resource_def: + type: STARKDB-nested.yaml + properties: + my_nested_parameter: {get_param: my_nested_parameter} diff --git a/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_default_value_specified.yaml b/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_default_value_specified.yaml index e57ebe5..cd2a398 100644 --- a/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_default_value_specified.yaml +++ b/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_default_value_specified.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,9 +37,12 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- parameters: - a!: + a$: type: string label: human-readable name of the parameter description: description of the parameter @@ -51,3 +54,4 @@ parameters: - allowed_pattern: "[A-Z]+[a-zA-Z0-9]*" description: User name must start with an uppercase character immutable: true + diff --git a/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_invalid_keys.yaml b/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_invalid_keys.yaml index c3cc4c5..8fc93b0 100644 --- a/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_invalid_keys.yaml +++ b/ice_validator/tests/fixtures/test_heat_parameter_section/fail/parameter_invalid_keys.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,9 +37,12 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- parameters: - a!: + a$: type: string label: human-readable name of the parameter description: description of the parameter @@ -52,3 +55,4 @@ parameters: description: User name must start with an uppercase character immutable: true dummy_key: "dummy_key" + diff --git a/ice_validator/tests/fixtures/test_initial_configuration/fail/fail.yaml b/ice_validator/tests/fixtures/test_initial_configuration/fail/fail.yaml new file mode 100644 index 0000000..d37fa18 --- /dev/null +++ b/ice_validator/tests/fixtures/test_initial_configuration/fail/fail.yaml @@ -0,0 +1,52 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START======================================================= +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# +--- + a: 1 + b: + c: 3 + d: 4 + e: + f: 4 + g: + h: + test: test + k: g +basdnafdlsnsakdlfsdaf + test: out diff --git a/ice_validator/tests/fixtures/test_initial_configuration/pass/good_yaml_eg.yaml b/ice_validator/tests/fixtures/test_initial_configuration/pass/good_yaml_eg.yaml new file mode 100644 index 0000000..559c598 --- /dev/null +++ b/ice_validator/tests/fixtures/test_initial_configuration/pass/good_yaml_eg.yaml @@ -0,0 +1,52 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START======================================================= +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# +--- + a: 1 + b: + c: 3 + d: 4 + e: + f: 4 + g: + h: + test: test + k: g + + test: out \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_nested_templates/fail/heat_template_missing_nested_files.yaml b/ice_validator/tests/fixtures/test_nested_parameters/fail/heat_template.yaml similarity index 89% rename from ice_validator/tests/fixtures/test_nested_templates/fail/heat_template_missing_nested_files.yaml rename to ice_validator/tests/fixtures/test_nested_parameters/fail/heat_template.yaml index 87a3aa6..a6a8a0e 100644 --- a/ice_validator/tests/fixtures/test_nested_templates/fail/heat_template_missing_nested_files.yaml +++ b/ice_validator/tests/fixtures/test_nested_parameters/fail/heat_template.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,8 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- -nested_template_description: base +description: base parameters: vm_type_volume_name_0: @@ -50,13 +53,13 @@ resources: server_0: type: nested_template_1.yaml properties: - name: {get_param: server_name_0} + name: { get_param: server_name_0 } my_resource_group_1: - type: OS::Nova::Server + type: OS::Heat::ResourceGroup properties: count: 5 - resource_def: { type: nested_template_2.yaml } + resource_def: { type: nested_template_bad.yaml } outputs: vm_type_volume_id_0: - value: {get_resource: vm_type_volume_0} \ No newline at end of file + value: {get_resource: vm_type_volume_0} diff --git a/ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_1.yaml b/ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_1.yaml similarity index 97% rename from ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_1.yaml rename to ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_1.yaml index cb8e4a9..5f2732f 100644 --- a/ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_1.yaml +++ b/ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_1.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,6 +37,9 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- heat_template_version: 2013-05-23 @@ -56,4 +59,4 @@ resources: type: OS::Nova::Server properties: image: myimage - flavor: m1.small \ No newline at end of file + flavor: m1.small diff --git a/ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_bad.yaml b/ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_bad.yaml new file mode 100644 index 0000000..9271e4b --- /dev/null +++ b/ice_validator/tests/fixtures/test_nested_parameters/fail/nested_template_bad.yaml @@ -0,0 +1,71 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +--- +heat_template_version: 2013-05-23 + +resources: + volume: + type: OS::Cinder::Volume + properties: + size: 1 + + volume_attachment: + type: OS::Cinder::VolumeAttachment + properties: + volume_id: { get_resource: volume } + instance_uuid: { get_resource: instance } + + instance: + type: OS::Nova::Server + properties: + image: myimage + flavor: m1.small + +parameters: + admin_volume_size_0: + type: number + description: Size of the volume to be created. + constraints: + - range: { min: 1, max: 1024 } + description: nested templates MAY NOT have constraints. + diff --git a/ice_validator/tests/fixtures/test_nested_templates/pass/valid_nested_heat_template.yaml b/ice_validator/tests/fixtures/test_nested_parameters/pass/heat_template.yaml similarity index 86% rename from ice_validator/tests/fixtures/test_nested_templates/pass/valid_nested_heat_template.yaml rename to ice_validator/tests/fixtures/test_nested_parameters/pass/heat_template.yaml index 74b795f..bb9585b 100644 --- a/ice_validator/tests/fixtures/test_nested_templates/pass/valid_nested_heat_template.yaml +++ b/ice_validator/tests/fixtures/test_nested_parameters/pass/heat_template.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,7 +37,18 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- +description: base + +parameters: + vm_type_volume_name_0: + type: string + vm_type_volume_size_0: + type: number + resources: server_0: type: nested_template_1.yaml @@ -47,4 +58,8 @@ resources: type: OS::Heat::ResourceGroup properties: count: 5 - resource_def: { type: nested_template_2.yaml } \ No newline at end of file + resource_def: { type: nested_template_good.yaml } + +outputs: + vm_type_volume_id_0: + value: {get_resource: vm_type_volume_0} diff --git a/ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_2.yaml b/ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_1.yaml similarity index 97% rename from ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_2.yaml rename to ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_1.yaml index cb8e4a9..5f2732f 100644 --- a/ice_validator/tests/fixtures/test_nested_templates/pass/nested_template_2.yaml +++ b/ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_1.yaml @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -37,6 +37,9 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +# VERSION = '1.0.0' + --- heat_template_version: 2013-05-23 @@ -56,4 +59,4 @@ resources: type: OS::Nova::Server properties: image: myimage - flavor: m1.small \ No newline at end of file + flavor: m1.small diff --git a/ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_good.yaml b/ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_good.yaml new file mode 100644 index 0000000..5f2732f --- /dev/null +++ b/ice_validator/tests/fixtures/test_nested_parameters/pass/nested_template_good.yaml @@ -0,0 +1,62 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +--- +heat_template_version: 2013-05-23 + +resources: + volume: + type: OS::Cinder::Volume + properties: + size: 1 + + volume_attachment: + type: OS::Cinder::VolumeAttachment + properties: + volume_id: { get_resource: volume } + instance_uuid: { get_resource: instance } + + instance: + type: OS::Nova::Server + properties: + image: myimage + flavor: m1.small diff --git a/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail0.yaml b/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail0.yaml new file mode 100644 index 0000000..94473c3 --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail0.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "environment_context" of type "string". +# FAIL: no "environment_context" +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: environment_context} + +parameters: + environment_Kontext: + type: string diff --git a/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail1.yaml b/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail1.yaml new file mode 100644 index 0000000..daaf406 --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_environment_context/fail/fail1.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "environment_context" of type "string". +# FAIL: "environment_context" not type "string" +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: environment_context} + +parameters: + environment_context: + type: number diff --git a/ice_validator/tests/fixtures/test_nova_servers_environment_context/pass/pass.yaml b/ice_validator/tests/fixtures/test_nova_servers_environment_context/pass/pass.yaml new file mode 100644 index 0000000..c882d66 --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_environment_context/pass/pass.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "environment_context" of type "string". + +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: environment_context} + +parameters: + environment_context: + type: string diff --git a/ice_validator/tests/fixtures/test_nova_servers_resource_ids/pass/valid_heat_template.yaml b/ice_validator/tests/fixtures/test_nova_servers_resource_ids/pass/valid_heat_template.yaml index 3796de9..eb07cae 100644 --- a/ice_validator/tests/fixtures/test_nova_servers_resource_ids/pass/valid_heat_template.yaml +++ b/ice_validator/tests/fixtures/test_nova_servers_resource_ids/pass/valid_heat_template.yaml @@ -60,7 +60,7 @@ resources: flavor: { get_param: vm_type_b_flavor_name} image: { get_param: vm_type_b_image_name} - VM_TYPE_B_SERVER_1: + vm_type_b_server_1: type: OS::Nova::Server properties: name: { get_param: vm_type_b_name_1 } diff --git a/ice_validator/tests/fixtures/test_nova_servers_vm_types/fail/inconsistent_vm_type.yaml b/ice_validator/tests/fixtures/test_nova_servers_vm_types/fail/inconsistent_vm_type.yaml index 219bf94..253905c 100644 --- a/ice_validator/tests/fixtures/test_nova_servers_vm_types/fail/inconsistent_vm_type.yaml +++ b/ice_validator/tests/fixtures/test_nova_servers_vm_types/fail/inconsistent_vm_type.yaml @@ -67,4 +67,15 @@ resources: name: { get_param: vm_type_b_name_1 } flavor: { get_param: vm_type_b_flavor_name} image: { get_param: vm_type_b_image_name} - \ No newline at end of file + networks: + - port: { get_resource: vm_type_b_0_int_vm_type_b_port_0 } + + int_vm_type_b_net_id: + type: OS::Neutron::Net + properties: + fnsdf: nksldfnkl + + vm_type_b_0_int_vm_type_b_port_0: + type: OS::Neutron::Port + properties: + network: { get_resource: int_vm_type_b_net_id } diff --git a/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail0.yaml b/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail0.yaml new file mode 100644 index 0000000..762ffc0 --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail0.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "workload_context" of type "string". +# FAIL: no "workload_context" +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: workload_context} + +parameters: + workload_Kontext: + type: string diff --git a/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail1.yaml b/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail1.yaml new file mode 100644 index 0000000..e713737 --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_workload_context/fail/fail1.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "workload_context" of type "string". +# FAIL: "workload_context" not type "string" +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: workload_context} + +parameters: + workload_context: + type: number diff --git a/ice_validator/tests/fixtures/test_nova_servers_workload_context/pass/pass.yaml b/ice_validator/tests/fixtures/test_nova_servers_workload_context/pass/pass.yaml new file mode 100644 index 0000000..c7138aa --- /dev/null +++ b/ice_validator/tests/fixtures/test_nova_servers_workload_context/pass/pass.yaml @@ -0,0 +1,59 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +# resource of type "OS::Nova::Server" has metadata +# which references parameter "workload_context" of type "string". + +--- +resources: + vm_type_a_server_0: + type: OS::Nova::Server + properties: + name: { get_param: [vm_type_a_names, 0] } + flavor: { get_param: vm_type_a_flavor_name} + image: { get_param: vm_type_a_image_name} + metadata: + my_attribute: {get_param: workload_context} + +parameters: + workload_context: + type: string diff --git a/ice_validator/tests/fixtures/test_port_resource_ids/pass/valid_template.yaml b/ice_validator/tests/fixtures/test_port_resource_ids/pass/valid_template.yaml index 50f2bd1..504fbdc 100644 --- a/ice_validator/tests/fixtures/test_port_resource_ids/pass/valid_template.yaml +++ b/ice_validator/tests/fixtures/test_port_resource_ids/pass/valid_template.yaml @@ -94,7 +94,7 @@ parameters: int_vpnnet_net_id: type: string - description: network id for the internal network vpnnet + description: network id for the internal network vpnnet int_oam_net_name: type: string description: name for the OAM network to be created in the resources section diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_1.yaml b/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_1.yaml deleted file mode 100644 index 702b639..0000000 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_1.yaml +++ /dev/null @@ -1,139 +0,0 @@ -# -*- coding: utf8 -*- -# ============LICENSE_START======================================================= -# org.onap.vvp/validation-scripts -# =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the "License"); -# you may not use this software except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# -# Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); -# you may not use this documentation except in compliance with the License. -# You may obtain a copy of the License at -# -# https://creativecommons.org/licenses/by/4.0/ -# -# Unless required by applicable law or agreed to in writing, documentation -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ============LICENSE_END============================================ -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ---- -heat_template_version: 2013-05-23 - -description: Simple template to deploy a single compute instance - -parameters: - vnf_id: - description: Unique ID for this VNF - type: string - vf_module_id: - description: Unique ID for this VF module - type: string - vnf_name: - type: string - description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM - ex1_vm_names: - type: comma_delimited_list - description: Name of the VM - ex1_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex1_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex1_server_index: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } - -resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - networks: - - network: { get_param: int_network_net_id } - user_data: - get_resource: ex_software_config_0 - - ex1_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_3.yaml b/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_3.yaml deleted file mode 100644 index 37374db..0000000 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_definition_3.yaml +++ /dev/null @@ -1,115 +0,0 @@ -heat_template_version: 2013-05-23 - -description: Simple template to deploy a single compute instance - -parameters: - vnf_id: - description: Unique ID for this VNF - type: string - vf_module_id: - description: Unique ID for this VF module - type: string - vnf_name: - type: string - description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM - ex1_vm_names: - type: comma_delimited_list - description: Name of the VM - ex1_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex1_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - int_network_net_id: - type: string - label: Network name - description: Name of the network the nova server will connect to - ex1_server_index: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } - availability_zone_0: - type: string - description: availabilityzone name - - -resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_serverGroup: - type: OS::Nova::ServerGroup - properties: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - availability_zones: { list_join: [',', [ { get_param: availability_zone_0 }, { get_param: availability_zone_1 } ] ] } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - networks: - - network: { get_param: int_network_net_id } - user_data: - get_resource: ex_software_config_0 - - ex1_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_2.yaml b/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_2.yaml deleted file mode 100644 index 10dd0dd..0000000 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/fail/missing_param_reference_2.yaml +++ /dev/null @@ -1,120 +0,0 @@ -heat_template_version: 2013-05-23 - -description: Simple template to deploy a single compute instance - -parameters: - vnf_id: - description: Unique ID for this VNF - type: string - vf_module_id: - description: Unique ID for this VF module - type: string - vnf_name: - type: string - description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM - ex1_vm_names: - type: comma_delimited_list - description: Name of the VM - ex1_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex1_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - int_network_net_id: - type: string - label: Network name - description: Name of the network the nova server will connect to - ex1_server_index: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } - availability_zone_0: - type: string - description: availabilityzone name - availability_zone_1: - type: string - description: availabilityzone name - availability_zone_2: - type: string - description: availabilityzone name - -resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_serverGroup: - type: OS::Nova::ServerGroup - properties: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - availability_zones: { list_join: [',', [ { get_param: availability_zone_0 }, { get_param: availability_zone_2 } ] ] } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - networks: - - network: { get_param: int_network_net_id } - user_data: - get_resource: ex_software_config_0 - - ex1_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_1.yaml b/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_1.yaml deleted file mode 100644 index e852402..0000000 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_1.yaml +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf8 -*- -# ============LICENSE_START======================================================= -# org.onap.vvp/validation-scripts -# =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the "License"); -# you may not use this software except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# -# Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); -# you may not use this documentation except in compliance with the License. -# You may obtain a copy of the License at -# -# https://creativecommons.org/licenses/by/4.0/ -# -# Unless required by applicable law or agreed to in writing, documentation -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ============LICENSE_END============================================ -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ---- -heat_template_version: 2013-05-23 - -description: Simple template to deploy a single compute instance - -parameters: - vnf_id: - description: Unique ID for this VNF - type: string - vf_module_id: - description: Unique ID for this VF module - type: string - vnf_name: - type: string - description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM - ex1_vm_names: - type: comma_delimited_list - description: Name of the VM - ex1_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex1_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex1_server_index_0: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } - ex1_server_info: - type: json - label: Json containing server index - description: Json containing the index of server - -resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - metering.stack: { get_param: "OS::stack_id" } - project_id: { get_param: "OS::project_id" } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - user_data: - get_resource: ex_software_config_0 - - ex1_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index_0 } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - ex1_nova_server_2: - type: OS::Nova::Server - properties: - name: - get_param: - - ex1_vm_names - - get_param: - - ex1_server_info - - ex1_server_metadata - - ex1_server_index_1 - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } \ No newline at end of file diff --git a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_2.yaml b/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_2.yaml deleted file mode 100644 index ff8421f..0000000 --- a/ice_validator/tests/fixtures/test_referenced_and_defined_parameters_match/pass/params_referenced_are_defined_and_vice_versa_2.yaml +++ /dev/null @@ -1,157 +0,0 @@ -# -*- coding: utf8 -*- -# ============LICENSE_START======================================================= -# org.onap.vvp/validation-scripts -# =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the "License"); -# you may not use this software except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# -# Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); -# you may not use this documentation except in compliance with the License. -# You may obtain a copy of the License at -# -# https://creativecommons.org/licenses/by/4.0/ -# -# Unless required by applicable law or agreed to in writing, documentation -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ============LICENSE_END============================================ -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ---- -heat_template_version: 2013-05-23 - -description: Simple template to deploy a single compute instance - -parameters: - vnf_id: - description: Unique ID for this VNF - type: string - vf_module_id: - description: Unique ID for this VF module - type: string - vnf_name: - type: string - description: Unique name for this VNF instance - ex_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - ex_vm_name: - type: string - description: Name of the VM - ex1_vm_names: - type: comma_delimited_list - description: Name of the VM - ex1_image_name: - type: string - label: Image name or ID - description: Image to be used for compute instance - ex1_flavor_name: - type: string - label: Flavor - description: Type of instance (flavor) to be used - ex1_key: - type: string - label: key pair - description: Name of the key apir the nova server will use - int_network_net_id: - type: string - label: Network name - description: Name of the network the nova server will connect to - ex1_server_index: - type: number - label: server index - description: Index of server - constraint: - - range: { min: 1, max: 100 } - availability_zone_0: - type: string - description: availabilityzone name - availability_zone_1: - type: string - description: availabilityzone name - -resources: - ex_software_config_0: - type: OS::Heat::SoftwareConfig - properties: - group: ungrouped - config: - params: - $stack_name: { get_param: 'OS::stack_name' } - - ex_nova_serverGroup: - type: OS::Nova::ServerGroup - properties: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - availability_zones: { list_join: [',', [ { get_param: availability_zone_0 }, { get_param: availability_zone_1 } ] ] } - - ex_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: ex_vm_name } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex_image_name } - flavor: { get_param: ex_flavor_name } - key_name: { get_param: ex_key } - networks: - - network: { get_param: int_network_net_id } - user_data: - get_resource: ex_software_config_0 - - ex1_nova_server_0: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, 0 ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } - - ex1_nova_server_1: - type: OS::Nova::Server - properties: - name: { get_param: [ ex1_vm_names, { get_param: ex1_server_index } ] } - metadata: - vnf_id: { get_param: vnf_id } - vf_module_id: { get_param: vf_module_id } - vnf_name: { get_param: vnf_name } - image: { get_param: ex1_image_name} - flavor: { get_param: ex1_flavor_name } - key_name: { get_param: ex1_key } diff --git a/ice_validator/tests/fixtures/test_resource_has_no_condtion/fail/fail.yaml b/ice_validator/tests/fixtures/test_resource_has_no_condtion/fail/fail.yaml new file mode 100644 index 0000000..343d761 --- /dev/null +++ b/ice_validator/tests/fixtures/test_resource_has_no_condtion/fail/fail.yaml @@ -0,0 +1,60 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +--- + +resources: + vm_type_b_server_0: + type: OS::Nova::Server + properties: + availability_zone: { get_param: availability_zone_a } + name: { get_param: vm_type_b_name_0 } + flavor: { get_param: vm_type_b_flavor_name} + image: { get_param: vm_type_b_image_name} + metadata: + vnf_name: { get_param: vnf_name } + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + key_name: { get_param: vm_type_b_key_name } + conditions: + condition1: True + diff --git a/ice_validator/tests/fixtures/test_resource_has_no_condtion/pass/pass.yaml b/ice_validator/tests/fixtures/test_resource_has_no_condtion/pass/pass.yaml new file mode 100644 index 0000000..6f745d8 --- /dev/null +++ b/ice_validator/tests/fixtures/test_resource_has_no_condtion/pass/pass.yaml @@ -0,0 +1,58 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +# VERSION = '1.0.0' + +--- + +resources: + vm_type_b_server_0: + type: OS::Nova::Server + properties: + availability_zone: { get_param: availability_zone_a } + name: { get_param: vm_type_b_name_0 } + flavor: { get_param: vm_type_b_flavor_name} + image: { get_param: vm_type_b_image_name} + metadata: + vnf_name: { get_param: vnf_name } + vnf_id: { get_param: vnf_id } + vf_module_id: { get_param: vf_module_id } + key_name: { get_param: vm_type_b_key_name } + diff --git a/ice_validator/tests/fixtures/test_unique_resources_across_template/fail/duplicate_resource_template.yml b/ice_validator/tests/fixtures/test_unique_resources_across_template/fail/duplicate_resource_template.yml index 40543d1..d4abed5 100644 --- a/ice_validator/tests/fixtures/test_unique_resources_across_template/fail/duplicate_resource_template.yml +++ b/ice_validator/tests/fixtures/test_unique_resources_across_template/fail/duplicate_resource_template.yml @@ -42,17 +42,9 @@ resources: volume_1: type: OS::Cinder::Volume properties: - name: - str_replace: - template: VF_NAME_STACK_NAME_oam_volume - params: - VNF_NAME: {get_param: vnf_module_id } + name: test_name + volume_1: type: OS::Cinder::Volume properties: - name: - str_replace: - template: VF_NAME_STACK_NAME_oam_volume - params: - VNF_NAME: {get_param: vnf_name } - STACK_NAME: { get_param: 'OS::stack_name' } + name: test_name diff --git a/ice_validator/tests/fixtures/test_volume_outputs_consumed/fail/more_outputs_than_parameters.yaml b/ice_validator/tests/fixtures/test_volume_outputs_consumed/fail/more_outputs_than_base_parameters.yaml similarity index 100% rename from ice_validator/tests/fixtures/test_volume_outputs_consumed/fail/more_outputs_than_parameters.yaml rename to ice_validator/tests/fixtures/test_volume_outputs_consumed/fail/more_outputs_than_base_parameters.yaml diff --git a/ice_validator/tests/test_availability_zone.py b/ice_validator/tests/test_availability_zone.py index 4f250b8..33d07e1 100644 --- a/ice_validator/tests/test_availability_zone.py +++ b/ice_validator/tests/test_availability_zone.py @@ -43,18 +43,18 @@ import re import pytest -import yaml +from tests import cached_yaml as 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) @@ -65,7 +65,7 @@ def test_availability_zone_naming(heat_template): invalid_availability_zones = set() - for v1 in yml["resources"].values(): + for k1, v1 in yml["resources"].items(): if not isinstance(v1, dict): continue if "properties" not in v1: @@ -75,13 +75,16 @@ 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 "get_param" not in v2: + invalid_availability_zones.add(k1) + elif 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_base_template_names.py b/ice_validator/tests/test_base_template_names.py index f9196a9..dbc8815 100644 --- a/ice_validator/tests/test_base_template_names.py +++ b/ice_validator/tests/test_base_template_names.py @@ -70,7 +70,10 @@ def test_base_template_names(template_dir): if check_basename_ending('volume', filename): continue - if RE_BASE.search(filename): + if RE_BASE.search(filename.lower()): base_template_count += 1 - msg = 'must be 1 "*_base_*" in %s not %d' % (filenames, base_template_count) - assert base_template_count == 1, msg + assert base_template_count == 1, ( + 'must be 1 "*_base_*" in %s not %d' % ( + filenames, + base_template_count)) + diff --git a/ice_validator/tests/test_cloud_config_resource_id.py b/ice_validator/tests/test_cloud_config_resource_id.py index de82fe4..2adf860 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,17 +75,14 @@ def test_cloud_config(heat_template): break else: bad.add(rid) - assert not bad, "CloudConfigs %s have {vm-type} not in %s" % ( + assert not bad, 'CloudConfigs %s have {vm-type} not in %s' % ( list(bad), - list(resource_vm_types), - ) + 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 58b0f39..46a0917 100644 --- a/ice_validator/tests/test_env_and_yaml_same_name.py +++ b/ice_validator/tests/test_env_and_yaml_same_name.py @@ -39,27 +39,32 @@ # 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-38474', 'R-81725', 'R-53433') 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 5d6949a..227f0bf 100644 --- a/ice_validator/tests/test_env_no_resource_registry.py +++ b/ice_validator/tests/test_env_no_resource_registry.py @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2018 AT&T Intellectual Property. All rights reserved. @@ -38,22 +38,25 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +'''test env file has no resource_registry +''' + +from tests import cached_yaml as 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_parameters.py b/ice_validator/tests/test_environment_file_parameters.py new file mode 100644 index 0000000..547ab5b --- /dev/null +++ b/ice_validator/tests/test_environment_file_parameters.py @@ -0,0 +1,621 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +""" environment file structure +""" +import re +import pytest + +from .helpers import validates, get_environment_pair + + +VERSION = '1.0.0' + +# pylint: disable=invalid-name + + +def check_parameter_exists(pattern, parameters): + if not parameters: + return False + + for param in parameters: + if pattern.search(param): + return True + + return False + + +def check_param_in_env_file(environment_pair, param, DESIRED): + + if not environment_pair: + pytest.skip("No heat/env pair could be identified") + + env_file = environment_pair.get("eyml") + + pattern = re.compile(r'^{}$'.format(param)) + + if "parameters" not in env_file: + pytest.skip("No parameters specified in the environment file") + + return check_parameter_exists(pattern, + env_file.get("parameters", {}) + ) is not DESIRED + + +""" +This function supports this structure, deviations +may or may not work without enhancement + +resource_id: + type: + properties: + prop0: { get_param: parameter_0 } + prop1: # this is a list of dicts + - nested_prop_0: { get_param: parameter_1 } + - nested_prop_1: { get_param: [parameter_2, {index}] } + prop2: # this is a dict of dicts + nested_prop_0: { get_param: parameter_1 } +""" + + +def check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + resource_type_inverse=False, + nested_prop='', + exclude_resource=''): + + if not environment_pair: + pytest.skip("No heat/env pair could be identified") + + env_file = environment_pair.get("eyml") + template_file = environment_pair.get("yyml") + + if "parameters" not in env_file: + pytest.skip("No parameters specified in the environment file") + + invalid_parameters = [] + + if template_file: + for resource, resource_prop in template_file.get("resources", {}).items(): + + if exclude_resource and re.match(exclude_resource, resource): + continue + + if resource_prop.get("type") == resource_type or \ + (resource_prop.get("type") != resource_type + and resource_type_inverse): + + pattern = False + + if not resource_prop.get("properties"): + continue + + resource_parameter = resource_prop.get("properties").get(prop) + + if not resource_parameter: + continue + + if isinstance(resource_parameter, list) and nested_prop: + for param in resource_parameter: + + nested_param = param.get(nested_prop) + if not nested_param: + continue + + pattern = nested_param.get("get_param") + + if not pattern: + continue + + if isinstance(pattern, list): + pattern = pattern[0] + + elif isinstance(resource_parameter, dict): + + if nested_prop and nested_prop in resource_parameter: + resource_parameter = resource_parameter.get(nested_prop) + + pattern = resource_parameter.get("get_param") + + else: + continue + + if not pattern: + continue + + if check_param_in_env_file(environment_pair, pattern, DESIRED): + invalid_parameters.append(pattern) + + return set(invalid_parameters) + + +@validates('R-91125') +def test_nova_server_image_parameter_exists_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "image" + DESIRED = True + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type) + + assert not invalid_parameters, ("OS::Nova::Server {} parameters not" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-69431') +def test_nova_server_flavor_parameter_exists_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "flavor" + DESIRED = True + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type) + + assert not invalid_parameters, ("OS::Nova::Server {} parameters not" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-22838') +def test_nova_server_name_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "name" + DESIRED = False + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type) + + assert not invalid_parameters, ("OS::Nova::Server {} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-59568') +def test_nova_server_az_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "availability_zone" + DESIRED = False + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type) + + assert not invalid_parameters, ("OS::Nova::Server {} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-20856') +def test_nova_server_vnf_id_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "vnf_id" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-72871') +def test_nova_server_vf_module_id_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "vf_module_id" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-36542') +def test_nova_server_vnf_name_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "vnf_name" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-80374') +def test_nova_server_vf_module_name_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "vf_module_name" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-02691') +def test_nova_server_workload_context_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "workload_context" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-13194') +def test_nova_server_environment_context_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "environment_context" + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-29872') +def test_nova_server_network_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "networks" + nested_prop = "network" + DESIRED = False + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + nested_prop=nested_prop) + + assert not invalid_parameters, ("{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + nested_prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-39841', + 'R-87123', + 'R-28795', + 'R-97201', + 'R-62590', + 'R-93496', + 'R-98905', + 'R-93030', + 'R-90206', + 'R-98569', + 'R-62590', + 'R-93496') +def test_neutron_port_fixedips_ipaddress_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "fixed_ips" + nested_prop = "ip_address" + DESIRED = False + resource_type = "OS::Neutron::Port" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + nested_prop=nested_prop) + + assert not invalid_parameters, ("{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + nested_prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-83677', + 'R-80829', + 'R-69634', + 'R-22288') +def test_neutron_port_fixedips_subnet_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "fixed_ips" + nested_prop = "subnet_id" + DESIRED = False + resource_type = "OS::Neutron::Port" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + nested_prop=nested_prop) + + assert not invalid_parameters, ("{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + nested_prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-83412', + 'R-83418') +def test_neutron_port_aap_ip_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "allowed_address_pairs" + nested_prop = "ip_address" + DESIRED = False + resource_type = "OS::Neutron::Port" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + nested_prop=nested_prop) + + assert not invalid_parameters, ("{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + nested_prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-99812') +def test_non_nova_server_name_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "name" + DESIRED = False + resource_type = "OS::Nova::Server" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + resource_type_inverse=True) + + assert not invalid_parameters, ("non-{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-92193') +def test_network_fqdn_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = r'^(.+?)_net_fqdn$' + DESIRED = False + + invalid_parameters = check_param_in_env_file(environment_pair, + prop, + DESIRED) + + assert not invalid_parameters, ("{} parameters" + " found in {} environment file {}" + .format(prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-76682') +def test_contrail_route_prefixes_parameter_doesnt_exist_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "interface_route_table_routes" + nested_prop = "interface_route_table_routes_route" + DESIRED = False + resource_type = "OS::ContrailV2::InterfaceRouteTable" + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + nested_prop=nested_prop) + + assert not invalid_parameters, ("{} {} parameters" + " found in {} environment file {}" + .format(resource_type, + nested_prop, + environment_pair.get("name"), + invalid_parameters)) + + +@validates('R-50011') +def test_heat_rg_count_parameter_exists_in_environment_file(heat_template): + + if pytest.config.getoption("validation_profile") == "heat_only": + pytest.skip("skipping test because validation profile is heat only") + + environment_pair = get_environment_pair(heat_template) + + prop = "count" + DESIRED = True + resource_type = "OS::Heat::ResourceGroup" + exclude_resource = re.compile(r'^(.+?)_subint_(.+?)_port_(.+?)_subinterfaces$') + + invalid_parameters = check_resource_parameter(environment_pair, + prop, + DESIRED, + resource_type, + exclude_resource=exclude_resource) + + assert not invalid_parameters, ("{} {} parameters not" + " found in {} environment file {}" + .format(resource_type, + prop, + environment_pair.get("name"), + invalid_parameters)) diff --git a/ice_validator/tests/test_environment_file_structure.py b/ice_validator/tests/test_environment_file_structure.py index 34d3b48..42786e9 100644 --- a/ice_validator/tests/test_environment_file_structure.py +++ b/ice_validator/tests/test_environment_file_structure.py @@ -41,69 +41,23 @@ """ environment file structure """ -import yaml -import pytest +from tests import cached_yaml as yaml 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", - ] - - 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, - ) - - -@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) - - -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"] - - 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) - ] - errors = [] - if 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)) + assert not missing_keys, '%s missing %s' % (env_file, missing_keys) 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 65d470c..a419585 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,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -38,12 +38,14 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # +import re from os import sep + import pytest -import re -import yaml -from .utils.nested_iterables import find_all_get_file_in_yml +from tests import cached_yaml as yaml + from .helpers import validates +from .utils.nested_iterables import find_all_get_file_in_yml @validates('R-99646') diff --git a/ice_validator/tests/test_heat_numeric_parameters.py b/ice_validator/tests/test_heat_numeric_parameters.py index 3345e4e..7cf5212 100644 --- a/ice_validator/tests/test_heat_numeric_parameters.py +++ b/ice_validator/tests/test_heat_numeric_parameters.py @@ -37,13 +37,15 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates + import pytest -import yaml +from tests import cached_yaml as yaml + +from .helpers import validates @validates('R-88863') -def test_numeric_parameter(yaml_file): +def test_numeric_parameter(heat_template): ''' Make sure all numeric parameters has either `range` or `allowed_values` specified @@ -51,7 +53,7 @@ def test_numeric_parameter(yaml_file): key_values = ["range", "allowed_values"] missing_constraints = [] - with open(yaml_file) as fh: + with open(heat_template) as fh: yml = yaml.load(fh) # skip if parameters are not defined diff --git a/ice_validator/tests/test_heat_pairs_provided.py b/ice_validator/tests/test_heat_pairs_provided.py index b9c8290..76aa276 100644 --- a/ice_validator/tests/test_heat_pairs_provided.py +++ b/ice_validator/tests/test_heat_pairs_provided.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -37,9 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates + from os import path +from .helpers import validates + @validates('R-86285', 'R-38474', 'R-81725', 'R-53433', 'R-56438', 'R-74304', 'R-91342', 'R-94509', 'R-31141') diff --git a/ice_validator/tests/test_heat_parameter_section.py b/ice_validator/tests/test_heat_parameter_section.py index dde4176..a226416 100644 --- a/ice_validator/tests/test_heat_parameter_section.py +++ b/ice_validator/tests/test_heat_parameter_section.py @@ -1,5 +1,5 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== # Copyright © 2018 AT&T Intellectual Property. All rights reserved. @@ -37,45 +37,28 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import pytest -import re -import yaml - -# one or more (alphanumeric or underscore) -RE_VALID_PARAMETER_NAME = re.compile(r"[\w_]+$") +"""parameters +""" -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"] +import re - with open(yaml_file) as fh: - yml = yaml.load(fh) +import pytest +from tests import cached_yaml as yaml - # skip if parameters are not defined - if "parameters" not in yml: - pytest.skip("No parameters specified in the heat template") +from .helpers import validates - invalid_params = [] - for v1 in yml["parameters"].values(): - if not isinstance(v1, dict): - continue - detected_keys = set(v1) & set(key_values) - if set(v1) != set(detected_keys): - invalid_params.append(str(v1)) +VERSION = '1.0.0' - assert not set(invalid_params) +# one or more (alphanumeric or underscore) +RE_VALID_PARAMETER_NAME = re.compile(r'[\w_]+$') -@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) @@ -87,19 +70,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) @@ -107,7 +90,9 @@ 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_parameters_contain_required_fields.py b/ice_validator/tests/test_heat_template_parameters_contain_required_fields.py index 6d9e502..9f0a5a8 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 @@ -37,9 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml + import pytest +from tests import cached_yaml as yaml + +from .helpers import validates @validates('R-36772', 'R-44001') diff --git a/ice_validator/tests/test_heat_template_structure.py b/ice_validator/tests/test_heat_template_structure.py index 1e0b8c8..32b448e 100644 --- a/ice_validator/tests/test_heat_template_structure.py +++ b/ice_validator/tests/test_heat_template_structure.py @@ -1,8 +1,8 @@ # -*- coding: utf8 -*- -# ============LICENSE_START======================================================= +# ============LICENSE_START==================================================== # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -37,76 +37,84 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # + +"""Test heat template structure +""" + +from tests import cached_yaml as yaml from .helpers import validates -import yaml + +VERSION = '1.2.0' + +# pylint: disable=invalid-name -def test_heat_template_structure(yaml_file): +@validates('R-27078') +def test_heat_template_structure_contains_heat_template_version(yaml_file): ''' - Check that all heat templates only have the allowed sections + Check that all heat templates have the required sections ''' - key_values = ["heat_template_version", "description", - "parameter_groups", "parameters", "resources", - "outputs", "conditions"] + required_key_values = ["heat_template_version"] with open(yaml_file) as fh: yml = yaml.load(fh) - assert all([k in key_values for k in yml]) + assert all([k in yml for k in required_key_values]), ( + "{} doesn't contain the {} section, but it is required" + .format(yaml_file, required_key_values[0])) -@validates('R-27078', 'R-39402', 'R-35414') -def test_heat_template_structure_contains_required_sections(yaml_file): +@validates('R-39402') +def test_heat_template_structure_contains_description(yaml_file): ''' Check that all heat templates have the required sections ''' - required_key_values = ["heat_template_version", "description", - "parameters", "resources"] + required_key_values = ["description"] with open(yaml_file) as fh: yml = yaml.load(fh) - assert all([k in yml for k in required_key_values]) + assert all([k in yml for k in required_key_values]), ( + "{} doesn't contain the {} section, but it is required" + .format(yaml_file, required_key_values[0])) -def test_heat_template_structure_sections_have_the_right_format(yaml_file): +@validates('R-35414') +def test_heat_template_structure_contains_parameters(yaml_file): ''' - Check that all heat templates have sections of the right format. - Do note that it only tests for dicts or not dicts currently. + Check that all heat templates have the required sections ''' - key_values = ["heat_template_version", "description", - "parameter_groups", "parameters", "resources", - "outputs", "conditions"] - key_values_not_dicts = ["heat_template_version", "description"] + required_key_values = ["parameters"] with open(yaml_file) as fh: yml = yaml.load(fh) + assert all([k in yml for k in required_key_values]), ( + "{} doesn't contain the {} section, but it is required" + .format(yaml_file, required_key_values[0])) + - is_dict = 0 - should_be_dict = 0 - is_not_dict = 0 - should_not_be_dict = 0 - for key_value in key_values: - if key_value in yml: - if isinstance(yml[key_value], dict): - is_dict += 1 - if key_value not in key_values_not_dicts: - should_be_dict += 1 - elif not isinstance(yml[key_value], list): - is_not_dict += 1 - if key_value in key_values_not_dicts: - should_not_be_dict += 1 - assert (is_dict == should_be_dict and - is_not_dict == should_not_be_dict) +@validates('R-23664') +def test_heat_template_structure_contains_resources(heat_template): + ''' + Check that all heat templates have the required sections + ''' + required_key_values = ["resources"] + + with open(heat_template) as fh: + yml = yaml.load(fh) + assert all([k in yml for k in required_key_values]), ( + "{} doesn't contain the {} section, but it is required" + .format(heat_template, required_key_values[0])) @validates('R-11441') def test_parameter_type(yaml_file): - types = [ - 'string', - 'number', - 'json', - 'comma_delimited_list', - 'boolean', - ] + '''A VNF's Heat Orchestration Template's parameter type **MUST** + be one of the following values: + ''' + types = ['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(): @@ -121,3 +129,4 @@ def test_parameter_type(yaml_file): yaml_file, key, typ) + diff --git a/ice_validator/tests/test_initial_configuration.py b/ice_validator/tests/test_initial_configuration.py new file mode 100644 index 0000000..7944970 --- /dev/null +++ b/ice_validator/tests/test_initial_configuration.py @@ -0,0 +1,149 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START======================================================= +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +from os import path + +import pytest +from tests import cached_yaml as yaml + +from .helpers import validates +from yamllint.config import YamlLintConfig +from yamllint import linter +from .utils.nested_files import check_for_invalid_nesting +from .utils.nested_iterables import find_all_get_resource_in_yml +from .utils.nested_iterables import find_all_get_param_in_yml + +""" +Order tests by number so they execute in order for base tests +""" + + +@pytest.mark.base +@validates('R-95303') +def test_00_valid_yaml(filename): + ''' + Read in each .yaml or .env file. If it is successfully parsed as yaml, save + contents, else add filename to list of bad yaml files. Log the result of + parse attempt. + ''' + conf = YamlLintConfig('rules: {}') + + if path.splitext(filename)[-1] in [".yml", ".yaml", ".env"]: + gen = linter.run(open(filename), conf) + errors = list(gen) + + assert not errors, "Error parsing file {} with error {}".format(filename, errors) + else: + pytest.skip("The file does not have any of the extensions .yml,\ + .yaml, or .env") + + +@pytest.mark.base +def test_02_all_referenced_resources_exists(yaml_file): + ''' + Check that all resources referenced by get_resource + actually exists in all yaml files + ''' + with open(yaml_file) as fh: + yml = yaml.load(fh) + + # skip if resources are not defined + if "resources" not in yml: + pytest.skip("No resources specified in the yaml file") + + resource_ids = yml['resources'].keys() + referenced_resource_ids = find_all_get_resource_in_yml(yml) + + missing_referenced_resources = set() + for referenced_resource_id in referenced_resource_ids: + if referenced_resource_id not in resource_ids: + missing_referenced_resources.add(referenced_resource_id) + + assert not missing_referenced_resources, ( + 'missing referenced resources %s' % list( + missing_referenced_resources)) + + +@pytest.mark.base +def test_01_valid_nesting(yaml_file): + ''' + Check that the nesting is following the proper format and + that all nested files exists and are parsable + ''' + invalid_nesting = [] + + with open(yaml_file) as fh: + yml = yaml.load(fh) + if "resources" in yml: + try: + invalid_nesting.extend(check_for_invalid_nesting( + yml["resources"], + yaml_file, + path.dirname(yaml_file))) + except Exception: + invalid_nesting.append(yaml_file) + + assert not invalid_nesting, \ + "invalid nested file detected in file {}\n\n".format(invalid_nesting) + + +@pytest.mark.base +def test_03_all_get_param_have_defined_parameter(yaml_file): + ''' + Check that all referenced parameters are actually defined + as parameters + ''' + invalid_get_params = [] + with open(yaml_file) as fh: + yml = yaml.load(fh) + + resource_params = find_all_get_param_in_yml(yml) + + parameters = set(yml.get('parameters', {}).keys()) + if not parameters: + pytest.skip("no parameters detected") + + for rp in resource_params: + if rp not in parameters: + invalid_get_params.append(rp) + + assert not invalid_get_params, ( + "get_param reference detected without corresponding parameter defined {}" + .format(invalid_get_params)) diff --git a/ice_validator/tests/test_multipart_mime_resource_id.py b/ice_validator/tests/test_multipart_mime_resource_id.py index fe6fe47..1660399 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,17 +75,14 @@ def test_multipart_mime(heat_template): break else: bad.add(rid) - assert not bad, "MultipartMime %s have {vm-type} not in %s" % ( + assert not bad, 'MultipartMime %s have {vm-type} not in %s' % ( list(bad), - list(resource_vm_types), - ) + 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_parameters.py b/ice_validator/tests/test_nested_parameters.py new file mode 100644 index 0000000..a1af4bd --- /dev/null +++ b/ice_validator/tests/test_nested_parameters.py @@ -0,0 +1,80 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +"""heat parameters +""" + +import os + +import pytest +from tests import cached_yaml as yaml + +from .helpers import validates +from .utils.nested_files import get_list_of_nested_files + +VERSION = '1.0.0' + + +@validates('R-00011') +def test_nested_parameter(yaml_file): + ''' + A VNF's Heat Orchestration Template's Nested YAML file's + parameter's **MUST NOT** have a parameter constraint defined. + + ''' + with open(yaml_file) as fh: + yml = yaml.load(fh) + dirname = os.path.dirname(yaml_file) + nested_files = get_list_of_nested_files(yml, dirname) + if nested_files: + for filename in nested_files: + with open(filename) as fh: + template = yaml.load(fh) + parameters = template.get('parameters') + if parameters and isinstance(parameters, dict): + for param, value in parameters.items(): + if isinstance(value, dict): + assert 'constraints' not in value, ( + '%s parameter "%s" has "constraints"' % ( + filename, + param)) + else: + pytest.skip('No nested files') + diff --git a/ice_validator/tests/test_network_format.py b/ice_validator/tests/test_network_format.py index 4bd13ad..7fb343a 100644 --- a/ice_validator/tests/test_network_format.py +++ b/ice_validator/tests/test_network_format.py @@ -37,11 +37,13 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates import pytest -import yaml -from .utils.network_roles import get_network_role_from_port, property_uses_get_resource +from tests import cached_yaml as yaml + +from .helpers import validates +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 a1b3b06..98d4401 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 @@ -39,9 +39,12 @@ # import pytest -import yaml +from tests import cached_yaml as yaml +from .helpers import validates + +@validates('R-93177') def test_network_format_use_get_param_or_get_resource(heat_template): ''' Make sure all network properties only use get_param diff --git a/ice_validator/tests/test_nova_servergroup_policies.py b/ice_validator/tests/test_nova_servergroup_policies.py index 6915fd4..6a49822 100644 --- a/ice_validator/tests/test_nova_servergroup_policies.py +++ b/ice_validator/tests/test_nova_servergroup_policies.py @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest diff --git a/ice_validator/tests/test_nova_servers_environment_context.py b/ice_validator/tests/test_nova_servers_environment_context.py new file mode 100644 index 0000000..9e01ce0 --- /dev/null +++ b/ice_validator/tests/test_nova_servers_environment_context.py @@ -0,0 +1,102 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +'''environment context +''' + +import pytest +from tests import cached_yaml as yaml + +from .helpers import validates + +VERSION = '1.0.0' + + +@validates('R-20308') +def test_environment_context(heat_template): + ''' + A VNF's Heat Orchestration Template's OS::Nova::Server Resource + metadata map value parameter 'environment_context' **MUST** + be declared as type: 'string'. + ''' + with open(heat_template) as fh: + yml = yaml.load(fh) + + if "parameters" not in yml: + pytest.skip("No parameters specified in the heat template") + if "resources" not in yml: + pytest.skip("No resources specified in the heat template") + + for resource, v in yml["resources"].items(): + if (not isinstance(v, dict) + or v.get('type') != 'OS::Nova::Server' + or 'properties' not in v): + continue + metadata = v['properties'].get('metadata') + if not isinstance(metadata, dict): + continue + error = validate_metadata(metadata, yml['parameters']) + if error: + assert False, '%s resource "%s" %s' % ( + heat_template, + resource, + error) + + +def validate_metadata(metadata, parameters): + '''validate metatdata. + Ensure metadata references parameter environment_context + is a string. + Return error message string or None if no errors. + ''' + for value in metadata.values(): + if isinstance(value, dict): + if 'get_param' in value: + if value['get_param'] == 'environment_context': + wc = parameters.get('environment_context', {}) + if wc.get('type') == 'string': + break + else: + return ('must have parameter "environment_context"' + ' of type "string"') + break + else: + return None + diff --git a/ice_validator/tests/test_nova_servers_index.py b/ice_validator/tests/test_nova_servers_index.py index 85ce335..9ce843a 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,18 +89,10 @@ 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): @@ -111,7 +103,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 @@ -125,3 +117,4 @@ def get_types(resources, indexed_resource_ids): if x and len(x) == 1: all_vm_types[rid] = list(x)[0] # x is a set. return all_vm_types + diff --git a/ice_validator/tests/test_nova_servers_resource_ids.py b/ice_validator/tests/test_nova_servers_resource_ids.py index d35fce5..dd3e156 100644 --- a/ice_validator/tests/test_nova_servers_resource_ids.py +++ b/ice_validator/tests/test_nova_servers_resource_ids.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -39,18 +39,20 @@ # import pytest -import yaml +from tests import cached_yaml as yaml + from .helpers import validates from .utils.vm_types import get_vm_type_for_nova_server -@validates("R-01455", "R-48067", "R-00977") -def test_nova_servers_valid_resource_ids(heat_template): - """ +@validates('R-40499', + 'R-57282') +def test_nova_servers_valid_resource_ids(yaml_file): + ''' Make sure all nova servers have valid resource ids - """ + ''' - with open(heat_template) as fh: + with open(yaml_file) as fh: yml = yaml.load(fh) # skip if resources are not defined @@ -68,10 +70,29 @@ def test_nova_servers_valid_resource_ids(heat_template): vm_type = get_vm_type_for_nova_server(v1) if not vm_type: - continue - vm_type = vm_type.lower() - - if vm_type + "_" not in k1.lower(): - invalid_nova_servers.append(k1) + # could not determine vm_type + invalid_nova_servers.append({"resource": k1, "vm_type": "none found"}) + else: + k1_split = k1.split("_server_") + k1_prefix = k1_split[0] + if k1_prefix != vm_type: + # vm_type on server doesn't match + invalid_nova_servers.append({"resource": k1, "vm_type": vm_type}) + else: + if len(k1_split) == 2: + k1_suffix = k1_split[1] + try: + int(k1_suffix) + except ValueError: + # vm_type_index is not an integer + invalid_nova_servers.append({"resource": k1, "vm_type": vm_type, "vm_type_index": k1_suffix}) + else: + # vm_type_index not found + invalid_nova_servers.append({"resource": k1, "vm_type": vm_type, "vm_type_index": "none found"}) - assert not set(invalid_nova_servers) + assert not invalid_nova_servers, \ + "Invalid OS::Nova::Server resource ids detected {}\n" \ + "OS::Nova::Server resource ids must be in the form " \ + "_server_ \n" \ + " is derived from flavor, image and name properties " \ + "".format(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 48abe04..233304c 100644 --- a/ice_validator/tests/test_nova_servers_vm_types.py +++ b/ice_validator/tests/test_nova_servers_vm_types.py @@ -37,14 +37,21 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates import pytest -import yaml +import re + +from tests import cached_yaml as yaml + +from .helpers import validates + from .utils.vm_types import get_vm_types_for_resource +from .utils.vm_types import get_vm_types + +from .utils.network_roles import get_network_roles -@validates('R-57282', 'R-40499') +@validates('R-57282') def test_vm_type_consistent_on_nova_servers(heat_template): ''' Make sure all nova servers have properly formatted properties @@ -70,4 +77,117 @@ def test_vm_type_consistent_on_nova_servers(heat_template): if len(vm_types) != 1: invalid_nova_servers.append(k) - assert not set(invalid_nova_servers) + assert not set(invalid_nova_servers), \ + "vm_types not consistant on the following resources {}" \ + .format(invalid_nova_servers) + + +@validates('R-48067', + 'R-00977') +def test_vm_type_network_role_collision(yaml_file): + with open(yaml_file) as fh: + yml = yaml.load(fh) + + # skip if resources are not defined + if "resources" not in yml: + pytest.skip("No resources specified in the heat template") + + resources = yml["resources"] + + vm_types = get_vm_types(resources) + network_roles = get_network_roles(resources) + + collisions = [] + for nr in network_roles: + for vt in vm_types: + if vt in nr or nr in vt: + collisions.append({"vm_type": vt, "network_role": nr}) + + assert not collisions, \ + "vm_type and network_role should not be substrings {}" .format(collisions) + + +@validates('R-50436', + 'R-45188', + 'R-40499') +def test_nova_server_flavor_parameter(yaml_file): + + prop = "flavor" + check_nova_parameter_format(prop, yaml_file) + + +@validates('R-51430', + 'R-54171', + 'R-87817') +def test_nova_server_name_parameter(yaml_file): + + prop = "name" + check_nova_parameter_format(prop, yaml_file) + + +@validates('R-71152', + 'R-45188', + 'R-57282') +def test_nova_server_image_parameter(yaml_file): + + prop = "image" + check_nova_parameter_format(prop, yaml_file) + + +def check_nova_parameter_format(prop, yaml_file): + + formats = { + "string": { + "name": re.compile(r'(.+?)_name_\d+$'), + "flavor": re.compile(r'(.+?)_flavor_name$'), + "image": re.compile(r'(.+?)_image_name$') + }, + "comma_delimited_list": { + "name": re.compile(r'(.+?)_names$') + } + } + + with open(yaml_file) as fh: + yml = yaml.load(fh) + + # skip if resources are not defined + if "resources" not in yml: + pytest.skip("No resources specified in the heat template") + + # skip if resources are not defined + if "parameters" not in yml: + pytest.skip("No parameters specified in the heat template") + + invalid_parameters = [] + + for k, v in yml["resources"].items(): + if not isinstance(v, dict): + continue + if v.get('type') != 'OS::Nova::Server': + continue + + prop_param = v.get("properties", {}) \ + .get(prop, {}) \ + .get("get_param") + + if not prop_param: + pytest.skip("{} doesn't have property {}".format(k, prop)) + elif isinstance(prop_param, list): + prop_param = prop_param[0] + + template_param_type = yml.get("parameters", {}) \ + .get(prop_param, {}) \ + .get("type") + + if not template_param_type: + pytest.skip("could not determine param type for {}".format(prop_param)) + + format_match = formats.get(template_param_type, {}) \ + .get(prop) + + if not format_match or not format_match.match(prop_param): + invalid_parameters.append(prop_param) + + assert not set(invalid_parameters), \ + "invalid {} parameters detected {}" \ + .format(prop, invalid_parameters) 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 79bc4b2..6b1a668 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 @@ -39,7 +39,7 @@ # import pytest -import yaml +from tests import cached_yaml as yaml def test_vm_type_assignments_on_nova_servers_only_use_get_param(heat_template): diff --git a/ice_validator/tests/test_nova_servers_workload_context.py b/ice_validator/tests/test_nova_servers_workload_context.py new file mode 100644 index 0000000..650a6e1 --- /dev/null +++ b/ice_validator/tests/test_nova_servers_workload_context.py @@ -0,0 +1,102 @@ +# -*- coding: utf8 -*- +# ============LICENSE_START==================================================== +# org.onap.vvp/validation-scripts +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the "License"); +# you may not use this software except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# + +'''workload context +''' + +import pytest +from tests import cached_yaml as yaml + +from .helpers import validates + +VERSION = '1.0.0' + + +@validates('R-74978') +def test_workload_context(heat_template): + ''' + A VNF's Heat Orchestration Template's OS::Nova::Server Resource + metadata map value parameter 'workload_context' **MUST** + be declared as type: 'string'. + ''' + with open(heat_template) as fh: + yml = yaml.load(fh) + + if "parameters" not in yml: + pytest.skip("No parameters specified in the heat template") + if "resources" not in yml: + pytest.skip("No resources specified in the heat template") + + for resource, v in yml["resources"].items(): + if (not isinstance(v, dict) + or v.get('type') != 'OS::Nova::Server' + or 'properties' not in v): + continue + metadata = v['properties'].get('metadata') + if not isinstance(metadata, dict): + continue + error = validate_metadata(metadata, yml['parameters']) + if error: + assert False, '%s resource "%s" %s' % ( + heat_template, + resource, + error) + + +def validate_metadata(metadata, parameters): + '''validate metatdata. + Ensure metadata references parameter workload_context + is a string. + Return error message string or None if no errors. + ''' + for value in metadata.values(): + if isinstance(value, dict): + if 'get_param' in value: + if value['get_param'] == 'workload_context': + wc = parameters.get('workload_context', {}) + if wc.get('type') == 'string': + break + else: + return ('must have parameter "workload_context"' + ' of type "string"') + break + else: + return None + diff --git a/ice_validator/tests/test_port_resource_ids.py b/ice_validator/tests/test_port_resource_ids.py index 511af35..076c479 100644 --- a/ice_validator/tests/test_port_resource_ids.py +++ b/ice_validator/tests/test_port_resource_ids.py @@ -39,37 +39,34 @@ # import re + import pytest -import yaml +from tests import cached_yaml as yaml + from .helpers import validates +from .utils.network_roles import get_network_role_from_port, \ + get_network_type_from_port, \ + property_uses_get_resource 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", -) + + +@validates('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) @@ -77,23 +74,21 @@ def test_port_resource_ids(heat_template): if "resources" not in yml: 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"] + port_patterns = {'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 @@ -106,18 +101,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] @@ -145,9 +140,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_required_parameters_no_constraints.py b/ice_validator/tests/test_required_parameters_no_constraints.py index 9e89191..4036162 100644 --- a/ice_validator/tests/test_required_parameters_no_constraints.py +++ b/ice_validator/tests/test_required_parameters_no_constraints.py @@ -37,10 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates import pytest -import yaml +from tests import cached_yaml as yaml + +from .helpers import validates @validates('R-55218', 'R-98374', 'R-44318') 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 bbfcf2d..9b38722 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,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -39,7 +39,7 @@ # import pytest -import yaml +from tests import cached_yaml as yaml def test_required_parameters_provided_in_heat_template(heat_template): diff --git a/ice_validator/tests/test_resource_ids_alphanumeric_only.py b/ice_validator/tests/test_resource_ids_alphanumeric_only.py index 8342520..d5080f4 100644 --- a/ice_validator/tests/test_resource_ids_alphanumeric_only.py +++ b/ice_validator/tests/test_resource_ids_alphanumeric_only.py @@ -37,11 +37,14 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml -import pytest + import re +import pytest +from tests import cached_yaml as yaml + +from .helpers import validates + @validates('R-75141') def test_alphanumeric_resource_ids_only(yaml_file): diff --git a/ice_validator/tests/test_servers_have_optional_metadata.py b/ice_validator/tests/test_servers_have_optional_metadata.py index de40fdf..01e87e0 100644 --- a/ice_validator/tests/test_servers_have_optional_metadata.py +++ b/ice_validator/tests/test_servers_have_optional_metadata.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest diff --git a/ice_validator/tests/test_servers_have_required_metadata.py b/ice_validator/tests/test_servers_have_required_metadata.py index 3a12b9d..3e84d43 100644 --- a/ice_validator/tests/test_servers_have_required_metadata.py +++ b/ice_validator/tests/test_servers_have_required_metadata.py @@ -37,10 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml import pytest +from tests import cached_yaml as yaml + +from .helpers import validates @validates('R-37437', 'R-71493', 'R-72483') 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 1b5f869..f7df880 100644 --- a/ice_validator/tests/test_servers_metadata_use_get_param.py +++ b/ice_validator/tests/test_servers_metadata_use_get_param.py @@ -37,9 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml + import pytest +from tests import cached_yaml as yaml + +from .helpers import validates @validates('R-97199') diff --git a/ice_validator/tests/test_subnet_format.py b/ice_validator/tests/test_subnet_format.py index 51b513c..bc183ef 100644 --- a/ice_validator/tests/test_subnet_format.py +++ b/ice_validator/tests/test_subnet_format.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -38,23 +38,29 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import pytest -import yaml -from .utils.network_roles import get_network_role_from_port, property_uses_get_resource import re +import pytest +from tests import cached_yaml as yaml + +from .utils.network_roles import get_network_role_from_port, \ + property_uses_get_resource + 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) @@ -82,9 +88,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 b462ef5..7487089 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 @@ -39,7 +39,7 @@ # import pytest -import yaml +from tests import cached_yaml as yaml def test_subnet_format_use_get_param_or_get_resource(heat_template): diff --git a/ice_validator/tests/test_unique_name_resources.py b/ice_validator/tests/test_unique_name_resources.py index df803dd..bb09706 100644 --- a/ice_validator/tests/test_unique_name_resources.py +++ b/ice_validator/tests/test_unique_name_resources.py @@ -37,11 +37,12 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml +from tests import cached_yaml as yaml import pytest +from .helpers import validates + @validates('R-40899') def test_unique_name_resources(yaml_files): 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 fed7e90..f7a202d 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 @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest 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 00df3b5..45369b4 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 @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest 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 d8fd066..f6a5f3a 100644 --- a/ice_validator/tests/test_unique_resources_across_all_templates.py +++ b/ice_validator/tests/test_unique_resources_across_all_templates.py @@ -37,10 +37,13 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml + import collections +from tests import cached_yaml as yaml + +from .helpers import validates + @validates('R-16447') def test_unique_resources_across_all_yaml_files(yaml_files): diff --git a/ice_validator/tests/test_unique_resources_across_template.py b/ice_validator/tests/test_unique_resources_across_template.py index 6bfc43c..b811cdb 100644 --- a/ice_validator/tests/test_unique_resources_across_template.py +++ b/ice_validator/tests/test_unique_resources_across_template.py @@ -55,10 +55,10 @@ def test_unique_resources_across_yaml_file(yaml_file): try: with open(yaml_file) as fh: - yml = yaml.load(fh) + yaml.load(fh) # Assert yaml file dont have resources - assert len(yml["resources"]) != 0 + # assert len(yml["resources"]) != 0 except ConstructorError as ce: print(ce) diff --git a/ice_validator/tests/test_vm_type_resource_id.py b/ice_validator/tests/test_vm_type_resource_id.py index 39a11ef..beb6745 100644 --- a/ice_validator/tests/test_vm_type_resource_id.py +++ b/ice_validator/tests/test_vm_type_resource_id.py @@ -68,6 +68,8 @@ 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_vm_type_syntax.py b/ice_validator/tests/test_vm_type_syntax.py index b44118b..b2455c2 100644 --- a/ice_validator/tests/test_vm_type_syntax.py +++ b/ice_validator/tests/test_vm_type_syntax.py @@ -69,6 +69,7 @@ def test_vm_type_syntax(heat_template): pytest.skip("No resources") t = set() t.update(*[vm_types.get_vm_types_for_resource(r) - for r in v.resources.values()]) + for r in v.resources.values()]) bad = [x for x in t if not RE_VM_TYPE.match(x) or RE_VM_TYPE_NG.match(x)] assert not bad, 'bad vm-types %s' % bad + diff --git a/ice_validator/tests/test_volume_format_outputs.py b/ice_validator/tests/test_volume_format_outputs.py index 3a00275..8be3723 100644 --- a/ice_validator/tests/test_volume_format_outputs.py +++ b/ice_validator/tests/test_volume_format_outputs.py @@ -37,13 +37,11 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -from .helpers import validates -import yaml +from tests import cached_yaml as yaml import pytest -@validates('R-79531') def test_volume_format_outputs(volume_template): ''' Check that the values are properly provided to the outputs section diff --git a/ice_validator/tests/test_volume_outputs_consumed.py b/ice_validator/tests/test_volume_outputs_consumed.py index 3ee7178..575e5dc 100644 --- a/ice_validator/tests/test_volume_outputs_consumed.py +++ b/ice_validator/tests/test_volume_outputs_consumed.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed @@ -37,15 +37,72 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. # +import glob +import os + +import pytest +from tests import cached_yaml as yaml + from .helpers import validates -@validates('R-11200', 'R-89913', 'R-07443') -def test_volume_outputs_consumed(heat_volume_pair): - ''' +def expected_template_module_pair(volume_path): + """Returns the path to the expected base or incremental module for a given volume""" + base_dir, filename = os.path.split(volume_path) + return os.path.join(base_dir, filename.replace("_volume", "")) + + +@validates("R-82732") +def test_volume_module_name_matches_incremental_or_base_module(volume_template): + expected_template_name = expected_template_module_pair(volume_template) + assert os.path.exists( + expected_template_name + ), "Could not find corresponding module ({}) for volume module ({}".format( + expected_template_name, volume_template + ) + + +@validates("R-11200", "R-07443") +def test_volume_outputs_consumed(template_dir, volume_template): + """ Check that all outputs in a volume template is consumed by the corresponding heat template - ''' - outputs = heat_volume_pair["vyml"]["outputs"].keys() - parameters = heat_volume_pair["yyml"]["parameters"].keys() - assert set(outputs) <= set(parameters) + """ + pair_template = expected_template_module_pair(volume_template) + + # Make sure all the output parameters in the volume module are + # consumed by the expected base or incremental module + if not os.path.exists(pair_template): + pytest.skip("Expected pair module not found") + with open(volume_template, "r") as f: + volume = yaml.load(f) + with open(pair_template, "r") as f: + pair = yaml.load(f) + outputs = set(volume.get("outputs", {}).keys()) + parameters = set(pair.get("parameters", {}).keys()) + missing_output_parameters = outputs.difference(parameters) + assert not missing_output_parameters, ( + "The output parameters ({}) in {} were not all " + "used by the expected module {}".format( + ",".join(missing_output_parameters), volume_template, pair_template + ) + ) + + # Now make sure that none of the output parameters appear in any other + # template + template_files = set(glob.glob("*.yaml")) + errors = {} + for template_path in template_files: + if template_path in (pair_template, volume_template): + continue # Skip these files since we already checked this pair + with open(template_path, "r") as f: + template = yaml.load(f) + parameters = set(template.get("parameters", {}).keys()) + misused_outputs = outputs.intersection(parameters) + if misused_outputs: + errors[template_path] = misused_outputs + message = ", ".join( + "{} ({})".format(path, ", ".join(params)) for path, params in errors.items() + ) + assert not errors, "Volume output parameters detected in unexpected modules: " + \ + message diff --git a/ice_validator/tests/test_volume_resource_ids.py b/ice_validator/tests/test_volume_resource_ids.py index 45b05e7..9f0d176 100644 --- a/ice_validator/tests/test_volume_resource_ids.py +++ b/ice_validator/tests/test_volume_resource_ids.py @@ -39,17 +39,19 @@ # import re + import pytest -import yaml +from tests import cached_yaml as yaml + 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,24 +59,25 @@ 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) @@ -83,15 +86,17 @@ 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,27 +107,27 @@ def test_volume_resource_ids(heat_template): 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] @@ -132,9 +137,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): diff --git a/ice_validator/tests/test_volume_templates.py b/ice_validator/tests/test_volume_templates.py index 191ae9d..6d2a44c 100644 --- a/ice_validator/tests/test_volume_templates.py +++ b/ice_validator/tests/test_volume_templates.py @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest diff --git a/ice_validator/tests/test_volume_templates_outputs.py b/ice_validator/tests/test_volume_templates_outputs.py index f18f1cd..1a779c6 100644 --- a/ice_validator/tests/test_volume_templates_outputs.py +++ b/ice_validator/tests/test_volume_templates_outputs.py @@ -38,7 +38,7 @@ # ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml def test_volume_templates_contains_outputs(volume_template): diff --git a/ice_validator/tests/utils/__init__.py b/ice_validator/tests/utils/__init__.py index ec11176..1fdd0c9 100644 --- a/ice_validator/tests/utils/__init__.py +++ b/ice_validator/tests/utils/__init__.py @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.vvp/validation-scripts # =================================================================== -# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. # =================================================================== # # Unless otherwise specified, all software contained herein is licensed