Implement tosca-parser/heat-translator integration

Change-Id: Idf902cd01bd369cfede83842e1ae295bff3da710
Implements: bp/tosca-parser-integration
This commit is contained in:
Bob.Haddleton 2016-02-03 20:14:09 -06:00 committed by Bob Haddleton
parent bab51c88b5
commit d6b102b201
35 changed files with 2030 additions and 317 deletions

View File

@ -0,0 +1,72 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: ubuntu
flavor: m1.small
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
monitoring_policy:
properties:
name: http_ping
monitoring_params:
retry: 5
timeout: 10
port: 8000
actions:
failure: respawn
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,73 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
monitoring_policy:
properties:
name: ping
monitoring_params:
monitoring_delay: 45
count: 3
interval: .5
timeout: 2
actions:
failure: respawn
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,137 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP11:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP12:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP13:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU1
VDU2:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.medium
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP21:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU2
CP22:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU2
CP23:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU2
VDU3:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP31:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU3
CP32:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU3
CP33:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU3
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: net_mgmt
vendor: Tacker
VL2:
type: tosca.nodes.nfv.VL
properties:
network_name: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,63 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,71 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: OpenWRT with services
metadata:
template_name: OpenWRT
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: OpenWRT
flavor: m1.tiny
config: |
param0: key1
param1: key2
mgmt_driver: openwrt
monitoring_policy:
name: ping
actions:
- {trigger: failure, action: respawn}
parameters:
count: "3"
interval: "10"
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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

@ -29,3 +29,4 @@ oslo.rootwrap>=2.0.0 # Apache-2.0
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0
tosca-parser>=0.4.0 # Apache-2.0
heat-translator>=0.4.0 # Apache-2.0

View File

@ -37,6 +37,10 @@ class MGMTDriverNotSpecified(exceptions.InvalidInput):
message = _('mgmt driver is not specified')
class MultipleMGMTDriversSpecified(exceptions.InvalidInput):
message = _('More than one MGMT Driver per template is not supported')
class ServiceTypesNotSpecified(exceptions.InvalidInput):
message = _('service types are not specified')
@ -85,6 +89,14 @@ class ParamYAMLNotWellFormed(exceptions.InvalidInput):
message = _("Parameter YAML not well formed - %(error_msg_details)s")
class ToscaParserFailed(exceptions.InvalidInput):
message = _("tosca-parser failed: - %(error_msg_details)s")
class HeatTranslatorFailed(exceptions.InvalidInput):
message = _("heat-translator failed: - %(error_msg_details)s")
class InputValuesMissing(exceptions.InvalidInput):
message = _("Parameter input values missing for the key '%(key)s'")

View File

@ -0,0 +1,72 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: ubuntu
flavor: m1.small
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
monitoring_policy:
properties:
name: http_ping
monitoring_params:
retry: 5
timeout: 10
port: 8000
actions:
failure: respawn
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,73 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
monitoring_policy:
properties:
name: ping
monitoring_params:
monitoring_delay: 45
count: 3
interval: .5
timeout: 2
actions:
failure: respawn
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,137 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP11:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP12:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP13:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU1
VDU2:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.medium
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP21:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU2
CP22:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU2
CP23:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU2
VDU3:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP31:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU3
CP32:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU3
CP33:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL3
- virtualBinding:
node: VDU3
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: net_mgmt
vendor: Tacker
VL2:
type: tosca.nodes.nfv.VL
properties:
network_name: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,63 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Demo example
metadata:
template_name: sample-tosca-vnfd
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
availability_zone: nova
mgmt_driver: noop
config: |
param0: key1
param1: key2
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
CP2:
type: tosca.nodes.nfv.CP.Tacker
requirements:
- virtualLink:
node: VL2
- virtualBinding:
node: VDU1
CP3:
type: tosca.nodes.nfv.CP.Tacker
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: net0
vendor: Tacker
VL3:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker

View File

@ -0,0 +1,63 @@
# Copyright 2016 Brocade Communications System, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file 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.
from oslo_config import cfg
from tacker.tests import constants
from tacker.tests.functional.vnfm import base
from tacker.tests.utils import read_file
CONF = cfg.CONF
VNF_CIRROS_CREATE_TIMEOUT = 120
class VnfTestToscaCreate(base.BaseTackerTest):
def test_create_delete_vnf_tosca_no_monitoring(self):
data = dict()
data['tosca'] = read_file('sample-tosca-vnfd.yaml')
toscal = data['tosca']
tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}
# Create vnfd with tosca template
vnfd_instance = self.client.create_vnfd(body=tosca_arg)
self.assertIsNotNone(vnfd_instance)
# Create vnf with vnfd_id
vnfd_id = vnfd_instance['vnfd']['id']
vnf_name = 'test_tosca_vnf_with_cirros_no_monitoring'
vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
vnf_instance = self.client.create_vnf(body=vnf_arg)
self.validate_vnf_instance(vnfd_instance, vnf_instance)
vnf_id = vnf_instance['vnf']['id']
vnf_current_status = self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual(vnf_current_status, 'ACTIVE')
self.assertIsNotNone(self.client.show_vnf(vnf_id)['vnf']['mgmt_url'])
# Delete vnf_instance with vnf_id
try:
self.client.delete_vnf(vnf_id)
except Exception:
assert False, "vnf Delete failed"
# Delete vnfd_instance
try:
self.client.delete_vnfd(vnfd_id)
except Exception:
assert False, "vnfd Delete failed"

View File

@ -0,0 +1,82 @@
# Copyright 2016 Brocade Communications System, Inc.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file 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.
from oslo_config import cfg
from tacker.common import utils
from tacker.tests import constants
from tacker.tests.functional.vnfm import base
from tacker.tests.utils import read_file
from tacker.vm.tosca import utils as toscautils
from toscaparser.tosca_template import ToscaTemplate
import yaml
CONF = cfg.CONF
class VnfTestToscaMultipleVDU(base.BaseTackerTest):
def test_create_delete_tosca_vnf_with_multiple_vdus(self):
data = dict()
input_yaml = read_file('sample-tosca-vnfd-multi-vdu.yaml')
data['tosca'] = input_yaml
toscal = data['tosca']
tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}
# Create vnfd with tosca template
vnfd_instance = self.client.create_vnfd(body=tosca_arg)
self.assertIsNotNone(vnfd_instance)
# Create vnf with vnfd_id
vnfd_id = vnfd_instance['vnfd']['id']
vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':
"test_tosca_vnf_with_multiple_vdus"}}
vnf_instance = self.client.create_vnf(body=vnf_arg)
vnf_id = vnf_instance['vnf']['id']
self.wait_until_vnf_active(vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
self.assertEqual(self.client.show_vnf(vnf_id)['vnf']['status'],
'ACTIVE')
self.validate_vnf_instance(vnfd_instance, vnf_instance)
# Validate mgmt_url with input yaml file
mgmt_url = self.client.show_vnf(vnf_id)['vnf']['mgmt_url']
self.assertIsNotNone(mgmt_url)
mgmt_dict = yaml.load(str(mgmt_url))
input_dict = yaml.load(input_yaml)
toscautils.updateimports(input_dict)
tosca = ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=input_dict)
vdus = toscautils.findvdus(tosca)
self.assertEqual(len(mgmt_dict.keys()), len(vdus))
for vdu in vdus:
self.assertIsNotNone(mgmt_dict[vdu.name])
self.assertEqual(True, utils.is_valid_ipv4(mgmt_dict[vdu.name]))
# Delete vnf_instance with vnf_id
try:
self.client.delete_vnf(vnf_id)
except Exception:
assert False, "vnf Delete of test_vnf_with_multiple_vdus failed"
# Delete vnfd_instance
try:
self.client.delete_vnfd(vnfd_id)
except Exception:
assert False, "vnfd Delete of sample-vnfd-multiple-vdus failed"

