From c981d65451e9e17b9ae025f89b9c754fda61cd2a Mon Sep 17 00:00:00 2001 From: Cong Phuoc Hoang Date: Sat, 2 Feb 2019 03:50:27 +0900 Subject: [PATCH] Fix issue in 'post_process_heat_template' function If users specify parameters in 'flavor' or 'image' properties of a VDU, HOT template can not be processed properly because there is a missmatch between TOSCA and HOT template. This patch will change 'get_input' to 'get_param' to fix that issue. Change-Id: I353e9d9d70dc6249a62dcdd1281b7b60d28d7d30 Closes-Bug: #1813135 Depends-On: Ib95ed31c70073cb732d41defe5bdc8027eadfeec --- .../vnfd/tosca-vnfd-param-values.yaml | 1 + .../vnfd/tosca-vnfd-with-params.yaml | 55 ++++++++- ...mple-tosca-vnf-artifacts-image-values.yaml | 10 ++ ...mple-tosca-vnfd-param-artifacts-image.yaml | 104 ++++++++++++++++++ .../tests/functional/vnfm/test_vnfm_param.py | 28 +++-- ...hot_tosca_artifacts_image_vnfd_params.yaml | 46 ++++++++ .../tosca_artifacts_image_vnfd_params.yaml | 84 ++++++++++++++ .../infra_drivers/openstack/test_openstack.py | 10 ++ tacker/tosca/utils.py | 4 + 9 files changed, 331 insertions(+), 11 deletions(-) create mode 100644 tacker/tests/etc/samples/sample-tosca-vnf-artifacts-image-values.yaml create mode 100644 tacker/tests/etc/samples/sample-tosca-vnfd-param-artifacts-image.yaml create mode 100644 tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_tosca_artifacts_image_vnfd_params.yaml create mode 100644 tacker/tests/unit/vnfm/infra_drivers/openstack/data/tosca_artifacts_image_vnfd_params.yaml diff --git a/samples/tosca-templates/vnfd/tosca-vnfd-param-values.yaml b/samples/tosca-templates/vnfd/tosca-vnfd-param-values.yaml index 7b0f14e54..32c074790 100644 --- a/samples/tosca-templates/vnfd/tosca-vnfd-param-values.yaml +++ b/samples/tosca-templates/vnfd/tosca-vnfd-param-values.yaml @@ -1,5 +1,6 @@ { image_name: 'cirros-0.4.0-x86_64-disk', + image_source: 'http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img', flavor: 'm1.tiny', zone: 'nova', network: 'net_mgmt', diff --git a/samples/tosca-templates/vnfd/tosca-vnfd-with-params.yaml b/samples/tosca-templates/vnfd/tosca-vnfd-with-params.yaml index 33b60842c..0ede65842 100644 --- a/samples/tosca-templates/vnfd/tosca-vnfd-with-params.yaml +++ b/samples/tosca-templates/vnfd/tosca-vnfd-with-params.yaml @@ -11,6 +11,10 @@ topology_template: type: string description: Image Name + image_source: + type: string + description: Image source + flavor: type: string description: Flavor Information @@ -51,7 +55,7 @@ topology_template: param0: key1 param1: key2 - CP1: + CP11: type: tosca.nodes.nfv.CP.Tacker properties: management: { get_input: management } @@ -62,7 +66,7 @@ topology_template: - virtualBinding: node: VDU1 - CP2: + CP12: type: tosca.nodes.nfv.CP.Tacker properties: anti_spoofing_protection: false @@ -72,7 +76,7 @@ topology_template: - virtualBinding: node: VDU1 - CP3: + CP13: type: tosca.nodes.nfv.CP.Tacker properties: anti_spoofing_protection: false @@ -82,6 +86,51 @@ topology_template: - virtualBinding: node: VDU1 + VDU2: + type: tosca.nodes.nfv.VDU.Tacker + properties: + flavor: { get_input: flavor } + availability_zone: { get_input: zone } + mgmt_driver: noop + config: | + param0: key1 + param1: key2 + artifacts: + VNFImage: + type: tosca.artifacts.Deployment.Image.VM + file: { get_input: image_source } + + CP21: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: { get_input: management } + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU2 + + CP22: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL2 + - virtualBinding: + node: VDU2 + + CP23: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL3 + - virtualBinding: + node: VDU2 + VL1: type: tosca.nodes.nfv.VL properties: diff --git a/tacker/tests/etc/samples/sample-tosca-vnf-artifacts-image-values.yaml b/tacker/tests/etc/samples/sample-tosca-vnf-artifacts-image-values.yaml new file mode 100644 index 000000000..4c7ebaeb8 --- /dev/null +++ b/tacker/tests/etc/samples/sample-tosca-vnf-artifacts-image-values.yaml @@ -0,0 +1,10 @@ +{ + image_source: 'http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img', + flavor: 'm1.tiny', + zone: 'nova', + network: 'net_mgmt', + management: 'true', + pkt_in_network: 'net0', + pkt_out_network: 'net1', + vendor: 'tacker' +} diff --git a/tacker/tests/etc/samples/sample-tosca-vnfd-param-artifacts-image.yaml b/tacker/tests/etc/samples/sample-tosca-vnfd-param-artifacts-image.yaml new file mode 100644 index 000000000..d0ff7c109 --- /dev/null +++ b/tacker/tests/etc/samples/sample-tosca-vnfd-param-artifacts-image.yaml @@ -0,0 +1,104 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +description: VNF TOSCA template with input parameters + +metadata: + template_name: sample-tosca-vnfd + +topology_template: + inputs: + image_source: + type: string + description: Image source + + flavor: + type: string + description: Flavor Information + + zone: + type: string + description: Zone Information + + network: + type: string + description: mgmt network + + management: + type: string + description: management network + + pkt_in_network: + type: string + description: In network + + pkt_out_network: + type: string + description: Out network + + vendor: + type: string + description: Vendor information + + node_templates: + VDU1: + type: tosca.nodes.nfv.VDU.Tacker + properties: + flavor: {get_input: flavor} + availability_zone: { get_input: zone } + mgmt_driver: noop + config: | + param0: key1 + param1: key2 + artifacts: + VNFImage: + type: tosca.artifacts.Deployment.Image.VM + file: { get_input: image_source } + + CP1: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: { get_input: management } + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU1 + + CP2: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL2 + - virtualBinding: + node: VDU1 + + CP3: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL3 + - virtualBinding: + node: VDU1 + + VL1: + type: tosca.nodes.nfv.VL + properties: + network_name: { get_input: network } + vendor: {get_input: vendor} + + VL2: + type: tosca.nodes.nfv.VL + properties: + network_name: { get_input: pkt_in_network } + vendor: {get_input: vendor} + + VL3: + type: tosca.nodes.nfv.VL + properties: + network_name: { get_input: pkt_out_network } + vendor: {get_input: vendor} diff --git a/tacker/tests/functional/vnfm/test_vnfm_param.py b/tacker/tests/functional/vnfm/test_vnfm_param.py index 809328836..888a24e5d 100644 --- a/tacker/tests/functional/vnfm/test_vnfm_param.py +++ b/tacker/tests/functional/vnfm/test_vnfm_param.py @@ -107,15 +107,27 @@ class VnfmTestParam(base.BaseTackerTest): 'sample-tosca-vnfd-param.yaml', vnfd_name) self._test_vnfd_delete(vnfd_instance) - def test_vnf_param_tosca_template(self): - vnfd_name = 'cirros_vnfd_tosca_param' - vnfd_instance = self._test_vnfd_create( - 'sample-tosca-vnfd-param.yaml', vnfd_name) - values_str = read_file('sample-tosca-vnf-values.yaml') + def test_vnf_param_tosca_template_default(self): + self._test_vnf_param_tosca_template( + vnfd_name='cirros_vnfd_tosca_param', + vnfd_file='sample-tosca-vnfd-param.yaml', + param_file='sample-tosca-vnf-values.yaml', + vnf_name='test_vnf_with_parameters_tosca_template') + + def test_vnf_param_with_artifacts_image_tosca_template(self): + self._test_vnf_param_tosca_template( + vnfd_name='cirros_vnfd_tosca_param_artifacts_image', + vnfd_file='sample-tosca-vnfd-param-artifacts-image.yaml', + param_file='sample-tosca-vnf-artifacts-image-values.yaml', + vnf_name='test_vnf_with_param_artifacts_image_tosca_templ') + + def _test_vnf_param_tosca_template(self, vnfd_file, vnfd_name, + param_file, vnf_name): + vnfd_instance = self._test_vnfd_create(vnfd_file, vnfd_name) + values_str = read_file(param_file) values_dict = yaml.safe_load(values_str) - vnf_instance, param_values_dict = self._test_vnf_create(vnfd_instance, - 'test_vnf_with_parameters_tosca_template', - values_dict) + vnf_instance, param_values_dict = self._test_vnf_create( + vnfd_instance, vnf_name, values_dict) self.assertEqual(values_dict, param_values_dict) self._test_vnf_delete(vnf_instance) vnf_id = vnf_instance['vnf']['id'] diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_tosca_artifacts_image_vnfd_params.yaml b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_tosca_artifacts_image_vnfd_params.yaml new file mode 100644 index 000000000..86c5e0378 --- /dev/null +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_tosca_artifacts_image_vnfd_params.yaml @@ -0,0 +1,46 @@ +description: > + Generic VDU with parameterized image and flavor + +heat_template_version: 2013-05-23 +outputs: + mgmt_ip-VDU1: + value: {get_attr: [CP1, fixed_ips, 0, ip_address]} +parameters: + image_source: + default: http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img + description: Image source for the server + type: string +resources: + CP1: + properties: + network: net_mgmt + port_security_enabled: False + type: OS::Neutron::Port + CP2: + properties: + network: pkt_in + port_security_enabled: False + type: OS::Neutron::Port + CP3: + properties: + network: pkt_out + port_security_enabled: False + type: OS::Neutron::Port + VDU1: + properties: + config_drive: False + flavor: m1.tiny + image: {get_resource: VDU1_image} + networks: + - port: { get_resource: CP1 } + - port: { get_resource: CP2 } + - port: { get_resource: CP3 } + user_data_format: SOFTWARE_CONFIG + type: OS::Nova::Server + VDU1_image: + properties: + container_format: bare + disk_format: raw + location: {get_param: image_source} + name: VNFImage + type: OS::Glance::WebImage diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/tosca_artifacts_image_vnfd_params.yaml b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/tosca_artifacts_image_vnfd_params.yaml new file mode 100644 index 000000000..a2331147a --- /dev/null +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/tosca_artifacts_image_vnfd_params.yaml @@ -0,0 +1,84 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +description: Generic VDU with parameterized image and flavor + +metadata: + template_name: OpenWRT + +topology_template: + + inputs: + + image_source: + type: string + description: Image source for the server + default: OpenWRT + + node_templates: + + VDU1: + type: tosca.nodes.nfv.VDU.Tacker + properties: + image: m1.tiny + flavor: m1.tiny + monitoring_policy: + name: ping + actions: + failure: respawn + parameters: + count: 3 + interval: 10 + artifacts: + VNFImage: + type: tosca.artifacts.Deployment.Image.VM + file: { get_input: image_source } + + CP1: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: true + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU1 + + CP2: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL2 + - virtualBinding: + node: VDU1 + + CP3: + type: tosca.nodes.nfv.CP.Tacker + properties: + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL3 + - virtualBinding: + node: VDU1 + + VL1: + type: tosca.nodes.nfv.VL + properties: + network_name: net_mgmt + vendor: Tacker + + VL2: + type: tosca.nodes.nfv.VL + properties: + network_name: pkt_in + vendor: Tacker + + VL3: + type: tosca.nodes.nfv.VL + properties: + network_name: pkt_out + vendor: Tacker + diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py b/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py index 60ec3df5e..e1509c9fc 100644 --- a/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py @@ -492,6 +492,16 @@ class TestOpenStack(base.TestCase): input_params ) + def test_tosca_artifacts_image_params(self): + input_params = 'image_source: ' \ + 'http://download.cirros-cloud.net/' \ + '0.4.0/cirros-0.4.0-x86_64-disk.img' + self._test_assert_equal_for_tosca_templates( + 'tosca_artifacts_image_vnfd_params.yaml', + 'hot_tosca_artifacts_image_vnfd_params.yaml', + input_params + ) + def test_create_tosca_scale(self): self._test_assert_equal_for_tosca_templates( 'tosca_scale.yaml', diff --git a/tacker/tosca/utils.py b/tacker/tosca/utils.py index 74af06e84..e98e56dad 100644 --- a/tacker/tosca/utils.py +++ b/tacker/tosca/utils.py @@ -418,6 +418,10 @@ def add_resources_tpl(heat_dict, hot_res_tpl): } for prop, val in (vdu_dict).items(): + # change from 'get_input' to 'get_param' to meet HOT template + if isinstance(val, dict): + if 'get_input' in val: + val['get_param'] = val.pop('get_input') heat_dict["resources"][res_name]["properties"][prop] = val if heat_dict["resources"].get(vdu): heat_dict["resources"][vdu]["properties"][res] = {