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-3T11:08:39',
48 # "jobId": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9"
51 "jobId": "NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
53 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
54 ret = [0, json.JSONEncoder().encode(create_vnf_resp), '200']
55 ret2 = [0, json.JSONEncoder().encode(job_info), '200']
56 mock_call_req.side_effect = [r1, ret, r1, ret2]
58 'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367',
59 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a',
60 'vnfDescriptorId': 'vcpe_vfw_zte_1_0',
62 'sdncontroller': 'e4d637f1-a4ec-4c59-8b20-4e8ab34daba9',
63 'NatIpRange': '192.167.0.10-192.168.0.20',
64 'm6000_mng_ip': '192.168.11.11',
65 'externalPluginManageNetworkName': 'plugin_net_2014',
66 'location': '516cee95-e8ca-4d26-9268-38e343c2e31e',
67 'externalManageNetworkName': 'mng_net_2017',
68 'sfc_data_network': 'sfc_data_net_2016',
69 'externalDataNetworkName': 'Flow_out_net',
73 response = self.client.post("/api/gvnfmdriver/v1/1/vnfs",
74 data=json.dumps(req_data), content_type="application/json")
75 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
78 "jobId": "NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
80 self.assertEqual(expect_data, response.data)
82 @mock.patch.object(restcall, 'call_req')
83 def test_terminate_vnf(self, mock_call_req):
85 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
87 "type": "gvnfmdriver",
91 "description": "vnfm",
93 "url": "http://10.74.44.11",
96 "createTime": "2016-07-06 15:33:18"
98 job_info = {"vnfInstanceId": "1", "vnfLcOpId": "1"}
101 "responseDescriptor": {
104 "statusDescription": "",
107 "responseHistoryList": [
111 "statusDescription": "",
118 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
119 r2 = [0, json.JSONEncoder().encode(job_info), "200"]
120 job_ret = [0, json.JSONEncoder().encode(job_status_info), "200"]
121 r3 = [0, json.JSONEncoder().encode(None), "200"]
122 mock_call_req.side_effect = [r1, r2, r1, job_ret, r1, r3]
123 response = self.client.post("/api/gvnfmdriver/v1/ztevnfmid/vnfs/2/terminate")
124 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
126 @mock.patch.object(restcall, 'call_req')
127 def test_query_vnf(self, mock_call_req):
129 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
131 "type": "gvnfmdriver",
135 "description": "vnfm",
136 "certificateUrl": "",
137 "url": "http://10.74.44.11",
140 "createTime": "2016-07-06 15:33:18"
145 "instantiationState": "INSTANTIATED",
146 "vnfSoftwareVersion": "v1.2.3"
149 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
150 r2 = [0, json.JSONEncoder().encode(job_info), "200"]
151 mock_call_req.side_effect = [r1, r2]
152 response = self.client.get("/api/gvnfmdriver/v1/19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee/vnfs/88")
153 self.assertEqual(status.HTTP_200_OK, response.status_code)
156 "vnfInstanceId": "88",
157 "vnfStatus": "ACTIVE",
161 self.assertEqual(expect_resp_data, response.data)
163 @mock.patch.object(restcall, 'call_req')
164 def test_operation_status(self, mock_call_req):
168 'name': 'ZTE_VNFM_237_62',
169 'vimId': '516cee95-e8ca-4d26-9268-38e343c2e31e',
170 'url': 'http: //192.168.237.165: 2324',
171 'certificateUrl': '',
173 'vnfmId': 'b0797c9b-3da9-459c-b25c-3813e9d8fd70',
175 'type': 'gvnfmdriver',
176 'createTime': '2016-10-3111: 08: 39',
180 "jobId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9",
181 "responseDescriptor": {
184 "status": "PROCESSING",
185 "statusDescription": "OMC VMs are decommissioned in VIM",
187 "responseHistoryList": [
193 "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
199 "jobId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9",
200 "responseDescriptor": {
203 "status": "PROCESSING",
204 "statusDescription": "OMC VMs are decommissioned in VIM",
206 "responseHistoryList": [
212 "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
217 r1 = [0, json.JSONEncoder().encode(vnfm_info), '200']
218 r2 = [0, json.JSONEncoder().encode(resp_body), '200']
219 mock_call_req.side_effect = [r1, r2]
220 response = self.client.get("/api/gvnfmdriver/v1/%s/jobs/%s?responseId=0"
221 % (vnfm_info["vnfmId"], expected_body["jobId"]))
223 self.assertEqual(status.HTTP_200_OK, response.status_code)
224 self.assertDictEqual(expected_body, response.data)
226 @mock.patch.object(restcall, 'call_req')
227 def test_grantvnf(self, mock_call_req):
229 "vnfInstanceId": "1",
230 "vnfLcmOpOccId": "2",
233 "operation": "INSTANTIATE",
234 "isAutomaticInvocation": True,
235 "instantiationLevelId": "5",
241 "resourceTemplateId": "3",
242 "resourceTemplate": {
243 "vimConnectionId": "4",
244 "resourceProviderId": "5",
246 "vimLevelResourceType": "7"
250 "placementConstraints": [
252 "affinityOrAntiAffinity": "AFFINITY",
256 "idType": "RES_MGMT",
258 "vimConnectionId": "2",
259 "resourceProviderId": "3"
266 "sameResourceGroup": True,
269 "idType": "RES_MGMT",
271 "vimConnectionId": "2",
272 "resourceProviderId": "3"
277 "additionalParams": {},
288 'id': 'Identifier of the garnt',
289 'vnfInstanceId': 'Identifier of the related VNF instance',
290 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
292 # 'vimConnections': [],
295 # 'computeReservationId': None,
296 # 'networkReservationId': None,
297 # 'storageReservationId': None,
298 # 'addResources': None,
299 # 'tempResources': None,
300 # 'removeResource': None,
301 # 'updateResource': None,
303 # 'extVirtualLinks': None,
304 # 'extManagedVirtualLinks': None,
305 # 'additionalParams': None,
307 'self': {'href': 'URI of this resource'},
308 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'},
309 'vnfInstance': {'href': 'Related VNF instance'}
313 mock_call_req.return_value = [0, json.JSONEncoder().encode(grant), '201']
314 response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
315 data=json.dumps(data), content_type='application/json')
316 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
318 'id': 'Identifier of the garnt',
319 'vnfInstanceId': 'Identifier of the related VNF instance',
320 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
322 # 'vimConnections': [],
325 # 'computeReservationId': None,
326 # 'networkReservationId': None,
327 # 'storageReservationId': None,
328 # 'addResources': None,
329 # 'tempResources': None,
330 # 'removeResource': None,
331 # 'updateResource': None,
333 # 'extVirtualLinks': None,
334 # 'extManagedVirtualLinks': None,
335 # 'additionalParams': None,
337 'self': {'href': 'URI of this resource'},
338 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'},
339 'vnfInstance': {'href': 'Related VNF instance'}
342 self.assertDictEqual(expect_resp_data, response.data)
344 @mock.patch.object(restcall, 'call_req')
345 def test_grantvnf_failed(self, mock_call_req):
347 "vnfInstanceId": "1",
348 "vnfLcmOpOccId": "2",
351 "operation": "INSTANTIATE",
352 "isAutomaticInvocation": True,
353 "instantiationLevelId": "5",
359 "resourceTemplateId": "3",
360 "resourceTemplate": {
361 "vimConnectionId": "4",
362 "resourceProviderId": "5",
364 "vimLevelResourceType": "7"
368 "placementConstraints": [
370 "affinityOrAntiAffinity": "AFFINITY",
374 "idType": "RES_MGMT",
376 "vimConnectionId": "2",
377 "resourceProviderId": "3"
384 "sameResourceGroup": True,
387 "idType": "RES_MGMT",
389 "vimConnectionId": "2",
390 "resourceProviderId": "3"
395 "additionalParams": {},
405 mock_call_req.return_value = [1, json.JSONEncoder().encode(""), '201']
406 response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
407 data=json.dumps(data), content_type='application/json')
408 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
410 @mock.patch.object(restcall, 'call_req')
411 def test_notify(self, mock_call_req):
414 "vimInfoId": "111111",
419 "protocolType": "None"
424 "password": "password"
426 "interfaceEndpoint": "http://127.0.0.1/api/v1"
430 "resourceDefinitionId": "xxxxx",
434 "removeResource": "",
436 "computeResourceFlavour": {
447 "additionalParam": ""
449 r2 = [0, json.JSONEncoder().encode(vim_info), "200"]
450 mock_call_req.side_effect = [r2]
452 "vnfmInstId": "876543211",
453 "notificationType": "string",
454 "subscriptionId": "string",
455 "timeStamp": "1234567890",
456 "notificationStatus": "START",
457 "operationState": "STARTING",
458 "vnfInstanceId": "string",
459 "operation": "INSTANTIATE",
460 "isAutomaticInvocation": True,
461 "vnfLcmOpOccId": "string",
465 "changeType": "ADDED",
467 "vimConnectionId": "string",
468 "resourceProviderId": "string",
469 "resourceId": "string",
470 "vimLevelResourceType": "string"
473 "affectedVnfcCpIds": [],
474 "addedStorageResourceIds": [],
475 "removedStorageResourceIds": [],
477 "affectedVirtualLinks": [{
479 "virtualLinkDescId": "string",
480 "changeType": "ADDED",
482 "vimConnectionId": "string",
483 "resourceProviderId": "string",
484 "resourceId": "string",
485 "vimLevelResourceType": "network",
488 "affectedVirtualStorages": [{
490 "virtualStorageDescId": "string",
491 "changeType": "ADDED",
493 "vimConnectionId": "string",
494 "resourceProviderId": "string",
495 "resourceId": "string",
496 "vimLevelResourceType": "network",
501 "vnfInstanceName": "string",
502 "vnfInstanceDescription": "string",
503 "vnfConfigurableProperties": {},
506 "vimConnectionInfo": [{
514 "vnfPkgId": "string",
516 "vnfProvider": "string",
517 "vnfProductName": "string",
518 "vnfSoftwareVersion": "string",
519 "vnfdVersion": "string"
521 "changedExtConnectivity": [{
524 "vimConnectionId": "string",
525 "resourceProviderId": "string",
526 "resourceId": "string",
527 "vimLevelResourceType": "string"
532 "vimConnectionId": "string",
533 "resourceProviderId": "string",
534 "resourceId": "string",
535 "vimLevelResourceType": "string"
537 "cpInstanceId": "string"
541 response = self.client.post("/api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification",
542 data=json.dumps(req_data),
543 content_type='application/json')
544 self.assertEqual(status.HTTP_200_OK, response.status_code)
545 expect_resp_data = None
546 self.assertEqual(expect_resp_data, response.data)
548 @mock.patch.object(restcall, 'call_req')
549 def test_get_vnfpkgs(self, mock_call_req):
556 mock_call_req.return_value = [0, json.JSONEncoder().encode(vnfpkgs_info), '200']
557 resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages")
558 self.assertEqual(status.HTTP_200_OK, resp.status_code)
559 self.assertEqual(1, len(resp.data["csars"]))
560 self.assertEqual("1", resp.data["csars"][0]["csarId"])
561 self.assertEqual("2", resp.data["csars"][0]["vnfdId"])
563 @mock.patch.object(restcall, 'call_req')
564 def test_get_vnfpkgs_failed(self, mock_call_req):
565 mock_call_req.return_value = [1, json.JSONEncoder().encode(""), '200']
566 resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages")
567 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code)
569 @mock.patch.object(restcall, 'call_req')
570 def test_get_vnflcmopocc_with_id(self, mock_call_req):
571 vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16"
573 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
575 "type": "gvnfmdriver",
579 "description": "vnfm",
580 "certificateUrl": "",
581 "url": "http://10.74.44.11",
584 "createTime": "2016-07-06T15:33:18"
586 dummy_single_vnf_lcm_op = {
588 "operationState": "STARTING",
589 "stateEnteredTime": "2018-07-09",
590 "startTime": "2018-07-09",
591 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
593 "operation": "SCALE",
594 "isAutomaticInvocation": False,
595 "operationParams": {},
596 "isCancelPending": False,
599 "resourceChanges": None,
601 "changedExtConnectivity": None,
606 "vnfInstance": "demo"
609 mock_call_req.return_value = [0, json.JSONEncoder().encode(dummy_single_vnf_lcm_op), status.HTTP_200_OK]
610 resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId))
611 self.assertEqual(dummy_single_vnf_lcm_op, resp.data)
612 self.assertEqual(status.HTTP_200_OK, resp.status_code)
614 @mock.patch.object(restcall, 'call_req')
615 def test_get_vnflcmopocc_failed(self, mock_call_req):
616 vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16"
618 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
620 "type": "gvnfmdriver",
624 "description": "vnfm",
625 "certificateUrl": "",
626 "url": "http://10.74.44.11",
629 "createTime": "2016-07-06 15:33:18"
631 mock_call_req.return_value = [1, json.JSONEncoder().encode({}), status.HTTP_500_INTERNAL_SERVER_ERROR]
632 resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId))
633 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code)
635 @mock.patch.object(restcall, 'call_req')
636 def test_subscribe_successfully(self, mock_call_req):
638 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
640 "type": "gvnfmdriver",
644 "description": "vnfm",
645 "certificateUrl": "",
646 "url": "http://10.74.44.11",
649 "createTime": "2016-07-06 15:33:18"
651 lccn_subscription_request_data = {
653 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
654 "operationTypes": ["INSTANTIATE"],
655 "operationStates": ["STARTING"]
657 "callbackUri": "http://aurl.com",
659 "authType": ["BASIC"],
661 "username": "username",
662 "password": "password"
666 lccn_subscription_data = {
667 "id": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
668 "callbackUri": "http://aurl.com",
670 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
671 "operationTypes": ["INSTANTIATE"],
672 "operationStates": ["STARTING"]
675 "self": {"href": "URI of this resource."}
678 ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
679 ret_from_vnfm = [0, json.JSONEncoder().encode(lccn_subscription_data), status.HTTP_201_CREATED]
680 mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
681 response = self.client.post(
682 "/api/gvnfmdriver/v1/%s/subscriptions" % vnfm_info['vnfmId'],
683 json.dumps(lccn_subscription_request_data),
684 content_type='application/json'
686 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
687 self.assertEqual(lccn_subscription_data, response.data)
689 @mock.patch.object(restcall, 'call_req')
690 def test_subscribe_failed(self, mock_call_req):
692 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
694 "type": "gvnfmdriver",
698 "description": "vnfm",
699 "certificateUrl": "",
700 "url": "http://10.74.44.11",
703 "createTime": "2016-07-06 15:33:18"
705 lccn_subscription_request_data = {
707 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
708 "operationTypes": ["INSTANTIATE"],
709 "operationStates": ["STARTING"],
711 "callbackUri": "http://aurl.com",
713 "authType": ["BASIC"],
715 "username": "username",
716 "password": "password"
720 ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
721 ret_from_vnfm = [1, None, status.HTTP_303_SEE_OTHER]
722 mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
723 response = self.client.post(
724 "/api/gvnfmdriver/v1/%s/subscriptions" % vnfm_info['vnfmId'],
725 json.dumps(lccn_subscription_request_data),
726 content_type='application/json'
728 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
730 @mock.patch.object(restcall, 'call_req')
731 def test_operate_vnf_404_NotFound(self, mock_call_req):
733 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
735 "type": "gvnfmdriver",
739 "description": "vnfm",
740 "certificateUrl": "",
741 "url": "http://10.74.44.11",
744 "createTime": "2016-07-06 15:33:18"
747 "changeStateTo": "STARTED"
749 probDetail = {"status": 404, "detail": "VNF Instance not found"}
750 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
751 r2 = [1, json.JSONEncoder().encode(probDetail), "404", ""]
752 mock_call_req.side_effect = [r1, r2]
753 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
754 data=json.dumps(req_data), content_type="application/json")
755 self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
756 self.assertEqual(probDetail, response.data)
758 @mock.patch.object(restcall, 'call_req')
759 def test_operate_vnf_409_Conflict(self, mock_call_req):
761 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
763 "type": "gvnfmdriver",
767 "description": "vnfm",
768 "certificateUrl": "",
769 "url": "http://10.74.44.11",
772 "createTime": "2016-07-06 15:33:18"
775 "changeStateTo": "STOPPED",
776 "stopType": "GRACEFUL",
777 "gracefulStopTimeout": 2
779 probDetail = {"status": 409, "detail": "VNF Instance not in Instantiated State"}
780 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
781 r2 = [1, json.JSONEncoder().encode(probDetail), "409", ""]
782 mock_call_req.side_effect = [r1, r2]
783 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
784 data=json.dumps(req_data), content_type="application/json")
785 self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
786 self.assertEqual(probDetail, response.data)
788 @mock.patch.object(restcall, 'call_req')
789 def test_operate_vnf_success(self, mock_call_req):
791 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
793 "type": "gvnfmdriver",
797 "description": "vnfm",
798 "certificateUrl": "",
799 "url": "http://10.74.44.11",
802 "createTime": "2016-07-06 15:33:18"
805 "changeStateTo": "STOPPED",
806 "stopType": "GRACEFUL",
807 "gracefulStopTimeout": 2
809 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
810 r2 = [0, json.JSONEncoder().encode(''), "202", "/vnf_lc_ops/NF-OPERATE-12-2a3be946-b01d-11e8-9302-08002705b121"]
811 mock_call_req.side_effect = [r1, r2]
812 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
813 data=json.dumps(req_data), content_type="application/json")
814 self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
815 self.assertEqual("/vnf_lc_ops/NF-OPERATE-12-2a3be946-b01d-11e8-9302-08002705b121", response['Location'])
818 @mock.patch.object(restcall, 'call_req')
819 def test_heal_vnf_404_NotFound(self, mock_call_req):
821 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
823 "type": "gvnfmdriver",
827 "description": "vnfm",
828 "certificateUrl": "",
829 "url": "http://10.74.44.11",
832 "createTime": "2016-07-06 15:33:18"
839 "vmname": "vduinstname"
842 probDetail = {"status": 404, "detail": "VNF Instance not found"}
843 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
844 r2 = [1, json.JSONEncoder().encode(probDetail), "404", ""]
845 mock_call_req.side_effect = [r1, r2]
846 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
847 data=json.dumps(req_data), content_type="application/json")
848 self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
849 self.assertEqual(probDetail, response.data)
851 @mock.patch.object(restcall, 'call_req')
852 def test_heal_vnf_409_Conflict(self, mock_call_req):
854 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
856 "type": "gvnfmdriver",
860 "description": "vnfm",
861 "certificateUrl": "",
862 "url": "http://10.74.44.11",
865 "createTime": "2016-07-06 15:33:18"
872 "vmname": "vduinstname"
875 probDetail = {"status": 409, "detail": "VNF Instance not in Instantiated State"}
876 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
877 r2 = [1, json.JSONEncoder().encode(probDetail), "409", ""]
878 mock_call_req.side_effect = [r1, r2]
879 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
880 data=json.dumps(req_data), content_type="application/json")
881 self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
882 self.assertEqual(probDetail, response.data)
884 @mock.patch.object(restcall, 'call_req')
885 def test_heal_vnf_success(self, mock_call_req):
887 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
889 "type": "gvnfmdriver",
893 "description": "vnfm",
894 "certificateUrl": "",
895 "url": "http://10.74.44.11",
898 "createTime": "2016-07-06 15:33:18"
905 "vmname": "vduinstname"
908 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
909 r2 = [0, json.JSONEncoder().encode(''), "202", "/vnf_lc_ops/NF-HEAL-12-2a3be946-b01d-11e8-9302-08002705b121"]
910 mock_call_req.side_effect = [r1, r2]
911 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
912 data=json.dumps(req_data), content_type="application/json")
913 self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
914 self.assertEqual(None, response.data)
915 self.assertEqual("/vnf_lc_ops/NF-HEAL-12-2a3be946-b01d-11e8-9302-08002705b121", response['Location'])
917 def test_health_check(self):
918 response = self.client.get("/api/gvnfmdriver/v1/health_check")
919 self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
920 resp_data = json.loads(response.content)
921 self.assertEqual({"status": "active"}, resp_data)