View File

@ -0,0 +1,39 @@
# Copyright 2016 Brocade Communications System, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file 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.
from oslo_config import cfg
from tacker.tests.functional.vnfm import base
from tacker.tests.utils import read_file
CONF = cfg.CONF
class VnfdTestCreate(base.BaseTackerTest):
def test_create_list_delete_tosca_vnfd(self):
data = dict()
data['tosca'] = read_file('sample-tosca-vnfd.yaml')
toscal = data['tosca']
tosca_arg = {'vnfd': {'attributes': {'vnfd': toscal}}}
vnfd_instance = self.client.create_vnfd(body=tosca_arg)
self.assertIsNotNone(vnfd_instance)
vnfds = self.client.list_vnfds().get('vnfds')
self.assertIsNotNone(vnfds, "List of vnfds are Empty after Creation")
vnfd_id = vnfd_instance['vnfd']['id']
try:
self.client.delete_vnfd(vnfd_id)
except Exception:
assert False, "vnfd Delete failed"

View File

@ -13,37 +13,32 @@
# License for the specific language governing permissions and limitations
# under the License.
import codecs
import os
def _get_template(name):
filename = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../vm/infra_drivers/heat/data/", name)
f = codecs.open(filename, encoding='utf-8', errors='strict')
return f.read()
vnfd_openwrt = _get_template('openwrt.yaml')
vnfd_ipparams_template = _get_template('vnf_cirros_template_ipaddr.yaml')
ipparams = _get_template('vnf_cirros_param_values_ipaddr.yaml')
vnfd_userdata_template = _get_template('vnf_cirros_template_user_data.yaml')
userdata_params = _get_template('vnf_cirros_param_values_user_data.yaml')
config_data = _get_template('config_data.yaml')
def get_dummy_vnfd_obj():
return {u'vnfd': {u'service_types': [{u'service_type': u'vnfd'}],
'name': 'dummy_vnfd', 'tenant_id':
u'ad7ebc56538745a08ef7c5e97f8bd437', u'mgmt_driver': u'noop',
u'infra_driver': u'fake_driver', u'attributes': {u'vnfd':
u'template_name: OpenWRT'
u' \r\ndescription: OpenWRT router'
u'\r\n\r\nservice_properties:\r\n'
u' Id: sample-vnfd\r\n vendor:'
u' tacker\r\n version: '
u'1\r\n\r\nvdus:'
u'\r\n vdu1:\r\n id: vdu1\r\n'
u' vm_image:'
u' cirros-0.3.2-x86_64-uec\r\n'
u' instance_type: m1.tiny\r\n\r\n'
u' network_interfaces:\r\n'
u' management:\r\n'
u' network: net_mgmt\r\n'
u' management: true\r\n'
u' pkt_in:\r\n network:'
u' net0\r\n pkt_out:\r\n'
u' network: net1\r\n\r\n'
u' placement_policy:\r\n'
u' availability_zone: nova\r\n'
u'\r'
u'\n auto-scaling: noop\r\n'
u' monitoring_policy: noop\r\n'
u' failure_policy: noop\r\n\r\n'
u' config:\r\n param0: key0'
u'\r\n param1: key1'},
'name': 'dummy_vnfd',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
u'mgmt_driver': u'noop',
u'infra_driver': u'fake_driver',
u'attributes': {u'vnfd': vnfd_openwrt},
'description': 'dummy_vnfd_description'},
u'auth': {u'tenantName': u'admin', u'passwordCredentials': {
u'username': u'admin', u'password': u'devstack'}}}
@ -67,26 +62,18 @@ def get_dummy_device_obj():
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': u'template_name: '
u'OpenWRT\r\ndescription: OpenWRT with services\r\n\r\nvdus:\r\n '
u'vdu1:\r\n id: vdu1\r\n vm_image: cirros-0.3.2-x86_64-uec\r\n '
u' instance_type: m1.tiny\r\n service_type: firewall\r\n '
u'mgmt_driver: openwrt\r\n\r\n network_interfaces:\r\n '
u'management:\r\n network: net_mgmt\r\n management: True'
u'\r\n pkt_in:\r\n network: net0\r\n pkt_out:\r\n '
u' network: net1\r\n\r\n placement_policy:\r\n '
u'availability_zone: nova\r\n\r\n auto-scaling: noop\r\n\r\n '
u'monitoring_policy: noop\r\n failure_policy: noop\r\n\r\n '
u'monitoring_parameter:\r\n a:\r\n\r\n config:\r\n '
u'param0: key0\r\n param1: key1\r\n\r\n'}, 'id':
u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'param_values': u''}, 'id':
'eb84260e-5ff7-4332-b032-50a14d6c1123', 'description':
u'OpenWRT with services'}
'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': vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
'name': u'openwrt_services'},
'mgmt_url': None, 'service_context': [],
'attributes': {u'param_values': u''},
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
'description': u'OpenWRT with services'}
def get_dummy_device_obj_config_attr():
@ -94,32 +81,16 @@ def get_dummy_device_obj_config_attr():
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': u'template_name: '
u'OpenWRT\r\ndescription: OpenWRT with services\r\n\r\nvdus:\r\n '
u'vdu1:\r\n id: vdu1\r\n vm_image: cirros-0.3.2-x86_64-uec\r\n '
u' instance_type: m1.tiny\r\n service_type: firewall\r\n '
u'mgmt_driver: openwrt\r\n\r\n network_interfaces:\r\n '
u'management:\r\n network: net_mgmt\r\n management: True'
u'\r\n pkt_in:\r\n network: net0\r\n pkt_out:\r\n '
u' network: net1\r\n\r\n placement_policy:\r\n '
u'availability_zone: nova\r\n\r\n auto-scaling: noop\r\n\r\n '
u'monitoring_policy: noop\r\n failure_policy: noop\r\n\r\n '
u'monitoring_parameter:\r\n a:\r\n\r\n config:\r\n '
u'param0: key0\r\n param1: key1\r\n\r\n'}, 'id':
u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
'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': vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'config': u"vdus:\n vdu1:\n config:\n "
u"firewall: |\n package firewall"
u"\n\n config defaults\n "
u" option syn_flood '1'\n "
u" option input 'ACCEPT'\n "
u" option output 'ACCEPT'\n "
u" option forward "
u"'REJECT'\n"}, 'id':
'eb84260e-5ff7-4332-b032-50a14d6c1123',
'attributes': {u'config': config_data},
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
'description': u'OpenWRT with services'}
@ -138,86 +109,46 @@ def get_dummy_device_update_config_attr():
def get_dummy_device_obj_ipaddr_attr():
return {'status': 'PENDING_CREATE', 'device_template': {'service_types':
return {'status': 'PENDING_CREATE',
'device_template': {'service_types':
[{'service_type': u'vnfd', 'id':
u'16f8b3f7-a9ff-4338-bbe5-eee48692c468'}, {'service_type':
u'router', 'id': u'58878cb7-689f-47a5-9c2d-654e49e2357f'},
{'service_type': u'firewall', 'id':
u'd016144f-42a6-44f4-93f6-52d201998916'}], 'description':
u'Parameterized VNF descriptor for IP addresses', 'tenant_id':
u'4dd6c1d7b6c94af980ca886495bcfed0', 'mgmt_driver': u'noop',
'infra_driver': u'heat', 'attributes': {u'vnfd': u'template_name: '
u'cirros_ipaddr_template\ndescription: Parameterized VNF descriptor '
u'for IP addresses\nservice_properties:\n Id: cirros\n vendor: '
u'ACME\n version: 1\n type:\n - router\n - firewall\n\nvdus:\n'
u' vdu1:\n id: vdu1\n vm_image: { get_input: vm_image }\n '
u'instance_type: {get_input: flavor }\n service_type: {get_input: '
u'service}\n mgmt_driver: noop\n\n network_interfaces:\n '
u'management:\n network: { get_input: network }\n '
u'management: { get_input: management }\n addresses: '
u'{ get_input: mgmt_ip}\n pkt_in:\n network: { get_input: '
u'pkt_in_network }\n addresses: { get_input: pkt_in_ip}\n '
u'pkt_out:\n network: { get_input: pkt_out_network }\n '
u'addresses: { get_input: pkt_out_ip}\n\n placement_policy:\n '
u'availability_zone: { get_input: zone }\n\n auto-scaling: noop\n\n'
u' monitoring_policy: noop\n failure_policy: noop\n\n config:'
u'\n param0: key0\n param1: key1\n'}, 'id':
u'24c31ea1-2e28-4de2-a6cb-8d389a502c75', 'name': u'ip_vnfd'}, 'name':
u'test_ip', 'tenant_id': u'8273659b56fc46b68bd05856d1f08d14', 'id':
'd1337add-d5a1-4fd4-9447-bb9243c8460b', 'instance_id': None,
'mgmt_url': None, 'service_context': [], 'services': [],
'attributes': {u'param_values': u'vdus:\n vdu1:\n param:\n '
u' vm_image: cirros-0.3.4-x86_64-uec\n flavor: m1.tiny\n '
u' service: firewall\n pkt_in_network: net0\n '
u'pkt_out_network: net1\n zone: nova\n management: True'
u'\n network: net_mgmt\n mgmt_ip:\n - '
u'192.168.120.98\n pkt_in_ip:\n - 10.10.0.98\n '
u'pkt_out_ip:\n - 10.10.1.98\n'}, 'template_id':
u'24c31ea1-2e28-4de2-a6cb-8d389a502c75', 'description':
u'Parameterized VNF descriptor for IP addresses'}
u'd016144f-42a6-44f4-93f6-52d201998916'}],
'description': u'Parameterized VNF descriptor for IP addresses',
'tenant_id': u'4dd6c1d7b6c94af980ca886495bcfed0',
'mgmt_driver': u'noop',
'infra_driver': u'heat',
'attributes': {u'vnfd': vnfd_ipparams_template},
'id': u'24c31ea1-2e28-4de2-a6cb-8d389a502c75', 'name': u'ip_vnfd'},
'name': u'test_ip',
'tenant_id': u'8273659b56fc46b68bd05856d1f08d14',
'id': 'd1337add-d5a1-4fd4-9447-bb9243c8460b',
'instance_id': None, 'mgmt_url': None, 'service_context': [],
'services': [],
'attributes': {u'param_values': ipparams},
'template_id': u'24c31ea1-2e28-4de2-a6cb-8d389a502c75',
'description': u'Parameterized VNF descriptor for IP addresses'}
def get_dummy_device_obj_userdata_attr():
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
u'test_userdata', 'tenant_id': u'8273659b56fc46b68bd05856d1f08d14',
return {'status': 'PENDING_CREATE', 'instance_id': None,
'name': u'test_userdata',
'tenant_id': u'8273659b56fc46b68bd05856d1f08d14',
'template_id': u'206e343f-c580-4494-a739-525849edab7f',
'device_template': {'service_types': [{'service_type': u'firewall',
'id': u'1fcc2d7c-a6b6-4263-8cac-9590f059a555'}, {'service_type':
u'router', 'id': u'8c99106d-826f-46eb-91a1-08dfdc78c04b'},
{'service_type': u'vnfd', 'id':
u'9bf289ec-c0e1-41fc-91d7-110735a70221'}], 'description':
u"Parameterized VNF descriptor", 'tenant_id':
u'8273659b56fc46b68bd05856d1f08d14', 'mgmt_driver': u'noop',
'infra_driver': u'heat', 'attributes': {u'vnfd':
u"template_name: cirros_user_data\ndescription: "
u"Parameterized VNF descriptor\nservice_properties:"
u"\n Id: cirros\n vendor: ACME\n version: 1\n "
u"type:\n - router\n - firewall\n\nvdus:\n "
u"vdu1:\n id: vdu1\n vm_image: { get_input: "
u"vm_image }\n instance_type: {get_input: flavor "
u"}\n service_type: {get_input: service}\n "
u"mgmt_driver: noop\n user_data: {get_input: "
u"user_data}\n user_data_format: {get_input: "
u"user_data_format}\n\n network_interfaces:\n "
u" management:\n network: { get_input: "
u"network }\n management: { get_input: "
u"management }\n pkt_in:\n network: "
u"{ get_input: pkt_in_network }\n pkt_out:\n "
u" network: { get_input: pkt_out_network }\n\n "
u" placement_policy:\n availability_zone: { "
u"get_input: zone }\n\n auto-scaling: noop\n\n "
u" monitoring_policy: noop\n failure_policy: noop"
u"\n\n config:\n param0: key0\n param1:"
u" key1\n"}, 'id':
u'206e343f-c580-4494-a739-525849edab7f', 'name':
u'9bf289ec-c0e1-41fc-91d7-110735a70221'}],
'description': u"Parameterized VNF descriptor",
'tenant_id': u'8273659b56fc46b68bd05856d1f08d14',
'mgmt_driver': u'noop',
'infra_driver': u'heat',
'attributes': {u'vnfd': vnfd_userdata_template},
'id': u'206e343f-c580-4494-a739-525849edab7f', 'name':
u'cirros_user_data'}, 'mgmt_url': None, 'service_context': [],
'services': [], 'attributes': {u'param_values': u'vdus:\n vdu1:\n'
u' param:\n vm_image: cirros-0.3.4-x86_64-uec\n '
u'flavor: m1.tiny\n service: firewall\n pkt_in_network: '
u'net0\n pkt_out_network: net1\n zone: nova\n '
u'management: True\n network: net_mgmt\n '
u'user_data_format: RAW\n user_data: |\n #!/bin/sh\n '
u' echo "my hostname is `hostname`" > /tmp/hostname\n '
u'df -h > /home/cirros/diskinfo\n'}, 'id':
'18685f68-2b2a-4185-8566-74f54e548811', 'description':
u"Parameterized VNF descriptor"}
'services': [], 'attributes': {u'param_values': userdata_params},
'id': '18685f68-2b2a-4185-8566-74f54e548811',
'description': u"Parameterized VNF descriptor"}

