1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from rest_framework.test import APIClient
19 from rest_framework import status
20 from lcm.pub.database.models import NfInstModel
21 from lcm.pub.utils import restcall
24 class VnfGrantViewTest(unittest.TestCase):
26 self.client = APIClient()
31 @mock.patch.object(restcall, 'call_req')
32 def test_grant_vnf_normal(self, mock_call_req):
38 "operation": "INSTANTIATE",
39 "isAutomaticInvocation": True,
40 "instantiationLevelId": "5",
46 "resourceTemplateId": "3",
48 "vimConnectionId": "4",
49 "resourceProviderId": "5",
51 "vimLevelResourceType": "7"
55 "placementConstraints": [
57 "affinityOrAntiAffinity": "AFFINITY",
63 "vimConnectionId": "2",
64 "resourceProviderId": "3"
71 "sameResourceGroup": True,
76 "vimConnectionId": "2",
77 "resourceProviderId": "3"
82 "additionalParams": {},
96 mock_call_req.return_value = [0, json.JSONEncoder().encode(vimConnections), '200']
97 response = self.client.post("/api/nslcm/v2/grants", data=data, format='json')
98 self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.content)
99 resp_data = json.loads(response.content)
101 "id": resp_data.get("id"),
102 "vnfInstanceId": "1",
103 "vnfLcmOpOccId": "2",
111 self.assertEqual(expect_resp_data, resp_data)
113 def test_grant_vnf_when_vnfinst_not_exist(self):
115 "vnfInstanceId": "1",
116 "vnfLcmOpOccId": "2",
119 "operation": "INSTANTIATE",
120 "isAutomaticInvocation": True,
121 "instantiationLevelId": "5",
127 "resourceTemplateId": "3",
130 "placementConstraints": [
132 "affinityOrAntiAffinity": "AFFINITY",
136 "idType": "RES_MGMT",
138 "vimConnectionId": "2",
139 "resourceProviderId": "3"
146 "sameResourceGroup": True,
149 "idType": "RES_MGMT",
151 "vimConnectionId": "2",
152 "resourceProviderId": "3"
157 "additionalParams": {},
167 response = self.client.post("/api/nslcm/v2/grants", data=data, format='json')
168 self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
170 def test_get_notify_vnf_normal(self):
171 response = self.client.get("/api/nslcm/v2/ns/1/vnfs/1/Notify")
172 self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content)
174 def test_notify_vnf_normal(self):
177 "notificationType": "string",
178 "subscriptionId": "string",
179 "timeStamp": "string",
180 "notificationStatus": "START",
181 "operationState": "STARTING",
182 "vnfInstanceId": "string",
183 "operation": "INSTANTIATE",
184 "isAutomaticInvocation": True,
185 "vnfLcmOpOccId": "string",
189 "changeType": "ADDED",
191 "vimConnectionId": "string",
192 "resourceProviderId": "string",
193 "resourceId": "string",
194 "vimLevelResourceType": "string"
197 "affectedVnfcCpIds": [],
198 "addedStorageResourceIds": [],
199 "removedStorageResourceIds": [],
201 "affectedVirtualLinks": [{
203 "virtualLinkDescId": "string",
204 "changeType": "ADDED",
206 "vimConnectionId": "string",
207 "resourceProviderId": "string",
208 "resourceId": "string",
209 "vimLevelResourceType": "network",
212 "affectedVirtualStorages": [{
214 "virtualStorageDescId": "string",
215 "changeType": "ADDED",
217 "vimConnectionId": "string",
218 "resourceProviderId": "string",
219 "resourceId": "string",
220 "vimLevelResourceType": "network",
225 "vnfInstanceName": "string",
226 "vnfInstanceDescription": "string",
227 "vnfConfigurableProperties": {
228 "additionalProp1": "string",
229 "additionalProp2": "string",
230 "additionalProp3": "string"
233 "additionalProp1": "string",
234 "additionalProp2": "string",
235 "additionalProp3": "string"
238 "additionalProp1": "string",
239 "additionalProp2": "string",
240 "additionalProp3": "string"
242 "vimConnectionInfo": [{
247 "additionalProp1": "string",
248 "additionalProp2": "string",
249 "additionalProp3": "string"
252 "additionalProp1": "string",
253 "additionalProp2": "string",
254 "additionalProp3": "string"
257 "additionalProp1": "string",
258 "additionalProp2": "string",
259 "additionalProp3": "string"
262 "vnfPkgId": "string",
264 "vnfProvider": "string",
265 "vnfProductName": "string",
266 "vnfSoftwareVersion": "string",
267 "vnfdVersion": "string"
269 "changedExtConnectivity": [{
272 "vimConnectionId": "string",
273 "resourceProviderId": "string",
274 "resourceId": "string",
275 "vimLevelResourceType": "string"
280 "vimConnectionId": "string",
281 "resourceProviderId": "string",
282 "resourceId": "string",
283 "vimLevelResourceType": "string"
285 "cpInstanceId": "string"
307 NfInstModel.objects.create(nfinstid='22',
310 response = self.client.post("/api/nslcm/v2/ns/1/vnfs/2/Notify", data=data, format='json')
311 self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content)