summaryrefslogtreecommitdiffstats
path: root/zte
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-06 19:07:52 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-06 19:07:52 +0800
commit7a5549f8a1da26d13cd5bb3e861f4ee6ea77be7e (patch)
treeea17b769e292a34a8d9ed7d09b93bf01a15ac199 /zte
parentbbca42c0dc51dbffaa06ce376aef15fa7b7c850d (diff)
Add vfc-ztevnfmdriver heal auto-swagger
Change-Id: Id9dbcfd9a9d275d3b700b8d9a8599409684d72f6 Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte')
-rw-r--r--zte/vmanager/driver/interfaces/serializers.py3
-rw-r--r--zte/vmanager/driver/interfaces/tests.py6
-rw-r--r--zte/vmanager/driver/interfaces/views.py14
3 files changed, 14 insertions, 9 deletions
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py
index 70a6541a..2e601185 100644
--- a/zte/vmanager/driver/interfaces/serializers.py
+++ b/zte/vmanager/driver/interfaces/serializers.py
@@ -19,8 +19,7 @@ class AffectedvmSerializer(serializers.Serializer):
extention = serializers.CharField(
help_text="extention",
max_length=255,
- required=True,
- allow_null=True)
+ required=True, allow_blank=True)
vmid = serializers.CharField(
help_text="vmid",
max_length=255,
diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py
index da414847..24c7fbdf 100644
--- a/zte/vmanager/driver/interfaces/tests.py
+++ b/zte/vmanager/driver/interfaces/tests.py
@@ -473,10 +473,8 @@ class InterfacesTest(TestCase):
'isgrace': 'force'
}
- response = self.client.post(
- "/api/ztevnfmdriver/v1/200/vnfs/201/heal",
- data=json.dumps(heal_vnf_data),
- content_type='application/json')
+ response = self.client.post("/api/ztevnfmdriver/v1/200/vnfs/201/heal", data=json.dumps(heal_vnf_data),
+ content_type='application/json')
self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertDictEqual(job_info, response.data)
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index cd51c694..485657e2 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -450,13 +450,17 @@ class Heal(APIView):
try:
logger.info("request.data = %s", request.data)
logger.info("requested_url = %s", request.get_full_path())
+ healReqSerializer = HealReqSerializer(data=request.data)
+ if not healReqSerializer.is_valid():
+ raise Exception(healReqSerializer.errors)
+
ret = get_vnfminfo_from_nslcm(vnfmid)
if ret[0] != 0:
return Response(data={'error': ret[1]}, status=ret[2])
vnfm_info = json.JSONDecoder().decode(ret[1])
data = {}
- data['action'] = ignorcase_get(request.data, 'action')
- affectedvm = ignorcase_get(request.data, 'affectedvm')
+ data['action'] = ignorcase_get(healReqSerializer.data, 'action')
+ affectedvm = ignorcase_get(healReqSerializer.data, 'affectedvm')
data['affectedvm'] = []
if isinstance(affectedvm, list):
data['affectedvm'] = affectedvm
@@ -479,7 +483,11 @@ class Heal(APIView):
raise Exception('heal error')
resp_data = json.JSONDecoder().decode(ret[1])
logger.info("resp_data=%s", resp_data)
- return Response(data=resp_data, status=status.HTTP_202_ACCEPTED)
+ healRespSerializer = HealRespSerializer(data=resp_data)
+ if not healRespSerializer.is_valid():
+ raise Exception(healRespSerializer.errors)
+
+ return Response(data=healRespSerializer.data, status=status.HTTP_202_ACCEPTED)
except Exception as e:
logger.error("Error occurred when healing VNF,error:%s", e.message)
logger.error(traceback.format_exc())