View File

@ -0,0 +1,12 @@
vdus:
vdu1:
config:
firewall: |
package firewall
config defaults
option syn_flood '1'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'REJECT'

View File

@ -0,0 +1,26 @@
description: OpenWRT with services
heat_template_version: 2013-05-23
outputs:
mgmt_ip-vdu1:
description: management ip address
value:
get_attr: [vdu1-net_mgmt-port, fixed_ips, 0, ip_address]
resources:
vdu1:
properties:
availability_zone: nova
config_drive: true
flavor: m1.tiny
image: cirros-0.3.2-x86_64-uec
metadata: {param0: key0, param1: key1}
networks:
- port: {get_resource: vdu1-net_mgmt-port}
- {network: net0}
- {network: net1}
type: OS::Nova::Server
vdu1-net_mgmt-port:
properties:
fixed_ips: []
network: net_mgmt
port_security_enabled: false
type: OS::Neutron::Port

View File

@ -0,0 +1,41 @@
description: Parameterized VNF descriptor for IP addresses
heat_template_version: 2013-05-23
outputs:
mgmt_ip-vdu1:
description: management ip address
value:
get_attr: [vdu1-net_mgmt-port, fixed_ips, 0, ip_address]
resources:
vdu1:
properties:
availability_zone: nova
config_drive: true
flavor: m1.tiny
image: cirros-0.3.4-x86_64-uec
metadata: {param0: key0, param1: key1}
networks:
- port: {get_resource: vdu1-net_mgmt-port}
- port: {get_resource: vdu1-net0-port}
- port: {get_resource: vdu1-net1-port}
type: OS::Nova::Server
vdu1-net0-port:
properties:
fixed_ips:
- {ip_address: 10.10.0.98}
network: net0
port_security_enabled: false
type: OS::Neutron::Port
vdu1-net1-port:
properties:
fixed_ips:
- {ip_address: 10.10.1.98}
network: net1
port_security_enabled: false
type: OS::Neutron::Port
vdu1-net_mgmt-port:
properties:
fixed_ips:
- {ip_address: 192.168.120.98}
network: net_mgmt
port_security_enabled: false
type: OS::Neutron::Port

