)
resource = ConstraintResourceRefSerializer(
help_text="References to resources in the constraint rule.",
- many=True
+ many=True,
+ required=False
)
class VimConstraintSerializer(serializers.Serializer):
sameResourceGroup = serializers.BooleanField(
help_text="Set to true when the constraint applies not only to the same VIM connection, but also to the same infrastructure resource group.",
- required=False,
- allow_null=True
+ required=False
)
resource = ConstraintResourceRefSerializer(
help_text="References to resources in the constraint rule.",
- many=True
+ many=True,
+ required=False
)
)
addResources = ResourceDefinitionSerializer(
help_text="List of resource definitions in the VNFD for resources to be added by the LCM operation.",
- many=True
+ many=True,
+ required=False
)
tempResources = ResourceDefinitionSerializer(
help_text="List of resource definitions in the VNFD for resources to be temporarily instantiated during the runtime of the LCM operation.",
- many=True
+ many=True,
+ required=False
)
removeResources = ResourceDefinitionSerializer(
help_text="Provides the definitions of resources to be removed by the LCM operation.",
- many=True
+ many=True,
+ required=False
)
updateResources = ResourceDefinitionSerializer(
help_text="Provides the definitions of resources to be modified by the LCM operation.",
- many=True
+ many=True,
+ required=False
)
placementConstraints = PlacementConstraintSerializer(
help_text="Placement constraints that the VNFM may send to the NFVO in order to influence the resource placement decision.",
- many=True
+ many=True,
+ required=False
)
vimConstraints = VimConstraintSerializer(
help_text="Used by the VNFM to require that multiple resources are managed through the same VIM connection.",
- many=True
+ many=True,
+ required=False
)
additionalParams = serializers.DictField(
help_text="Additional parameters passed by the VNFM.",
)
_links = GrantRequestLinksSerializer(
help_text="Links to resources related to this request.",
- required=True
+ required=False
)
class VimAssetsSerializer(serializers.Serializer):
computeResourceFlavours = VimComputeResourceFlavourSerializer(
help_text="Mappings between virtual compute descriptors defined in the VNFD and compute resource flavours managed in the VIM.",
- many=True
+ many=True,
+ required=False
)
softwareImages = VimSoftwareImageSerializer(
help_text="Mappings between software images defined in the VNFD and software images managed in the VIM.",
- many=True
+ many=True,
+ required=False
)
)
ipAddresses = IpAddresseSerializer(
help_text="List of IP addresses to assign to the CP instance.",
- many=True
+ many=True,
+ required=False
)
)
cpProtocolData = CpProtocolDataSerializer(
help_text="Parameters for configuring the network protocols on the link port that connects the CP to a VL.",
- many=True
+ many=True,
+ required=False
)
)
cpConfig = VnfExtCpConfigSerializer(
help_text="List of instance data that need to be configured on the CP instances created from the respective CPD.",
- many=True
+ many=True,
+ required=False
)
)
extCps = VnfExtCpDataSerializer(
help_text="External CPs of the VNF to be connected to this external VL.",
- many=True
+ many=True,
+ required=False
)
extLinkPorts = ExtLinkPortDataSerializer(
help_text="Externally provided link ports to be used to connect external connection points to this external VL.",
- many=True
+ many=True,
+ required=False
)
)
vimConnections = VimConnectionInfoSerializer(
help_text="Provides information regarding VIM connections that are approved to be used by the VNFM to allocate resources.",
- many=True
+ many=True,
+ required=False
)
zones = ZoneInfoSerializer(
help_text="Identifies resource zones where the resources are approved to be allocated by the VNFM.",
- many=True
+ many=True,
+ required=False
)
zoneGroups = ZoneGroupInfoSerializer(
help_text="Information about groups of resource zones.",
- many=True
+ many=True,
+ required=False
)
computeReservationId = serializers.CharField(
help_text="Information that identifies a reservation applicable to the compute resource requirements.",
)
addResources = GrantInfoSerializer(
help_text="List of resources that are approved to be added.",
- many=True
+ many=True,
+ required=False
)
tempResources = GrantInfoSerializer(
help_text="List of resources that are approved to be temporarily instantiated during the runtime of the lifecycle operation.",
- many=True
+ many=True,
+ required=False
)
removeResources = GrantInfoSerializer(
help_text="List of resources that are approved to be removed.",
- many=True
+ many=True,
+ required=False
)
updateResources = GrantInfoSerializer(
help_text="List of resources that are approved to be modified.",
- many=True
+ many=True,
+ required=False
)
vimAssets = VimAssetsSerializer(
help_text="Information about assets for the VNF that are managed by the NFVO in the VIM.",
)
extVirtualLinks = ExtVirtualLinkDataSerializer(
help_text="Information about external VLs to connect the VNF to.",
- many=True
+ many=True,
+ required=False
)
extManagedVirtualLinks = ExtManagedVirtualLinkDataSerializer(
help_text="Information about internal VLs that are managed by other entities than the VNFM.",
- many=True
+ many=True,
+ required=False
)
_links = GrantLinksSerializer(
help_text="Links to resources related to this resource.",
- required=True
+ required=False
)
--- /dev/null
+# Copyright 2018 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import json
+from django.test import Client
+from rest_framework import status
+
+
+class VnfGrantViewTest(unittest.TestCase):
+ def setUp(self):
+ self.client = Client()
+
+ def tearDown(self):
+ pass
+
+ def test_grant_vnf_normal(self):
+ data = {
+ "vnfInstanceId": "1",
+ "vnfLcmOpOccId": "2",
+ "vnfdId": "3",
+ "flavourId": "4",
+ "operation": "INSTANTIATE",
+ "isAutomaticInvocation": True,
+ "instantiationLevelId": "5",
+ "addResources": [
+ {
+ "id": "1",
+ "type": "COMPUTE",
+ "vduId": "2",
+ "resourceTemplateId": "3",
+ "resource": {
+ "vimConnectionId": "4",
+ "resourceProviderId": "5",
+ "resourceId": "6",
+ "vimLevelResourceType": "7"
+ }
+ }
+ ],
+ "placementConstraints": [
+ {
+ "affinityOrAntiAffinity": "AFFINITY",
+ "scope": "NFVI_POP",
+ "resource": [
+ {
+ "idType": "RES_MGMT",
+ "resourceId": "1",
+ "vimConnectionId": "2",
+ "resourceProviderId": "3"
+ }
+ ]
+ }
+ ],
+ "vimConstraints": [
+ {
+ "sameResourceGroup": True,
+ "resource": [
+ {
+ "idType": "RES_MGMT",
+ "resourceId": "1",
+ "vimConnectionId": "2",
+ "resourceProviderId": "3"
+ }
+ ]
+ }
+ ],
+ "additionalParams": {},
+ "_links": {
+ "vnfLcmOpOcc": {
+ "href": "1"
+ },
+ "vnfInstance": {
+ "href": "2"
+ }
+ }
+ }
+ response = self.client.post("/api/nslcm/v2/grants", data=data, format='json')
+ self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.content)
+ resp_data = json.loads(response.content)
+ expect_resp_data = {
+ "id": resp_data.get("id"),
+ "vnfInstanceId": "1",
+ "vnfLcmOpOccId": "2"
+ }
+ self.assertEqual(expect_resp_data, resp_data)