1 # Copyright 2017 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.
17 from django.test import Client
18 from django.test import TestCase
19 from rest_framework import status
20 from driver.pub.utils import restcall
23 class InterfacesTest(TestCase):
25 self.client = Client()
30 @mock.patch.object(restcall, 'call_req')
31 def test_instantiate_vnf(self, mock_call_req):
35 'name': 'ZTE_VNFM_237_62',
36 'vimId': '516cee95-e8ca-4d26-9268-38e343c2e31e',
37 'url': 'http: //192.168.237.165: 2324',
40 'vnfmId': 'b0797c9b-3da9-459c-b25c-3813e9d8fd70',
42 'type': 'gvnfmdriver',
43 'createTime': '2016-10-3111: 08: 39',
48 "jobId": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9"
52 "vnfLcOpId": "NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
54 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
55 ret = [0, json.JSONEncoder().encode(job_info), '200']
56 ret2 = [0, json.JSONEncoder().encode(vnflcm_info), '200']
57 mock_call_req.side_effect = [r1, ret, r1, ret2]
59 'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367',
60 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a',
61 'vnfDescriptorId': 'vcpe_vfw_zte_1_0',
63 'sdncontroller': 'e4d637f1-a4ec-4c59-8b20-4e8ab34daba9',
64 'NatIpRange': '192.167.0.10-192.168.0.20',
65 'm6000_mng_ip': '192.168.11.11',
66 'externalPluginManageNetworkName': 'plugin_net_2014',
67 'location': '516cee95-e8ca-4d26-9268-38e343c2e31e',
68 'externalManageNetworkName': 'mng_net_2017',
69 'sfc_data_network': 'sfc_data_net_2016',
70 'externalDataNetworkName': 'Flow_out_net',
74 response = self.client.post("/api/gvnfmdriver/v1/1/vnfs",
75 data=json.dumps(req_data), content_type="application/json")
76 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
79 "jobId": "NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
81 self.assertEqual(expect_data, response.data)
83 @mock.patch.object(restcall, 'call_req')
84 def test_terminate_vnf(self, mock_call_req):
86 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
88 "type": "gvnfmdriver",
92 "description": "vnfm",
94 "url": "http://10.74.44.11",
97 "createTime": "2016-07-06 15:33:18"
99 job_info = {"vnfInstanceId": "1", "vnfLcOpId": "1"}
102 "responseDescriptor": {
105 "statusDescription": "",
108 "responseHistoryList": [
112 "statusDescription": "",
119 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
120 r2 = [0, json.JSONEncoder().encode(job_info), "200"]
121 job_ret = [0, json.JSONEncoder().encode(job_status_info), "200"]
122 r3 = [0, json.JSONEncoder().encode(None), "200"]
123 mock_call_req.side_effect = [r1, r2, r1, job_ret, r1, r3]
124 response = self.client.post("/api/gvnfmdriver/v1/ztevnfmid/vnfs/2/terminate")
125 self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
126 self.assertEqual(None, response.data)
128 @mock.patch.object(restcall, 'call_req')
129 def test_query_vnf(self, mock_call_req):
131 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
133 "type": "gvnfmdriver",
137 "description": "vnfm",
138 "certificateUrl": "",
139 "url": "http://10.74.44.11",
142 "createTime": "2016-07-06 15:33:18"
147 "instantiationState": "INSTANTIATED",
148 "vnfSoftwareVersion": "v1.2.3"
151 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
152 r2 = [0, json.JSONEncoder().encode(job_info), "200"]
153 mock_call_req.side_effect = [r1, r2]
154 response = self.client.get("/api/gvnfmdriver/v1/19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee/vnfs/88")
155 self.assertEqual(status.HTTP_200_OK, response.status_code)
158 "vnfInstanceId": "88",
159 "vnfStatus": "ACTIVE",
163 self.assertEqual(expect_resp_data, response.data)
165 @mock.patch.object(restcall, 'call_req')
166 def test_operation_status(self, mock_call_req):
170 'name': 'ZTE_VNFM_237_62',
171 'vimId': '516cee95-e8ca-4d26-9268-38e343c2e31e',
172 'url': 'http: //192.168.237.165: 2324',
173 'certificateUrl': '',
175 'vnfmId': 'b0797c9b-3da9-459c-b25c-3813e9d8fd70',
177 'type': 'gvnfmdriver',
178 'createTime': '2016-10-3111: 08: 39',
182 "jobId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9",
183 "responseDescriptor": {
186 "status": "PROCESSING",
187 "statusDescription": "OMC VMs are decommissioned in VIM",
189 "responseHistoryList": [
195 "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
202 "vnfLcOpId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9",
203 "responseDescriptor": {
206 "lcmOperationStatus": "PROCESSING",
207 "statusDescription": "OMC VMs are decommissioned in VIM",
209 "responseHistoryList": [
215 "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
221 r1 = [0, json.JSONEncoder().encode(vnfm_info), '200']
222 r2 = [0, json.JSONEncoder().encode(resp_body), '200']
223 mock_call_req.side_effect = [r1, r2]
224 response = self.client.get("/api/gvnfmdriver/v1/%s/jobs/%s?responseId=0"
225 % (vnfm_info["vnfmId"], expected_body["jobId"]))
226 self.assertEqual(status.HTTP_200_OK, response.status_code)
227 self.assertDictEqual(expected_body, response.data)
229 @mock.patch.object(restcall, 'call_req')
230 def test_grantvnf(self, mock_call_req):
236 "vimid": "516cee95-e8ca-4d26-9268-38e343c2e31e"
240 "vnfmid": "13232222",
241 "nfvoid": "03212234",
243 "exvimidlist ": "exvimid",
244 "tenant": " tenant1",
245 "vnfinstanceid": "1234",
246 "operationright": "0",
258 mock_call_req.return_value = [0, json.JSONEncoder().encode(vim_info), '201']
259 response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
260 data=json.dumps(req_data), content_type='application/json')
261 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
263 "vimid": "516cee95-e8ca-4d26-9268-38e343c2e31e",
266 self.assertDictEqual(expect_resp_data, response.data)
268 @mock.patch.object(restcall, 'call_req')
269 def test_notify(self, mock_call_req):
272 "vimInfoId": "111111",
277 "protocolType": "None"
282 "password": "password"
284 "interfaceEndpoint": "http://127.0.0.1/api/v1"
288 "resourceDefinitionId": "xxxxx",
292 "removeResource": "",
294 "computeResourceFlavour": {
305 "additionalParam": ""
307 r2 = [0, json.JSONEncoder().encode(vim_info), "200"]
308 mock_call_req.side_effect = [r2]
311 "vnfmid": "876543211",
313 "timestamp": "1234567890",
314 "vnfinstanceid": "1",
333 response = self.client.post("/api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification",
334 data=json.dumps(req_data),
335 content_type='application/json')
336 self.assertEqual(status.HTTP_200_OK, response.status_code)
337 expect_resp_data = None
338 self.assertEqual(expect_resp_data, response.data)
340 @mock.patch.object(restcall, 'call_req')
341 def test_get_vnfpkgs(self, mock_call_req):
348 mock_call_req.return_value = [0, json.JSONEncoder().encode(vnfpkgs_info), '200']
349 resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages")
350 self.assertEqual(status.HTTP_200_OK, resp.status_code)
351 self.assertEqual(1, len(resp.data["csars"]))
352 self.assertEqual("1", resp.data["csars"][0]["csarId"])
353 self.assertEqual("2", resp.data["csars"][0]["vnfdId"])