View File

@ -0,0 +1,34 @@
description: Parameterized VNF descriptor
heat_template_version: 2013-05-23
outputs:
mgmt_ip-vdu1:
description: management ip address
value:
get_attr: [vdu1-net_mgmt-port, fixed_ips, 0, ip_address]
resources:
vdu1:
properties:
availability_zone: nova
config_drive: true
flavor: m1.tiny
image: cirros-0.3.4-x86_64-uec
metadata: {param0: key0, param1: key1}
networks:
- port: {get_resource: vdu1-net_mgmt-port}
- {network: net0}
- {network: net1}
user_data: '#!/bin/sh
echo "my hostname is `hostname`" > /tmp/hostname
df -h > /home/cirros/diskinfo
'
user_data_format: RAW
type: OS::Nova::Server
vdu1-net_mgmt-port:
properties:
fixed_ips: []
network: net_mgmt
port_security_enabled: false
type: OS::Neutron::Port

View File

@ -0,0 +1,24 @@
heat_template_version: 2013-05-23
description: 'OpenWRT with services
'
parameters: {}
resources:
VDU1:
type: OS::Nova::Server
properties:
config_drive: false
flavor: m1.tiny
image: OpenWRT
networks:
- port:
get_resource: CP1
user_data_format: SOFTWARE_CONFIG
CP1:
type: OS::Neutron::Port
properties:
network: existing_network_1
outputs:
mgmt_ip-VDU1:
value:
get_attr: [CP1, fixed_ips, 0, ip_address]

View File

@ -0,0 +1,35 @@
template_name: OpenWRT
description: OpenWRT with services
vdus:
vdu1:
id: vdu1
vm_image: cirros-0.3.2-x86_64-uec
instance_type: m1.tiny
service_type: firewall
mgmt_driver: openwrt
network_interfaces:
management:
network: net_mgmt
management: True
pkt_in:
network: net0
pkt_out:
network: net1
placement_policy:
availability_zone: nova
auto-scaling: noop
monitoring_policy: noop
failure_policy: noop
monitoring_parameter:
a:
config:
param0: key0
param1: key1

View File

@ -0,0 +1,54 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: OpenWRT with services
metadata:
template_name: OpenWRT
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
properties:
image: OpenWRT
flavor: m1.tiny
config: |
param0: key1
param1: key2
mgmt_driver: openwrt
monitoring_policy:
name: ping
actions:
- {trigger: failure, action: respawn}
parameters:
count: "3"
interval: "10"
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: existing_network_1
vendor: ACME
# policies:
# - monitor_policy:
# type: tosca.policies.tacker.Monitoring.Ping
# description: Apply monitoring policy to VDUs
# targets: [ VDU1 ]
# properties:
# parameters:
# count: "3"
# interval: "10"
# actions:
# - {trigger: failure, action: respawn}

View File

@ -0,0 +1,17 @@
vdus:
vdu1:
param:
vm_image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
service: firewall
pkt_in_network: net0
pkt_out_network: net1
zone: nova
management: True
network: net_mgmt
mgmt_ip:
- 192.168.120.98
pkt_in_ip:
- 10.10.0.98
pkt_out_ip:
- 10.10.1.98

View File

@ -0,0 +1,16 @@
vdus:
vdu1:
param:
vm_image: cirros-0.3.4-x86_64-uec
flavor: m1.tiny
service: firewall
pkt_in_network: net0
pkt_out_network: net1
zone: nova
management: True
network: net_mgmt
user_data_format: RAW
user_data: |
#!/bin/sh
echo "my hostname is `hostname`" > /tmp/hostname
df -h > /home/cirros/diskinfo

View File

@ -0,0 +1,42 @@
template_name: cirros_ipaddr_template
description: Parameterized VNF descriptor for IP addresses
service_properties:
Id: cirros
vendor: ACME
version: 1
type:
- router
- firewall
vdus:
vdu1:
id: vdu1
vm_image: { get_input: vm_image }
instance_type: {get_input: flavor }
service_type: {get_input: service}
mgmt_driver: noop
network_interfaces:
management:
network: { get_input: network }
management: { get_input: management }
addresses: { get_input: mgmt_ip}
pkt_in:
network: { get_input: pkt_in_network }
addresses: { get_input: pkt_in_ip}
pkt_out:
network: { get_input: pkt_out_network }
addresses: { get_input: pkt_out_ip}
placement_policy:
availability_zone: { get_input: zone }
auto-scaling: noop
monitoring_policy: noop
failure_policy: noop
config:
param0: key0
param1: key1

View File

@ -0,0 +1,41 @@
template_name: cirros_user_data
description: Parameterized VNF descriptor
service_properties:
Id: cirros
vendor: ACME
version: 1
type:
- router
- firewall
vdus:
vdu1:
id: vdu1
vm_image: { get_input: vm_image }
instance_type: {get_input: flavor }
service_type: {get_input: service}
mgmt_driver: noop
user_data: {get_input: user_data}
user_data_format: {get_input: user_data_format}
network_interfaces:
management:
network: { get_input: network }
management: { get_input: management }
pkt_in:
network: { get_input: pkt_in_network }
pkt_out:
network: { get_input: pkt_out_network }
placement_policy:
availability_zone: { get_input: zone }
auto-scaling: noop
monitoring_policy: noop
failure_policy: noop
config:
param0: key0
param1: key1

