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
This commit is contained in:
Cong Phuoc Hoang 2019-02-02 03:50:27 +09:00 committed by dharmendra kushwaha
parent 1a3c027724
commit c981d65451
9 changed files with 331 additions and 11 deletions

View File

@ -1,5 +1,6 @@
{ {
image_name: 'cirros-0.4.0-x86_64-disk', 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', flavor: 'm1.tiny',
zone: 'nova', zone: 'nova',
network: 'net_mgmt', network: 'net_mgmt',

View File

@ -11,6 +11,10 @@ topology_template:
type: string type: string
description: Image Name description: Image Name
image_source:
type: string
description: Image source
flavor: flavor:
type: string type: string
description: Flavor Information description: Flavor Information
@ -51,7 +55,7 @@ topology_template:
param0: key1 param0: key1
param1: key2 param1: key2
CP1: CP11:
type: tosca.nodes.nfv.CP.Tacker type: tosca.nodes.nfv.CP.Tacker
properties: properties:
management: { get_input: management } management: { get_input: management }
@ -62,7 +66,7 @@ topology_template:
- virtualBinding: - virtualBinding:
node: VDU1 node: VDU1
CP2: CP12:
type: tosca.nodes.nfv.CP.Tacker type: tosca.nodes.nfv.CP.Tacker
properties: properties:
anti_spoofing_protection: false anti_spoofing_protection: false
@ -72,7 +76,7 @@ topology_template:
- virtualBinding: - virtualBinding:
node: VDU1 node: VDU1
CP3: CP13:
type: tosca.nodes.nfv.CP.Tacker type: tosca.nodes.nfv.CP.Tacker
properties: properties:
anti_spoofing_protection: false anti_spoofing_protection: false
@ -82,6 +86,51 @@ topology_template:
- virtualBinding: - virtualBinding:
node: VDU1 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: VL1:
type: tosca.nodes.nfv.VL type: tosca.nodes.nfv.VL
properties: properties:

View File

@ -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'
}

View File

@ -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}

View File

@ -107,15 +107,27 @@ class VnfmTestParam(base.BaseTackerTest):
'sample-tosca-vnfd-param.yaml', vnfd_name) 'sample-tosca-vnfd-param.yaml', vnfd_name)
self._test_vnfd_delete(vnfd_instance) self._test_vnfd_delete(vnfd_instance)
def test_vnf_param_tosca_template(self): def test_vnf_param_tosca_template_default(self):
vnfd_name = 'cirros_vnfd_tosca_param' self._test_vnf_param_tosca_template(
vnfd_instance = self._test_vnfd_create( vnfd_name='cirros_vnfd_tosca_param',
'sample-tosca-vnfd-param.yaml', vnfd_name) vnfd_file='sample-tosca-vnfd-param.yaml',
values_str = read_file('sample-tosca-vnf-values.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) values_dict = yaml.safe_load(values_str)
vnf_instance, param_values_dict = self._test_vnf_create(vnfd_instance, vnf_instance, param_values_dict = self._test_vnf_create(
'test_vnf_with_parameters_tosca_template', vnfd_instance, vnf_name, values_dict)
values_dict)
self.assertEqual(values_dict, param_values_dict) self.assertEqual(values_dict, param_values_dict)
self._test_vnf_delete(vnf_instance) self._test_vnf_delete(vnf_instance)
vnf_id = vnf_instance['vnf']['id'] vnf_id = vnf_instance['vnf']['id']

View File

@ -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

View File

@ -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

View File

@ -492,6 +492,16 @@ class TestOpenStack(base.TestCase):
input_params 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): def test_create_tosca_scale(self):
self._test_assert_equal_for_tosca_templates( self._test_assert_equal_for_tosca_templates(
'tosca_scale.yaml', 'tosca_scale.yaml',

View File

@ -418,6 +418,10 @@ def add_resources_tpl(heat_dict, hot_res_tpl):
} }
for prop, val in (vdu_dict).items(): 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 heat_dict["resources"][res_name]["properties"][prop] = val
if heat_dict["resources"].get(vdu): if heat_dict["resources"].get(vdu):
heat_dict["resources"][vdu]["properties"][res] = { heat_dict["resources"][vdu]["properties"][res] = {