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):
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)
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)
def test_heal_vnf_url(self, mock_run):
data = {
- "healVnfData": {
+ "healVnfData": [{
"vnfInstanceId": self.nf_inst_id,
"cause": "vm is down",
"additionalParams": {
"vmname": "xgw-smp11"
}
}
- }
+ }]
}
response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.ns_inst_id, data=data)
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": {
"vmname": "xgw-smp11"
}
}
- }
+ }]
}
NSHealService(self.ns_inst_id, data, self.job_id).run()
ns_inst_id = "2"
data = {
- "healVnfData": {
+ "healVnfData": [{
"vnfInstanceId": self.nf_inst_id,
"cause": "vm is down",
"additionalParams": {
"vmname": "xgw-smp11"
}
}
- }
+ }]
}
response = self.client.post("/api/nslcm/v1/ns/%s/heal" % ns_inst_id, data=data)
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