View File

@ -13,7 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import codecs
import mock
import os
import testtools
from tacker import context
@ -35,7 +37,22 @@ class FakeHeatClient(mock.Mock):
return self.Stack()
def _get_template(name):
filename = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "data/", name)
f = codecs.open(filename, encoding='utf-8', errors='strict')
return f.read()
class TestDeviceHeat(testtools.TestCase):
hot_template = _get_template('hot_openwrt.yaml')
hot_param_template = _get_template('hot_openwrt_params.yaml')
hot_ipparam_template = _get_template('hot_openwrt_ipparams.yaml')
vnfd_openwrt = _get_template('openwrt.yaml')
tosca_openwrt = _get_template('test_tosca_openwrt.yaml')
hot_tosca_openwrt = _get_template('hot_tosca_openwrt.yaml')
config_data = _get_template('config_data.yaml')
def setUp(self):
super(TestDeviceHeat, self).setUp()
self.context = context.get_admin_context()
@ -54,68 +71,31 @@ class TestDeviceHeat(testtools.TestCase):
patcher = mock.patch(target, new)
return patcher.start()
def _get_device_template(self, template):
return {'device_template': {'attributes': {'vnfd': template}}}
def _get_expected_device_template(self, template):
return {'device_template': {'attributes': {'vnfd': template},
'description': 'OpenWRT with services',
'mgmt_driver': 'openwrt',
'name': 'OpenWRT'}}
def _get_expected_fields(self):
return {'stack_name':
'tacker.vm.infra_drivers.heat.heat_DeviceHeat-eb84260e'
'-5ff7-4332-b032-50a14d6c1123', 'template':
'description: OpenWRT with services\nheat_template_version: '
'2013-05-23\noutputs:\n mgmt_ip-vdu1:\n description: '
'management ip address\n value:\n get_attr: [vdu1-net_mgmt'
'-port, fixed_ips, 0, ip_address]\nresources:\n vdu1:\n '
'properties:\n availability_zone: nova\n config_drive: '
'true\n flavor: m1.tiny\n image: cirros-0.3.2-x86_64-uec'
'\n metadata: {param0: key0, param1: key1}\n networks:\n'
' - port: {get_resource: vdu1-net_mgmt-port}\n - '
'{network: net0}\n - {network: net1}\n type: OS::Nova::'
'Server\n vdu1-net_mgmt-port:\n properties:\n fixed_ips: '
'[]\n network: net_mgmt\n port_security_enabled: false\n'
' type: OS::Neutron::Port\n'}
'-5ff7-4332-b032-50a14d6c1123', 'template': self.hot_template}
def _get_expected_fields_user_data(self):
return {'stack_name':
'tacker.vm.infra_drivers.heat.heat_DeviceHeat-18685f68'
'-2b2a-4185-8566-74f54e548811', 'template':
'description: Parameterized VNF descriptor\nheat_template_version:'
' 2013-05-23\noutputs:\n mgmt_ip-vdu1:\n description: '
'management ip address\n value:\n get_attr: '
'[vdu1-net_mgmt-port, fixed_ips, 0, ip_address]\nresources:\n '
'vdu1:\n properties:\n availability_zone: nova\n '
'config_drive: true\n flavor: m1.tiny\n image: '
'cirros-0.3.4-x86_64-uec\n metadata: {param0: key0, param1: '
'key1}\n networks:\n - port: {get_resource: '
'vdu1-net_mgmt-port}\n - {network: net0}\n - '
'{network: net1}\n user_data: \'#!/bin/sh\n\n '
'echo "my hostname is `hostname`" > /tmp/hostname\n\n '
'df -h > /home/cirros/diskinfo\n\n \'\n '
'user_data_format: RAW\n type: OS::Nova::Server\n '
'vdu1-net_mgmt-port:\n properties:\n fixed_ips: []\n '
'network: net_mgmt\n port_security_enabled: false\n '
'type: OS::Neutron::Port\n'}
'-2b2a-4185-8566-74f54e548811',
'template': self.hot_param_template}
def _get_expected_fields_ipaddr_data(self):
return {'stack_name':
'tacker.vm.infra_drivers.heat.heat_DeviceHeat-d1337add'
'-d5a1-4fd4-9447-bb9243c8460b', 'template':
'description: Parameterized VNF descriptor for IP addresses\n'
'heat_template_version: 2013-05-23\noutputs:\n mgmt_ip-vdu1:\n '
' description: management ip address\n value:\n '
'get_attr: [vdu1-net_mgmt-port, fixed_ips, 0, ip_address]\n'
'resources:\n vdu1:\n properties:\n availability_zone: '
'nova\n config_drive: true\n flavor: m1.tiny\n '
'image: cirros-0.3.4-x86_64-uec\n metadata: {param0: key0, '
'param1: key1}\n networks:\n - port: {get_resource: '
'vdu1-net_mgmt-port}\n - port: {get_resource: vdu1-net0-port}'
'\n - port: {get_resource: vdu1-net1-port}\n type: '
'OS::Nova::Server\n vdu1-net0-port:\n properties:\n '
'fixed_ips:\n - {ip_address: 10.10.0.98}\n network: net0'
'\n port_security_enabled: false\n type: '
'OS::Neutron::Port\n vdu1-net1-port:\n properties:\n '
'fixed_ips:\n - {ip_address: 10.10.1.98}\n network: net1'
'\n port_security_enabled: false\n type: '
'OS::Neutron::Port\n vdu1-net_mgmt-port:\n properties:\n '
'fixed_ips:\n - {ip_address: 192.168.120.98}\n network: '
'net_mgmt\n port_security_enabled: false\n '
'type: OS::Neutron::Port\n'}
'-d5a1-4fd4-9447-bb9243c8460b',
'template': self.hot_ipparam_template}
def _get_expected_device_wait_obj(self):
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
@ -126,19 +106,9 @@ class TestDeviceHeat(testtools.TestCase):
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': u'template_name: '
u'OpenWRT\r\ndescription: OpenWRT with services\r\n\r\nvdus:\r\n '
u'vdu1:\r\n id: vdu1\r\n vm_image: cirros-0.3.2-x86_64-uec\r\n '
u' instance_type: m1.tiny\r\n service_type: firewall\r\n '
u'mgmt_driver: openwrt\r\n\r\n network_interfaces:\r\n '
u'management:\r\n network: net_mgmt\r\n management: True'
u'\r\n pkt_in:\r\n network: net0\r\n pkt_out:\r\n '
u' network: net1\r\n\r\n placement_policy:\r\n '
u'availability_zone: nova\r\n\r\n auto-scaling: noop\r\n\r\n '
u'monitoring_policy: noop\r\n failure_policy: noop\r\n\r\n '
u'monitoring_parameter:\r\n a:\r\n\r\n config:\r\n '
u'param0: key0\r\n param1: key1\r\n\r\n'}, 'id':
u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
'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':
@ -154,19 +124,9 @@ class TestDeviceHeat(testtools.TestCase):
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': u'template_name: '
u'OpenWRT\r\ndescription: OpenWRT with services\r\n\r\nvdus:\r\n '
u'vdu1:\r\n id: vdu1\r\n vm_image: cirros-0.3.2-x86_64-uec\r\n '
u' instance_type: m1.tiny\r\n service_type: firewall\r\n '
u'mgmt_driver: openwrt\r\n\r\n network_interfaces:\r\n '
u'management:\r\n network: net_mgmt\r\n management: True'
u'\r\n pkt_in:\r\n network: net0\r\n pkt_out:\r\n '
u' network: net1\r\n\r\n placement_policy:\r\n '
u'availability_zone: nova\r\n\r\n auto-scaling: noop\r\n\r\n '
u'monitoring_policy: noop\r\n failure_policy: noop\r\n\r\n '
u'monitoring_parameter:\r\n a:\r\n\r\n config:\r\n '
u'param0: key0\r\n param1: key1\r\n\r\n'}, 'id':
u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
'infra_driver': u'heat',
'attributes': {u'vnfd': self.vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'config': 'vdus:\n vdu1:\n config: {firewall: '
'"package firewall\\n\\nconfig defaults'
@ -230,3 +190,56 @@ class TestDeviceHeat(testtools.TestCase):
device_id, device_obj,
device_config_obj)
self.assertEqual(device_obj, expected_device_update)
def test_create_device_template_pre_tosca(self):
dtemplate = self._get_device_template(self.tosca_openwrt)
exp_tmpl = self._get_expected_device_template(self.tosca_openwrt)
self.heat_driver.create_device_template_pre(None, None, dtemplate)
self.assertEqual(dtemplate, exp_tmpl)
def _get_expected_fields_tosca(self):
return {'stack_name':
'tacker.vm.infra_drivers.heat.heat_DeviceHeat-eb84260e'
'-5ff7-4332-b032-50a14d6c1123',
'template': self.hot_tosca_openwrt}
def _get_expected_tosca_device(self):
exp_tmpl = self._get_expected_device_template(self.tosca_openwrt)
return {'device_template': exp_tmpl['device_template'],
'description': u'OpenWRT with services',
'attributes': {'heat_template': self.hot_tosca_openwrt,
'monitoring_policy': '{"vdus": {"VDU1":'
' {"name": "ping", "actions": [{"trigger":'
' "failure", "action": "respawn"}],'
' "parameters": {"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'}
def _get_dummy_tosca_device(self, template=''):
tosca_template = getattr(self, 'tosca_' + template, None)
if not tosca_template:
tosca_template = self.tosca_openwrt
device = utils.get_dummy_device_obj()
dtemplate = self._get_expected_device_template(tosca_template)
dtemplate['service_types'] = [{'service_type': 'vnfd', 'id':
'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}]
dtemplate['tenant_id'] = 'ad7ebc56538745a08ef7c5e97f8bd437'
device['device_template'] = dtemplate['device_template']
return device
def test_create_tosca(self):
# self.skipTest("Not ready yet")
device = self._get_dummy_tosca_device()
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
expected_fields = self._get_expected_fields_tosca()
expected_device = self._get_expected_tosca_device()
result = self.heat_driver.create(plugin=None, context=self.context,
device=device)
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
self.assertEqual(device, expected_device)

View File

@ -0,0 +1,122 @@
# Copyright 2016 - Nokia
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file 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.
import codecs
import os
import testtools
import yaml
from tacker.vm.tosca import utils as toscautils
from toscaparser.tosca_template import ToscaTemplate
from translator.hot.tosca_translator import TOSCATranslator
def _get_template(name):
filename = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"infra_drivers/heat/data/", name)
f = codecs.open(filename, encoding='utf-8', errors='strict')
return f.read()
class TestToscaUtils(testtools.TestCase):
tosca_openwrt = _get_template('test_tosca_openwrt.yaml')
vnfd_dict = yaml.load(tosca_openwrt)
toscautils.updateimports(vnfd_dict)
tosca = ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=vnfd_dict)
def setUp(self):
super(TestToscaUtils, self).setUp()
def test_updateimport(self):
importspath = os.path.abspath('./tacker/vm/tosca/lib/')
file1 = importspath + '/tacker_defs.yaml'
file2 = importspath + '/tacker_nfv_defs.yaml'
expected_imports = [file1, file2]
self.assertEqual(self.vnfd_dict['imports'], expected_imports)
def test_get_mgmt_driver(self):
expected_mgmt_driver = 'openwrt'
mgmt_driver = toscautils.get_mgmt_driver(self.tosca)
self.assertEqual(mgmt_driver, expected_mgmt_driver)
def test_get_vdu_monitoring(self):
expected_monitoring = {'vdus': {'VDU1': {'actions':
[{'action': 'respawn',
'trigger': 'failure'}],
'name': 'ping',
'parameters': {'count': '3',
'interval': '10'}}}}
monitoring = toscautils.get_vdu_monitoring(self.tosca)
self.assertEqual(monitoring, expected_monitoring)
def test_get_mgmt_ports(self):
expected_mgmt_ports = {'mgmt_ip-VDU1': 'CP1'}
mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
self.assertEqual(mgmt_ports, expected_mgmt_ports)
def test_post_process_template(self):
tosca2 = ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=self.vnfd_dict)
toscautils.post_process_template(tosca2)
invalidNodes = 0
for nt in tosca2.nodetemplates:
if (nt.type_definition.is_derived_from(toscautils.MONITORING) or
nt.type_definition.is_derived_from(toscautils.FAILURE) or
nt.type_definition.is_derived_from(toscautils.PLACEMENT)):
invalidNodes += 1
self.assertEqual(invalidNodes, 0)
deletedProperties = 0
if nt.type in toscautils.delpropmap.keys():
for prop in toscautils.delpropmap[nt.type]:
for p in nt.get_properties_objects():
if prop == p.name:
deletedProperties += 1
self.assertEqual(deletedProperties, 0)
convertedProperties = 0
if nt.type in toscautils.convert_prop:
for prop in toscautils.convert_prop[nt.type].keys():
for p in nt.get_properties_objects():
if prop == p.name:
convertedProperties += 1
self.assertEqual(convertedProperties, 0)
def test_post_process_heat_template(self):
tosca1 = ToscaTemplate(parsed_params={}, a_file=False,
yaml_dict_tpl=self.vnfd_dict)
toscautils.post_process_template(tosca1)
translator = TOSCATranslator(tosca1, {})
heat_template_yaml = translator.translate()
expected_heat_tpl = _get_template('hot_tosca_openwrt.yaml')
mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
heat_tpl = toscautils.post_process_heat_template(
heat_template_yaml, mgmt_ports)
heatdict = yaml.load(heat_tpl)
expecteddict = yaml.load(expected_heat_tpl)
self.assertEqual(heatdict, expecteddict)
def test_findvdus(self):
vdus = toscautils.findvdus(self.tosca)
self.assertEqual(len(vdus), 1)
for vdu in vdus:
self.assertEqual(vdu.type_definition.is_derived_from(
toscautils.TACKERVDU), True)

