summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopengzhang <zhang.maopeng1@zte.com.cn>2019-04-26 15:25:28 +0800
committermaopengzhang <zhang.maopeng1@zte.com.cn>2019-04-26 16:08:03 +0800
commit752bf0132e7db519597e32525b33db4fd56a7643 (patch)
tree943935b370ab2d2d45ee7b17edd55aa7d52955bd
parent4715e9de59c877c6ee9615df9fb1ff61b73d66e1 (diff)
Add job_* enum and const in public
Add job_* enum and const in public Change-Id: I4cfc1bb34f674752b29ab7e7f2dd7fee2f3ce941 Issue-ID: VFC-1241 Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r--lcm/ns/biz/ns_heal.py15
-rw-r--r--lcm/ns/biz/ns_instantiate_flow.py15
-rw-r--r--lcm/ns/biz/ns_manual_scale.py13
-rw-r--r--lcm/ns/biz/ns_terminate.py15
-rw-r--r--lcm/ns/biz/ns_update.py23
-rw-r--r--lcm/ns/biz/scaleaspect.py1
-rw-r--r--lcm/ns/tests/test_ns_heal.py4
-rw-r--r--lcm/ns/tests/test_ns_manual_scale.py3
-rw-r--r--lcm/ns/tests/test_sol_ns_heal_api.py3
-rw-r--r--lcm/ns/tests/test_sol_ns_scale_api.py3
-rw-r--r--lcm/ns/tests/tests_ns_terminate.py4
-rw-r--r--lcm/ns/views/deprecated/heal_ns_view.py6
-rw-r--r--lcm/ns/views/deprecated/scale_ns_views.py3
-rw-r--r--lcm/ns/views/deprecated/term_ns_view.py3
-rw-r--r--lcm/ns/views/deprecated/update_ns_view.py3
-rw-r--r--lcm/ns/views/sol/heal_ns_view.py3
-rw-r--r--lcm/ns/views/sol/scale_ns_views.py3
-rw-r--r--lcm/ns/views/sol/terminate_ns_view.py2
-rw-r--r--lcm/ns/views/sol/update_ns_view.py3
-rw-r--r--lcm/ns_vnfs/biz/create_vnfs.py76
-rw-r--r--lcm/ns_vnfs/biz/heal_vnfs.py35
-rw-r--r--lcm/ns_vnfs/biz/scale_vnfs.py8
-rw-r--r--lcm/ns_vnfs/biz/terminate_nfs.py3
-rw-r--r--lcm/ns_vnfs/biz/update_vnfs.py8
-rw-r--r--lcm/ns_vnfs/biz/verify_vnfs.py18
-rw-r--r--lcm/ns_vnfs/biz/wait_job.py3
-rw-r--r--lcm/ns_vnfs/const.py2
-rw-r--r--lcm/ns_vnfs/tests/tests.py4
-rw-r--r--lcm/ns_vnfs/urls.py5
-rw-r--r--lcm/ns_vnfs/views/views.py3
-rw-r--r--lcm/pub/const.py15
-rw-r--r--lcm/pub/enum.py46
-rw-r--r--lcm/pub/exceptions.py15
-rw-r--r--lcm/pub/utils/jobutil.py16
34 files changed, 223 insertions, 159 deletions
diff --git a/lcm/ns/biz/ns_heal.py b/lcm/ns/biz/ns_heal.py
index 096561e0..19994dfa 100644
--- a/lcm/ns/biz/ns_heal.py
+++ b/lcm/ns/biz/ns_heal.py
@@ -21,12 +21,12 @@ import traceback
from lcm.ns.enum import NS_INST_STATUS
from lcm.pub.database.models import JobModel, NSInstModel, NfInstModel, VNFCInstModel, VmInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
-JOB_ERROR = 255
logger = logging.getLogger(__name__)
@@ -44,11 +44,11 @@ class NSHealService(threading.Thread):
try:
self.do_biz()
except NSLCMException as e:
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
except Exception as e:
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns heal fail')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'ns heal fail')
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
def do_biz(self):
@@ -64,7 +64,6 @@ class NSHealService(threading.Thread):
ns_info = NSInstModel.objects.filter(id=self.ns_instance_id)
if not ns_info:
errmsg = 'NS [id=%s] does not exist' % self.ns_instance_id
- logger.error(errmsg)
raise NSLCMException(errmsg)
self.heal_ns_data = ignore_case_get(self.request_data, 'healNsData')
@@ -77,7 +76,6 @@ class NSHealService(threading.Thread):
if not self.heal_ns_data and not self.heal_vnf_data:
errmsg = 'healNsData and healVnfData parameters does not exist or value is incorrect.'
- logger.error(errmsg)
raise NSLCMException(errmsg)
def do_heal(self):
@@ -89,7 +87,6 @@ class NSHealService(threading.Thread):
self.update_job(90, desc='nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId'))
else:
errmsg = 'nf heal failed'
- logger.error(errmsg)
raise NSLCMException(errmsg)
else:
ns_heal_params = self.prepare_ns_heal_params(self.heal_ns_data)
@@ -194,9 +191,9 @@ class NSHealService(threading.Thread):
job_result = JobModel.objects.get(jobid=sub_job_id)
time.sleep(query_interval)
end_time = datetime.datetime.now()
- if job_result.progress == 100:
+ if job_result.progress == JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.FINISHED
- elif job_result.progress > 100:
+ elif job_result.progress > JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.ERROR
else:
continue
diff --git a/lcm/ns/biz/ns_instantiate_flow.py b/lcm/ns/biz/ns_instantiate_flow.py
index 913e8686..04532c26 100644
--- a/lcm/ns/biz/ns_instantiate_flow.py
+++ b/lcm/ns/biz/ns_instantiate_flow.py
@@ -20,14 +20,13 @@ from threading import Thread
from lcm.pub.utils.syscomm import fun_name
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils import restcall
+from lcm.pub.enum import JOB_PROGRESS, JOB_ERROR_CODE
from lcm.pub.exceptions import NSLCMException
from lcm.workflows.graphflow.flow.flow import GraphFlow
from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
-logger = logging.getLogger(__name__)
-RESULT_OK, RESULT_NG = "0", "1"
-JOB_ERROR = 255
+logger = logging.getLogger(__name__)
config = {
"CreateVnf": {"module": "lcm.ns_vnfs", "class": "CreateVnf"},
@@ -63,7 +62,7 @@ def run_ns_instantiate(input_data, occ_id):
logger.debug("Enter %s, input_data is %s", fun_name(), input_data)
ns_inst_id = ignore_case_get(input_data, "nsInstanceId")
job_id = ignore_case_get(input_data, "jobId")
- update_job(job_id, 10, "true", "Start to prepare the NS instantiate workflow parameter")
+ update_job(job_id, 10, JOB_ERROR_CODE.NO_ERROR, "Start to prepare the NS instantiate workflow parameter")
deploy_graph = build_deploy_graph(input_data)
TaskSet = build_TaskSet(input_data)
ns_instantiate_ok = False
@@ -77,19 +76,19 @@ def run_ns_instantiate(input_data, occ_id):
gf.task_manager.wait_tasks_done(gf.sort_nodes)
if gf.task_manager.is_all_task_finished():
logger.debug("NS is instantiated!")
- update_job(job_id, 90, "true", "Start to post deal")
+ update_job(job_id, 90, JOB_ERROR_CODE.NO_ERROR, "Start to post deal")
post_deal(ns_inst_id, "true")
- update_job(job_id, 100, "true", "Create NS successfully.")
+ update_job(job_id, JOB_PROGRESS.FINISHED, JOB_ERROR_CODE.NO_ERROR, "Create NS successfully.")
NsLcmOpOcc.update(occ_id, "COMPLETED")
ns_instantiate_ok = True
except NSLCMException as e:
logger.error("Failded to Create NS: %s", e.message)
- update_job(job_id, JOB_ERROR, "255", "Failded to Create NS.")
+ update_job(job_id, JOB_PROGRESS.ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.")
NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.message)
post_deal(ns_inst_id, "false")
except Exception as e:
logger.error(traceback.format_exc())
- update_job(job_id, JOB_ERROR, "255", "Failded to Create NS.")
+ update_job(job_id, JOB_PROGRESS.ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.")
NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.message)
post_deal(ns_inst_id, "false")
return ns_instantiate_ok
diff --git a/lcm/ns/biz/ns_manual_scale.py b/lcm/ns/biz/ns_manual_scale.py
index 9c3286ed..2db55292 100644
--- a/lcm/ns/biz/ns_manual_scale.py
+++ b/lcm/ns/biz/ns_manual_scale.py
@@ -21,7 +21,8 @@ from lcm.ns.biz.scaleaspect import get_scale_vnf_data_info_list
from lcm.ns.enum import NS_INST_STATUS
from lcm.pub.database.models import JobModel, NSInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService
from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
@@ -44,12 +45,12 @@ class NSManualScaleService(threading.Thread):
try:
self.do_biz()
except NSLCMException as e:
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns scale fail')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'ns scale fail')
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
finally:
self.update_ns_status(NS_INST_STATUS.ACTIVE)
@@ -59,7 +60,7 @@ class NSManualScaleService(threading.Thread):
self.update_ns_status(NS_INST_STATUS.SCALING)
self.check_and_set_params()
self.do_vnfs_scale()
- self.update_job(100, desc='ns scale success')
+ self.update_job(JOB_PROGRESS.FINISHED, desc='ns scale success')
NsLcmOpOcc.update(self.occ_id, "COMPLETED")
def check_and_set_params(self):
@@ -118,9 +119,9 @@ class NSManualScaleService(threading.Thread):
job_result = JobModel.objects.get(jobid=sub_job_id)
time.sleep(query_interval)
end_time = datetime.datetime.now()
- if job_result.progress == 100:
+ if job_result.progress == JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.FINISHED
- if job_result.progress > 100:
+ if job_result.progress > JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.ERROR
return JOB_MODEL_STATUS.TIMEOUT
diff --git a/lcm/ns/biz/ns_terminate.py b/lcm/ns/biz/ns_terminate.py
index 832603fa..810f60a7 100644
--- a/lcm/ns/biz/ns_terminate.py
+++ b/lcm/ns/biz/ns_terminate.py
@@ -26,8 +26,7 @@ from lcm.pub.utils import restcall
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.pub.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,15 +54,15 @@ 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)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, "ns terminate fail.")
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, "ns terminate fail.")
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
def cancel_vl_list(self):
@@ -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
diff --git a/lcm/ns/biz/ns_update.py b/lcm/ns/biz/ns_update.py
index e27d41c4..c61071f4 100644
--- a/lcm/ns/biz/ns_update.py
+++ b/lcm/ns/biz/ns_update.py
@@ -17,19 +17,16 @@ import traceback
import datetime
import time
-from lcm.ns.enum import NS_INST_STATUS
+from lcm.ns.enum import NS_INST_STATUS, OPERATIONAL_STATE, STOP_TYPE
from lcm.pub.database.models import JobModel, NSInstModel
from lcm.ns_vnfs.biz.update_vnfs import NFOperateService
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
-from lcm.pub.utils.enumutil import enum
from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc
-JOB_ERROR = 255
logger = logging.getLogger(__name__)
-OPERATIONAL_STATES = enum(STOPPED='STOPPED', STARTED='STARTED')
-STOP_TYPE = enum(GRACEFUL='GRACEFUL', FORCEFUL='FORCEFUL')
class NSUpdateService(threading.Thread):
@@ -47,20 +44,20 @@ class NSUpdateService(threading.Thread):
self.do_biz()
except NSLCMException as e:
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
except Exception as e:
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns update fail')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'ns update fail')
NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message)
def do_biz(self):
- self.update_job(1, desc='ns update start')
+ self.update_job(JOB_PROGRESS.STARTED, desc='ns update start')
self.get_and_check_params()
self.update_ns_status(NS_INST_STATUS.UPDATING)
self.do_update()
self.update_ns_status(NS_INST_STATUS.ACTIVE)
- self.update_job(100, desc='ns update success')
+ self.update_job(JOB_PROGRESS.FINISHED, desc='ns update success')
NsLcmOpOcc.update(self.occ_id, "COMPLETED")
def get_and_check_params(self):
@@ -116,7 +113,7 @@ class NSUpdateService(threading.Thread):
'ChangeStateTo does not exist or value is incorrect.')
graceful_stop_timeout = ''
operational_states = ignore_case_get(change_state_to, 'OperationalStates')
- if operational_states == OPERATIONAL_STATES.STOPPED:
+ if operational_states == OPERATIONAL_STATE.STOPPED:
stop_type = ignore_case_get(vnf_data, 'stopType')
if stop_type == STOP_TYPE.GRACEFUL:
graceful_stop_timeout = ignore_case_get(vnf_data, 'gracefulStopTimeout')
@@ -137,9 +134,9 @@ class NSUpdateService(threading.Thread):
job_result = JobModel.objects.get(jobid=sub_job_id)
time.sleep(query_interval)
end_time = datetime.datetime.now()
- if job_result.progress == 100:
+ if job_result.progress == JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.FINISHED
- elif job_result.progress > 100:
+ elif job_result.progress > JOB_PROGRESS.FINISHED:
return JOB_MODEL_STATUS.ERROR
else:
continue
diff --git a/lcm/ns/biz/scaleaspect.py b/lcm/ns/biz/scaleaspect.py
index 18a45e71..21842cd5 100644
--- a/lcm/ns/biz/scaleaspect.py
+++ b/lcm/ns/biz/scaleaspect.py
@@ -23,7 +23,6 @@ from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.enum import VNF_STATUS
logger = logging.getLogger(__name__)
-SCALE_TYPE = ("SCALE_NS", "SCALE_VNF")
scale_vnf_data_mapping = {
"vnfInstanceId": "",
diff --git a/lcm/ns/tests/test_ns_heal.py b/lcm/ns/tests/test_ns_heal.py
index bd37c266..2f2f05c3 100644
--- a/lcm/ns/tests/test_ns_heal.py
+++ b/lcm/ns/tests/test_ns_heal.py
@@ -20,7 +20,8 @@ from lcm.ns.biz.ns_heal import NSHealService
from lcm.ns.enum import NS_INST_STATUS
from lcm.pub.database.models import NSInstModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
from lcm.ns.tests import HEAL_NS_DICT, HEAL_VNF_DICT, VNFD_MODEL_DICT
@@ -116,6 +117,7 @@ class TestHealNsViews(TestCase):
heal_ns_json = HEAL_NS_DICT.copy()
heal_ns_json["healNsData"]["vnfInstanceId"] = self.nf_inst_id
response = self.client.post("/api/nslcm/v1/ns/%s/heal" % ns_inst_id, data=heal_ns_json, format='json')
+ print response.data
self.assertEqual(response.data["error"], "NS Not Found")
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertIn("error", response.data)
diff --git a/lcm/ns/tests/test_ns_manual_scale.py b/lcm/ns/tests/test_ns_manual_scale.py
index 06b88df5..142c3ee8 100644
--- a/lcm/ns/tests/test_ns_manual_scale.py
+++ b/lcm/ns/tests/test_ns_manual_scale.py
@@ -26,7 +26,8 @@ from lcm.pub.database.models import NSInstModel, JobModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi import catalog
from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE
from lcm.ns.tests import SCALING_MAP_DICT, VNFD_MODEL_DICT, SCALE_NS_DICT
diff --git a/lcm/ns/tests/test_sol_ns_heal_api.py b/lcm/ns/tests/test_sol_ns_heal_api.py
index 1235056b..04a4bcc3 100644
--- a/lcm/ns/tests/test_sol_ns_heal_api.py
+++ b/lcm/ns/tests/test_sol_ns_heal_api.py
@@ -23,7 +23,8 @@ from rest_framework import status
from lcm.ns.biz.ns_heal import NSHealService
from lcm.pub.database.models import NSInstModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.tests import VNFD_MODEL_DICT, HEAL_NS_DICT, HEAL_VNF_DICT
diff --git a/lcm/ns/tests/test_sol_ns_scale_api.py b/lcm/ns/tests/test_sol_ns_scale_api.py
index bc71b09f..e8df1105 100644
--- a/lcm/ns/tests/test_sol_ns_scale_api.py
+++ b/lcm/ns/tests/test_sol_ns_scale_api.py
@@ -21,7 +21,8 @@ from rest_framework.test import APIClient
from lcm.ns.biz.ns_manual_scale import NSManualScaleService
from lcm.pub.database.models import NSInstModel, JobModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.tests import VNFD_MODEL_DICT, SCALE_NS_DICT
diff --git a/lcm/ns/tests/tests_ns_terminate.py b/lcm/ns/tests/tests_ns_terminate.py
index e49dafcf..48868bd9 100644
--- a/lcm/ns/tests/tests_ns_terminate.py
+++ b/lcm/ns/tests/tests_ns_terminate.py
@@ -21,8 +21,8 @@ from rest_framework import status
from lcm.ns.biz.ns_terminate import TerminateNsService
from lcm.pub.database.models import NfInstModel, NSInstModel
from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
class TestTerminateNsViews(TestCase):
diff --git a/lcm/ns/views/deprecated/heal_ns_view.py b/lcm/ns/views/deprecated/heal_ns_view.py
index 87519654..ef1f6cda 100644
--- a/lcm/ns/views/deprecated/heal_ns_view.py
+++ b/lcm/ns/views/deprecated/heal_ns_view.py
@@ -22,7 +22,8 @@ from lcm.ns.biz.ns_heal import NSHealService
from lcm.ns.serializers.deprecated.ns_serializers import _HealNsReqSerializer
from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
logger = logging.getLogger(__name__)
@@ -52,6 +53,9 @@ class NSHealView(APIView):
logger.debug("Leave HealNSView::post ret=%s", resp_serializer.data)
return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
+ except NSLCMException as e:
+ logger.error("Exception in HealNSView: %s", e.message)
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
logger.error("Exception in HealNSView: %s", e.message)
return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
diff --git a/lcm/ns/views/deprecated/scale_ns_views.py b/lcm/ns/views/deprecated/scale_ns_views.py
index 20f7b51e..d901cd7f 100644
--- a/lcm/ns/views/deprecated/scale_ns_views.py
+++ b/lcm/ns/views/deprecated/scale_ns_views.py
@@ -22,7 +22,8 @@ from lcm.ns.biz.ns_manual_scale import NSManualScaleService
from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
from lcm.ns.serializers.deprecated.ns_serializers import _ManualScaleNsReqSerializer
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
logger = logging.getLogger(__name__)
diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py
index 870615d4..0aa89187 100644
--- a/lcm/ns/views/deprecated/term_ns_view.py
+++ b/lcm/ns/views/deprecated/term_ns_view.py
@@ -20,7 +20,8 @@ from rest_framework.views import APIView
from lcm.ns.biz.ns_terminate import TerminateNsService
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializer, _NsOperateJobSerializer
logger = logging.getLogger(__name__)
diff --git a/lcm/ns/views/deprecated/update_ns_view.py b/lcm/ns/views/deprecated/update_ns_view.py
index 12bcf6ad..8160c622 100644
--- a/lcm/ns/views/deprecated/update_ns_view.py
+++ b/lcm/ns/views/deprecated/update_ns_view.py
@@ -23,7 +23,8 @@ from lcm.ns.biz.ns_update import NSUpdateService
from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
from lcm.ns.serializers.sol.update_serializers import UpdateNsReqSerializer
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
logger = logging.getLogger(__name__)
diff --git a/lcm/ns/views/sol/heal_ns_view.py b/lcm/ns/views/sol/heal_ns_view.py
index 6faefd95..6dfef8d1 100644
--- a/lcm/ns/views/sol/heal_ns_view.py
+++ b/lcm/ns/views/sol/heal_ns_view.py
@@ -19,7 +19,8 @@ from rest_framework.views import APIView
from lcm.ns.biz.ns_heal import NSHealService
from lcm.ns.serializers.sol.heal_serializers import HealNsReqSerializer
from lcm.pub.exceptions import BadRequestException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.const import NS_OCC_BASE_URI
from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
from .common import view_safe_call_with_log
diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py
index 708c3942..af233815 100644
--- a/lcm/ns/views/sol/scale_ns_views.py
+++ b/lcm/ns/views/sol/scale_ns_views.py
@@ -19,7 +19,8 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from lcm.ns.biz.ns_manual_scale import NSManualScaleService
from lcm.ns.serializers.sol.scale_ns_serializers import ScaleNsRequestSerializer
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.const import NS_OCC_BASE_URI
from lcm.pub.exceptions import BadRequestException
from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
diff --git a/lcm/ns/views/sol/terminate_ns_view.py b/lcm/ns/views/sol/terminate_ns_view.py
index af07dbd3..97d6044e 100644
--- a/lcm/ns/views/sol/terminate_ns_view.py
+++ b/lcm/ns/views/sol/terminate_ns_view.py
@@ -20,7 +20,7 @@ from rest_framework.views import APIView
from lcm.ns.biz.ns_terminate import TerminateNsService
from lcm.pub.utils.jobutil import JobUtil
-from lcm.pub.utils.jobutil import JOB_TYPE
+from lcm.pub.enum import JOB_TYPE
from lcm.pub.utils.values import ignore_case_get
from lcm.ns.serializers.sol.terminate_ns_serializers import TerminateNsReqSerializer
from lcm.pub.exceptions import BadRequestException
diff --git a/lcm/ns/views/sol/update_ns_view.py b/lcm/ns/views/sol/update_ns_view.py
index 2bf91a92..d160375f 100644
--- a/lcm/ns/views/sol/update_ns_view.py
+++ b/lcm/ns/views/sol/update_ns_view.py
@@ -22,7 +22,8 @@ from rest_framework.views import APIView
from lcm.ns.biz.ns_update import NSUpdateService
from lcm.ns.serializers.sol.update_serializers import UpdateNsReqSerializer
from lcm.pub.exceptions import BadRequestException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.ns.const import NS_OCC_BASE_URI
from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
from .common import view_safe_call_with_log
diff --git a/lcm/ns_vnfs/biz/create_vnfs.py b/lcm/ns_vnfs/biz/create_vnfs.py
index 19f1ce53..a968d640 100644
--- a/lcm/ns_vnfs/biz/create_vnfs.py
+++ b/lcm/ns_vnfs/biz/create_vnfs.py
@@ -14,40 +14,46 @@
import json
import logging
+from threading import Thread
import traceback
import uuid
-from threading import Thread
from lcm.ns.enum import OWNER_TYPE
+from lcm.ns_vnfs.const import NFVO_VNF_INST_TIMEOUT_SECOND
+from lcm.ns_vnfs.biz.subscribe import SubscriptionCreation
+from lcm.ns_vnfs.biz.wait_job import wait_job_finish
+from lcm.ns_vnfs.enum import VNF_STATUS, INST_TYPE, INST_TYPE_NAME
from lcm.pub.config.config import REPORT_TO_AAI
+from lcm.pub.config.config import REG_TO_MSB_REG_PARAM, OOF_BASE_URL, OOF_PASSWD, OOF_USER
+from lcm.pub.config.config import CUST_NAME, CUST_LAT, CUST_LONG
from lcm.pub.database.models import NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel, OOFDataModel
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE, JOB_PROGRESS, JOB_ERROR_CODE
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.aai import create_vnf_aai
from lcm.pub.msapi.extsys import get_vnfm_by_id
from lcm.pub.msapi.resmgr import create_vnf, create_vnf_creation_info
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.msapi.vnfmdriver import send_nf_init_request
-from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil, JOB_TYPE
+from lcm.pub.utils import restcall
+from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.share_lock import do_biz_with_share_lock
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
-from lcm.pub.utils import restcall
-from lcm.ns_vnfs.const import NFVO_VNF_INST_TIMEOUT_SECOND
-from lcm.ns_vnfs.enum import VNF_STATUS, INST_TYPE, INST_TYPE_NAME
-from lcm.ns_vnfs.biz.wait_job import wait_job_finish
-from lcm.pub.config.config import REG_TO_MSB_REG_PARAM, OOF_BASE_URL, OOF_PASSWD, OOF_USER
-from lcm.pub.config.config import CUST_NAME, CUST_LAT, CUST_LONG
-from lcm.ns_vnfs.biz.subscribe import SubscriptionCreation
+
logger = logging.getLogger(__name__)
def prepare_create_params():
nf_inst_id = str(uuid.uuid4())
- NfInstModel(nfinstid=nf_inst_id, status=VNF_STATUS.INSTANTIATING, create_time=now_time(),
- lastuptime=now_time()).save()
+ NfInstModel(
+ nfinstid=nf_inst_id,
+ status=VNF_STATUS.INSTANTIATING,
+ create_time=now_time(),
+ lastuptime=now_time()
+ ).save()
job_id = JobUtil.create_job(INST_TYPE_NAME.VNF, JOB_TYPE.CREATE_VNF, nf_inst_id)
- JobUtil.add_job_status(job_id, 0, 'create vnf record in database.', 0)
+ JobUtil.add_job_status(job_id, JOB_PROGRESS.STARTED, 'create vnf record in database.', JOB_ERROR_CODE.NO_ERROR)
return nf_inst_id, job_id
@@ -88,7 +94,7 @@ class CreateVnfs(Thread):
self.subscribe()
self.write_vnf_creation_info()
self.save_info_to_db()
- JobUtil.add_job_status(self.job_id, 100, 'vnf instantiation success', 0)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, 'vnf instantiation success', JOB_ERROR_CODE.NO_ERROR)
except NSLCMException as e:
self.vnf_inst_failed_handle(e.message)
except Exception:
@@ -111,8 +117,7 @@ class CreateVnfs(Thread):
def check_nf_name_exist(self):
is_exist = NfInstModel.objects.filter(nf_name=self.vnf_inst_name).exists()
if is_exist:
- logger.error('The name of NF instance already exists.')
- raise NSLCMException('The name of NF instance already exists.')
+ raise NSLCMException('The name of VNF instance already exists.')
def get_vnfd_id(self):
if self.vnfd_id:
@@ -135,7 +140,6 @@ class CreateVnfs(Thread):
self.vnf_inst_name = self.vnf_inst_name[:30]
self.vnf_inst_name = self.vnf_inst_name.replace("-", "_")
return
- logger.error('Can not found vnf in nsd model')
raise NSLCMException('Can not found vnf in nsd model')
def check_nf_package_valid(self):
@@ -321,9 +325,15 @@ class CreateVnfs(Thread):
req_body = self.build_homing_request()
base_url = OOF_BASE_URL
resources = "/api/oof/v1/placement"
- resp = restcall.call_req(base_url=base_url, user=OOF_USER, passwd=OOF_PASSWD,
- auth_type=restcall.rest_oneway_auth, resource=resources,
- method="POST", content=json.dumps(req_body), additional_headers="")
+ resp = restcall.call_req(
+ base_url=base_url,
+ user=OOF_USER,
+ passwd=OOF_PASSWD,
+ auth_type=restcall.rest_oneway_auth,
+ resource=resources,
+ method="POST",
+ content=json.dumps(req_body),
+ additional_headers="")
resp_body = resp[-2]
resp_status = resp[-1]
if resp_body:
@@ -332,8 +342,10 @@ class CreateVnfs(Thread):
logger.warn("Missing OOF sync response")
logger.debug(("OOF sync response code is %s") % resp_status)
if str(resp_status) != '202' or resp[0] != 0:
- OOFDataModel.objects.filter(request_id=req_body["requestInfo"]["requestId"],
- transaction_id=req_body["requestInfo"]["transactionId"]).update(
+ OOFDataModel.objects.filter(
+ request_id=req_body["requestInfo"]["requestId"],
+ transaction_id=req_body["requestInfo"]["transactionId"]
+ ).update(
request_status="failed",
vim_id="none",
cloud_owner="none",
@@ -368,15 +380,15 @@ class CreateVnfs(Thread):
create_vnf(data)
def wait_vnfm_job_finish(self):
- ret = wait_job_finish(vnfm_id=self.vnfm_inst_id,
- vnfo_job_id=self.job_id,
- vnfm_job_id=self.vnfm_job_id,
- progress_range=[10, 90],
- timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
+ ret = wait_job_finish(
+ vnfm_id=self.vnfm_inst_id,
+ vnfo_job_id=self.job_id,
+ vnfm_job_id=self.vnfm_job_id,
+ progress_range=[10, 90],
+ timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
if ret != JOB_MODEL_STATUS.FINISHED:
- logger.error('VNF instantiation failed on VNFM side. ret=[%s]', ret)
- raise NSLCMException('VNF instantiation failed on VNFM side.')
+ raise NSLCMException('VNF instantiation failed from VNFM. The job status is %s' % ret)
def subscribe(self):
data = {
@@ -392,8 +404,8 @@ class CreateVnfs(Thread):
'nf_inst_id': self.nf_inst_id,
'ns_inst_id': self.ns_inst_id,
'vnfm_inst_id': self.vnfm_inst_id,
- 'vms': [{'vmId': vm_inst_info.resouceid, 'vmName': vm_inst_info.vmname, 'vmStatus': 'ACTIVE'} for
- vm_inst_info in vm_inst_infos]}
+ 'vms': [{'vmId': vm_inst_info.resouceid, 'vmName': vm_inst_info.vmname, 'vmStatus': 'ACTIVE'} for vm_inst_info in vm_inst_infos]
+ }
create_vnf_creation_info(data)
logger.debug("write_vnf_creation_info end")
@@ -405,8 +417,7 @@ class CreateVnfs(Thread):
def vnf_inst_failed_handle(self, error_msg):
logger.error('VNF instantiation failed, detail message: %s' % error_msg)
- NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status=VNF_STATUS.FAILED,
- lastuptime=now_time())
+ NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status=VNF_STATUS.FAILED, lastuptime=now_time())
JobUtil.add_job_status(self.job_id, 255, 'VNF instantiation failed, detail message: %s' % error_msg, 0)
def save_vnf_inst_id_in_vnffg(self):
@@ -416,7 +427,6 @@ class CreateVnfs(Thread):
continue
vnffg_inst_infos = VNFFGInstModel.objects.filter(vnffgdid=vnffg['vnffg_Id'], nsinstid=self.ns_inst_id)
if not vnffg_inst_infos:
- logger.error('Vnffg instance not exist.')
raise NSLCMException('Vnffg instance not exist.')
vnf_list = vnffg_inst_infos[0].vnflist
vnffg_inst_infos.update(vnf_list=vnf_list + ',' + self.nf_inst_id if vnf_list else self.nf_inst_id)
diff --git a/lcm/ns_vnfs/biz/heal_vnfs.py b/lcm/ns_vnfs/biz/heal_vnfs.py
index 9821878b..fa3702fa 100644
--- a/lcm/ns_vnfs/biz/heal_vnfs.py
+++ b/lcm/ns_vnfs/biz/heal_vnfs.py
@@ -23,9 +23,9 @@ from lcm.pub.database.models import NfInstModel, VNFCInstModel, VmInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.vnfmdriver import send_nf_heal_request
from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
-from lcm.ns_vnfs.const import JOB_ERROR
from lcm.ns_vnfs.enum import VNF_STATUS
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
@@ -39,7 +39,6 @@ class NFHealService(threading.Thread):
self.vnf_instance_id = vnf_instance_id
self.data = data
self.job_id = JobUtil.create_job("NF", JOB_TYPE.HEAL_VNF, vnf_instance_id)
-
self.nf_model = {}
self.nf_additional_params = {}
self.nf_heal_params = {}
@@ -48,34 +47,28 @@ class NFHealService(threading.Thread):
def run(self):
try:
- self.do_biz()
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.STARTED, 'vnf heal start')
+ self.get_and_check_params()
+ self.update_nf_status(VNF_STATUS.HEALING)
+ self.send_nf_healing_request()
+ self.update_nf_status(VNF_STATUS.ACTIVE)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, 'vnf heal success')
except NSLCMException as e:
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
except:
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'nf heal fail')
-
- def do_biz(self):
- self.update_job(1, desc='nf heal start')
- self.get_and_check_params()
- self.update_nf_status(VNF_STATUS.HEALING)
- self.send_nf_healing_request()
- self.update_nf_status(VNF_STATUS.ACTIVE)
- self.update_job(100, desc='nf heal success')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'vnf heal fail')
def get_and_check_params(self):
nf_info = NfInstModel.objects.filter(nfinstid=self.vnf_instance_id)
if not nf_info:
- logger.error('NF instance[id=%s] does not exist' % self.vnf_instance_id)
- raise NSLCMException('NF instance[id=%s] does not exist' % self.vnf_instance_id)
+ raise NSLCMException('VNF instance[id=%s] does not exist' % self.vnf_instance_id)
logger.debug('vnfd_model = %s, vnf_instance_id = %s' % (nf_info[0].vnfd_model, self.vnf_instance_id))
self.nf_model = nf_info[0].vnfd_model
self.m_nf_inst_id = nf_info[0].mnfinstid
self.vnfm_inst_id = nf_info[0].vnfm_inst_id
self.nf_additional_params = ignore_case_get(self.data, 'additionalParams')
-
if not self.nf_additional_params:
- logger.error('additionalParams parameter does not exist or value incorrect')
raise NSLCMException('additionalParams parameter does not exist or value incorrect')
actionvminfo = ignore_case_get(self.nf_additional_params, 'actionvminfo')
@@ -120,8 +113,7 @@ class NFHealService(threading.Thread):
vnfm_job_id = ignore_case_get(rsp, 'jobId')
if not vnfm_job_id:
return
- ret = wait_job_finish(self.vnfm_inst_id, self.job_id, vnfm_job_id, progress_range=None, timeout=1200,
- mode='1')
+ ret = wait_job_finish(self.vnfm_inst_id, self.job_id, vnfm_job_id, progress_range=None, timeout=1200, mode='1')
if ret != JOB_MODEL_STATUS.FINISHED:
logger.error('[NF heal] nf heal failed')
raise NSLCMException("nf heal failed")
@@ -140,8 +132,5 @@ class NFHealService(threading.Thread):
return vmid
return vms.first().vmname
- def update_job(self, progress, desc=''):
- JobUtil.add_job_status(self.job_id, progress, desc)
-
def update_nf_status(self, status):
NfInstModel.objects.filter(nfinstid=self.vnf_instance_id).update(status=status)
diff --git a/lcm/ns_vnfs/biz/scale_vnfs.py b/lcm/ns_vnfs/biz/scale_vnfs.py
index 07dfbcbc..f3ed736b 100644
--- a/lcm/ns_vnfs/biz/scale_vnfs.py
+++ b/lcm/ns_vnfs/biz/scale_vnfs.py
@@ -19,9 +19,9 @@ import traceback
from lcm.pub.database.models import NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.vnfmdriver import send_nf_scaling_request
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
-from lcm.ns_vnfs.const import JOB_ERROR
from lcm.ns_vnfs.enum import VNF_STATUS
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
@@ -43,11 +43,11 @@ class NFManualScaleService(threading.Thread):
try:
self.do_biz()
except NSLCMException as e:
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
except Exception as ex:
logger.error(ex.message)
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'VNF scale failed')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'VNF scale failed')
finally:
self.update_nf_status()
diff --git a/lcm/ns_vnfs/biz/terminate_nfs.py b/lcm/ns_vnfs/biz/terminate_nfs.py
index 4ab624b7..c479348e 100644
--- a/lcm/ns_vnfs/biz/terminate_nfs.py
+++ b/lcm/ns_vnfs/biz/terminate_nfs.py
@@ -24,7 +24,8 @@ from lcm.pub.msapi import resmgr
from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai, query_vserver_aai, delete_vserver_aai
from lcm.pub.msapi.extsys import split_vim_to_owner_region, get_vim_by_id
from lcm.pub.msapi.vnfmdriver import send_nf_terminate_request
-from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.const import NFVO_VNF_INST_TIMEOUT_SECOND
from lcm.ns_vnfs.enum import VNF_STATUS, INST_TYPE
diff --git a/lcm/ns_vnfs/biz/update_vnfs.py b/lcm/ns_vnfs/biz/update_vnfs.py
index 1098a1d2..82bb92e1 100644
--- a/lcm/ns_vnfs/biz/update_vnfs.py
+++ b/lcm/ns_vnfs/biz/update_vnfs.py
@@ -20,9 +20,9 @@ import traceback
from lcm.pub.database.models import NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.vnfmdriver import send_nf_operate_request
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
-from lcm.ns_vnfs.const import JOB_ERROR
from lcm.ns_vnfs.enum import VNF_STATUS
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
@@ -46,10 +46,10 @@ class NFOperateService(threading.Thread):
try:
self.do_biz()
except NSLCMException as e:
- JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message)
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.message)
except:
logger.error(traceback.format_exc())
- JobUtil.add_job_status(self.job_id, JOB_ERROR, 'nf update fail')
+ JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'nf update fail')
def do_biz(self):
self.update_job(1, desc='nf update start')
diff --git a/lcm/ns_vnfs/biz/verify_vnfs.py b/lcm/ns_vnfs/biz/verify_vnfs.py
index 650cb255..32bb94f2 100644
--- a/lcm/ns_vnfs/biz/verify_vnfs.py
+++ b/lcm/ns_vnfs/biz/verify_vnfs.py
@@ -18,9 +18,9 @@ import threading
import traceback
import time
-from lcm.ns_vnfs.const import JOB_ERROR
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE, JOB_PROGRESS
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils.restcall import req_by_msb
@@ -46,10 +46,10 @@ class VerifyVnfs(threading.Thread):
self.do_func_test()
self.verify_ok = True
except NSLCMException as e:
- self.update_job(JOB_ERROR, e.message)
+ self.update_job(JOB_PROGRESS.ERROR, e.message)
except:
logger.error(traceback.format_exc())
- self.update_job(JOB_ERROR, 'Unknown error in vnf verify.')
+ self.update_job(JOB_PROGRESS.ERROR, 'Unknown error in vnf verify.')
finally:
logger.warn("Ignore terminate vnf operation")
if self.verify_ok:
@@ -119,11 +119,11 @@ class VerifyVnfs(threading.Thread):
if ret[0] != 0:
raise NSLCMException("Failed to call term vnf: %s" % ret[1])
rsp_data = json.JSONDecoder().decode(ret[1])
- end_progress = 100 if self.verify_ok else JOB_ERROR
- term_progress = 95 if self.verify_ok else JOB_ERROR
+ end_progress = 100 if self.verify_ok else JOB_PROGRESS.ERROR
+ term_progress = 95 if self.verify_ok else JOB_PROGRESS.ERROR
if not self.wait_until_job_done(rsp_data["jobId"], term_progress):
logger.error("Vnf(%s) term failed", self.vnf_inst_id)
- end_progress = JOB_ERROR
+ end_progress = JOB_PROGRESS.ERROR
self.update_job(end_progress, "Term vnf end.")
def update_job(self, progress, desc=''):
@@ -152,7 +152,7 @@ class VerifyVnfs(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:
if 'already onBoarded' in job_desc:
logger.warn("%s:%s", job_id, job_desc)
job_end_normal, job_timeout = True, False
@@ -193,7 +193,7 @@ class VerifyVnfs(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:
if 'already onBoarded' in job_desc:
logger.warn("%s:%s", job_id, job_desc)
job_end_normal, job_timeout = True, False
diff --git a/lcm/ns_vnfs/biz/wait_job.py b/lcm/ns_vnfs/biz/wait_job.py
index a1788ef7..34724964 100644
--- a/lcm/ns_vnfs/biz/wait_job.py
+++ b/lcm/ns_vnfs/biz/wait_job.py
@@ -17,7 +17,8 @@ import logging
import math
-from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_MODEL_STATUS
from lcm.pub.msapi.vnfmdriver import query_vnfm_job
from lcm.pub.utils.values import ignore_case_get
diff --git a/lcm/ns_vnfs/const.py b/lcm/ns_vnfs/const.py
index d3edfe47..3f69750e 100644
--- a/lcm/ns_vnfs/const.py
+++ b/lcm/ns_vnfs/const.py
@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
-JOB_ERROR = 255
NFVO_VNF_INST_TIMEOUT_SECOND = 3000
SCALAR_UNIT_DICT = {
"B": 1,
diff --git a/lcm/ns_vnfs/tests/tests.py b/lcm/ns_vnfs/tests/tests.py
index 6a2ed6bc..1ca861ec 100644
--- a/lcm/ns_vnfs/tests/tests.py
+++ b/lcm/ns_vnfs/tests/tests.py
@@ -21,8 +21,8 @@ from rest_framework import status
from lcm.pub.database.models import NfInstModel, JobModel, NSInstModel, VmInstModel, OOFDataModel, SubscriptionModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils import restcall
-from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.enum import JOB_MODEL_STATUS, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
diff --git a/lcm/ns_vnfs/urls.py b/lcm/ns_vnfs/urls.py
index de1ae6e8..6b5b2597 100644
--- a/lcm/ns_vnfs/urls.py
+++ b/lcm/ns_vnfs/urls.py
@@ -31,11 +31,8 @@ urlpatterns = [
url(r'^api/nslcm/v1/vnfms/(?P<vnfmid>[0-9a-zA-Z_-]+)', NfVnfmInfoView.as_view()),
# url(r'^api/nslcm/v1/vims/(?P<vimid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
url(r'^api/nslcm/v1/vims/(?P<cloudowner>[0-9a-zA-Z_-]+)/(?P<cloudregionid>[0-9a-zA-Z_-]+)', NfVimInfoView.as_view()),
-
- # move form v2
url(r'^api/nslcm/v2/grants$', VnfGrantView.as_view()),
- url(r'^api/nslcm/v2/ns/(?P<vnfmId>[0-9a-zA-Z_-]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z_-]+)/Notify$',
- VnfNotifyView.as_view()),
+ url(r'^api/nslcm/v2/ns/(?P<vnfmId>[0-9a-zA-Z_-]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z_-]+)/Notify$', VnfNotifyView.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/lcm/ns_vnfs/views/views.py b/lcm/ns_vnfs/views/views.py
index fea09a9e..7d53d4ce 100644
--- a/lcm/ns_vnfs/views/views.py
+++ b/lcm/ns_vnfs/views/views.py
@@ -22,7 +22,8 @@ from rest_framework.views import APIView
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.extsys import get_vnfm_by_id, get_vim_by_id_vim_info
-from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
+from lcm.pub.utils.jobutil import JobUtil
+from lcm.pub.enum import JOB_TYPE
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
from lcm.ns_vnfs.biz.get_vnfs import GetVnf, GetVnfVms
diff --git a/lcm/pub/const.py b/lcm/pub/const.py
new file mode 100644
index 00000000..024973e9
--- /dev/null
+++ b/lcm/pub/const.py
@@ -0,0 +1,15 @@
+# Copyright 2016 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
diff --git a/lcm/pub/enum.py b/lcm/pub/enum.py
new file mode 100644
index 00000000..0a667a51
--- /dev/null
+++ b/lcm/pub/enum.py
@@ -0,0 +1,46 @@
+# Copyright 2019 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from lcm.pub.utils.enumutil import enum
+
+JOB_STATUS = enum(
+ FINISH=1,
+ PROCESSING=0
+)
+JOB_MODEL_STATUS = enum(
+ ERROR='error',
+ FINISHED='finished',
+ PROCESSING='processing',
+ STARTED='started',
+ TIMEOUT='timeout'
+)
+JOB_TYPE = enum(
+ CREATE_VNF="create vnf",
+ HEAL_VNF="heal vnf",
+ GRANT_VNF="grant vnf",
+ MANUAL_SCALE_VNF="manual scale vnf",
+ TERMINATE_NS="terminate ns",
+ TERMINATE_VNF="terminate vnf",
+ UPDATE_NS="update ns"
+)
+JOB_PROGRESS = enum(
+ ERROR=255,
+ FINISHED=100,
+ PARTLY_FINISHED=101,
+ STARTED=0
+)
+JOB_ERROR_CODE = enum(
+ NO_ERROR="0",
+ ERROR="255"
+)
diff --git a/lcm/pub/exceptions.py b/lcm/pub/exceptions.py
index 6078ce7d..b1a39232 100644
--- a/lcm/pub/exceptions.py
+++ b/lcm/pub/exceptions.py
@@ -11,15 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import logging
+logger = logging.getLogger(__name__)
-class NSLCMException(Exception):
+
+class BaseException(Exception):
+ def __init__(self, message):
+ super(BaseException, self).__init__(message)
+ logger.error(self.message)
+
+
+class BadRequestException(BaseException):
pass
-class BadRequestException(Exception):
+class NSLCMException(BaseException):
pass
-class SeeOtherException(Exception):
+class SeeOtherException(BaseException):
pass
diff --git a/lcm/pub/utils/jobutil.py b/lcm/pub/utils/jobutil.py
index 3aa56354..8a68fcbb 100644
--- a/lcm/pub/utils/jobutil.py
+++ b/lcm/pub/utils/jobutil.py
@@ -12,28 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
+from functools import reduce
import logging
-import uuid
import traceback
+import uuid
from lcm.pub.database.models import JobStatusModel, JobModel
+from lcm.pub.enum import JOB_STATUS
from lcm.pub.utils import idutil
-from functools import reduce
logger = logging.getLogger(__name__)
-def enum(**enums):
- return type('Enum', (), enums)
-
-
-JOB_STATUS = enum(PROCESSING=0, FINISH=1)
-JOB_MODEL_STATUS = enum(STARTED='started', PROCESSING='processing', FINISHED='finished', ERROR='error',
- TIMEOUT='timeout')
-JOB_TYPE = enum(CREATE_VNF="create vnf", TERMINATE_VNF="terminate vnf", GRANT_VNF="grant vnf", MANUAL_SCALE_VNF="manual scale vnf",
- HEAL_VNF="heal vnf", TERMINATE_NS="terminate ns", UPDATE_NS="update ns")
-
-
class JobUtil(object):
def __init__(self):
pass