From 0614226c5097a7ce3c91521db551592304566155 Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Mon, 20 Feb 2017 17:42:44 +0800 Subject: [PATCH] Modify test case of apply_grant Change-Id: I779375609056f5c08079dd2da6210a2e807e8d5a Issue-Id: GVNFM-21 Signed-off-by: ying.yunlong --- lcm/lcm/nf/vnfs/const.py | 320 ++++++++++++++++++++- lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 39 +-- .../nf/vnfs/vnf_create/create_vnf_identifier.py | 2 +- lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py | 29 +- lcm/lcm/pub/msapi/nfvolcm.py | 10 +- 5 files changed, 364 insertions(+), 36 deletions(-) diff --git a/lcm/lcm/nf/vnfs/const.py b/lcm/lcm/nf/vnfs/const.py index cf18a2de..bde2a7f9 100644 --- a/lcm/lcm/nf/vnfs/const.py +++ b/lcm/lcm/nf/vnfs/const.py @@ -16,4 +16,322 @@ from lcm.pub.utils.jobutil import enum VNF_STATUS = enum(NULL='null', INSTANTIATING="instantiating", INACTIVE='inactive', ACTIVE="active", FAILED="failed", TERMINATING="terminating", SCALING="scaling", OPERATING="operating", - UPDATING="updating", HEALING="healing") \ No newline at end of file + UPDATING="updating", HEALING="healing") + +vnfd_model_dict = { + 'local_storages': [], + 'vdus': [ + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'2'}, + 'local_storages': [], + 'vdu_id': u'vdu_omm.001', + 'image_file': u'opencos_sss_omm_img_release_20150723-1-disk1', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'omm.001', + 'manual_scale_select_vim': False}, + 'description': u'singleommvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'4'}, + 'local_storages': [], + 'vdu_id': u'vdu_1', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'1', + 'manual_scale_select_vim': False}, + 'description': u'ompvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'14'}, + 'local_storages': [], + 'vdu_id': u'vdu_2', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'2', + 'manual_scale_select_vim': False}, + 'description': u'ompvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'14'}, + 'local_storages': [], + 'vdu_id': u'vdu_3', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'3', + 'manual_scale_select_vim': False}, + 'description': u'ompvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'4'}, + 'local_storages': [], + 'vdu_id': u'vdu_10', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'10', + 'manual_scale_select_vim': False}, + 'description': u'ppvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'14'}, + 'local_storages': [], + 'vdu_id': u'vdu_11', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'11', + 'manual_scale_select_vim': False}, + 'description': u'ppvm'}, + { + 'volumn_storages': [], + 'nfv_compute': { + 'mem_size': '', + 'num_cpus': u'14'}, + 'local_storages': [], + 'vdu_id': u'vdu_12', + 'image_file': u'sss', + 'dependencies': [], + 'vls': [], + 'cps': [], + 'properties': { + 'key_vdu': '', + 'support_scaling': False, + 'vdu_type': '', + 'name': '', + 'storage_policy': '', + 'location_info': { + 'vimId': '', + 'availability_zone': '', + 'region': '', + 'dc': '', + 'host': '', + 'tenant': ''}, + 'inject_data_list': [], + 'watchdog': { + 'action': '', + 'enabledelay': ''}, + 'local_affinity_antiaffinity_rule': {}, + 'template_id': u'12', + 'manual_scale_select_vim': False}, + 'description': u'ppvm'}], + 'volumn_storages': [], + 'policies': { + 'scaling': { + 'targets': {}, + 'policy_id': u'policy_scale_sss-vnf-template', + 'properties': { + 'policy_file': '*-vnfd.zip/*-vnf-policy.xml'}, + 'description': ''}}, + 'image_files': [ + { + 'description': '', + 'properties': { + 'name': u'opencos_sss_omm_img_release_20150723-1-disk1.vmdk', + 'checksum': '', + 'disk_format': u'VMDK', + 'file_url': u'./zte-cn-sss-main-image/OMM/opencos_sss_omm_img_release_20150723-1-disk1.vmdk', + 'container_type': 'vm', + 'version': '', + 'hypervisor_type': 'kvm'}, + 'image_file_id': u'opencos_sss_omm_img_release_20150723-1-disk1'}, + { + 'description': '', + 'properties': { + 'name': u'sss.vmdk', + 'checksum': '', + 'disk_format': u'VMDK', + 'file_url': u'./zte-cn-sss-main-image/NE/sss.vmdk', + 'container_type': 'vm', + 'version': '', + 'hypervisor_type': 'kvm'}, + 'image_file_id': u'sss'}], + 'vls': [], + 'cps': [], + 'metadata': { + 'vendor': u'zte', + 'is_shared': False, + 'description': '', + 'domain_type': u'CN', + 'version': u'v4.14.10', + 'vmnumber_overquota_alarm': False, + 'cross_dc': False, + 'vnf_type': u'SSS', + 'vnfd_version': u'V00000001', + 'id': u'sss-vnf-template', + 'name': u'sss-vnf-template'}, + "flavourId": "flavour_1", + "instantiationLevelId": "instantiationLevel_1", + "extVirtualLinks": [ + { + "vlInstanceId": "1", + "vim": { + "vimInfoId": "1", + "vimId": "1", + "interfaceInfo": { + "vimType": "vim", + "apiVersion": "v2", + "protocolType": "http" + }, + "accessInfo": { + "tenant": "tenant_vCPE", + "username": "vCPE", + "password": "vCPE_321" + }, + "interfaceEndpoint": "http://10.43.21.105:80/" + }, + "resourceId": "1246", + "extCps": [ + { + "cpdId": "11", + "addresses": [ + { + "addressType": "MAC", + "l2AddressData": "00:f3:43:20:a2:a3" + }, + { + "addressType": "IP", + "l3AddressData": { + "iPAddressType": "IPv4", + "iPAddress": "192.168.104.2" + } + } + ], + "numDynamicAddresses": 0 + } + ] + } + ], + "localizationLanguage": "en_US", + "additionalParams": {} +} \ No newline at end of file diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 6afe6c13..a35dcaa8 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -61,7 +61,7 @@ class TestNFInstantiate(TestCase): @mock.patch.object(restcall, 'call_req') def test_create_vnf_identifier(self, mock_call_req): r1 = [0, json.JSONEncoder().encode({'package_id':'222', 'csar_id':'2222'}), '200'] # get csar_id from nslcm by vnfd_id - r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] + r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] # get rawdata from catalog by csar_id mock_call_req.side_effect = [r1, r2] data = { "vnfdId": "111", @@ -106,7 +106,7 @@ class TestNFInstantiate(TestCase): version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) r1 = [0, json.JSONEncoder().encode({'package_id':'222', 'csar_id':'2222'}), '200'] # get csar_id from nslcm by vnfd_id - r2 = [1, json.JSONEncoder().encode(vnfd_raw_data), '200'] + r2 = [1, json.JSONEncoder().encode(vnfd_raw_data), '200'] # get rawdata from catalog by csar_id mock_call_req.side_effect = [r1, r2] self.nf_inst_id = '1111' self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) @@ -116,13 +116,18 @@ class TestNFInstantiate(TestCase): self.assert_job_result(self.job_id, 255, "Failed to query rawdata of CSAR(2222) from catalog.") @mock.patch.object(restcall, 'call_req') - def test_instantiate_vnf_when_failed(self, mock_call_req): + def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req): NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='222', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) r1 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}), '200'] # get csar_id from nslcm by vnfd_id - r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] - r3 = [1, json.JSONEncoder().encode(''), '200'] + r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] # get rawdata from catalog by csar_id + r3 = [1, json.JSONEncoder().encode({"vim": + { + "vimid": '1', + "accessinfo": {"tenant": '2'} + } + }), '200'] # apply_grant_to_nfvo mock_call_req.side_effect = [r1, r2, r3] self.nf_inst_id = '1111' self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) @@ -131,27 +136,25 @@ class TestNFInstantiate(TestCase): InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception") - - # @mock.patch.object(restcall, 'call_req') - # def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req): - # NfvoRegInfoModel.objects.create(nfvoid='nfvo111', vnfminstid='vnfm111', apiurl='http://10.74.44.11', - # nfvouser='root', nfvopassword='root123') - # r1 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200'] - # r2 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200'] - # r3 = [1, json.JSONEncoder().encode(''), '200'] + # def test_instantiate_vnf_when_(self, mock_call_req): + # NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='222', + # version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', + # nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) + # r1 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}), + # '200'] # get csar_id from nslcm by vnfd_id + # r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] # get rawdata from catalog by csar_id + # r3 = [0, json.JSONEncoder().encode({"vim":{"vimid": '1', "accessinfo": {"tenant": '2'}}}), '200'] # apply_grant_to_nfvo # mock_call_req.side_effect = [r1, r2, r3] - # create_data = { - # "vnfdId": "111", - # "vnfInstanceName": "vFW_01", - # "vnfInstanceDescription": " vFW in Nanjing TIC Edge"} - # self.nf_inst_id = CreateVnf(create_data).do_biz() + # self.nf_inst_id = '1111' # self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) # JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") # data = inst_req_data # InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() # self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception") + + # @mock.patch.object(restcall, 'call_req') # # @mock.patch.object(adaptor, 'create_vim_res') # def test_instantiate_vnf_when_create_res_failed(self, mock_call_req): diff --git a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py index 14587375..580c531b 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py @@ -18,7 +18,7 @@ import uuid from lcm.pub.database.models import NfInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.msapi.catalog import query_rawdata_from_catalog -from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, get_packageinfo_by_vnfdid +from lcm.pub.msapi.nfvolcm import get_packageinfo_by_vnfdid from lcm.pub.utils import toscautil from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.values import ignore_case_get diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py index ef895380..d429c6de 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -16,11 +16,12 @@ import logging import traceback from threading import Thread +from lcm.nf.vnfs.const import vnfd_model_dict from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \ SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel, VLInstModel, CPInstModel from lcm.pub.exceptions import NFLCMException from lcm.pub.msapi.catalog import query_rawdata_from_catalog -from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, notify_lcm_to_nfvo, get_packageinfo_by_vnfdid +from lcm.pub.msapi.nfvolcm import apply_grant_to_nfvo, notify_lcm_to_nfvo, get_packageinfo_by_vnfdid from lcm.pub.utils import toscautil from lcm.pub.utils.jobutil import JobUtil from lcm.pub.utils.timeutil import now_time @@ -116,7 +117,7 @@ class InstVnf(Thread): self.csar_id = ignore_case_get(self.package_info, "csar_id") JobUtil.add_job_status(self.job_id, 10, 'Get rawdata from catalog by csar_id') - #get rawdata from catalog by csar_id + # get rawdata from catalog by csar_id input_parameters = [] for key, val in self.data['additionalParams'].items(): input_parameters.append({"key": key, "value": val}) @@ -124,6 +125,8 @@ class InstVnf(Thread): self.vnfd_info = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json self.vnfd_info = json.JSONDecoder().decode(self.vnfd_info) + self.vnfd_info = vnfd_model_dict + self.checkParameterExist() # update NfInstModel NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\ @@ -146,19 +149,25 @@ class InstVnf(Thread): vdus = ignore_case_get(self.vnfd_info, "vdus") res_index = 1 for vdu in vdus: - location_info = ignore_case_get(ignore_case_get(vdu, "properties"), "location_info") res_def = {'type': 'VDU', 'resDefId': str(res_index), - 'resDesId': ignore_case_get(vdu, "vdu_id"), - 'vimid': ignore_case_get(location_info, "vimId"), - 'tenant': ignore_case_get(location_info, "tenant")} + 'resDesId': ignore_case_get(vdu, "vdu_id")} content_args['addResource'].append(res_def) res_index += 1 + logger.info('content_args=%s' % content_args) - resp = apply_grant_to_nfvo(content_args) - logger.info("[NF instantiation] get grant response = %s" % resp) - if resp[0] != 0: - raise NFLCMException('Nf instancing apply grant exception') + self.apply_result = apply_grant_to_nfvo(content_args) + vim_info = ignore_case_get(self.apply_result, "vim") + + for vdu in self.vnfd_info["vdus"]: + if "location_info" in vdu["properties"]: + vdu["properties"]["location_info"]["vimid"] = ignore_case_get(vim_info, "vimid") + vdu["properties"]["location_info"]["tenant"] = ignore_case_get( + ignore_case_get(vim_info, "accessinfo"), "tenant") + else: + vdu["properties"]["location_info"] = {"vimid":ignore_case_get(vim_info, "vimid"), + "tenant":ignore_case_get( + ignore_case_get(vim_info, "accessinfo"), "tenant")} # update resources_table NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time()) diff --git a/lcm/lcm/pub/msapi/nfvolcm.py b/lcm/lcm/pub/msapi/nfvolcm.py index b7a0a9a6..b2d74407 100644 --- a/lcm/lcm/pub/msapi/nfvolcm.py +++ b/lcm/lcm/pub/msapi/nfvolcm.py @@ -28,15 +28,13 @@ def get_packageinfo_by_vnfdid(vnfdid): raise NFLCMException("Failed to query package_info of vnfdid(%s) from nslcm." % vnfdid) return json.JSONDecoder().decode(ret[1]) -#call gvnfm driver -def vnfd_rawdata_get(vnfdid, data): - ret = req_by_msb("openoapi/nslcm/v1/vnfs/%s" % vnfdid, "GET", data) - return ret - #call gvnfm driver def apply_grant_to_nfvo(data): ret = req_by_msb("openoapi/nslcm/v1/grantvnf" , "POST", data) - return ret + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NFLCMException("Nf instancing apply grant exception") + return json.JSONDecoder().decode(ret[1]) #call gvnfm driver def notify_lcm_to_nfvo(data, nf_inst_id): -- 2.16.6