diff options
-rw-r--r-- | lcm/ns/serializers/create_ns_serializers.py | 145 | ||||
-rw-r--r-- | lcm/ns/serializers/ns_serializers.py | 16 | ||||
-rw-r--r-- | lcm/ns/tests/test_ns_create.py | 14 | ||||
-rw-r--r-- | lcm/ns/views/create_ns_view.py | 11 |
4 files changed, 59 insertions, 127 deletions
diff --git a/lcm/ns/serializers/create_ns_serializers.py b/lcm/ns/serializers/create_ns_serializers.py index 64f5e9d2..3128f1d1 100644 --- a/lcm/ns/serializers/create_ns_serializers.py +++ b/lcm/ns/serializers/create_ns_serializers.py @@ -43,17 +43,15 @@ class IpOverEthernetAddressDataSerializer(serializers.Serializer): ipAddresses = serializers.ListField(help_text="List of IP addresses to assign to the extCP instance.", child=IpAddress( help_text="List of IP addresses to assign to the extCP instance.", - required=True), required=False, allow_null=True) + required=True), required=False, allow_null=True, ) class cpProtocolDataSerializer(serializers.Serializer): layerProtocol = serializers.ChoiceField(help_text="Identifier of layer(s) and protocol(s).", choices=["IP_OVER_ETHERNET"], required=True) - ipOverEthernet = serializers.ListField(help_text="Network address data for IP over Ethernet to assign to" - "the extCP instance.", - child=(IpOverEthernetAddressDataSerializer( - help_text="This typerepresents network address data for IP" - "over Ethernet.", required=True)), required=True) + ipOverEthernet = IpOverEthernetAddressDataSerializer(help_text="Network address data for IP over Ethernet" + " to assign to the extCP instance.", + required=True, many=True) class PnfExtCpInfoSerializer(serializers.Serializer): @@ -63,11 +61,8 @@ class PnfExtCpInfoSerializer(serializers.Serializer): cpdId = serializers.CharField(help_text="Identifier of (reference to) the Connection Point Descriptor" "(CPD) for this CP.", required=True) - cpProtocolData = serializers.ListField(help_text="Parameters for configuring the network protocols on" - "the CP.", - child=(cpProtocolDataSerializer(help_text="This type represents" - "network protocol data", - required=True)), required=True) + cpProtocolData = cpProtocolDataSerializer(help_text="Parameters for configuring the network protocols on" + "the CP.", required=True, many=True) class PnfInfoSerializer(serializers.Serializer): @@ -81,11 +76,8 @@ class PnfInfoSerializer(serializers.Serializer): pnfProfileId = serializers.CharField(help_text="Identifier of the related PnfProfile in the NSD on which " "the PNF is based.", required=True) - cpInfo = serializers.ListField(help_text="Information on the external CP of the PNF", - child=(PnfExtCpInfoSerializer(help_text="This type represents the" - "information about the external " - "CP of the PNF.", required=True)), - required=True) + cpInfo = PnfExtCpInfoSerializer(help_text="Information on the external CP of the PNF", + required=True, many=True) class ResourceHandleSerializer(serializers.Serializer): @@ -104,13 +96,9 @@ class ResourceHandleSerializer(serializers.Serializer): class NsVirtualLinkInfoSerializer(serializers.Serializer): id = serializers.CharField(help_text="Identifier of the VL instance.", required=True) nsVirtualLinkDescId = serializers.CharField(help_text="Identifier of the VLD in the NSD.", required=True) - resourceHandle = serializers.ListField(help_text="Identifier(s) of the virtualised network resource(s) " - "realizing the VL instance", - child=(ResourceHandleSerializer( - help_text="This type represents the information that allows" - "addressing a virtualised resource that is used by a" - "VNF instance or by an NS instance.", - required=True)), required=True) + resourceHandle = ResourceHandleSerializer(help_text="Identifier(s) of the virtualised network resource(s)" + " realizing the VL instance", + required=True, many=True) class NsCpHandleSerializer(serializers.Serializer): @@ -129,7 +117,6 @@ class NsCpHandleSerializer(serializers.Serializer): "instance.", required=False, allow_null=True) -# end 167 class MaskSerializer(serializers.Serializer): startingPoint = serializers.CharField(help_text="Indicates the offset between the last bit of the source" "mac address and the first bit of the sequence of bits" @@ -164,13 +151,8 @@ class NfpRuleSerializer(serializers.Serializer): destinationIpAddressPrefix = serializers.CharField(help_text="Indicates the destination IP address range" "in CIDRformat.", required=False, allow_null=True) - extendedCriteria = serializers.ListField(help_text="Indicates values of specific bits in a frame", - child=(MaskSerializer(help_text="The Mask data type identifies" - "the value to be matched for a" - "sequence of bits at a particular" - " location in a frame", - required=True)), - required=False, allow_null=True) + extendedCriteria = MaskSerializer(help_text="Indicates values of specific bits in a frame", + required=False, allow_null=True, many=True) class NfpInfoSerializer(serializers.Serializer): @@ -180,12 +162,9 @@ class NfpInfoSerializer(serializers.Serializer): nfpName = serializers.CharField(help_text="Human readable name for the NFP instance.", required=False, allow_null=True) description = serializers.CharField(help_text="Human readable description for the NFP instance.", - required=False, allow_null=True) - nscpHandle = serializers.ListField(help_text="Identifier(s) of the CPs and/or SAPs which the NFP " - "passes by", - child=NsCpHandleSerializer( - help_text="This type represents an identifier of the CP or SAP" - "instance"), required=True) + required=True) + nscpHandle = NsCpHandleSerializer(help_text="Identifier(s) of the CPs and/or SAPs which the NFP " + "passes by", required=True, many=True) totalCp = serializers.CharField(help_text="Total number of CP and SAP instances in this NFP" "instance.", required=False, allow_null=True) nfpRule = NfpRuleSerializer(help_text="The NfpRule data type is an expression of the conditions that " @@ -210,16 +189,11 @@ class VnffgInfoSerializer(serializers.Serializer): "thisVNFFG instance.", child=serializers.CharField( help_text="ID of ns virtual link info"), required=True) - nsCpHandle = serializers.ListField(help_text="Identifiers of the CP instances attached to the constituent" - "VNFs and PNFs or the SAP instances of the VNFFG.", - child=NsCpHandleSerializer(help_text="This type represents an" - "identifier of the CP or SAP" - "instance", required=False), - required=True, allow_null=False) - nfpInfo = serializers.ListField(help_text="Information on the NFP instances.", - child=(NfpInfoSerializer(help_text="This type represents an NFP instance", - - required=True)), required=True, allow_null=False) + nsCpHandle = NsCpHandleSerializer(help_text="Identifiers of the CP instances attached to the " + "constituent VNFs and PNFs or the SAP instances of " + "the VNFFG.", required=True, allow_null=False, many=True) + nfpInfo = NfpInfoSerializer(help_text="Information on the NFP instances.", + required=True, allow_null=False, many=True) class AddressRange(serializers.Serializer): @@ -248,10 +222,8 @@ class ipAddressesSerializer(serializers.Serializer): class IpOverEthernetAddressInfoSerializer(serializers.Serializer): macAddress = serializers.CharField(help_text="Assigned MAC address", required=True) - ipAddresses = serializers.ListField(help_text="Addresses assigned to the CP or SAP instance.", - child=(ipAddressesSerializer(help_text="Serializer of ip addresses", - required=True)), - required=False, allow_null=True) + ipAddresses = ipAddressesSerializer(help_text="Addresses assigned to the CP or SAP instance.", + required=False, allow_null=True, many=True) class CpProtocolInfoSerializer(serializers.Serializer): @@ -269,11 +241,8 @@ class SapInfoSerializer(serializers.Serializer): sapName = serializers.CharField(help_text="Human readable name for the SAP instance.", required=True) description = serializers.CharField(help_text="Human readable description for the SAP instance.", required=True) - sapProtocolInfo = serializers.ListField(help_text="Network protocol information for this SAP.", - child=(CpProtocolInfoSerializer( - help_text="This type describes the protocol layer(s) that a" - "CP or SAP uses together with protocol-related" - "information", required=True)), required=True) + sapProtocolInfo = CpProtocolInfoSerializer(help_text="Network protocol information for this SAP.", + required=True, many=True) class NsScaleInfoSerializer(serializers.Serializer): @@ -321,62 +290,30 @@ class CreateNsRespSerializer(serializers.Serializer): required=True) nsdInfoId = serializers.CharField(help_text="Identifier of the NSD information object on which the " "NS instance is based.", required=True) - flavourId = serializers.CharField(help_text="Identifier of the NS deployment flavour applied to " "the NS instance.", required=False, allow_null=True) - vnfInstance = serializers.ListField(help_text="Information on constituent VNF(s) of the NS instance.", - child=(VnfInstanceSerializer(help_text="This type represents a VNF" - "instance", required=True)), - required=False, allow_null=True) - - pnfInfo = serializers.ListField(help_text="Information on the PNF(s) that are part of the NS instance.", - child=(PnfInfoSerializer(help_text="This type represents the information " - "about a PNF that is part of an NS instance.", required=True)), - required=False, allow_null=True) - virtualLinkInfo = serializers.ListField(help_text="Information on the VL(s) of the NS instance.", - child=(NsVirtualLinkInfoSerializer(help_text="This type specifies the" - "information about an" - "NS VL instance.", - required=True)), required=False, - allow_null=True) - vnffgInfo = serializers.ListField(help_text="Information on the VNFFG(s) of the NS instance", - child=(VnffgInfoSerializer(help_text="This type specifies the information" - "about a VNFFG instance.", required=True)), - required=False, allow_null=True) - sapInfo = serializers.ListField(help_text="Information on the SAP(s) of the NS instance", - child=(SapInfoSerializer(help_text="This type represents an SAP" - "instance.", required=True)), - required=False, allow_null=True) + vnfInstance = VnfInstanceSerializer(help_text="Information on constituent VNF(s) of the NS instance.", + required=False, allow_null=True, many=True) + + pnfInfo = PnfInfoSerializer(help_text="Information on the PNF(s) that are part of the NS instance.", + required=False, allow_null=True, many=True) + virtualLinkInfo = NsVirtualLinkInfoSerializer(help_text="Information on the VL(s) of the NS instance.", + required=False, allow_null=True, many=True) + vnffgInfo = VnffgInfoSerializer(help_text="Information on the VNFFG(s) of the NS instance", + required=False, allow_null=True, many=True) + sapInfo = SapInfoSerializer(help_text="Information on the SAP(s) of the NS instance", + required=False, allow_null=True, many=True) nestedNsInstanceId = serializers.ListField(help_text="Identifier of the nested NS(s) of the NS instance.", child=serializers.CharField(help_text="nested of the NS" "instance",), required=False, allow_null=True) nsState = serializers.ChoiceField(help_text="The state of the NS instance.", required=True, choices=["NOT_INSTANTIATED", "INSTANTIATED"]) - nsScaleStatus = serializers.ListField(help_text="Status of each NS scaling aspect declared in the" + nsScaleStatus = NsScaleInfoSerializer(help_text="Status of each NS scaling aspect declared in the" "applicable DF, how 'big' the NS instance has been" "scaled w.r.t. that aspect.", - child=(NsScaleInfoSerializer(help_text="This type represents the" - "target NS Scale level for" - "each NS scaling aspect of" - "the current deployment" - "flavour.")), required=False, - allow_null=True) - additionalAffinityOrAntiAffinityRule = serializers.ListField(help_text="Information on the additional" - "affinity or anti-affinity rule" - "from NS instantiation operation.", - child=(AffinityOrAntiAffinityRuleSerializer( - help_text="This type describes the " - "additional affinity or" - "anti-affinity rule applicable" - "between the VNF instances to" - "be instantiated in the NS" - "instantiation operation" - "request or between the VNF" - "instances to be instantiated" - "in the NS instantiation" - "operation request and the" - "existing VNF instances.", - required=True)), required=False, - allow_null=True) + required=False, allow_null=True, many=True) + additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer( + help_text="Information on the additional affinity or anti-affinity rule from NS instantiation " + "operation.", required=False, allow_null=True, many=True) _links = Links(help_text="Links to resources related to this resource.", required=True) diff --git a/lcm/ns/serializers/ns_serializers.py b/lcm/ns/serializers/ns_serializers.py index 2e44b696..322facb4 100644 --- a/lcm/ns/serializers/ns_serializers.py +++ b/lcm/ns/serializers/ns_serializers.py @@ -16,22 +16,6 @@ from rest_framework import serializers from lcm.ns_pnfs.serializers.pnf_serializer import PnfInstanceSerializer -class ContextSerializer(serializers.Serializer): - globalCustomerId = serializers.CharField(help_text="Global customer ID", required=False, allow_null=True, allow_blank=True) - serviceType = serializers.CharField(help_text="Service type", required=False, allow_null=True, allow_blank=True) - - -class CreateNsReqSerializer(serializers.Serializer): - csarId = serializers.CharField(help_text="Package ID of NS", required=False, allow_null=True, allow_blank=True) - nsName = serializers.CharField(help_text="Name of NS", required=False, allow_null=True, allow_blank=True) - description = serializers.CharField(help_text="Description of NS", required=False, allow_null=True, allow_blank=True) - context = ContextSerializer(help_text="Context of NS", required=False) - - -class CreateNsRespSerializer(serializers.Serializer): - nsInstanceId = serializers.CharField(help_text="ID of NS instance", required=True) - - class VnfInstSerializer(serializers.Serializer): vnfInstanceId = serializers.CharField(help_text="ID of VNF instance", required=True) vnfInstanceName = serializers.CharField(help_text="Name of VNF instance", required=False, allow_null=True, allow_blank=True) diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py index db14da3c..e32d7e48 100644 --- a/lcm/ns/tests/test_ns_create.py +++ b/lcm/ns/tests/test_ns_create.py @@ -51,7 +51,8 @@ class TestNsInstantiate(TestCase): }, "csarId": self.nsd_id, "nsName": "ns", - "description": "description" + "nsDescription": "description", + 'nsdId': 'nsdId' } response = self.client1.post("/api/nslcm/v1/ns", data=data, format='json') self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code) @@ -59,7 +60,9 @@ class TestNsInstantiate(TestCase): @mock.patch.object(CreateNSService, "do_biz") def test_create_ns_empty_data(self, mock_do_biz): mock_do_biz.side_effect = Exception("Exception in CreateNS.") - data = {} + data = { + 'nsdId': 'nsdId' + } response = self.client.post("/api/nslcm/v1/ns", data=data) self.assertEqual(response.data["error"], "Exception in CreateNS.") self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -72,7 +75,8 @@ class TestNsInstantiate(TestCase): data = { 'csarId': new_nsd_id, 'nsName': 'ns', - 'description': 'description' + 'nsDescription': 'description', + 'nsdId': 'nsdId' } response = self.client.post("/api/nslcm/v1/ns", data=data) self.assertEqual(response.data["error"], "nsd not exists.") @@ -85,7 +89,7 @@ class TestNsInstantiate(TestCase): data = { 'csarId': '1', 'nsName': 'ns', - 'description': 'description' + 'nsDescription': 'description' } response = self.client.post("/api/nslcm/v1/ns", data=data) self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -102,7 +106,7 @@ class TestNsInstantiate(TestCase): data = { 'csarId': '1', 'nsName': 'ns1', - 'description': 'description' + 'nsDescription': 'description' } response = self.client.post("/api/nslcm/v1/ns", data=data) self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/ns/views/create_ns_view.py b/lcm/ns/views/create_ns_view.py index 14bd829d..6aae1f86 100644 --- a/lcm/ns/views/create_ns_view.py +++ b/lcm/ns/views/create_ns_view.py @@ -21,7 +21,7 @@ from drf_yasg.utils import swagger_auto_schema from lcm.ns.biz.ns_create import CreateNSService from lcm.ns.biz.ns_get import GetNSInfoService -from lcm.ns.serializers.ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer +from lcm.ns.serializers.create_ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer from lcm.ns.serializers.ns_serializers import QueryNsRespSerializer from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.values import ignore_case_get @@ -74,7 +74,14 @@ class CreateNSView(APIView): ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz() logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id) - resp_serializer = CreateNsRespSerializer(data={'nsInstanceId': ns_inst_id}) + resp_serializer = CreateNsRespSerializer( + data={'nsInstanceId': ns_inst_id, + 'nsInstanceName': 'nsInstanceName', + 'nsInstanceDescription': 'nsInstanceDescription', + 'nsdId': 123, + 'nsdInfoId': 456, + 'nsState': 'NOT_INSTANTIATED', + '_links': {'self': {'href': 'href'}}}) if not resp_serializer.is_valid(): raise NSLCMException(resp_serializer.errors) return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) |