Correct number_of_endpoints number in vnffgd samples.
Add a function to validate vnffg property number_of_endpoints Add some UT testcases for this function. Change-Id: I5180c551f5d6571491c80a9f4bbcb3c74c3c5572
This commit is contained in:
parent
f01d81e047
commit
9bbad6dc26
|
@ -45,7 +45,7 @@ topology_template:
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 2
|
||||||
dependent_virtual_link: [VL12,VL22]
|
dependent_virtual_link: [VL12,VL22]
|
||||||
connection_point: [CP12,CP22]
|
connection_point: [CP12,CP22]
|
||||||
constituent_vnfs: [VNFD1,VNFD2]
|
constituent_vnfs: [VNFD1,VNFD2]
|
||||||
|
|
|
@ -32,7 +32,7 @@ topology_template:
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 2
|
||||||
dependent_virtual_link: [VL12,VL22]
|
dependent_virtual_link: [VL12,VL22]
|
||||||
connection_point: [CP12,CP22]
|
connection_point: [CP12,CP22]
|
||||||
constituent_vnfs: [VNFD1,VNFD2]
|
constituent_vnfs: [VNFD1,VNFD2]
|
||||||
|
|
|
@ -344,7 +344,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
|
||||||
template_db.template['vnffgd']['topology_template'] = \
|
template_db.template['vnffgd']['topology_template'] = \
|
||||||
vnffgd_topology_template
|
vnffgd_topology_template
|
||||||
|
|
||||||
vnf_members = self._get_vnffg_property(template_db,
|
vnf_members = self._get_vnffg_property(template_db.template,
|
||||||
'constituent_vnfs')
|
'constituent_vnfs')
|
||||||
LOG.debug(_('Constituent VNFs: %s'), vnf_members)
|
LOG.debug(_('Constituent VNFs: %s'), vnf_members)
|
||||||
vnf_mapping = self._get_vnf_mapping(context, vnffg.get(
|
vnf_mapping = self._get_vnf_mapping(context, vnffg.get(
|
||||||
|
@ -479,8 +479,8 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
|
||||||
return chain_list
|
return chain_list
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_vnffg_property(template_db, vnffg_property):
|
def _get_vnffg_property(template, vnffg_property):
|
||||||
template = template_db.template['vnffgd']['topology_template']
|
template = template['vnffgd']['topology_template']
|
||||||
vnffg_name = list(template['groups'].keys())[0]
|
vnffg_name = list(template['groups'].keys())[0]
|
||||||
try:
|
try:
|
||||||
return template['groups'][vnffg_name]['properties'][vnffg_property]
|
return template['groups'][vnffg_name]['properties'][vnffg_property]
|
||||||
|
|
|
@ -117,6 +117,11 @@ class VnffgdCpNoForwardingException(exceptions.TackerException):
|
||||||
"included in forwarding path")
|
"included in forwarding path")
|
||||||
|
|
||||||
|
|
||||||
|
class VnffgdWrongEndpointNumber(exceptions.TackerException):
|
||||||
|
message = _("Specified number_of_endpoints %(number)s is not equal to "
|
||||||
|
"the number of connection_point %(cps)s")
|
||||||
|
|
||||||
|
|
||||||
class VnffgdInUse(exceptions.InUse):
|
class VnffgdInUse(exceptions.InUse):
|
||||||
message = _('VNFFGD %(vnffgd_id)s is still in use')
|
message = _('VNFFGD %(vnffgd_id)s is still in use')
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,46 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
||||||
LOG.exception(_("tosca-parser error: %s"), str(e))
|
LOG.exception(_("tosca-parser error: %s"), str(e))
|
||||||
raise nfvo.ToscaParserFailed(error_msg_details=str(e))
|
raise nfvo.ToscaParserFailed(error_msg_details=str(e))
|
||||||
|
|
||||||
|
@log.log
|
||||||
|
def validate_vnffgd_path(self, template):
|
||||||
|
temp = template['vnffgd']['topology_template']
|
||||||
|
vnffg_name = list(temp['groups'].keys())[0]
|
||||||
|
nfp_name = temp['groups'][vnffg_name]['members'][0]
|
||||||
|
path = self._get_nfp_attribute(template, nfp_name,
|
||||||
|
'path')
|
||||||
|
|
||||||
|
prev_element = None
|
||||||
|
known_forwarders = set()
|
||||||
|
for element in path:
|
||||||
|
if element.get('forwarder') in known_forwarders:
|
||||||
|
if prev_element is not None and element.get('forwarder')\
|
||||||
|
!= prev_element['forwarder']:
|
||||||
|
raise nfvo.VnffgdDuplicateForwarderException(
|
||||||
|
forwarder=element.get('forwarder')
|
||||||
|
)
|
||||||
|
elif prev_element is not None and element.get(
|
||||||
|
'capability') == prev_element['capability']:
|
||||||
|
raise nfvo.VnffgdDuplicateCPException(
|
||||||
|
cp=element.get('capability')
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
known_forwarders.add(element.get('forwarder'))
|
||||||
|
prev_element = element
|
||||||
|
|
||||||
|
@log.log
|
||||||
|
def validate_vnffg_properties(self, template):
|
||||||
|
|
||||||
|
# check whether number_of_endpoints is same with connection_point
|
||||||
|
connection_point = self._get_vnffg_property(
|
||||||
|
template, 'connection_point')
|
||||||
|
number_endpoint = self._get_vnffg_property(
|
||||||
|
template, 'number_of_endpoints')
|
||||||
|
|
||||||
|
if len(connection_point) != number_endpoint:
|
||||||
|
raise nfvo.VnffgdWrongEndpointNumber(
|
||||||
|
number=number_endpoint,
|
||||||
|
cps=connection_point)
|
||||||
|
|
||||||
@log.log
|
@log.log
|
||||||
def create_vnffgd(self, context, vnffgd):
|
def create_vnffgd(self, context, vnffgd):
|
||||||
template = vnffgd['vnffgd']
|
template = vnffgd['vnffgd']
|
||||||
|
@ -219,28 +259,11 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
||||||
raise nfvo.VnffgdInvalidTemplate(template=template.get('template'))
|
raise nfvo.VnffgdInvalidTemplate(template=template.get('template'))
|
||||||
else:
|
else:
|
||||||
self.validate_tosca(template['template']['vnffgd'])
|
self.validate_tosca(template['template']['vnffgd'])
|
||||||
temp = template['template']['vnffgd']['topology_template']
|
|
||||||
vnffg_name = list(temp['groups'].keys())[0]
|
self.validate_vnffgd_path(template['template'])
|
||||||
nfp_name = temp['groups'][vnffg_name]['members'][0]
|
|
||||||
path = self._get_nfp_attribute(template['template'], nfp_name,
|
self.validate_vnffg_properties(template['template'])
|
||||||
'path')
|
|
||||||
prev_element = None
|
|
||||||
known_forwarders = set()
|
|
||||||
for element in path:
|
|
||||||
if element.get('forwarder') in known_forwarders:
|
|
||||||
if prev_element is not None and element.get('forwarder')\
|
|
||||||
!= prev_element['forwarder']:
|
|
||||||
raise nfvo.VnffgdDuplicateForwarderException(
|
|
||||||
forwarder=element.get('forwarder')
|
|
||||||
)
|
|
||||||
elif prev_element is not None and element.get(
|
|
||||||
'capability') == prev_element['capability']:
|
|
||||||
raise nfvo.VnffgdDuplicateCPException(
|
|
||||||
cp=element.get('capability')
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
known_forwarders.add(element.get('forwarder'))
|
|
||||||
prev_element = element
|
|
||||||
return super(NfvoPlugin, self).create_vnffgd(context, vnffgd)
|
return super(NfvoPlugin, self).create_vnffgd(context, vnffgd)
|
||||||
|
|
||||||
@log.log
|
@log.log
|
||||||
|
@ -295,7 +318,7 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
||||||
nfp['classifier_id'])
|
nfp['classifier_id'])
|
||||||
template_db = self._get_resource(context, vnffg_db.VnffgTemplate,
|
template_db = self._get_resource(context, vnffg_db.VnffgTemplate,
|
||||||
vnffg_dict['vnffgd_id'])
|
vnffg_dict['vnffgd_id'])
|
||||||
vnf_members = self._get_vnffg_property(template_db,
|
vnf_members = self._get_vnffg_property(template_db.template,
|
||||||
'constituent_vnfs')
|
'constituent_vnfs')
|
||||||
new_vnffg['vnf_mapping'] = super(NfvoPlugin, self)._get_vnf_mapping(
|
new_vnffg['vnf_mapping'] = super(NfvoPlugin, self)._get_vnf_mapping(
|
||||||
context, new_vnffg.get('vnf_mapping'), vnf_members)
|
context, new_vnffg.get('vnf_mapping'), vnf_members)
|
||||||
|
|
|
@ -50,6 +50,8 @@ vnfd_alarm_respawn_tosca_template = _get_template(
|
||||||
vnfd_alarm_scale_tosca_template = _get_template(
|
vnfd_alarm_scale_tosca_template = _get_template(
|
||||||
'test_tosca_vnfd_alarm_scale.yaml')
|
'test_tosca_vnfd_alarm_scale.yaml')
|
||||||
nsd_tosca_template = yaml.safe_load(_get_template('tosca_nsd_template.yaml'))
|
nsd_tosca_template = yaml.safe_load(_get_template('tosca_nsd_template.yaml'))
|
||||||
|
vnffgd_wrong_cp_number_template = yaml.safe_load(_get_template(
|
||||||
|
'tosca_vnffgd_wrong_cp_number_template.yaml'))
|
||||||
|
|
||||||
|
|
||||||
def get_dummy_vnfd_obj():
|
def get_dummy_vnfd_obj():
|
||||||
|
|
|
@ -448,6 +448,16 @@ class TestNfvoPlugin(db_base.SqlTestCase):
|
||||||
self.nfvo_plugin.validate_tosca,
|
self.nfvo_plugin.validate_tosca,
|
||||||
template)
|
template)
|
||||||
|
|
||||||
|
def test_validate_vnffg_properties(self):
|
||||||
|
template = {'vnffgd': utils.vnffgd_tosca_template}
|
||||||
|
self.nfvo_plugin.validate_vnffg_properties(template)
|
||||||
|
|
||||||
|
def test_validate_vnffg_properties_wrong_number(self):
|
||||||
|
template = {'vnffgd': utils.vnffgd_wrong_cp_number_template}
|
||||||
|
self.assertRaises(nfvo.VnffgdWrongEndpointNumber,
|
||||||
|
self.nfvo_plugin.validate_vnffg_properties,
|
||||||
|
template)
|
||||||
|
|
||||||
def test_create_vnffgd(self):
|
def test_create_vnffgd(self):
|
||||||
vnffgd_obj = utils.get_dummy_vnffgd_obj()
|
vnffgd_obj = utils.get_dummy_vnffgd_obj()
|
||||||
result = self.nfvo_plugin.create_vnffgd(self.context, vnffgd_obj)
|
result = self.nfvo_plugin.create_vnffgd(self.context, vnffgd_obj)
|
||||||
|
|
|
@ -34,7 +34,7 @@ topology_template:
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 3
|
||||||
dependent_virtual_link: [VL1,VL2,VL3]
|
dependent_virtual_link: [VL1,VL2,VL3]
|
||||||
connection_point: [CP11,CP12,CP32]
|
connection_point: [CP11,CP12,CP32]
|
||||||
constituent_vnfs: [VNF1,VNF3]
|
constituent_vnfs: [VNF1,VNF3]
|
||||||
|
|
|
@ -39,7 +39,7 @@ topology_template:
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 3
|
||||||
dependent_virtual_link: [VL1,VL2,VL3]
|
dependent_virtual_link: [VL1,VL2,VL3]
|
||||||
connection_point: [CP11,CP12,CP32]
|
connection_point: [CP11,CP12,CP32]
|
||||||
constituent_vnfs: [VNF1,VNF3]
|
constituent_vnfs: [VNF1,VNF3]
|
||||||
|
|
|
@ -34,7 +34,7 @@ topology_template:
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 3
|
||||||
dependent_virtual_link: [VL1,VL2,VL3]
|
dependent_virtual_link: [VL1,VL2,VL3]
|
||||||
connection_point: [CP11,CP12,CP32]
|
connection_point: [CP11,CP12,CP32]
|
||||||
constituent_vnfs: [VNF1,VNF3]
|
constituent_vnfs: [VNF1,VNF3]
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||||
|
|
||||||
|
description: example template
|
||||||
|
|
||||||
|
topology_template:
|
||||||
|
description: Example VNFFG template
|
||||||
|
|
||||||
|
node_templates:
|
||||||
|
|
||||||
|
Forwarding_path1:
|
||||||
|
type: tosca.nodes.nfv.FP.Tacker
|
||||||
|
description: creates path (CP11->CP12->CP32)
|
||||||
|
properties:
|
||||||
|
id: 51
|
||||||
|
policy:
|
||||||
|
type: ACL
|
||||||
|
criteria:
|
||||||
|
- blah: tenant1_net
|
||||||
|
- destination_port_range: 80-1024
|
||||||
|
- ip_proto: 6
|
||||||
|
- ip_dst_prefix: 192.168.1.2/24
|
||||||
|
path:
|
||||||
|
- forwarder: VNF1
|
||||||
|
capability: CP11
|
||||||
|
- forwarder: VNF1
|
||||||
|
capability: CP12
|
||||||
|
- forwarder: VNF3
|
||||||
|
capability: CP32
|
||||||
|
|
||||||
|
groups:
|
||||||
|
VNFFG1:
|
||||||
|
type: tosca.groups.nfv.VNFFG
|
||||||
|
description: HTTP to Corporate Net
|
||||||
|
properties:
|
||||||
|
vendor: tacker
|
||||||
|
version: 1.0
|
||||||
|
number_of_endpoints: 4
|
||||||
|
dependent_virtual_link: [VL1,VL2,VL3]
|
||||||
|
connection_point: [CP11,CP12,CP32]
|
||||||
|
constituent_vnfs: [VNF1,VNF3]
|
||||||
|
members: [Forwarding_path1]
|
|
@ -25,7 +25,7 @@
|
||||||
properties:
|
properties:
|
||||||
vendor: tacker
|
vendor: tacker
|
||||||
version: 1.0
|
version: 1.0
|
||||||
number_of_endpoints: 5
|
number_of_endpoints: 3
|
||||||
dependent_virtual_link: [VL1,VL2,VL3]
|
dependent_virtual_link: [VL1,VL2,VL3]
|
||||||
connection_point: [CP11,CP12,CP32]
|
connection_point: [CP11,CP12,CP32]
|
||||||
constituent_vnfs: [VNF1,VNF3]
|
constituent_vnfs: [VNF1,VNF3]
|
||||||
|
|
Loading…
Reference in New Issue