"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
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({
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({
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({
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({
})
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
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:
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")
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")
sfc_status = ret[1]["sfcStatus"]
if sfc_status != "active":
raise NSLCMException("Status of SFC(%s) is not active" % sfc_inst_id)
-
-
-
-
-
-
-
# 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()
@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)
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')
"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):
mock_call_req.side_effect = side_effect
self.assertTrue(build_in.run_ns_instantiate(wf_input))
-
-
-
-
-
-
-
-
-
-
-
-