Change in terminate 63/60163/1
authorbiancunkang <bian.cunkang@zte.com.cn>
Mon, 13 Aug 2018 01:24:00 +0000 (09:24 +0800)
committerbiancunkang <bian.cunkang@zte.com.cn>
Mon, 13 Aug 2018 01:24:00 +0000 (09:24 +0800)
Change-Id: I8804b873e88531081901e749b8f66bdbe41d7424
Issue-ID: VFC-1015
Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
lcm/lcm/nf/biz/terminate_vnf.py
lcm/lcm/nf/views/terminate_vnf_view.py

index e23d5ef..5d51512 100644 (file)
@@ -14,6 +14,7 @@
 
 import json
 import logging
+import traceback
 from threading import Thread
 
 from lcm.nf.const import VNF_STATUS, RESOURCE_MAP
@@ -40,6 +41,7 @@ class TerminateVnf(Thread):
         self.inst_resource = {'volumn': [], 'network': [], 'subnet': [], 'port': [], 'flavor': [], 'vm': []}
 
     def run(self):
+        try:
             if self.term_pre():
                 self.grant_resource()
                 self.query_inst_resource()
@@ -47,6 +49,11 @@ class TerminateVnf(Thread):
                 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)
+        except Exception as e:
+            logger.error(e.message)
+            self.vnf_term_failed_handle(traceback.format_exc())
 
     def term_pre(self):
         vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
@@ -194,3 +201,8 @@ class TerminateVnf(Thread):
         logger.info('Send notify request to nfvo')
         resp = notify_lcm_to_nfvo(json.dumps(self.notify_data))
         logger.info('Lcm notify end, response: %s' % resp)
+
+    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())
+        JobUtil.add_job_status(self.job_id, 255, error_msg)
index 261c55e..c1903b7 100644 (file)
@@ -25,8 +25,7 @@ from lcm.nf.serializers.terminate_vnf_req import TerminateVnfRequestSerializer
 from lcm.nf.serializers.job_identifier import JobIdentifierSerializer\r
 from lcm.pub.exceptions import NFLCMException\r
 from lcm.pub.utils.jobutil import JobUtil\r
-from lcm.pub.utils.timeutil import now_time\r
-from lcm.pub.database.models import NfInstModel\r
+\r
 \r
 logger = logging.getLogger(__name__)\r
 \r
@@ -56,14 +55,9 @@ class TerminateVnfView(APIView):
 \r
             return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)\r
         except NFLCMException as e:\r
-            self.vnf_term_failed_handle(e.message)\r
+            logger.error(e.message)\r
             return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
         except Exception as e:\r
             logger.error(e.message)\r
-            self.vnf_term_failed_handle(traceback.format_exc())\r
+            logger.error(traceback.format_exc())\r
             return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)\r
-\r
-    def vnf_term_failed_handle(self, error_msg):\r
-        logger.error('VNF termination failed, detail message: %s' % error_msg)\r
-        NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='failed', lastuptime=now_time())\r
-        JobUtil.add_job_status(self.job_id, 255, error_msg)\r