diff options
author | yunlong ying <ying.yunlong@zte.com.cn> | 2017-02-25 06:57:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@open-o.org> | 2017-02-25 06:57:08 +0000 |
commit | 32d809c293bdf1481023bf088a51fdb9f2b6e965 (patch) | |
tree | e28dc66b4d1ea6a3c30176ffddff3e239500a8e3 | |
parent | 5e83503bd6ac74691f712ee5ce8e3ccf7a3009ed (diff) | |
parent | 99aa63f1ddcc9d97e0e98b493b51df566c96663f (diff) |
Merge "Add code of delete resources"
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py | 79 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py | 40 |
2 files changed, 57 insertions, 62 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py index 1e458e18..9ec2a257 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py @@ -24,6 +24,7 @@ from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, Ne from lcm.pub.utils import restcall from lcm.pub.utils.jobutil import JobUtil from lcm.pub.utils.timeutil import now_time +from lcm.pub.vimapi import api class TestNFTerminate(TestCase): @@ -54,47 +55,48 @@ class TestNFTerminate(TestCase): descp=job_detail) self.assertEqual(1, len(jobs)) - # def test_delete_vnf_identifier(self): - # NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', - # netype='', vnfd_model='', status='VNF_INSTANTIATED', nf_desc='', vnfdid='', - # vnfSoftwareVersion='', vnfConfigurableProperties='todo', - # localizationLanguage='EN_US', create_time=now_time()) - # response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") - # self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) - # self.assertEqual(None, response.data) - # - # def test_delete_vnf_identifier_when_vnf_not_exist(self): - # response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") - # self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) - # self.assertEqual("VnfInst(1111) does not exist", response.data["error"]) - # - # def test_delete_vnf_identifier_when_status_check_failed(self): - # NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', - # netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='', vnfdid='', - # vnfSoftwareVersion='', vnfConfigurableProperties='todo', - # localizationLanguage='EN_US', create_time=now_time()) - # response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") - # self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) - # self.assertEqual("Don't allow to delete vnf(status:[NOT_INSTANTIATED])", response.data["error"]) - # - # @mock.patch.object(TermVnf, 'run') - # def test_terminate_vnf(self, mock_run): - # mock_run.re.return_value = None - # response = self.client.post("/openoapi/vnflcm/v1/vnf_instances/12/terminate", data={}, format='json') - # self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) - # - # def test_terminate_vnf_when_inst_id_not_exist(self): - # data = {"terminationType": "GRACEFUL", - # "gracefulTerminationTimeout": 120} - # self.nf_inst_id = str(uuid.uuid4()) - # self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) - # JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") - # TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() - # self.assert_job_result(self.job_id, 255, "VnfInst(%s) does not exist" % self.nf_inst_id) + def test_delete_vnf_identifier(self): + NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', + netype='', vnfd_model='', status='VNF_INSTANTIATED', nf_desc='', vnfdid='', + vnfSoftwareVersion='', vnfConfigurableProperties='todo', + localizationLanguage='EN_US', create_time=now_time()) + response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") + self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) + self.assertEqual(None, response.data) + + def test_delete_vnf_identifier_when_vnf_not_exist(self): + response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") + self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + self.assertEqual("VnfInst(1111) does not exist", response.data["error"]) + + def test_delete_vnf_identifier_when_status_check_failed(self): + NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', + netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='', vnfdid='', + vnfSoftwareVersion='', vnfConfigurableProperties='todo', + localizationLanguage='EN_US', create_time=now_time()) + response = self.client.delete("/openoapi/vnflcm/v1/vnf_instances/1111") + self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + self.assertEqual("Don't allow to delete vnf(status:[NOT_INSTANTIATED])", response.data["error"]) + + @mock.patch.object(TermVnf, 'run') + def test_terminate_vnf(self, mock_run): + mock_run.re.return_value = None + response = self.client.post("/openoapi/vnflcm/v1/vnf_instances/12/terminate", data={}, format='json') + self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) + + def test_terminate_vnf_when_inst_id_not_exist(self): + data = {"terminationType": "GRACEFUL", + "gracefulTerminationTimeout": 120} + self.nf_inst_id = str(uuid.uuid4()) + self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) + JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") + TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() + self.assert_job_result(self.job_id, 255, "VnfInst(%s) does not exist" % self.nf_inst_id) @mock.patch.object(restcall, 'call_req') - def test_terminate_vnf_success(self, mock_call_req): + @mock.patch.object(api, 'call') + def test_terminate_vnf_success(self, mock_call, mock_call_req): NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', netype='', vnfd_model='', status='VNF_INSTANTIATED', nf_desc='', vnfdid='', vnfSoftwareVersion='', vnfConfigurableProperties='todo', @@ -102,6 +104,7 @@ class TestNFTerminate(TestCase): t1_apply_grant_result = [0, json.JSONEncoder().encode( {"vim": {"vimid": 'vimid_1', "accessinfo": {"tenant": 'tenantname_1'}}}), '200'] mock_call_req.side_effect = [t1_apply_grant_result] + mock_call.return_value = None data = {"terminationType": "FORCEFUL", "gracefulTerminationTimeout": 120} self.nf_inst_id = '1111' diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py index e8dc3a69..9060ad39 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py @@ -49,7 +49,7 @@ class TermVnf(Thread): self.term_pre() self.grant_resource() self.query_inst_resource() - # self.delete_resource() + self.delete_resource() # self.lcm_notify() JobUtil.add_job_status(self.job_id, 100, "Terminate Vnf success.") except NFLCMException as e: @@ -169,36 +169,28 @@ class TermVnf(Thread): logger.info('[query_vm_resource]:ret_vms=%s' % self.inst_resource['vm']) def delete_resource(self): + logger.error('rollback resource begin') 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() - SubNetworkInstModel.objects.filter(instid=self.nf_inst_id).delete() - 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("Delete resource failed") - - def do_notify_delete(self, ret): - logger.error('Deleting [%s] resource' % ret) - pass + def do_notify_delete(self, res_type, res_id): + logger.error('Deleting [%s] resource:resourceid [%s]' % (res_type, res_id)) + if res_type == adaptor.RES_VM: + VmInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + elif res_type == adaptor.RES_FLAVOR: + FlavourInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + elif res_type == adaptor.RES_PORT: + PortInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + elif res_type == adaptor.RES_SUBNET: + SubNetworkInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + elif res_type == adaptor.RES_NETWORK: + NetworkInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + elif res_type == adaptor.RES_VOLUME: + StorageInstModel.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() def lcm_notify(self): pass - # def load_nfvo_config(self): - # logger.info("[NF instantiation]get nfvo connection info start") - # reg_info = NfvoRegInfoModel.objects.filter(vnfminstid='vnfm111').first() - # if reg_info: - # self.vnfm_inst_id = reg_info.vnfminstid - # self.nfvo_inst_id = reg_info.nfvoid - # logger.info("[NF instantiation] Registered nfvo id is [%s]" % self.nfvo_inst_id) - # else: - # raise NFLCMException("Nfvo was not registered") - # logger.info("[NF instantiation]get nfvo connection info end") - def vnf_term_failed_handle(self, error_msg): logger.error('VNF termination failed, detail message: %s' % error_msg) NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time()) |