Align grant request with SOL003. 41/65541/5
authorlaili <lai.li@zte.com.cn>
Mon, 10 Sep 2018 12:57:00 +0000 (20:57 +0800)
committerLi Lai <lai.li@zte.com.cn>
Tue, 11 Sep 2018 01:55:50 +0000 (01:55 +0000)
- Modify grant response in gvnfmdriver.
- Add some serializers.

Change-Id: I7bbdcc4627dbdaa1a4634a1e270fdacfd945b242
Issue-ID: VFC-1101
Signed-off-by: laili <lai.li@zte.com.cn>
gvnfmadapter/driver/interfaces/serializers.py
gvnfmadapter/driver/interfaces/tests.py
gvnfmadapter/driver/interfaces/views.py

index 457b0f0..517a974 100644 (file)
@@ -14,7 +14,6 @@
 
 from rest_framework import serializers
 
-
 LCM_OPERATION_TYPES = [
     "INSTANTIATE",
     "SCALE",
@@ -27,6 +26,7 @@ LCM_OPERATION_TYPES = [
     "MODIFY_INFO"
 ]
 
+
 LCM_OPERATION_STATE_TYPES = [
     "STARTING",
     "PROCESSING",
@@ -37,6 +37,7 @@ LCM_OPERATION_STATE_TYPES = [
     "ROLLED_BACK"
 ]
 
+
 VNFCS_CHANGE_TYPES = [
     "ADDED",
     "REMOVED",
@@ -63,6 +64,84 @@ VLS_CHANGE_TYPES = [
 ]
 
 
+class ResourceHandleSerializer(serializers.Serializer):
+    vimConnectionId = serializers.CharField(
+        help_text="Identifier of the VIM connection to manage the resource.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+    resourceProviderId = serializers.CharField(
+        help_text="Identifier of the entity responsible for the management of the resource.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+    resourceId = serializers.CharField(
+        help_text="Identifier of the resource in the scope of the VIM or the resource provider.",
+        required=True
+    )
+    vimLevelResourceType = serializers.CharField(
+        help_text="Type of the resource in the scope of the VIM or the resource provider.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+
+
+class ResourceDefinitionSerializer(serializers.Serializer):
+    id = serializers.CharField(
+        help_text="Identifier of this ResourceDefinition, unique at least within the scope of the GrantRequest.",
+        required=True
+    )
+    type = serializers.ChoiceField(
+        help_text="Type of the resource definition referenced.",
+        choices=["COMPUTE", "VL", "STORAGE", "LINKPORT"],
+        required=True
+    )
+    vduId = serializers.CharField(
+        help_text="Reference to the related VDU in the VNFD applicable to this resource.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+    resourceTemplateId = serializers.CharField(
+        help_text="Reference to a resource template(such as VnfVirtualLinkDesc) in the VNFD.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+    resource = ResourceHandleSerializer(
+        help_text="Resource information for an existing resource.",
+        required=False,
+        allow_null=True
+    )
+
+
+class ConstraintResourceRefSerializer(serializers.Serializer):
+    idType = serializers.ChoiceField(
+        help_text="The type of the identifier.",
+        choices=["RES_MGMT", "GRANT"],
+        required=True
+    )
+    resourceId = serializers.CharField(
+        help_text="An actual resource-management-level identifier(idType=RES_MGMT), or an identifier that references a ResourceDefinition(idType=GRANT).",
+        required=True
+    )
+    vimConnectionId = serializers.CharField(
+        help_text="",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+    resourceProviderId = serializers.CharField(
+        help_text="Identifier of the resource provider. It shall only be present when idType = RES_MGMT.",
+        required=False,
+        allow_null=True,
+        allow_blank=True
+    )
+
+
 class AdditionalParams(serializers.Serializer):
     sdncontroller = serializers.CharField(help_text="sdncontroller", required=False)
     NatIpRange = serializers.CharField(help_text="NatIpRange", required=False)
index c886be7..cefe884 100644 (file)
@@ -286,31 +286,50 @@ class InterfacesTest(TestCase):
                 }
             }
         }
-        grant_resp_data = {
-            "id": "1",
-            "vnfInstanceId": "1",
-            "vnfLcmOpOccId": "2",
-            "vimConnections": [
-                {
-                    "id": "1",
-                    "vimId": "1"
-                }
-            ]
+        grant = {
+            'id': 'Identifier of the garnt',
+            'vnfInstanceId': 'Identifier of the related VNF instance',
+            'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
+            'vimConnections': [],
+            'zones': [],
+            'zoneGroups': [],
+            'computeReservationId': None,
+            'networkReservationId': None,
+            'storageReservationId': None,
+            'addResources': None,
+            'tempResources': None,
+            'removeResource': None,
+            'updateResource': None,
+            'vimAssets': None,
+            'extVirtualLinks': None,
+            'extManagedVirtualLinks': None,
+            'additionalParams': {},
+            '_links': None
         }
-        mock_call_req.return_value = [0, json.JSONEncoder().encode(grant_resp_data), '201']
+
+        mock_call_req.return_value = [0, json.JSONEncoder().encode(grant), '201']
         response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
                                    data=json.dumps(data), content_type='application/json')
         self.assertEqual(status.HTTP_201_CREATED, response.status_code)
         expect_resp_data = {
-            "id": "1",
-            "vnfInstanceId": "1",
-            "vnfLcmOpOccId": "2",
-            "vimConnections": [
-                {
-                    "id": "1",
-                    "vimId": "1"
-                }
-            ]
+            'id': 'Identifier of the garnt',
+            'vnfInstanceId': 'Identifier of the related VNF instance',
+            'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
+            'vimConnections': [],
+            'zones': [],
+            'zoneGroups': [],
+            'computeReservationId': None,
+            'networkReservationId': None,
+            'storageReservationId': None,
+            'addResources': None,
+            'tempResources': None,
+            'removeResource': None,
+            'updateResource': None,
+            'vimAssets': None,
+            'extVirtualLinks': None,
+            'extManagedVirtualLinks': None,
+            'additionalParams': {},
+            '_links': None
         }
         self.assertDictEqual(expect_resp_data, response.data)
 
index a2972ad..dc9f3f6 100644 (file)
@@ -233,7 +233,7 @@ class VnfOperInfo(APIView):
 
 class VnfGrantInfo(APIView):
     @swagger_auto_schema(
-        request_body=VnfGrantReqSerializer(),
+        request_body=VnfGrantReqSerializer(),  # TODO: not used
         responses={
             status.HTTP_201_CREATED: VnfGrantRespSerializer(),
             status.HTTP_404_NOT_FOUND: "The request body is wrong",
@@ -268,7 +268,7 @@ class VnfNotifyInfo(APIView):
             status.HTTP_500_INTERNAL_SERVER_ERROR: "The url is invalid"
         }
     )
-    def post(self, request, vnfmtype):
+    def post(self, request, vnfmtype):  # TODO: not compatable with VnfIdentifierCreationNotification and VnfIdentifierDeletionNotification
         try:
             logger.debug("[%s]req_data = %s", fun_name(), request.data)
             vnfminstid = ignorcase_get(request.data, 'vnfmInstId')