separate ns-heal 34/75434/1
authortianxing <15210838572@139.com>
Tue, 8 Jan 2019 08:34:20 +0000 (16:34 +0800)
committertianxing <15210838572@139.com>
Tue, 8 Jan 2019 08:34:29 +0000 (16:34 +0800)
Change-Id: I29830708d28cae7b4a46c75c81d625505c9d60cd
Signed-off-by: tianxing <15210838572@139.com>
Issue-ID: VFC-1230

lcm/ns/serializers/heal_serializers.py
lcm/ns/serializers/ns_serializers.py
lcm/ns/tests/test_ns_heal.py
lcm/ns/views/heal_ns_view.py

index a8d43e4..a935fde 100644 (file)
 from rest_framework import serializers
 
 
+class ActionVmSerializer(serializers.Serializer):
+    vmid = serializers.CharField(help_text="ID of VM", required=False, allow_null=True, allow_blank=True)
+    vduid = serializers.CharField(help_text="ID of vdu", required=False, allow_null=True, allow_blank=True)
+    vmname = serializers.CharField(help_text="Name of VM", required=False, allow_null=True, allow_blank=True)
+
+
+class HealNsAdditionalParamsSerializer(serializers.Serializer):
+    action = serializers.CharField(help_text="Action of NS heal", required=False, allow_null=True, allow_blank=True)
+    actionvminfo = ActionVmSerializer(help_text="VM info of action", required=False, allow_null=True)
+
+
 class HealVnfDataSerializer(serializers.Serializer):
     vnfInstanceId = serializers.CharField(help_text="Identifies the VNF instance,", required=True)
     cause = serializers.CharField(help_text="Indicates the reason why a healing procedure is required",
                                   required=False, allow_null=True, allow_blank=True)
     additionalParams = serializers.DictField(help_text="Additional parameters passed by the NFVO as input to "
                                                        "the healing process",
-                                             child=serializers.CharField(help_text="KeyValue Pairs",
-                                                                         allow_blank=True),
-                                             required=False, allow_null=True)
+                                             child=HealNsAdditionalParamsSerializer(
+                                                 help_text="KeyValue Pairs"), required=False, allow_null=True)
 
 
 class HealNsDataSerializer(serializers.Serializer):
@@ -37,10 +47,7 @@ class HealNsDataSerializer(serializers.Serializer):
 
 
 class HealNsReqSerializer(serializers.Serializer):
-    healVnfData = serializers.ListField(help_text="Provides the information needed to heal a VNF. ",
-                                        child=HealVnfDataSerializer(
-                                            help_text="This type represents the information to heal a VNF"
-                                                      "that is part of an NS", required=True),
-                                        required=False, allow_null=True)
+    healVnfData = HealVnfDataSerializer(help_text="Data of heal VNF", required=False, allow_null=True,
+                                        many=True)
     healNsData = HealNsDataSerializer(help_text="Provides the information needed to heal an NS",
                                       required=False, allow_null=True)
index faeda6c..2e44b69 100644 (file)
@@ -145,38 +145,6 @@ class TerminateNsReqSerializer(serializers.Serializer):
     gracefulTerminationTimeout = serializers.CharField(help_text="Timeout of NS graceful termination", required=False, allow_null=True, allow_blank=True)
 
 
