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"]))
222 self.assertEqual(status.HTTP_200_OK, response.status_code)
223 self.assertDictEqual(expected_body, response.data)
225 @mock.patch.object(restcall, 'call_req')
226 def test_grantvnf(self, mock_call_req):
228 "vnfInstanceId": "1",
229 "vnfLcmOpOccId": "2",
232 "operation": "INSTANTIATE",
233 "isAutomaticInvocation": True,
234 "instantiationLevelId": "5",
240 "resourceTemplateId": "3",
241 "resourceTemplate": {
242 "vimConnectionId": "4",
243 "resourceProviderId": "5",
245 "vimLevelResourceType": "7"
249 "placementConstraints": [
251 "affinityOrAntiAffinity": "AFFINITY",
255 "idType": "RES_MGMT",
257 "vimConnectionId": "2",
258 "resourceProviderId": "3"
265 "sameResourceGroup": True,
268 "idType": "RES_MGMT",
270 "vimConnectionId": "2",
271 "resourceProviderId": "3"
276 "additionalParams": {},
287 'id': 'Identifier of the garnt',
288 'vnfInstanceId': 'Identifier of the related VNF instance',
289 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
291 # 'vimConnections': [],
294 # 'computeReservationId': None,
295 # 'networkReservationId': None,
296 # 'storageReservationId': None,
297 # 'addResources': None,
298 # 'tempResources': None,
299 # 'removeResource': None,
300 # 'updateResource': None,
302 # 'extVirtualLinks': None,
303 # 'extManagedVirtualLinks': None,
304 # 'additionalParams': None,
306 'self': {'href': 'URI of this resource'},
307 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'},
308 'vnfInstance': {'href': 'Related VNF instance'}
312 mock_call_req.return_value = [0, json.JSONEncoder().encode(grant), '201']
313 response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
314 data=json.dumps(data), content_type='application/json')
315 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
317 'id': 'Identifier of the garnt',
318 'vnfInstanceId': 'Identifier of the related VNF instance',
319 'vnfLcmOpOccId': 'Identifier of the related VNF LcmOpOcc',
321 # 'vimConnections': [],
324 # 'computeReservationId': None,
325 # 'networkReservationId': None,
326 # 'storageReservationId': None,
327 # 'addResources': None,
328 # 'tempResources': None,
329 # 'removeResource': None,
330 # 'updateResource': None,
332 # 'extVirtualLinks': None,
333 # 'extManagedVirtualLinks': None,
334 # 'additionalParams': None,
336 'self': {'href': 'URI of this resource'},
337 'vnfLcmOpOcc': {'href': 'Related VNF lifecycle management operation occurrence'},
338 'vnfInstance': {'href': 'Related VNF instance'}
341 self.assertDictEqual(expect_resp_data, response.data)
343 @mock.patch.object(restcall, 'call_req')
344 def test_grantvnf_failed(self, mock_call_req):
346 "vnfInstanceId": "1",
347 "vnfLcmOpOccId": "2",
350 "operation": "INSTANTIATE",
351 "isAutomaticInvocation": True,
352 "instantiationLevelId": "5",
358 "resourceTemplateId": "3",
359 "resourceTemplate": {
360 "vimConnectionId": "4",
361 "resourceProviderId": "5",
363 "vimLevelResourceType": "7"
367 "placementConstraints": [
369 "affinityOrAntiAffinity": "AFFINITY",
373 "idType": "RES_MGMT",
375 "vimConnectionId": "2",
376 "resourceProviderId": "3"
383 "sameResourceGroup": True,
386 "idType": "RES_MGMT",
388 "vimConnectionId": "2",
389 "resourceProviderId": "3"
394 "additionalParams": {},
404 mock_call_req.return_value = [1, json.JSONEncoder().encode(""), '201']
405 response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
406 data=json.dumps(data), content_type='application/json')
407 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
409 @mock.patch.object(restcall, 'call_req')
410 def test_notify(self, mock_call_req):
413 "vimInfoId": "111111",
418 "protocolType": "None"
423 "password": "password"
425 "interfaceEndpoint": "http://127.0.0.1/api/v1"
429 "resourceDefinitionId": "xxxxx",
433 "removeResource": "",
435 "computeResourceFlavour": {
446 "additionalParam": ""
448 r2 = [0, json.JSONEncoder().encode(vim_info), "200"]
449 mock_call_req.side_effect = [r2]
451 "vnfmInstId": "876543211",
452 "notificationType": "string",
453 "subscriptionId": "string",
454 "timeStamp": "1234567890",
455 "notificationStatus": "START",
456 "operationState": "STARTING",
457 "vnfInstanceId": "string",
458 "operation": "INSTANTIATE",
459 "isAutomaticInvocation": True,
460 "vnfLcmOpOccId": "string",
464 "changeType": "ADDED",
466 "vimConnectionId": "string",
467 "resourceProviderId": "string",
468 "resourceId": "string",
469 "vimLevelResourceType": "string"
472 "affectedVnfcCpIds": [],
473 "addedStorageResourceIds": [],
474 "removedStorageResourceIds": [],
476 "affectedVirtualLinks": [{
478 "virtualLinkDescId": "string",
479 "changeType": "ADDED",
481 "vimConnectionId": "string",
482 "resourceProviderId": "string",
483 "resourceId": "string",
484 "vimLevelResourceType": "network",
487 "affectedVirtualStorages": [{
489 "virtualStorageDescId": "string",
490 "changeType": "ADDED",
492 "vimConnectionId": "string",
493 "resourceProviderId": "string",
494 "resourceId": "string",
495 "vimLevelResourceType": "network",
500 "vnfInstanceName": "string",
501 "vnfInstanceDescription": "string",
502 "vnfConfigurableProperties": {},
505 "vimConnectionInfo": [{
513 "vnfPkgId": "string",
515 "vnfProvider": "string",
516 "vnfProductName": "string",
517 "vnfSoftwareVersion": "string",
518 "vnfdVersion": "string"
520 "changedExtConnectivity": [{
523 "vimConnectionId": "string",
524 "resourceProviderId": "string",
525 "resourceId": "string",
526 "vimLevelResourceType": "string"
531 "vimConnectionId": "string",
532 "resourceProviderId": "string",
533 "resourceId": "string",
534 "vimLevelResourceType": "string"
536 "cpInstanceId": "string"
540 response = self.client.post("/api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification",
541 data=json.dumps(req_data),
542 content_type='application/json')
543 self.assertEqual(status.HTTP_200_OK, response.status_code)
544 expect_resp_data = None
545 self.assertEqual(expect_resp_data, response.data)
547 @mock.patch.object(restcall, 'call_req')
548 def test_get_vnfpkgs(self, mock_call_req):
555 mock_call_req.return_value = [0, json.JSONEncoder().encode(vnfpkgs_info), '200']
556 resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages")
557 self.assertEqual(status.HTTP_200_OK, resp.status_code)
558 self.assertEqual(1, len(resp.data["csars"]))
559 self.assertEqual("1", resp.data["csars"][0]["csarId"])
560 self.assertEqual("2", resp.data["csars"][0]["vnfdId"])
562 @mock.patch.object(restcall, 'call_req')
563 def test_get_vnfpkgs_failed(self, mock_call_req):
564 mock_call_req.return_value = [1, json.JSONEncoder().encode(""), '200']
565 resp = self.client.get("/api/gvnfmdriver/v1/vnfpackages")
566 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code)
568 @mock.patch.object(restcall, 'call_req')
569 def test_get_vnflcmopocc_with_id(self, mock_call_req):
570 vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16"
572 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
574 "type": "gvnfmdriver",
578 "description": "vnfm",
579 "certificateUrl": "",
580 "url": "http://10.74.44.11",
583 "createTime": "2016-07-06T15:33:18"
585 dummy_single_vnf_lcm_op = {
587 "operationState": "STARTING",
588 "stateEnteredTime": "2018-07-09",
589 "startTime": "2018-07-09",
590 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
592 "operation": "SCALE",
593 "isAutomaticInvocation": False,
594 "operationParams": {},
595 "isCancelPending": False,
598 "resourceChanges": None,
600 "changedExtConnectivity": None,
605 "vnfInstance": "demo"
608 mock_call_req.return_value = [0, json.JSONEncoder().encode(dummy_single_vnf_lcm_op), status.HTTP_200_OK]
609 resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId))
610 self.assertEqual(dummy_single_vnf_lcm_op, resp.data)
611 self.assertEqual(status.HTTP_200_OK, resp.status_code)
613 @mock.patch.object(restcall, 'call_req')
614 def test_get_vnflcmopocc_failed(self, mock_call_req):
615 vnfLcmOpOccId = "99442b18-a5c7-11e8-998c-bf1755941f16"
617 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
619 "type": "gvnfmdriver",
623 "description": "vnfm",
624 "certificateUrl": "",
625 "url": "http://10.74.44.11",
628 "createTime": "2016-07-06 15:33:18"
630 mock_call_req.return_value = [1, json.JSONEncoder().encode({}), status.HTTP_500_INTERNAL_SERVER_ERROR]
631 resp = self.client.get("/api/gvnfmdriver/v1/%s/vnf_lcm_op_occs/%s" % (vnfm_info['vnfmId'], vnfLcmOpOccId))
632 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, resp.status_code)
634 @mock.patch.object(restcall, 'call_req')
635 def test_subscribe_successfully(self, mock_call_req):
637 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
639 "type": "gvnfmdriver",
643 "description": "vnfm",
644 "certificateUrl": "",
645 "url": "http://10.74.44.11",
648 "createTime": "2016-07-06 15:33:18"
650 lccn_subscription_request_data = {
652 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
653 "operationTypes": ["INSTANTIATE"],
654 "operationStates": ["STARTING"]
656 "callbackUri": "http://aurl.com",
658 "authType": ["BASIC"],
660 "username": "username",
661 "password": "password"
665 lccn_subscription_data = {
666 "id": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
667 "callbackUri": "http://aurl.com",
669 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
670 "operationTypes": ["INSTANTIATE"],
671 "operationStates": ["STARTING"]
674 "self": {"href": "URI of this resource."}
677 ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
678 ret_from_vnfm = [0, json.JSONEncoder().encode(lccn_subscription_data), status.HTTP_201_CREATED]
679 mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
680 response = self.client.post(
681 "/api/gvnfmdriver/v1/%s/subscriptions" % vnfm_info['vnfmId'],
682 json.dumps(lccn_subscription_request_data),
683 content_type='application/json'
685 self.assertEqual(status.HTTP_201_CREATED, response.status_code)
686 self.assertEqual(lccn_subscription_data, response.data)
688 @mock.patch.object(restcall, 'call_req')
689 def test_subscribe_failed(self, mock_call_req):
691 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
693 "type": "gvnfmdriver",
697 "description": "vnfm",
698 "certificateUrl": "",
699 "url": "http://10.74.44.11",
702 "createTime": "2016-07-06 15:33:18"
704 lccn_subscription_request_data = {
706 "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
707 "operationTypes": ["INSTANTIATE"],
708 "operationStates": ["STARTING"],
710 "callbackUri": "http://aurl.com",
712 "authType": ["BASIC"],
714 "username": "username",
715 "password": "password"
719 ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
720 ret_from_vnfm = [1, None, status.HTTP_303_SEE_OTHER]
721 mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
722 response = self.client.post(
723 "/api/gvnfmdriver/v1/%s/subscriptions" % vnfm_info['vnfmId'],
724 json.dumps(lccn_subscription_request_data),
725 content_type='application/json'
727 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
729 @mock.patch.object(restcall, 'call_req')
730 def test_operate_vnf_404_NotFound(self, mock_call_req):
732 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
734 "type": "gvnfmdriver",
738 "description": "vnfm",
739 "certificateUrl": "",
740 "url": "http://10.74.44.11",
743 "createTime": "2016-07-06 15:33:18"
746 "changeStateTo": "STARTED"
748 probDetail = {"status": 404, "detail": "VNF Instance not found"}
749 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
750 r2 = [1, json.JSONEncoder().encode(probDetail), "404", ""]
751 mock_call_req.side_effect = [r1, r2]
752 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
753 data=json.dumps(req_data), content_type="application/json")
754 self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
755 self.assertEqual(probDetail, response.data)
757 @mock.patch.object(restcall, 'call_req')
758 def test_operate_vnf_409_Conflict(self, mock_call_req):
760 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
762 "type": "gvnfmdriver",
766 "description": "vnfm",
767 "certificateUrl": "",
768 "url": "http://10.74.44.11",
771 "createTime": "2016-07-06 15:33:18"
774 "changeStateTo": "STOPPED",
775 "stopType": "GRACEFUL",
776 "gracefulStopTimeout": 2
778 probDetail = {"status": 409, "detail": "VNF Instance not in Instantiated State"}
779 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
780 r2 = [1, json.JSONEncoder().encode(probDetail), "409", ""]
781 mock_call_req.side_effect = [r1, r2]
782 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
783 data=json.dumps(req_data), content_type="application/json")
784 self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
785 self.assertEqual(probDetail, response.data)
787 @mock.patch.object(restcall, 'call_req')
788 def test_operate_vnf_success(self, mock_call_req):
790 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
792 "type": "gvnfmdriver",
796 "description": "vnfm",
797 "certificateUrl": "",
798 "url": "http://10.74.44.11",
801 "createTime": "2016-07-06 15:33:18"
804 "changeStateTo": "STOPPED",
805 "stopType": "GRACEFUL",
806 "gracefulStopTimeout": 2
808 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
809 r2 = [0, json.JSONEncoder().encode(''), "202", "/vnf_lc_ops/NF-OPERATE-12-2a3be946-b01d-11e8-9302-08002705b121"]
810 mock_call_req.side_effect = [r1, r2]
811 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/operate",
812 data=json.dumps(req_data), content_type="application/json")
813 self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
814 self.assertEqual("/vnf_lc_ops/NF-OPERATE-12-2a3be946-b01d-11e8-9302-08002705b121", response['Location'])
817 @mock.patch.object(restcall, 'call_req')
818 def test_heal_vnf_404_NotFound(self, mock_call_req):
820 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
822 "type": "gvnfmdriver",
826 "description": "vnfm",
827 "certificateUrl": "",
828 "url": "http://10.74.44.11",
831 "createTime": "2016-07-06 15:33:18"
838 "vmname": "vduinstname"
841 probDetail = {"status": 404, "detail": "VNF Instance not found"}
842 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
843 r2 = [1, json.JSONEncoder().encode(probDetail), "404", ""]
844 mock_call_req.side_effect = [r1, r2]
845 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
846 data=json.dumps(req_data), content_type="application/json")
847 self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
848 self.assertEqual(probDetail, response.data)
850 @mock.patch.object(restcall, 'call_req')
851 def test_heal_vnf_409_Conflict(self, mock_call_req):
853 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
855 "type": "gvnfmdriver",
859 "description": "vnfm",
860 "certificateUrl": "",
861 "url": "http://10.74.44.11",
864 "createTime": "2016-07-06 15:33:18"
871 "vmname": "vduinstname"
874 probDetail = {"status": 409, "detail": "VNF Instance not in Instantiated State"}
875 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200", ""]
876 r2 = [1, json.JSONEncoder().encode(probDetail), "409", ""]
877 mock_call_req.side_effect = [r1, r2]
878 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
879 data=json.dumps(req_data), content_type="application/json")
880 self.assertEqual(status.HTTP_409_CONFLICT, response.status_code)
881 self.assertEqual(probDetail, response.data)
883 @mock.patch.object(restcall, 'call_req')
884 def test_heal_vnf_success(self, mock_call_req):
886 "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
888 "type": "gvnfmdriver",
892 "description": "vnfm",
893 "certificateUrl": "",
894 "url": "http://10.74.44.11",
897 "createTime": "2016-07-06 15:33:18"
904 "vmname": "vduinstname"
907 r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
908 r2 = [0, json.JSONEncoder().encode(''), "202", "/vnf_lc_ops/NF-HEAL-12-2a3be946-b01d-11e8-9302-08002705b121"]
909 mock_call_req.side_effect = [r1, r2]
910 response = self.client.post("/api/gvnfmdriver/v1/vnfmid/vnfs/2/heal",
911 data=json.dumps(req_data), content_type="application/json")
912 self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code)
913 self.assertEqual(None, response.data)
914 self.assertEqual("/vnf_lc_ops/NF-HEAL-12-2a3be946-b01d-11e8-9302-08002705b121", response['Location'])
916 def test_health_check(self):
917 response = self.client.get("/api/gvnfmdriver/v1/health_check")
918 self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
919 resp_data = json.loads(response.content)
920 self.assertEqual({"status": "active"}, resp_data)