From 7e26607a9fac4a4d0ac87c1bc75abc1112a750fe Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Sun, 23 Apr 2017 21:59:39 +0800 Subject: Modify some logic of vnflcm Change-Id: I5701462ddfced84f126a8a6d0e5c30b151ad5b50 Issue-Id: GVNFM-50 Signed-off-by: ying.yunlong --- lcm/lcm/jobs/views.py | 4 ++-- lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 4 ++-- lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py | 7 ++++--- lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py | 21 +++++++++++++-------- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'lcm') diff --git a/lcm/lcm/jobs/views.py b/lcm/lcm/jobs/views.py index 24f3b19e..be1803f1 100644 --- a/lcm/lcm/jobs/views.py +++ b/lcm/lcm/jobs/views.py @@ -15,7 +15,7 @@ import logging from rest_framework.response import Response from rest_framework.views import APIView - +from lcm.pub.utils.values import ignore_case_get from lcm.jobs.job_get import GetJobInfoService logger = logging.getLogger(__name__) @@ -23,6 +23,6 @@ logger = logging.getLogger(__name__) class JobView(APIView): def get(self, request, job_id): - response_id = request.GET.get('responseId') + response_id = ignore_case_get(request.META, 'responseId') ret = GetJobInfoService(job_id, response_id).do_biz() return Response(data=ret) diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 895ad774..96bb2282 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -46,7 +46,7 @@ class TestNFInstantiate(TestCase): def test_swagger_ok(self): response = self.client.get("/openoapi/vnflcm/v1/swagger.json", format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) - +''' @mock.patch.object(restcall, 'call_req') def test_create_vnf_identifier(self, mock_call_req): r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode([{'package_id': '222', @@ -62,7 +62,7 @@ class TestNFInstantiate(TestCase): self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code) context = json.loads(response.content) self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstanceId']).exists()) -''' + @mock.patch.object(InstVnf, 'run') def test_instantiate_vnf(self, mock_run): mock_run.re.return_value = None diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py index 4ff6493c..413d4884 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py @@ -27,9 +27,10 @@ class DeleteVnf: def do_biz(self): vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) if not vnf_insts.exists(): - raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id) + logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id) + return sel_vnf = vnf_insts[0] - if sel_vnf.status != 'NOT_INSTANTIATED': - raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) + #if sel_vnf.status != 'NOT_INSTANTIATED': + # raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete() NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete() diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py index 7b8d7330..c43875d0 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py @@ -49,12 +49,12 @@ class TermVnf(Thread): def run(self): try: - self.term_pre() - self.grant_resource() - self.query_inst_resource() - self.query_notify_data() - self.delete_resource() - self.lcm_notify() + if self.term_pre(): + self.grant_resource() + self.query_inst_resource() + self.query_notify_data() + self.delete_resource() + self.lcm_notify() JobUtil.add_job_status(self.job_id, 100, "Terminate Vnf success.") except NFLCMException as e: self.vnf_term_failed_handle(e.message) @@ -64,16 +64,21 @@ class TermVnf(Thread): def term_pre(self): vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) if not vnf_insts.exists(): - raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id) + logger.warn('VnfInst(%s) does not exist' % self.nf_inst_id) + return False + #raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id) sel_vnf = vnf_insts[0] #if sel_vnf.status != 'VNF_INSTANTIATED': # raise NFLCMException("Don't allow to terminate vnf(status:[%s])" % sel_vnf.status) if self.terminationType == 'GRACEFUL' and not self.gracefulTerminationTimeout: - raise NFLCMException("Graceful termination must set timeout") + logger.warn("Set Graceful default termination timeout = 60") + self.gracefulTerminationTimeout = 60 + #raise NFLCMException("Graceful termination must set timeout") NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status=VNF_STATUS.TERMINATING) JobUtil.add_job_status(self.job_id, 10, 'Nf terminating pre-check finish') logger.info("Nf terminating pre-check finish") + return True def grant_resource(self): logger.info("nf_cancel_task grant_resource begin") -- cgit 1.2.3-korg