summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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())