resolve python2->python3 issues
[vfc/nfvo/lcm.git] / lcm / ns / biz / ns_terminate.py
index 701e65c..b2776a6 100644 (file)
@@ -23,11 +23,10 @@ from lcm.pub.msapi.nslcm import call_from_ns_cancel_resource
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.utils import restcall
-from lcm.ns.const import OWNER_TYPE
+from lcm.ns.enum import OWNER_TYPE
 from lcm.pub.database.models import PNFInstModel
 from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
-
-JOB_ERROR = 255
+from lcm.jobs.enum import JOB_PROGRESS
 
 logger = logging.getLogger(__name__)
 
@@ -44,7 +43,7 @@ class TerminateNsService(threading.Thread):
     def run(self):
         try:
             if not NSInstModel.objects.filter(id=self.ns_inst_id):
-                JobUtil.add_job_status(self.job_id, 100, "Need not terminate.", '')
+                JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, "Need not terminate.", '')
                 NsLcmOpOcc.update(self.occ_id, "COMPLETED")
                 return
             JobUtil.add_job_status(self.job_id, 10, "Starting terminate...", '')
@@ -55,16 +54,16 @@ class TerminateNsService(threading.Thread):
             self.cancel_pnf_list()
 
             NSInstModel.objects.filter(id=self.ns_inst_id).update(status='null')
-            JobUtil.add_job_status(self.job_id, 100, "ns terminate ends.", '')
+            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, "ns terminate ends.", '')
             NsLcmOpOcc.update(self.occ_id, "COMPLETED")
         except NSLCMException as e:
-            JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
-            NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
+            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.args[0])
+            NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0])
         except Exception as e:
-            logger.error(e.message)
+            logger.error(e.args[0])
             logger.error(traceback.format_exc())
-            JobUtil.add_job_status(self.job_id, JOB_ERROR, "ns terminate fail.")
-            NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
+            JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, "ns terminate fail.")
+            NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0])
 
     def cancel_vl_list(self):
         array_vlinst = VLInstModel.objects.filter(ownertype=OWNER_TYPE.NS, ownerid=self.ns_inst_id)
@@ -83,7 +82,7 @@ class TerminateNsService(threading.Thread):
                     if str(result) == '0':
                         delete_result = "success"
             except Exception as e:
-                logger.error("[cancel_vl_list] error[%s]!" % e.message)
+                logger.error("[cancel_vl_list] error[%s]!" % e.args[0])
                 logger.error(traceback.format_exc())
             job_msg = "Delete vlinst:[%s] %s." % (vlinst.vlinstanceid, delete_result)
             JobUtil.add_job_status(self.job_id, cur_progress, job_msg)
@@ -105,7 +104,7 @@ class TerminateNsService(threading.Thread):
                     if str(result) == '0':
                         delete_result = "success"
             except Exception as e:
-                logger.error("[cancel_sfc_list] error[%s]!" % e.message)
+                logger.error("[cancel_sfc_list] error[%s]!" % e.args[0])
                 logger.error(traceback.format_exc())
             job_msg = "Delete sfcinst:[%s] %s." % (sfcinst.sfcid, delete_result)
             JobUtil.add_job_status(self.job_id, cur_progress, job_msg)
@@ -127,7 +126,7 @@ class TerminateNsService(threading.Thread):
                 if vnf_job_id:
                     delete_result = "deleting"
             except Exception as e:
-                logger.error("[cancel_vnf_list] error[%s]!" % e.message)
+                logger.error("[cancel_vnf_list] error[%s]!" % e.args[0])
                 logger.error(traceback.format_exc())
             job_msg = "Delete vnfinst:[%s] %s." % (vnfinst.nfinstid, delete_result)
             JobUtil.add_job_status(self.job_id, cur_progress, job_msg)
@@ -186,11 +185,11 @@ class TerminateNsService(threading.Thread):
                 logger.debug("%s:%s:%s", progress, new_response_id, job_desc)
                 response_id = new_response_id
                 count = 0
-            if progress == JOB_ERROR:
+            if progress == JOB_PROGRESS.ERROR:
                 job_timeout = False
                 logger.error("Job(%s) failed: %s", vnf_job_id, job_desc)
                 break
-            elif progress == 100:
+            elif progress == JOB_PROGRESS.FINISHED:
                 job_end_normal, job_timeout = True, False
                 logger.info("Job(%s) ended normally", vnf_job_id)
                 break
@@ -210,7 +209,7 @@ class TerminateNsService(threading.Thread):
                     if ret[0] == 0:
                         delete_result = "success"
                 except Exception as e:
-                    logger.error("[cancel_pnf_list] error[%s]!" % e.message)
+                    logger.error("[cancel_pnf_list] error[%s]!" % e.args[0])
                     logger.error(traceback.format_exc())
                 job_msg = "Delete pnfinst:[%s] %s" % (pnfinst.pnfId, delete_result)
                 cur_progress += step_progress