Improve code coverage of plugin module

Added new unit tests to cover create_vnfd method.

Change-Id: Ia202b4abb698660cd9b8d66d28e8baff069e555a
This commit is contained in:
shubham potale 2019-01-23 14:02:29 +00:00
parent e88a482576
commit ba86db640c
3 changed files with 74 additions and 0 deletions

View File

@ -30,6 +30,7 @@ def _get_template(name):
return f.read()
tosca_vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
tosca_invalid_vnfd = _get_template('test_tosca_parser_failure.yaml')
config_data = _get_template('config_data.yaml')
update_config_data = _get_template('update_config_data.yaml')
vnffg_params = _get_template('vnffg_params.yaml')
@ -77,6 +78,18 @@ def get_dummy_vnfd_obj():
u'username': u'admin', u'password': u'devstack'}}}}
def get_invalid_vnfd_obj():
return {u'vnfd': {u'service_types': [{u'service_type': u'vnfd'}],
'name': 'dummy_vnfd',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
u'attributes': {u'vnfd': yaml.safe_load(
tosca_invalid_vnfd)},
'description': 'dummy_vnfd_description',
'template_source': 'onboarded',
u'auth': {u'tenantName': u'admin', u'passwordCredentials': {
u'username': u'admin', u'password': u'devstack'}}}}
def get_dummy_vnfd_obj_inline():
return {u'vnfd': {u'service_types': [{u'service_type': u'vnfd'}],
'name': 'tmpl-koeak4tqgoqo8cr4-dummy_inline_vnf',

View File

@ -0,0 +1,27 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: OpenWRT with services
metadata:
template_name: OpenWRT
topology_template:
node_templates:
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
anti_spoofing_protection: false
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: existing_network_1
vendor: Tacker

View File

@ -320,6 +320,40 @@ class TestVNFMPlugin(db_base.SqlTestCase):
res_state=constants.RES_EVT_ONBOARDED,
res_type=constants.RES_TYPE_VNFD, tstamp=mock.ANY)
def test_create_vnfd_without_tosca_definitions_version(self):
vnfd_obj = utils.get_dummy_vnfd_obj()
vnfd_obj['vnfd']['attributes']['vnfd'].pop('tosca_definitions_version')
self.assertRaises(exceptions.Invalid,
self.vnfm_plugin.create_vnfd,
self.context, vnfd_obj)
def test_create_vnfd_with_empty_description(self):
vnfd_obj = utils.get_dummy_vnfd_obj()
vnfd_obj['vnfd']['description'] = ''
result = self.vnfm_plugin.create_vnfd(self.context, vnfd_obj)
self.assertIsNotNone(result)
# If vnfd description is an empty string, it sets the description of
# vnfd to the description that is present in the vnfd tosca template.
self.assertEqual(yaml.safe_load(
vnfd_obj['vnfd']['attributes']['vnfd'])['description'],
result['description'])
def test_create_vnfd_empty_name(self):
vnfd_obj = utils.get_dummy_vnfd_obj()
vnfd_obj['vnfd']['name'] = ''
result = self.vnfm_plugin.create_vnfd(self.context, vnfd_obj)
self.assertIsNotNone(result)
# If vnfd name is an empty string, it sets the name of vnfd to
# the name that is present in the vnfd tosca template.
self.assertEqual(yaml.safe_load(vnfd_obj['vnfd']['attributes']
['vnfd'])['metadata']['template_name'], result['name'])
def test_create_vnfd_with_tosca_parser_failure(self):
vnfd_obj = utils.get_invalid_vnfd_obj()
self.assertRaises(vnfm.ToscaParserFailed,
self.vnfm_plugin.create_vnfd,
self.context, vnfd_obj)
def test_create_vnfd_no_service_types(self):
vnfd_obj = utils.get_dummy_vnfd_obj()
vnfd_obj['vnfd'].pop('service_types')