diff options
-rw-r--r-- | lcm/jobs/const.py | 4 | ||||
-rw-r--r-- | lcm/jobs/tests/tests.py | 14 | ||||
-rw-r--r-- | lcm/jobs/views.py | 7 | ||||
-rw-r--r-- | lcm/ns/biz/ns_instantiate_flow.py | 4 | ||||
-rw-r--r-- | lcm/ns/biz/ns_terminate.py | 3 | ||||
-rw-r--r-- | lcm/ns_vnfs/biz/verify_vnfs.py | 4 | ||||
-rw-r--r-- | lcm/workflows/build_in.py | 23 | ||||
-rw-r--r-- | lcm/workflows/graphflow/task/lcm_async_rest_task.py | 5 | ||||
-rw-r--r-- | lcm/workflows/tests.py | 8 |
9 files changed, 39 insertions, 33 deletions
diff --git a/lcm/jobs/const.py b/lcm/jobs/const.py index c4185ab6..c0612b6e 100644 --- a/lcm/jobs/const.py +++ b/lcm/jobs/const.py @@ -11,6 +11,6 @@ # 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.config.config import MSB_BASE_URL -JOB_INSTANCE_URI = MSB_BASE_URL + '/api/nslcm/v1/jobs/%s' +JOB_INSTANCE_URI = '/api/nslcm/v1/jobs/%s' +JOB_INSTANCE_RESPONSE_ID_URI = '/api/nslcm/v1/jobs/%s?responseId=%s' diff --git a/lcm/jobs/tests/tests.py b/lcm/jobs/tests/tests.py index 2de0c2c5..7a1ef1ab 100644 --- a/lcm/jobs/tests/tests.py +++ b/lcm/jobs/tests/tests.py @@ -13,6 +13,7 @@ # limitations under the License. from django.test import TestCase +from lcm.jobs.const import JOB_INSTANCE_URI from lcm.jobs.enum import JOB_ACTION, JOB_STATUS, JOB_TYPE from lcm.jobs.tests import UPDATE_JOB_DICT, UPDATE_JOB_BAD_REQ_DICT from lcm.pub.database.models import JobModel, JobStatusModel @@ -42,7 +43,7 @@ class JobsViewTest(TestCase): progress=20, descp='Finish to instantiate NS.', errcode="0").save() - response = self.client.get("/api/nslcm/v1/jobs/%s" % self.job_id) + response = self.client.get(JOB_INSTANCE_URI % self.job_id) self.assertEqual(status.HTTP_200_OK, response.status_code, response.data) self.assertIn('jobId', response.data) self.assertIn('responseDescriptor', response.data) @@ -50,7 +51,7 @@ class JobsViewTest(TestCase): def test_query_ns_job_not_existed(self): job_id = 'test_job_id_not_existed' - response = self.client.get("/api/nslcm/v1/jobs/%s" % job_id) + response = self.client.get(JOB_INSTANCE_URI % job_id) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertIn('jobId', response.data) self.assertNotIn('responseDescriptor', response.data) @@ -84,7 +85,8 @@ class JobsViewTest(TestCase): progress=100, descp='Finish to instantiate NS.', errcode="0").save() - response = self.client.get("/api/nslcm/v1/jobs/%s?responseId=2" % self.job_id) + url = JOB_INSTANCE_URI % self.job_id + "?responseId=2" + response = self.client.get(url) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.job_id, response.data.get('jobId')) self.assertIn('responseDescriptor', response.data) @@ -104,11 +106,11 @@ class JobsViewTest(TestCase): progress=20, descp='NS instantiation progress is 20%.', errcode="0").save() - response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_DICT) + response = self.client.post(JOB_INSTANCE_URI % self.job_id, format='json', data=UPDATE_JOB_DICT) self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) def test_update_job_not_existed(self): - response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_DICT) + response = self.client.post(JOB_INSTANCE_URI % self.job_id, format='json', data=UPDATE_JOB_DICT) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) def test_update_job_with_bad_req(self): @@ -124,5 +126,5 @@ class JobsViewTest(TestCase): progress=20, descp='NS instantiation progress is 20%.', errcode="0").save() - response = self.client.post("/api/nslcm/v1/jobs/%s" % self.job_id, format='json', data=UPDATE_JOB_BAD_REQ_DICT) + response = self.client.post(JOB_INSTANCE_URI % self.job_id, format='json', data=UPDATE_JOB_BAD_REQ_DICT) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) diff --git a/lcm/jobs/views.py b/lcm/jobs/views.py index 2518b3c7..71306c11 100644 --- a/lcm/jobs/views.py +++ b/lcm/jobs/views.py @@ -88,9 +88,10 @@ class JobView(APIView): if jobs[-1].errcode != JOB_ERROR_CODE.ERROR: job_up_req = JobUpdReq(**request.data) desc = job_up_req.desc - errcode = JOB_ERROR_CODE.NO_ERROR if job_up_req.errcode in ('true', 'active') else JOB_ERROR_CODE.ERROR - logger.debug("errcode=%s", errcode) - JobUtil.add_job_status(job_id, job_up_req.progress, desc, error_code=errcode) + no_err_list = ('true', 'active', '0') + err_code = JOB_ERROR_CODE.NO_ERROR if job_up_req.errcode in no_err_list else JOB_ERROR_CODE.ERROR + logger.debug("errcode=%s", err_code) + JobUtil.add_job_status(job_id, job_up_req.progress, desc, error_code=err_code) job_update_resp = JobUpdResp('ok') resp_serializer = JobUpdRespSerializer(job_update_resp) logger.debug("Leave JobView::post, response=%s", resp_serializer.data) diff --git a/lcm/ns/biz/ns_instantiate_flow.py b/lcm/ns/biz/ns_instantiate_flow.py index 06057516..a247be3f 100644 --- a/lcm/ns/biz/ns_instantiate_flow.py +++ b/lcm/ns/biz/ns_instantiate_flow.py @@ -16,7 +16,7 @@ import json import logging import traceback from threading import Thread - +from lcm.jobs.const import JOB_INSTANCE_URI from lcm.pub.utils.syscomm import fun_name from lcm.pub.utils.values import ignore_case_get from lcm.pub.utils import restcall @@ -173,7 +173,7 @@ def post_deal(ns_inst_id, status): def update_job(job_id, progress, errcode, desc): logger.debug("job_id %s" % job_id) - uri = "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id) + uri = JOB_INSTANCE_URI % job_id data = json.JSONEncoder().encode({ "progress": progress, "errcode": errcode, diff --git a/lcm/ns/biz/ns_terminate.py b/lcm/ns/biz/ns_terminate.py index b2776a69..53973d3e 100644 --- a/lcm/ns/biz/ns_terminate.py +++ b/lcm/ns/biz/ns_terminate.py @@ -17,6 +17,7 @@ import threading import time import traceback +from lcm.jobs.const import JOB_INSTANCE_RESPONSE_ID_URI from lcm.pub.database.models import NSInstModel, VLInstModel, FPInstModel, NfInstModel from lcm.pub.exceptions import NSLCMException from lcm.pub.msapi.nslcm import call_from_ns_cancel_resource @@ -169,7 +170,7 @@ class TerminateNsService(threading.Thread): while count < retry_count: count = count + 1 time.sleep(interval_second) - uri = "/api/nslcm/v1/jobs/%s?responseId=%s" % (vnf_job_id, response_id) + uri = JOB_INSTANCE_RESPONSE_ID_URI % (vnf_job_id, response_id) ret = restcall.req_by_msb(uri, "GET") if ret[0] != 0: logger.error("Failed to query job: %s:%s", ret[2], ret[1]) diff --git a/lcm/ns_vnfs/biz/verify_vnfs.py b/lcm/ns_vnfs/biz/verify_vnfs.py index 55f80e1c..386af337 100644 --- a/lcm/ns_vnfs/biz/verify_vnfs.py +++ b/lcm/ns_vnfs/biz/verify_vnfs.py @@ -17,7 +17,7 @@ import os import threading import traceback import time - +from lcm.jobs.const import JOB_INSTANCE_RESPONSE_ID_URI from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.jobutil import JobUtil from lcm.jobs.enum import JOB_TYPE, JOB_PROGRESS, JOB_ACTION @@ -136,7 +136,7 @@ class VerifyVnfs(threading.Thread): while count < retry_count: count = count + 1 time.sleep(interval_second) - ret = req_by_msb("/api/nslcm/v1/jobs/%s?responseId=%s" % (job_id, response_id), "GET") + ret = req_by_msb(JOB_INSTANCE_RESPONSE_ID_URI % (job_id, response_id), "GET") if ret[0] != 0: logger.error("Failed to query job: %s:%s", ret[2], ret[1]) continue diff --git a/lcm/workflows/build_in.py b/lcm/workflows/build_in.py index c508545f..14ce0732 100644 --- a/lcm/workflows/build_in.py +++ b/lcm/workflows/build_in.py @@ -16,7 +16,8 @@ import logging import traceback from threading import Thread import time - +from lcm.jobs.const import JOB_INSTANCE_URI, JOB_INSTANCE_RESPONSE_ID_URI +from lcm.jobs.enum import JOB_ERROR_CODE from lcm.pub.utils.syscomm import fun_name from lcm.pub.utils.values import ignore_case_get from lcm.pub.utils import restcall @@ -61,40 +62,40 @@ def run_ns_instantiate(input_data, occ_id): sdnc_id = ignore_case_get(input_data, "sdnControllerId") g_jobs_status[job_id] = [1 for i in range(vnf_count)] try: - update_job(job_id, 10, "true", "Start to create VL") + update_job(job_id, 10, JOB_ERROR_CODE.NO_ERROR, "Start to create VL") for i in range(vl_count): create_vl(ns_inst_id, i + 1, nsd_json, ns_param_json) - update_job(job_id, 30, "true", "Start to create VNF") + update_job(job_id, 30, JOB_ERROR_CODE.NO_ERROR, "Start to create VNF") jobs = [create_vnf(ns_inst_id, i + 1, vnf_param_json) for i in range(vnf_count)] wait_until_jobs_done(job_id, jobs) [confirm_vnf_status(inst_id) for inst_id, _, _ in jobs] - update_job(job_id, 50, "true", "Start to create PNF") + update_job(job_id, 50, JOB_ERROR_CODE.NO_ERROR, "Start to create PNF") create_pnf(pnf_param_json) - update_job(job_id, 70, "true", "Start to create SFC") + update_job(job_id, 70, JOB_ERROR_CODE.NO_ERROR, "Start to create SFC") g_jobs_status[job_id] = [1 for i in range(sfc_count)] jobs = [create_sfc(ns_inst_id, i + 1, nsd_json, sdnc_id) for i in range(sfc_count)] wait_until_jobs_done(job_id, jobs) [confirm_sfc_status(inst_id) for inst_id, _, _ in jobs] - 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, 100, 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.args[0]) - update_job(job_id, JOB_ERROR, "255", "Failded to Create NS.") + update_job(job_id, JOB_ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.") NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0]) 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_ERROR, JOB_ERROR_CODE.ERROR, "Failded to Create NS.") NsLcmOpOcc.update(occ_id, operationState="FAILED", error=e.args[0]) post_deal(ns_inst_id, "false") finally: @@ -181,7 +182,7 @@ def post_deal(ns_inst_id, status): def update_job(job_id, progress, errcode, desc): - uri = "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id) + uri = JOB_INSTANCE_URI % job_id data = json.JSONEncoder().encode({ "progress": progress, "errcode": errcode, @@ -211,7 +212,7 @@ class JobWaitThread(Thread): while count < self.retry_count: count = count + 1 time.sleep(self.interval_second) - uri = "/api/nslcm/v1/jobs/%s?responseId=%s" % (self.job_id, response_id) + uri = JOB_INSTANCE_RESPONSE_ID_URI % (self.job_id, response_id) ret = restcall.req_by_msb(uri, "GET") if ret[0] != 0: logger.error("Failed to query job: %s:%s", ret[2], ret[1]) diff --git a/lcm/workflows/graphflow/task/lcm_async_rest_task.py b/lcm/workflows/graphflow/task/lcm_async_rest_task.py index 2e3b6061..39fde43b 100644 --- a/lcm/workflows/graphflow/task/lcm_async_rest_task.py +++ b/lcm/workflows/graphflow/task/lcm_async_rest_task.py @@ -14,6 +14,7 @@ import logging import json +from lcm.jobs.const import JOB_INSTANCE_URI from lcm.workflows.graphflow.task.async_rest_task import ASyncRestTask from lcm.pub.utils import restcall @@ -26,7 +27,7 @@ class LcmASyncRestTask(ASyncRestTask): def __init__(self, *args): super(LcmASyncRestTask, self).__init__(*args) - self.job_url = "/api/nslcm/v1/jobs/%s" + # self.job_url = JOB_INSTANCE_URI def call_rest(self, url, method, content=None): ret = restcall.req_by_msb(url, method, content) @@ -37,7 +38,7 @@ class LcmASyncRestTask(ASyncRestTask): logger.debug("get_ext_status %s", self.key) job_status = None if job_id: - url = "/api/nslcm/v1/jobs/%s" % job_id + url = JOB_INSTANCE_URI % job_id status, job_result = self.call_rest(url, self.GET) if status in self.STATUS_OK: progress = job_result["responseDescriptor"]["progress"] diff --git a/lcm/workflows/tests.py b/lcm/workflows/tests.py index 08e3477e..460e351d 100644 --- a/lcm/workflows/tests.py +++ b/lcm/workflows/tests.py @@ -22,8 +22,8 @@ from rest_framework import status from lcm.pub.database.models import WFPlanModel from lcm.pub.utils import restcall -from lcm.workflows import build_in from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc +from lcm.workflows import build_in class WorkflowViewTest(unittest.TestCase): @@ -127,7 +127,7 @@ class WorkflowViewTest(unittest.TestCase): "progress": 100, "statusDescription": "ok" }}), '200'], - "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): + "/api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): [0, '{}', '201'], "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id): [0, '{}', '201'] @@ -161,7 +161,7 @@ class WorkflowViewTest(unittest.TestCase): "detail": "vl1", "vlId": "1" }), '201'], - "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): + "/api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): [0, '{}', '201'], "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id): [0, '{}', '201'] @@ -210,7 +210,7 @@ class WorkflowViewTest(unittest.TestCase): "progress": 100, "statusDescription": "ok" }}), '200'], - "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): + "/api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): [0, '{}', '201'], "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id): [0, '{}', '201'] |