View File

@ -21,7 +21,9 @@ import time
from heatclient import exc as heatException
from oslo_config import cfg
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.utils import yamlparser
from translator.hot.tosca_translator import TOSCATranslator
import yaml
from tacker.common import clients
@ -30,6 +32,7 @@ from tacker.extensions import vnfm
from tacker.openstack.common import jsonutils
from tacker.openstack.common import log as logging
from tacker.vm.infra_drivers import abstract_driver
from tacker.vm.tosca import utils as toscautils
LOG = logging.getLogger(__name__)
@ -77,7 +80,32 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
return
vnfd_dict = yaml.load(vnfd_yaml)
KEY_LIST = (('name', 'template_name'), ('description', 'description'))
LOG.debug(_('vnfd_dict: %s'), vnfd_dict)
if 'tosca_definitions_version' in vnfd_dict:
# Prepend the tacker_defs.yaml import file with the full
# path to the file
toscautils.updateimports(vnfd_dict)
try:
tosca = ToscaTemplate(a_file=False, yaml_dict_tpl=vnfd_dict)
except Exception as e:
LOG.exception(_("tosca-parser error: %s"), str(e))
raise vnfm.ToscaParserFailed(error_msg_details=str(e))
if ('description' not in device_template_dict or
device_template_dict['description'] == ''):
device_template_dict['description'] = vnfd_dict.get(
'description', '')
if 'name' not in device_template_dict and 'metadata' in vnfd_dict:
device_template_dict['name'] = vnfd_dict['metadata'].get(
'template_name', '')
device_template_dict['mgmt_driver'] = toscautils.get_mgmt_driver(
tosca)
else:
KEY_LIST = (('name', 'template_name'),
('description', 'description'))
device_template_dict.update(
dict((key, vnfd_dict[vnfd_key]) for (key, vnfd_key) in KEY_LIST
@ -86,14 +114,20 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
vnfd_key in vnfd_dict and
vnfd_dict[vnfd_key] != '')))
service_types = vnfd_dict.get('service_properties', {}).get('type', [])
service_types = vnfd_dict.get('service_properties', {}).get('type',
[])
if service_types:
device_template_dict.setdefault('service_types', []).extend(
[{'service_type': service_type}
for service_type in service_types])
# TODO(anyone) - this code assumes one mgmt_driver per VNFD???
for vdu in vnfd_dict.get('vdus', {}).values():
mgmt_driver = vdu.get('mgmt_driver')
if mgmt_driver:
if device_template_dict.get(
'mgmt_driver', mgmt_driver) != mgmt_driver:
raise vnfm.MultipleMGMTDriversSpecified()
else:
device_template_dict['mgmt_driver'] = mgmt_driver
LOG.debug(_('device_template %s'), device_template)
@ -219,26 +253,50 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
LOG.debug('vnfd_yaml %s', vnfd_yaml)
if vnfd_yaml is not None:
vnfd_dict = yamlparser.simple_ordered_parse(vnfd_yaml)
LOG.debug('vnfd_dict %s', vnfd_dict)
monitoring_dict = {'vdus': {}}
if 'tosca_definitions_version' in vnfd_dict:
parsed_params = dev_attrs.pop('param_values', {})
toscautils.updateimports(vnfd_dict)
try:
tosca = ToscaTemplate(parsed_params=parsed_params,
a_file=False, yaml_dict_tpl=vnfd_dict)
except Exception as e:
LOG.debug("tosca-parser error: %s", str(e))
raise vnfm.ToscaParserFailed(error_msg_details=str(e))
monitoring_dict = toscautils.get_vdu_monitoring(tosca)
mgmt_ports = toscautils.get_mgmt_ports(tosca)
toscautils.post_process_template(tosca)
try:
translator = TOSCATranslator(tosca, parsed_params)
heat_template_yaml = translator.translate()
except Exception as e:
LOG.debug("heat-translator error: %s", str(e))
raise vnfm.HeatTranslatorFailed(error_msg_details=str(e))
heat_template_yaml = toscautils.post_process_heat_template(
heat_template_yaml, mgmt_ports)
else:
assert 'template' not in fields
assert 'template_url' not in fields
template_dict = yaml.load(HEAT_TEMPLATE_BASE)
outputs_dict = {}
template_dict['outputs'] = outputs_dict
vnfd_dict = yamlparser.simple_ordered_parse(vnfd_yaml)
LOG.debug('vnfd_dict %s', vnfd_dict)
if 'get_input' in vnfd_yaml:
self._process_parameterized_input(dev_attrs, vnfd_dict)
KEY_LIST = (('description', 'description'),
)
KEY_LIST = (('description', 'description'), )
for (key, vnfd_key) in KEY_LIST:
if vnfd_key in vnfd_dict:
template_dict[key] = vnfd_dict[vnfd_key]
monitoring_dict = {'vdus': {}}
for vdu_id, vdu_dict in vnfd_dict.get('vdus', {}).items():
template_dict.setdefault('resources', {})[vdu_id] = {
"type": "OS::Nova::Server"
@ -254,14 +312,16 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
self._process_vdu_network_interfaces(vdu_id, vdu_dict,
properties,
template_dict)
if 'user_data' in vdu_dict and 'user_data_format' in vdu_dict:
if ('user_data' in vdu_dict and
'user_data_format' in vdu_dict):
properties['user_data_format'] = vdu_dict[
'user_data_format']
properties['user_data'] = vdu_dict['user_data']
elif 'user_data' in vdu_dict or 'user_data_format' in vdu_dict:
elif ('user_data' in vdu_dict or
'user_data_format' in vdu_dict):
raise vnfm.UserDataFormatNotFound()
if ('placement_policy' in vdu_dict and
'availability_zone' in vdu_dict['placement_policy']):
if 'placement_policy' in vdu_dict:
if 'availability_zone' in vdu_dict['placement_policy']:
properties['availability_zone'] = vdu_dict[
'placement_policy']['availability_zone']
if 'config' in vdu_dict:
@ -271,17 +331,16 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
for key, value in metadata.items():
metadata[key] = value[:255]
monitoring_policy = vdu_dict.get('monitoring_policy', 'noop')
monitoring_policy = vdu_dict.get('monitoring_policy',
'noop')
failure_policy = vdu_dict.get('failure_policy', 'noop')
# Convert the old monitoring specification to the new format
# This should be removed after Mitaka
if monitoring_policy == 'ping' and failure_policy == 'respawn':
vdu_dict['monitoring_policy'] = {'ping': {
'actions':
{
'failure': 'respawn'
}}}
# Convert the old monitoring specification to the new
# network. This should be removed after Mitaka
if (monitoring_policy == 'ping' and
failure_policy == 'respawn'):
vdu_dict['monitoring_policy'] = {
'ping': {'actions': {'failure': 'respawn'}}}
vdu_dict.pop('failure_policy')
if monitoring_policy != 'noop':
@ -295,14 +354,16 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver):
'attributes', {})[vdu_id] = jsonutils.dumps(
{key: vdu_dict[key]})
if monitoring_dict.keys():
device['attributes']['monitoring_policy'] = jsonutils.dumps(
monitoring_dict)
heat_template_yaml = yaml.dump(template_dict)
fields['template'] = heat_template_yaml
if not device['attributes'].get('heat_template'):
device['attributes']['heat_template'] = heat_template_yaml
device['attributes']['heat_template'] = \
heat_template_yaml
if monitoring_dict.keys():
device['attributes']['monitoring_policy'] = \
jsonutils.dumps(monitoring_dict)
if 'stack_name' not in fields:
name = (__name__ + '_' + self.__class__.__name__ + '-' +

View File

View File

@ -0,0 +1,82 @@
data_types:
tosca.datatypes.tacker.ActionMap:
properties:
trigger:
type: string
required: true
action:
type: string
required: true
params:
type: map
entry_schema:
type: string
tosca.datatypes.tacker.MonitoringType:
properties:
name:
type: string
required: true
actions:
type: list
entry_schema:
type: tosca.datatypes.tacker.ActionMap
parameters:
type: map
entry_schema:
type: string
policy_types:
tosca.policies.tacker.Placement:
derived_from: tosca.policies.Root
tosca.policies.tacker.Failure:
derived_from: tosca.policies.Root
action:
type: string
tosca.policies.tacker.Failure.Respawn:
derived_from: tosca.policies.tacker.Failure
action: respawn
tosca.policies.tacker.Failure.Terminate:
derived_from: tosca.policies.tacker.Failure
action: log_and_kill
tosca.policies.tacker.Failure.Log:
derived_from: tosca.policies.tacker.Failure
action: log
tosca.policies.tacker.Monitoring:
derived_from: tosca.policies.Root
properties:
name:
type: string
required: true
parameters:
type: map
entry_schema:
type: string
actions:
type: map
entry_schema:
type: string
tosca.policies.tacker.Monitoring.NoOp:
derived_from: tosca.policies.tacker.Monitoring
properties:
name: noop
tosca.policies.tacker.Monitoring.Ping:
derived_from: tosca.policies.tacker.Monitoring
properties:
name: ping
tosca.policies.tacker.Monitoring.HttpPing:
derived_from: tosca.policies.tacker.Monitoring.Ping
properties:
name: http-ping
group_types:
tosca.groups.tacker.VDU:
derived_from: tosca.groups.Root

View File

@ -0,0 +1,46 @@
node_types:
tosca.nodes.nfv.VDU.Tacker:
derived_from: tosca.nodes.nfv.VDU
properties:
image:
# type: tosca.artifacts.Deployment.Image.VM
type: string
flavor:
type: string
availability_zone:
type: string
metadata:
type: map
entry_schema:
type: string
config_drive:
type: boolean
default: false
placement_policy:
# type: tosca.policies.tacker.Placement
type: string
monitoring_policy:
# type: tosca.policies.tacker.Monitoring
type: tosca.datatypes.tacker.MonitoringType
config:
type: string
mgmt_driver:
type: string
service_type:
type: string
tosca.nodes.nfv.CP.Tacker:
derived_from: tosca.nodes.nfv.CP
properties:
management:
type: boolean
required: false
anti_spoofing_protection:
type: boolean
required: false

158
tacker/vm/tosca/utils.py Normal file
View File

@ -0,0 +1,158 @@
# Copyright 2016 - Nokia
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file 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.
import os
import yaml
from tacker.common import log
from tacker.extensions import vnfm
from tacker.openstack.common import log as logging
from toscaparser.properties import Property
from toscaparser.utils import yamlparser
FAILURE = 'tosca.policies.tacker.Failure'
LOG = logging.getLogger(__name__)
MONITORING = 'tosca.policies.tacker.Monitoring'
PLACEMENT = 'tosca.policies.tacker.Placement'
TACKERCP = 'tosca.nodes.nfv.CP.Tacker'
TACKERVDU = 'tosca.nodes.nfv.VDU.Tacker'
TOSCA_BINDS_TO = 'tosca.relationships.network.BindsTo'
VDU = 'tosca.nodes.nfv.VDU'
delpropmap = {TACKERVDU: ('mgmt_driver', 'config', 'service_type',
'placement_policy', 'monitoring_policy',
'failure_policy'),
TACKERCP: ('management',)}
convert_prop = {TACKERCP: {'anti_spoofing_protection':
'port_security_enabled'}}
deletenodes = (MONITORING, FAILURE, PLACEMENT)
@log.log
def updateimports(template):
path = os.path.dirname(os.path.abspath(__file__)) + '/lib/'
defsfile = path + 'tacker_defs.yaml'
if 'imports' in template:
template['imports'].append(defsfile)
else:
template['imports'] = [defsfile]
if 'nfv' in template['tosca_definitions_version']:
nfvfile = path + 'tacker_nfv_defs.yaml'
template['imports'].append(nfvfile)
LOG.debug(_("%s") % path)
@log.log
def get_vdu_monitoring(template):
monitoring_dict = {'vdus': {}}
for nt in template.nodetemplates:
if nt.type_definition.is_derived_from(TACKERVDU):
mon_policy = nt.get_property_value('monitoring_policy') or 'noop'
# mon_data = {mon_policy['name']: {'actions': {'failure':
# 'respawn'}}}
if mon_policy != 'noop':
monitoring_dict['vdus'][nt.name] = mon_policy
return monitoring_dict
@log.log
def get_mgmt_ports(tosca):
mgmt_ports = {}
for nt in tosca.nodetemplates:
if nt.type_definition.is_derived_from(TACKERCP):
mgmt = nt.get_property_value('management') or None
if mgmt:
vdu = None
for rel, node in nt.relationships.items():
if rel.is_derived_from(TOSCA_BINDS_TO):
vdu = node.name
break
if vdu is not None:
name = 'mgmt_ip-%s' % vdu
mgmt_ports[name] = nt.name
LOG.debug('mgmt_ports: %s' % mgmt_ports)
return mgmt_ports
@log.log
def post_process_heat_template(heat_tpl, mgmt_ports):
heat_dict = yamlparser.simple_ordered_parse(heat_tpl)
for outputname, portname in mgmt_ports.items():
ipval = {'get_attr': [portname, 'fixed_ips', 0, 'ip_address']}
output = {outputname: {'value': ipval}}
if 'outputs' in heat_dict:
heat_dict['outputs'].update(output)
else:
heat_dict['outputs'] = output
LOG.debug(_('Added output for %s') % outputname)
return yaml.dump(heat_dict)
@log.log
def post_process_template(template):
for nt in template.nodetemplates:
if (nt.type_definition.is_derived_from(MONITORING) or
nt.type_definition.is_derived_from(FAILURE) or
nt.type_definition.is_derived_from(PLACEMENT)):
template.nodetemplates.remove(nt)
continue
if nt.type in delpropmap.keys():
for prop in delpropmap[nt.type]:
for p in nt.get_properties_objects():
if prop == p.name:
nt.get_properties_objects().remove(p)
if nt.type in convert_prop:
for prop in convert_prop[nt.type].keys():
for p in nt.get_properties_objects():
if prop == p.name:
schema_dict = {'type': p.type}
v = nt.get_property_value(p.name)
newprop = Property(convert_prop[nt.type][prop], v,
schema_dict)
nt.get_properties_objects().append(newprop)
nt.get_properties_objects().remove(p)
@log.log
def get_mgmt_driver(template):
mgmt_driver = None
for nt in template.nodetemplates:
if nt.type_definition.is_derived_from(TACKERVDU):
if (mgmt_driver and nt.get_property_value('mgmt_driver') !=
mgmt_driver):
raise vnfm.MultipleMGMTDriversSpecified()
else:
mgmt_driver = nt.get_property_value('mgmt_driver')
return mgmt_driver
def findvdus(template):
vdus = []
for nt in template.nodetemplates:
if nt.type_definition.is_derived_from(TACKERVDU):
vdus.append(nt)
return vdus