Merge "Convert parameters to dict before passing to TOSCA parser"
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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:
|
||||
flavor:
|
||||
constraints:
|
||||
- allowed_values: [m1.tiny, m1.small, m1.medium, m1.large, m1.large]
|
||||
default: m1.large
|
||||
description: Flavor name for the server
|
||||
type: string
|
||||
image:
|
||||
default: cirros
|
||||
description: Image name 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: { get_param: flavor }
|
||||
image: { get_param: image }
|
||||
networks:
|
||||
- port: { get_resource: CP1 }
|
||||
- port: { get_resource: CP2 }
|
||||
- port: { get_resource: CP3 }
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
type: OS::Nova::Server
|
||||
@@ -0,0 +1,86 @@
|
||||
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:
|
||||
flavor:
|
||||
type: string
|
||||
description: Flavor name for the server
|
||||
constraints:
|
||||
- valid_values: [ m1.tiny, m1.small, m1.medium, m1.large, m1.large ]
|
||||
default: m1.tiny
|
||||
|
||||
image:
|
||||
type: string
|
||||
description: Image name for the server
|
||||
default: OpenWRT
|
||||
|
||||
node_templates:
|
||||
|
||||
VDU1:
|
||||
type: tosca.nodes.nfv.VDU.Tacker
|
||||
properties:
|
||||
image: { get_input: image }
|
||||
flavor: { get_input: flavor }
|
||||
monitoring_policy:
|
||||
name: ping
|
||||
actions:
|
||||
failure: respawn
|
||||
parameters:
|
||||
count: 3
|
||||
interval: 10
|
||||
|
||||
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
|
||||
|
||||
@@ -96,23 +96,28 @@ class TestDeviceHeat(base.TestCase):
|
||||
'-d5a1-4fd4-9447-bb9243c8460b',
|
||||
'template': self.hot_ipparam_template}
|
||||
|
||||
def _get_expected_device_wait_obj(self):
|
||||
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
|
||||
u'test_openwrt', 'tenant_id':
|
||||
u'ad7ebc56538745a08ef7c5e97f8bd437', 'template_id':
|
||||
u'eb094833-995e-49f0-a047-dfb56aaf7c4e', 'device_template': {
|
||||
'service_types': [{'service_type': u'vnfd', 'id':
|
||||
u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}], 'description':
|
||||
u'OpenWRT with services', 'tenant_id':
|
||||
u'ad7ebc56538745a08ef7c5e97f8bd437', 'mgmt_driver': u'openwrt',
|
||||
'infra_driver': u'heat',
|
||||
'attributes': {u'vnfd': self.vnfd_openwrt},
|
||||
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
|
||||
u'openwrt_services'}, 'mgmt_url': '{"vdu1": "192.168.120.31"}',
|
||||
'service_context': [], 'attributes': {
|
||||
u'param_values': u''}, 'id':
|
||||
'eb84260e-5ff7-4332-b032-50a14d6c1123', 'description':
|
||||
u'OpenWRT with services'}
|
||||
def _get_expected_device_wait_obj(self, param_values=''):
|
||||
return {'status': 'PENDING_CREATE',
|
||||
'instance_id': None,
|
||||
'name': u'test_openwrt',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'template_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'device_template': {
|
||||
'service_types': [{
|
||||
'service_type': u'vnfd',
|
||||
'id': u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}],
|
||||
'description': u'OpenWRT with services',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
|
||||
'mgmt_driver': u'openwrt',
|
||||
'infra_driver': u'heat',
|
||||
'attributes': {u'vnfd': self.vnfd_openwrt},
|
||||
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
|
||||
'name': u'openwrt_services'},
|
||||
'mgmt_url': '{"vdu1": "192.168.120.31"}',
|
||||
'service_context': [],
|
||||
'attributes': {u'param_values': param_values},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'description': u'OpenWRT with services'}
|
||||
|
||||
def _get_expected_device_update_obj(self):
|
||||
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
|
||||
@@ -209,27 +214,34 @@ class TestDeviceHeat(base.TestCase):
|
||||
'-5ff7-4332-b032-50a14d6c1123',
|
||||
'template': _get_template(template)}
|
||||
|
||||
def _get_expected_tosca_device(self, tosca_tpl_name, hot_tpl_name):
|
||||
def _get_expected_tosca_device(self, tosca_tpl_name, hot_tpl_name,
|
||||
param_values=''):
|
||||
tosca_tpl = _get_template(tosca_tpl_name)
|
||||
exp_tmpl = self._get_expected_device_template(tosca_tpl)
|
||||
tosca_hw_dict = yaml.safe_load(_get_template(hot_tpl_name))
|
||||
return {'device_template': exp_tmpl['device_template'],
|
||||
'description': u'OpenWRT with services',
|
||||
'attributes': {'heat_template': tosca_hw_dict,
|
||||
'monitoring_policy': '{"vdus": {"VDU1":'
|
||||
' {"ping": {"name": "ping",'
|
||||
' "actions": {"failure": "respawn"},'
|
||||
' "parameters": {"count": 3, "interval": 10'
|
||||
'}, "monitoring_params": {"count": 3, '
|
||||
'"interval": 10}}}}}',
|
||||
'param_values': ''},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'instance_id': None, 'mgmt_url': None, 'name': u'test_openwrt',
|
||||
'service_context': [], 'status': 'PENDING_CREATE',
|
||||
'template_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437'}
|
||||
return {
|
||||
'device_template': exp_tmpl['device_template'],
|
||||
'description': u'OpenWRT with services',
|
||||
'attributes': {
|
||||
'heat_template': tosca_hw_dict,
|
||||
'monitoring_policy': '{"vdus": {"VDU1":'
|
||||
' {"ping": {"name": "ping",'
|
||||
' "actions": {"failure": "respawn"},'
|
||||
' "parameters": {"count": 3,'
|
||||
' "interval": 10'
|
||||
'}, "monitoring_params": {"count": 3, '
|
||||
'"interval": 10}}}}}',
|
||||
'param_values': param_values},
|
||||
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
|
||||
'instance_id': None,
|
||||
'mgmt_url': None,
|
||||
'name': u'test_openwrt',
|
||||
'service_context': [],
|
||||
'status': 'PENDING_CREATE',
|
||||
'template_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
|
||||
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437'}
|
||||
|
||||
def _get_dummy_tosca_device(self, template):
|
||||
def _get_dummy_tosca_device(self, template, input_params=''):
|
||||
tosca_template = _get_template(template)
|
||||
device = utils.get_dummy_device_obj()
|
||||
dtemplate = self._get_expected_device_template(tosca_template)
|
||||
@@ -237,15 +249,18 @@ class TestDeviceHeat(base.TestCase):
|
||||
'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}]
|
||||
dtemplate['tenant_id'] = 'ad7ebc56538745a08ef7c5e97f8bd437'
|
||||
device['device_template'] = dtemplate['device_template']
|
||||
device['attributes'] = {}
|
||||
device['attributes']['param_values'] = input_params
|
||||
return device
|
||||
|
||||
def _test_assert_equal_for_tosca_templates(self, tosca_tpl_name,
|
||||
hot_tpl_name):
|
||||
device = self._get_dummy_tosca_device(tosca_tpl_name)
|
||||
hot_tpl_name, input_params=''):
|
||||
device = self._get_dummy_tosca_device(tosca_tpl_name, input_params)
|
||||
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
|
||||
expected_fields = self._get_expected_fields_tosca(hot_tpl_name)
|
||||
expected_device = self._get_expected_tosca_device(tosca_tpl_name,
|
||||
hot_tpl_name)
|
||||
hot_tpl_name,
|
||||
input_params)
|
||||
result = self.heat_driver.create(plugin=None, context=self.context,
|
||||
device=device,
|
||||
auth_attr=utils.get_vim_auth_obj())
|
||||
@@ -340,3 +355,11 @@ class TestDeviceHeat(base.TestCase):
|
||||
'tosca_mgmt_sriov.yaml',
|
||||
'hot_tosca_mgmt_sriov.yaml'
|
||||
)
|
||||
|
||||
def test_tosca_params(self):
|
||||
input_params = 'image: cirros\nflavor: m1.large'
|
||||
self._test_assert_equal_for_tosca_templates(
|
||||
'tosca_generic_vnfd_params.yaml',
|
||||
'hot_tosca_generic_vnfd_params.yaml',
|
||||
input_params
|
||||
)
|
||||
|
||||
@@ -296,7 +296,15 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
|
||||
heatclient_)
|
||||
|
||||
def generate_hot_from_tosca(vnfd_dict):
|
||||
parsed_params = dev_attrs.pop('param_values', {})
|
||||
parsed_params = {}
|
||||
if ('param_values' in dev_attrs and
|
||||
dev_attrs['param_values'] != ""):
|
||||
try:
|
||||
parsed_params = yaml.load(dev_attrs['param_values'])
|
||||
except Exception as e:
|
||||
LOG.debug("Params not Well Formed: %s", str(e))
|
||||
raise vnfm.ParamYAMLNotWellFormed(
|
||||
error_msg_details=str(e))
|
||||
|
||||
toscautils.updateimports(vnfd_dict)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user