summaryrefslogtreecommitdiffstats
path: root/zte/vmanager
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-08 18:17:54 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-08 18:17:54 +0800
commitaaab856ff0d985a7cf2dee20de98b737622a03d9 (patch)
treedd2ac81d264bdf3717516cd618925391bea888f6 /zte/vmanager
parent881fc75bb1f3770651331e3a6b2c57a3f1f9c8cd (diff)
Add ztevnfmdriver query job swagger
Change-Id: I8febb3d1861ebb36d276e0bcf72880a832ffba0d Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte/vmanager')
-rw-r--r--zte/vmanager/driver/interfaces/serializers.py12
-rw-r--r--zte/vmanager/driver/interfaces/tests.py25
-rw-r--r--zte/vmanager/driver/interfaces/views.py17
3 files changed, 30 insertions, 24 deletions
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py
index f024d224..0e061f33 100644
--- a/zte/vmanager/driver/interfaces/serializers.py
+++ b/zte/vmanager/driver/interfaces/serializers.py
@@ -20,7 +20,7 @@ class JobHistorySerializer(serializers.Serializer):
help_text="Status of job",
required=True,
allow_null=False)
- progress = serializers.CharField(
+ progress = serializers.IntegerField(
help_text="Progress of job",
required=True,
allow_null=False)
@@ -31,8 +31,8 @@ class JobHistorySerializer(serializers.Serializer):
errorCode = serializers.CharField(
help_text="Error code of job",
required=False,
- allow_null=True)
- responseId = serializers.CharField(
+ allow_blank=True)
+ responseId = serializers.IntegerField(
help_text="Response index of job",
required=True,
allow_null=False)
@@ -43,7 +43,7 @@ class JobDescriptorSerializer(serializers.Serializer):
help_text="Status of job",
required=True,
allow_null=False)
- progress = serializers.CharField(
+ progress = serializers.IntegerField(
help_text="Progress of job",
required=True,
allow_null=False)
@@ -54,8 +54,8 @@ class JobDescriptorSerializer(serializers.Serializer):
errorCode = serializers.CharField(
help_text="Error code of job",
required=False,
- allow_null=True)
- responseId = serializers.CharField(
+ allow_blank=True)
+ responseId = serializers.IntegerField(
help_text="Response index of job",
required=True,
allow_null=False)
diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py
index 13f181c7..a0f27d72 100644
--- a/zte/vmanager/driver/interfaces/tests.py
+++ b/zte/vmanager/driver/interfaces/tests.py
@@ -229,33 +229,32 @@ class InterfacesTest(TestCase):
"description": ""
}
resp_body = {
- "responsedescriptor": {
+ "responseDescriptor": {
"status": "processing",
- "responsehistorylist": [
+ "responseHistoryList": [
{
"status": "error",
"progress": 255,
- "errorcode": "",
- "responseid": 20,
- "statusdescription": "'JsonParser' object has no attribute 'parser_info'"}],
- "responseid": 21,
- "errorcode": "",
+ "errorCode": "",
+ "responseId": 20,
+ "statusDescription": "'JsonParser' object has no attribute 'parser_info'"}],
+ "responseId": 21,
+ "errorCode": "",
"progress": 40,
- "statusdescription": "Create nf apply resource failed"},
- "jobid": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9"}
+ "statusDescription": "Create nf apply resource failed"},
+ "jobId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9"}
r1 = [0, json.JSONEncoder().encode(vnfm_info), '200']
r2 = [0, json.JSONEncoder().encode(resp_body), '200']
mock_call_req.side_effect = [r1, r2]
response = self.client.get(
"/api/ztevnfmdriver/v1/{vnfmid}/jobs/{jobid}?responseId={responseId}".format(
vnfmid=vnfm_info["vnfmId"],
- jobid=resp_body["jobid"],
- responseId=resp_body["responsedescriptor"]["responseid"]))
+ jobid=resp_body["jobId"],
+ responseId=resp_body["responseDescriptor"]["responseId"]))
self.assertEqual(status.HTTP_200_OK, response.status_code)
- expect_resp_data = resp_body
- self.assertDictEqual(expect_resp_data, response.data)
+ self.assertDictEqual(resp_body, response.data)
@mock.patch.object(restcall, 'call_req')
def test_grantvnf_005(self, mock_call_req):
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 89d8e48f..c664219e 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -236,25 +236,32 @@ class JobView(APIView):
logger.debug("[%s] request.data=%s", fun_name(), request.data)
ret = get_vnfminfo_from_nslcm(vnfmid)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
vnfm_info = json.JSONDecoder().decode(ret[1])
logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
operation_status_url = '/v1/jobs/{jobId}?NFVOID={nfvoId}&VNFMID={vnfmId}&ResponseID={responseId}'
+ responseId = ignorcase_get(request.GET, 'responseId')
+ query_url = operation_status_url.format(jobId=jobid, nfvoId=1, vnfmId=vnfmid, responseId=responseId)
ret = restcall.call_req(
base_url=ignorcase_get(vnfm_info, 'url'),
user=ignorcase_get(vnfm_info, 'userName'),
passwd=ignorcase_get(vnfm_info, 'password'),
auth_type=restcall.rest_no_auth,
- resource=operation_status_url.format(jobId=jobid, nfvoId=1, vnfmId=vnfmid,
- responseId=ignorcase_get(request.GET, 'responseId')),
+ resource=query_url,
method='get',
content={})
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
resp_data = json.JSONDecoder().decode(ret[1])
logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- return Response(data=resp_data, status=ret[2])
+ jobQueryRespSerializer = JobQueryRespSerializer(data=resp_data)
+ if not jobQueryRespSerializer.is_valid():
+ raise Exception(jobQueryRespSerializer.errors)
+
+ return Response(data=jobQueryRespSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
logger.error("Error occurred when getting operation status information,error:%s", e.message)
logger.error(traceback.format_exc())