From ddbced3e29882aed620a2729a6c43e533cfb7a4c Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Tue, 14 Feb 2017 09:21:41 +0800 Subject: update vnf instantiation test case Change-Id: I148528e165050c03598f0d57ff999e6cae2c30d0 Issue-Id: GVNFM-8 Signed-off-by: ying.yunlong --- lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 6 +++++- lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 9a1d3ef6..64f07d36 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -90,7 +90,10 @@ class TestNsInstantiate(TestCase): name='aaa_pnet_cp', tenant='admin', insttype=0, instid='1') def tearDown(self): - pass + VmInstModel.objects.all().delete() + NetworkInstModel.objects.all().delete() + SubNetworkInstModel.objects.all().delete() + PortInstModel.objects.all().delete() def assert_job_result(self, job_id, job_progress, job_detail): jobs = JobStatusModel.objects.filter( @@ -118,6 +121,7 @@ class TestNsInstantiate(TestCase): @mock.patch.object(InstVnf, 'run') def test_instantiate_vnf(self, mock_run): + mock_run.re.return_value = None response = self.client.post("/gvnfmapi/lcm/v1/vnf_instances/12/instantiate", data={}, format='json') self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py index f5c88eef..af5b51cc 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -288,7 +288,7 @@ class InstVnf(Thread): if res_type == adaptor.RES_VOLUME: logger.info('Create vloumns!') if ret["returnCode"] == adaptor.RES_NEW:#new create - self.inst_resource['volumn'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['volumn'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) JobUtil.add_job_status(self.job_id, progress, 'Create vloumns!') StorageInstModel.objects.create( storageid='1', @@ -301,7 +301,7 @@ class InstVnf(Thread): elif res_type == adaptor.RES_NETWORK: logger.info('Create networks!') if ret["returnCode"] == adaptor.RES_NEW: - self.inst_resource['network'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['network'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) # self.inst_resource['network'].append({"vim_id": "1"}, {"res_id": "2"}) JobUtil.add_job_status(self.job_id, progress, 'Create networks!') NetworkInstModel.objects.create( @@ -315,7 +315,7 @@ class InstVnf(Thread): elif res_type == adaptor.RES_SUBNET: logger.info('Create subnets!') if ret["returnCode"] == adaptor.RES_NEW: - self.inst_resource['subnet'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['subnet'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) # self.inst_resource['subnet'].append({"vim_id": "1"}, {"res_id": "2"}) JobUtil.add_job_status(self.job_id, progress, 'Create subnets!') SubNetworkInstModel.objects.create( @@ -330,7 +330,7 @@ class InstVnf(Thread): elif res_type == adaptor.RES_PORT: logger.info('Create ports!') if ret["returnCode"] == adaptor.RES_NEW: - self.inst_resource['port'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['port'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) # self.inst_resource['port'].append({"vim_id": "1"}, {"res_id": "2"}) JobUtil.add_job_status(self.job_id, progress, 'Create ports!') PortInstModel.objects.create( @@ -346,7 +346,7 @@ class InstVnf(Thread): elif res_type == adaptor.RES_FLAVOR: logger.info('Create flavors!') if ret["returnCode"] == adaptor.RES_NEW: - self.inst_resource['flavor'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['flavor'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) # self.inst_resource['flavor'].append({"vim_id": "1"}, {"res_id": "2"}) JobUtil.add_job_status(self.job_id, progress, 'Create flavors!') FlavourInstModel.objects.create( @@ -358,7 +358,7 @@ class InstVnf(Thread): elif res_type == adaptor.RES_VM: logger.info('Create vms!') if ret["returnCode"] == adaptor.RES_NEW: - self.inst_resource['vm'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]}) + self.inst_resource['vm'].append({"vim_id": ignore_case_get(ret, "vim_id")}, {"res_id": ignore_case_get(ret, "res_id")}) # self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"}) JobUtil.add_job_status(self.job_id, progress, 'Create vms!') VmInstModel.objects.create( @@ -372,8 +372,8 @@ class InstVnf(Thread): def do_rollback(self, args_=None): logger.error('error info : %s'%(args_)) - adaptor.delete_vim_res(self.inst_resource, self.do_notify_delete) + logger.error('rollback resource complete') StorageInstModel.objects.filter(instid=self.nf_inst_id).delete() NetworkInstModel.objects.filter(instid=self.nf_inst_id).delete() @@ -381,10 +381,10 @@ class InstVnf(Thread): PortInstModel.objects.filter(instid=self.nf_inst_id).delete() FlavourInstModel.objects.filter(instid=self.nf_inst_id).delete() VmInstModel.objects.filter(instid=self.nf_inst_id).delete() - + logger.error('delete table complete') raise NFLCMException("Create resource failed") def do_notify_delete(ret): - logger.error('Delete [%s] resource'%ret) + logger.error('Deleting [%s] resource'%ret) -- cgit 1.2.3-korg