Change-Id: I6e12b5ce627bf100b69e615b8502867f60d1086a
Issue-ID: VFC-456
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
def deploy_workflow_on_startup():
try:
if WFPlanModel.objects.filter():
def deploy_workflow_on_startup():
try:
if WFPlanModel.objects.filter():
logger.info("Deploy workflow successfully.")
except:
logger.error(traceback.format_exc())
logger.info("Deploy workflow successfully.")
except:
logger.error(traceback.format_exc())
"sdnControllerId": uuid of SDN controller
}
"""
"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
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)
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({
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
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({
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
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({
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)
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({
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)
})
restcall.req_by_msb(uri, "POST", data)
class JobWaitThread(Thread):
"""
Job Wait
"""
class JobWaitThread(Thread):
"""
Job Wait
"""
def __init__(self, inst_id, job_id, ns_job_id, index):
Thread.__init__(self)
self.inst_id = inst_id
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
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:
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!")
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")
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)
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")
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)
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.
# See the License for the specific language governing permissions and
# limitations under the License.
+import unittest
+
+import mock
from django.test import Client
from rest_framework import status
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.utils import restcall
-from lcm.pub.database.models import WFPlanModel, JobStatusModel
-from lcm.pub.utils.jobutil import JobUtil
from lcm.workflows import build_in
from lcm.workflows import build_in
class WorkflowViewTest(unittest.TestCase):
def setUp(self):
self.client = Client()
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.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({
"status": "1",
"message": "2",
"deployedId": "3",
"processId": "4"
"status": "1",
"message": "2",
"deployedId": "3",
"processId": "4"
+ }
+ 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)
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"
mock_call_req.return_value = [0, json.JSONEncoder().encode({
"status": "1",
"message": "2"
mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode({
"status": "2",
"message": "3",
"deployedId": "4",
"processId": "5"
mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode({
"status": "2",
"message": "3",
"deployedId": "4",
"processId": "5"
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')
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"
"result": "0",
"detail": "vl1",
"vlId": "1"
"api/nslcm/v1/ns/vnfs":
[0, json.JSONEncoder().encode({
"vnfInstId": "2",
"jobId": "11"
"api/nslcm/v1/ns/vnfs":
[0, json.JSONEncoder().encode({
"vnfInstId": "2",
"jobId": "11"
"api/nslcm/v1/ns/vnfs/2":
[0, json.JSONEncoder().encode({
"vnfStatus": "active"
"api/nslcm/v1/ns/vnfs/2":
[0, json.JSONEncoder().encode({
"vnfStatus": "active"
"api/nslcm/v1/ns/sfcs":
[0, json.JSONEncoder().encode({
"sfcInstId": "3",
"jobId": "111"
"api/nslcm/v1/ns/sfcs":
[0, json.JSONEncoder().encode({
"sfcInstId": "3",
"jobId": "111"
"api/nslcm/v1/ns/sfcs/3":
[0, json.JSONEncoder().encode({
"sfcStatus": "active"
"api/nslcm/v1/ns/sfcs/3":
[0, json.JSONEncoder().encode({
"sfcStatus": "active"
"/api/nslcm/v1/jobs/11?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
"/api/nslcm/v1/jobs/11?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
"/api/nslcm/v1/jobs/111?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
"/api/nslcm/v1/jobs/111?responseId=0":
[0, json.JSONEncoder().encode({"responseDescriptor": {
"responseId": "1",
"progress": 100,
"statusDescription": "ok"
"api/nslcm/v1/jobs/{jobId}".format(jobId=job_id):
[0, '{}', '201'],
"api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id):
"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))
mock_call_req.side_effect = side_effect
self.assertTrue(build_in.run_ns_instantiate(wf_input))
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)
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)