-class ActionVmSerializer(serializers.Serializer):
-    vmid = serializers.CharField(help_text="ID of VM", required=False, allow_null=True, allow_blank=True)
-    vduid = serializers.CharField(help_text="ID of vdu", required=False, allow_null=True, allow_blank=True)
-    vmname = serializers.CharField(help_text="Name of VM", required=False, allow_null=True, allow_blank=True)
-
-
-class HealNsAdditionalParamsSerializer(serializers.Serializer):
-    action = serializers.CharField(help_text="Action of NS heal", required=False, allow_null=True, allow_blank=True)
-    actionvminfo = ActionVmSerializer(help_text="VM info of action", required=False, allow_null=True)
-
-
-class HealVnfDataSerializer(serializers.Serializer):
-    vnfInstanceId = serializers.CharField(help_text="ID of VNF Instance", required=True)
-    cause = serializers.CharField(help_text="Cause of NS heal", required=False, allow_null=True, allow_blank=True)
-    additionalParams = HealNsAdditionalParamsSerializer(help_text="Additional params of NS heal", required=False, allow_null=True)
-
-
-class HealNsDataSerializer(serializers.Serializer):
-    degreeHealing = serializers.ChoiceField(help_text="degree of healing", choices=["HEAL_RESTORE", "HEAL_QOS", "HEAL_RESET", "PARTIAL_HEALING"], required=True)
-    actionsHealing = serializers.ListField(
-        help_text="A list of actions",
-        child=serializers.CharField(help_text="One action", required=True),
-        required=False)
-    healScript = serializers.CharField(help_text="script of NS heal", required=False, allow_null=True, allow_blank=True)
-    additionalParamsforNs = serializers.CharField(help_text="Addition params of NS heal", required=False, allow_null=True, allow_blank=True)
-
-
-class HealNsReqSerializer(serializers.Serializer):
-    healVnfData = HealVnfDataSerializer(help_text="Data of heal VNF", required=False, allow_null=True)
-    healNsData = HealNsDataSerializer(help_text="Data of heal NS", required=False, allow_null=True)
-
-
 class InstNsPostDealReqSerializer(serializers.Serializer):
     status = serializers.CharField(help_text="Status of NS Inst", required=True)
 
index 0707ebe..c4fbf98 100644 (file)
@@ -77,7 +77,7 @@ class TestHealNsViews(TestCase):
     def test_heal_vnf_url(self, mock_run):
 
         data = {
-            "healVnfData": {
+            "healVnfData": [{
                 "vnfInstanceId": self.nf_inst_id,
                 "cause": "vm is down",
                 "additionalParams": {
@@ -88,7 +88,7 @@ class TestHealNsViews(TestCase):
                         "vmname": "xgw-smp11"
                     }
                 }
-            }
+            }]
         }
 
         response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.ns_inst_id, data=data)
@@ -134,7 +134,7 @@ class TestHealNsViews(TestCase):
     def test_heal_vnf_thread(self, mock_start, mock_wait, mock_update):
 
         data = {
-            "healVnfData": {
+            "healVnfData": [{
                 "vnfInstanceId": self.nf_inst_id,
                 "cause": "vm is down",
                 "additionalParams": {
@@ -145,7 +145,7 @@ class TestHealNsViews(TestCase):
                         "vmname": "xgw-smp11"
                     }
                 }
-            }
+            }]
         }
 
         NSHealService(self.ns_inst_id, data, self.job_id).run()
@@ -182,7 +182,7 @@ class TestHealNsViews(TestCase):
         ns_inst_id = "2"
 
         data = {
-            "healVnfData": {
+            "healVnfData": [{
                 "vnfInstanceId": self.nf_inst_id,
                 "cause": "vm is down",
                 "additionalParams": {
@@ -192,7 +192,7 @@ class TestHealNsViews(TestCase):
                         "vmname": "xgw-smp11"
                     }
                 }
-            }
+            }]
         }
 
         response = self.client.post("/api/nslcm/v1/ns/%s/heal" % ns_inst_id, data=data)
index a0534e3..71242bc 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework.views import APIView
 from drf_yasg.utils import swagger_auto_schema
 
 from lcm.ns.biz.ns_heal import NSHealService
-from lcm.ns.serializers.ns_serializers import HealNsReqSerializer
+from lcm.ns.serializers.heal_serializers import HealNsReqSerializer
 from lcm.ns.serializers.ns_serializers import NsOperateJobSerializer
 from lcm.pub.exceptions import NSLCMException
 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE