aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-26 13:09:42 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-26 13:09:42 +0800
commitd93dd62d48a6e8062a508c7252464afee800e8c4 (patch)
tree0a92a78e820f0fc2a08caef5bd57ac8389a0215e
parent71e81d2345760e3d193c584b3e73cce5270d6872 (diff)
Fix vfc-catalog/workflows pep8 issue
Change-Id: I6e12b5ce627bf100b69e615b8502867f60d1086a Issue-ID: VFC-456 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/workflows/auto_deploy.py2
-rw-r--r--lcm/workflows/build_in.py18
-rw-r--r--lcm/workflows/tests.py44
-rw-r--r--lcm/workflows/views.py5
4 files changed, 28 insertions, 41 deletions
diff --git a/lcm/workflows/auto_deploy.py b/lcm/workflows/auto_deploy.py
index 8813542b..4f19d804 100644
--- a/lcm/workflows/auto_deploy.py
+++ b/lcm/workflows/auto_deploy.py
@@ -19,6 +19,7 @@ from lcm.pub.msapi import activiti
logger = logging.getLogger(__name__)
+
def deploy_workflow_on_startup():
try:
if WFPlanModel.objects.filter():
@@ -35,4 +36,3 @@ def deploy_workflow_on_startup():
logger.info("Deploy workflow successfully.")
except:
logger.error(traceback.format_exc())
-
diff --git a/lcm/workflows/build_in.py b/lcm/workflows/build_in.py
index 426e0c0a..cbc21858 100644
--- a/lcm/workflows/build_in.py
+++ b/lcm/workflows/build_in.py
@@ -43,6 +43,8 @@ format of input_data
"sdnControllerId": uuid of SDN controller
}
"""
+
+
def run_ns_instantiate(input_data):
logger.debug("Enter %s, input_data is %s", fun_name(), input_data)
ns_instantiate_ok = False
@@ -116,6 +118,7 @@ def create_vl(ns_inst_id, vl_index, nsd, ns_param):
logger.debug("Create VL(%s) successfully.", vl_id)
+
def create_vnf(ns_inst_id, vnf_index, nf_param):
uri = "api/nslcm/v1/ns/vnfs"
data = json.JSONEncoder().encode({
@@ -135,6 +138,7 @@ def create_vnf(ns_inst_id, vnf_index, nf_param):
logger.debug("Create VNF(%s) started.", vnf_inst_id)
return vnf_inst_id, job_id, vnf_index - 1
+
def create_sfc(ns_inst_id, fp_index, nsd_json, sdnc_id):
uri = "api/nslcm/v1/ns/sfcs"
data = json.JSONEncoder().encode({
@@ -155,6 +159,7 @@ def create_sfc(ns_inst_id, fp_index, nsd_json, sdnc_id):
logger.debug("Create SFC(%s) started.", sfc_inst_id)
return sfc_inst_id, job_id, fp_index - 1
+
def post_deal(ns_inst_id, status):
uri = "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id)
data = json.JSONEncoder().encode({
@@ -166,6 +171,7 @@ def post_deal(ns_inst_id, status):
logger.error("Failed to call post_deal(%s): %s", ns_inst_id, ret[1])
logger.debug("Call post_deal(%s, %s) successfully.", ns_inst_id, status)
+
def update_job(job_id, progress, errcode, desc):
uri = "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id)
data = json.JSONEncoder().encode({
@@ -175,11 +181,11 @@ def update_job(job_id, progress, errcode, desc):
})
restcall.req_by_msb(uri, "POST", data)
+
class JobWaitThread(Thread):
"""
Job Wait
"""
-
def __init__(self, inst_id, job_id, ns_job_id, index):
Thread.__init__(self)
self.inst_id = inst_id
@@ -226,6 +232,7 @@ class JobWaitThread(Thread):
if job_end_normal:
g_jobs_status[self.ns_job_id][self.index] = 0
+
def wait_until_jobs_done(g_job_id, jobs):
job_threads = []
for inst_id, job_id, index in jobs:
@@ -239,6 +246,7 @@ def wait_until_jobs_done(g_job_id, jobs):
logger.error("g_jobs_status[%s]: %s", g_job_id, g_jobs_status[g_job_id])
raise NSLCMException("Some jobs failed!")
+
def confirm_vnf_status(vnf_inst_id):
uri = "api/nslcm/v1/ns/vnfs/{vnfInstId}".format(vnfInstId=vnf_inst_id)
ret = restcall.req_by_msb(uri, "GET")
@@ -250,6 +258,7 @@ def confirm_vnf_status(vnf_inst_id):
if vnf_status != "active":
raise NSLCMException("Status of VNF(%s) is not active" % vnf_inst_id)
+
def confirm_sfc_status(sfc_inst_id):
uri = "api/nslcm/v1/ns/sfcs/{sfcInstId}".format(sfcInstId=sfc_inst_id)
ret = restcall.req_by_msb(uri, "GET")
@@ -260,10 +269,3 @@ def confirm_sfc_status(sfc_inst_id):
sfc_status = ret[1]["sfcStatus"]
if sfc_status != "active":
raise NSLCMException("Status of SFC(%s) is not active" % sfc_inst_id)
-
-
-
-
-
-
-
diff --git a/lcm/workflows/tests.py b/lcm/workflows/tests.py
index f6597c5c..c74f44d1 100644
--- a/lcm/workflows/tests.py
+++ b/lcm/workflows/tests.py
@@ -12,18 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import unittest
import json
-import mock
import os
+import unittest
+
+import mock
from django.test import Client
from rest_framework import status
+from lcm.pub.database.models import WFPlanModel
from lcm.pub.utils import restcall
-from lcm.pub.database.models import WFPlanModel, JobStatusModel
-from lcm.pub.utils.jobutil import JobUtil
from lcm.workflows import build_in
+
class WorkflowViewTest(unittest.TestCase):
def setUp(self):
self.client = Client()
@@ -34,12 +35,13 @@ class WorkflowViewTest(unittest.TestCase):
@mock.patch.object(restcall, 'upload_by_msb')
def test_deploy_workflow(self, mock_upload_by_msb):
- mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode({
+ res_data = {
"status": "1",
"message": "2",
"deployedId": "3",
"processId": "4"
- }), '202']
+ }
+ mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode(res_data), '202']
response = self.client.post("/api/nslcm/v1/workflow",
{"filePath": os.path.abspath(__file__)}, format='json')
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
@@ -51,13 +53,13 @@ class WorkflowViewTest(unittest.TestCase):
mock_call_req.return_value = [0, json.JSONEncoder().encode({
"status": "1",
"message": "2"
- }), '202']
+ }), '202']
mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode({
"status": "2",
"message": "3",
"deployedId": "4",
"processId": "5"
- }), '202']
+ }), '202']
WFPlanModel(deployed_id="1", process_id="2", status="3", message="4").save()
response = self.client.post("/api/nslcm/v1/workflow",
{"filePath": os.path.abspath(__file__), "forceDeploy": "True"}, format='json')
@@ -93,37 +95,37 @@ class WorkflowViewTest(unittest.TestCase):
"result": "0",
"detail": "vl1",
"vlId": "1"
- }), '201'],
+ }), '201'],
"api/nslcm/v1/ns/vnfs":
[0, json.JSONEncoder().encode({
"vnfInstId": "2",
"jobId": "11"
- }), '201'],
+ }), '201'],
"api/nslcm/v1/ns/vnfs/2":
[0, json.JSONEncoder().encode({
"vnfStatus": "active"
- }), '201'],
+ }), '201'],
"api/nslcm/v1/ns/sfcs":
[0, json.JSONEncoder().encode({
"sfcInstId": "3",
"jobId": "111"
- }), '201'],
+ }), '201'],
"api/nslcm/v1/ns/sfcs/3":
[0, json.JSONEncoder().encode({
"sfcStatus": "active"
- }), '201'],
+ }), '201'],
"/api/nslcm/v1/jobs/11?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
- }}), '200'],
+ }}), '200'],
"/api/nslcm/v1/jobs/111?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
- }}), '200'],
+ }}), '200'],
"api/nslcm/v1/jobs/{jobId}".format(jobId=job_id):
[0, '{}', '201'],
"api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id):
@@ -135,15 +137,3 @@ class WorkflowViewTest(unittest.TestCase):
mock_call_req.side_effect = side_effect
self.assertTrue(build_in.run_ns_instantiate(wf_input))
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lcm/workflows/views.py b/lcm/workflows/views.py
index 41779e87..8e48acb2 100644
--- a/lcm/workflows/views.py
+++ b/lcm/workflows/views.py
@@ -57,8 +57,3 @@ def deploy_workflow(request, *args, **kwargs):
return Response(data={'error': str(sys.exc_info())}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
logger.debug("Leave %s", fun_name())
return Response(data={'msg': 'OK'}, status=status.HTTP_202_ACCEPTED)
-
-
-
-
-