From 515c3241a0e4db90fa05f65e58cbf83df6d7f9c0 Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Fri, 24 Nov 2017 11:40:29 +0800 Subject: Remove vfc-ztevnfmdriver unused code Change-Id: I29569b54c3646a5026949ba62c2fdb3e35c489b4 Issue-ID: VFC-596 Signed-off-by: ying.yunlong --- zte/vmanager/driver/interfaces/tests.py | 249 +++++++++++++++--------------- zte/vmanager/driver/interfaces/views.py | 21 +-- zte/vmanager/driver/pub/config/config.py | 10 -- zte/vmanager/driver/pub/utils/restcall.py | 58 +------ 4 files changed, 131 insertions(+), 207 deletions(-) diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py index f8ef799b..a47c08ef 100644 --- a/zte/vmanager/driver/interfaces/tests.py +++ b/zte/vmanager/driver/interfaces/tests.py @@ -27,59 +27,77 @@ class InterfacesTest(TestCase): def tearDown(self): pass - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_instantiate_vnf_001(self, mock_call_req): - """ - Initate_VNF - """ - vnfm_info = {u'userName': u'admin', - u'vendor': u'ZTE', - u'name': u'ZTE_VNFM_237_62', - u'vimId': u'516cee95-e8ca-4d26-9268-38e343c2e31e', - u'url': u'http://192.168.237.165:2324', - u'certificateUrl': u'', - u'version': u'V1.0', - u'vnfmId': u'b0797c9b-3da9-459c-b25c-3813e9d8fd70', - u'password': u'admin', - u'type': u'ztevmanagerdriver', - u'createTime': u'2016-10-31 11:08:39', - u'description': u''} - vnfd_info = {u'vnfInstanceInfo': [{u'vnfInstanceId': u'59b79a9f-9e37-4f6c-acaf-5f41d9cb3f76', - u'vnfInstanceName': u'VFW_59b79a9f-9e37-4f6c-acaf-5f41d9cb3f76'}, - {u'vnfInstanceId': u'6c5e4bd3-e8a6-42d8-a7a4-53a8ef74c6ac', - u'vnfInstanceName': u'VFW_6c5e4bd3-e8a6-42d8-a7a4-53a8ef74c6ac'}, - {u'vnfInstanceId': u'930de5c9-8043-41df-ace8-ede2262a3713', - u'vnfInstanceName': u'VFW_930de5c9-8043-41df-ace8-ede2262a3713'}, - {u'vnfInstanceId': u'c677a305-a7bd-4baf-9eee-c383c588bb3c', - u'vnfInstanceName': u'VFW_c677a305-a7bd-4baf-9eee-c383c588bb3c'}, - {u'vnfInstanceId': u'e708e5c5-bdf4-436a-b928-826887806d82', - u'vnfInstanceName': u'VFW_e708e5c5-bdf4-436a-b928-826887806d82'}], - u'csarId': u'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a', - u'imageInfo': [ - {u'status': u'Enable', u'index': u'0', - u'vimId': u'516cee95-e8ca-4d26-9268-38e343c2e31e', - u'fileName': u'VFW_IMAGE_VCPE_ZTE', - u'vimUser': u'admin', - u'imageId': u'd2b73154-0414-466a-a1e6-51b9461b753a', - u'tenant': u'admin'}], - u'packageInfo': {u'usageState': u'NotInUse', - u'onBoardState': u'onBoarded', - u'name': u'VFW', - u'format': u'yaml', - u'provider': u'ZTE', - u'vnfdProvider': u'zte', - u'vnfdId': u'vcpe_vfw_zte_1_0', - u'deletionPending': False, - u'version': u'v1.0', - u'vnfVersion': u'1.0', - u'vnfdVersion': u'1.0.0', - u'processState': u'normal', - u'modifyTime': u'2016-10-31 16:21:32', - u'downloadUri': u'http://192.168.233.226:80/', - u'operationalState': u'Disabled', - u'createTime': u'2016-10-31 16:21:11', - u'size': u'12.1 MB'}} + vnfm_info = { + "userName": "admin", + "vendor": "ZTE", + "name": "ZTE_VNFM_237_62", + "vimId": "516cee95-e8ca-4d26-9268-38e343c2e31e", + "url": "http://192.168.237.165:2324", + "certificateUrl": "", + "version": "V1.0", + "vnfmId": "b0797c9b-3da9-459c-b25c-3813e9d8fd70", + "password": "admin", + "type": "ztevmanagerdriver", + "createTime": "2016-10-31 11:08:39", + "description": "" + } + vnfd_info = { + "vnfInstanceInfo": [ + { + "vnfInstanceId": "59b79a9f-9e37-4f6c-acaf-5f41d9cb3f76", + "vnfInstanceName": "VFW_59b79a9f-9e37-4f6c-acaf-5f41d9cb3f76" + }, + { + "vnfInstanceId": "6c5e4bd3-e8a6-42d8-a7a4-53a8ef74c6ac", + "vnfInstanceName": "VFW_6c5e4bd3-e8a6-42d8-a7a4-53a8ef74c6ac" + }, + { + "vnfInstanceId": "930de5c9-8043-41df-ace8-ede2262a3713", + "vnfInstanceName": "VFW_930de5c9-8043-41df-ace8-ede2262a3713" + }, + { + "vnfInstanceId": "c677a305-a7bd-4baf-9eee-c383c588bb3c", + "vnfInstanceName": "VFW_c677a305-a7bd-4baf-9eee-c383c588bb3c" + }, + { + "vnfInstanceId": "e708e5c5-bdf4-436a-b928-826887806d82", + "vnfInstanceName": "VFW_e708e5c5-bdf4-436a-b928-826887806d82" + } + ], + "csarId": "d852e1be-0aac-48f1-b1a4-cd825f6cdf9a", + "imageInfo": [ + { + "status": "Enable", + "index": "0", + "vimId": "516cee95-e8ca-4d26-9268-38e343c2e31e", + "fileName": "VFW_IMAGE_VCPE_ZTE", + "vimUser": "admin", + "imageId": "d2b73154-0414-466a-a1e6-51b9461b753a", + "tenant": "admin" + } + ], + "packageInfo": { + "usageState": "NotInUse", + "onBoardState": "onBoarded", + "name": "VFW", + "format": "yaml", + "provider": "ZTE", + "vnfdProvider": "zte", + "vnfdId": "vcpe_vfw_zte_1_0", + "deletionPending": False, + "version": "v1.0", + "vnfVersion": "1.0", + "vnfdVersion": "1.0.0", + "processState": "normal", + "modifyTime": "2016-10-3116: 21: 32", + "downloadUri": "http: //192.168.233.226: 80/", + "operationalState": "Disabled", + "createTime": "2016-10-3116: 21: 11", + "size": "12.1MB" + } + } packageInfo = { "size": "12.1 MB", "usageState": "NotInUse", @@ -104,18 +122,13 @@ class InterfacesTest(TestCase): } inst_response = { - u'vnfInstanceId': u'8', - u'jobid': u'NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9' + "vnfInstanceId": "8", + "jobid": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9" } ret = [0, json.JSONEncoder().encode(inst_response), '200'] - r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"] - r2 = [0, json.JSONEncoder().encode(vnfd_info), "200"] - r3 = [0, json.JSONEncoder().encode(packageInfo), "200"] - - # mock_call_req_aai.side_effect =[r1] mock_call_req.side_effect = [r1, r2, r3, ret] req_data = { @@ -141,12 +154,8 @@ class InterfacesTest(TestCase): expect_resp_data = {"jobid": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9", "vnfInstanceId": "8"} self.assertEqual(expect_resp_data, response.data) - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_terminate_vnf__002(self, mock_call_req): - """ - Terminate_VNF - """ r1 = [0, json.JSONEncoder().encode({ "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -162,7 +171,6 @@ class InterfacesTest(TestCase): "createTime": "2016-07-06 15:33:18"}), "200"] r2 = [0, json.JSONEncoder().encode({"vnfInstanceId": "1", "JobId": "1"}), "200"] - # mock_call_req_aai.side_effect = [r1] mock_call_req.side_effect = [r1, r2] response = self.client.post("/api/ztevmanagerdriver/v1/ztevnfmid/vnfs/vbras_innstance_id/terminate") @@ -171,12 +179,8 @@ class InterfacesTest(TestCase): expect_resp_data = {"jobid": "1", "vnfInstanceId": "1"} self.assertEqual(expect_resp_data, response.data) - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_query_vnf_003(self, mock_call_req): - """ - Query_VNF - """ r1 = [0, json.JSONEncoder().encode({ "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -192,7 +196,6 @@ class InterfacesTest(TestCase): "createTime": "2016-07-06 15:33:18"}), "200"] r2 = [0, json.JSONEncoder().encode({"vnfinstancestatus": "1"}), "200"] - # mock_call_req_aai.side_effect = [r1] mock_call_req.side_effect = [r1, r2] response = self.client.get("/api/ztevmanagerdriver/v1/ztevnfmid/vnfs/vbras_innstance_id") @@ -202,24 +205,22 @@ class InterfacesTest(TestCase): expect_resp_data = {"vnfInfo": {"vnfStatus": "1"}} self.assertEqual(expect_resp_data, response.data) - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_operation_status_004(self, mock_call_req): - """ - Operation_status - """ - vnfm_info = {u'userName': u'admin', - u'vendor': u'ZTE', - u'name': u'ZTE_VNFM_237_62', - u'vimId': u'516cee95-e8ca-4d26-9268-38e343c2e31e', - u'url': u'http://192.168.237.165:2324', - u'certificateUrl': u'', - u'version': u'V1.0', - u'vnfmId': u'b0797c9b-3da9-459c-b25c-3813e9d8fd70', - u'password': u'admin', - u'type': u'ztevmanagerdriver', - u'createTime': u'2016-10-31 11:08:39', - u'description': u''} + vnfm_info = { + "userName": "admin", + "vendor": "ZTE", + "name": "ZTE_VNFM_237_62", + "vimId": "516cee95-e8ca-4d26-9268-38e343c2e31e", + "url": "http://192.168.237.165:2324", + "certificateUrl": "", + "version": "V1.0", + "vnfmId": "b0797c9b-3da9-459c-b25c-3813e9d8fd70", + "password": "admin", + "type": "ztevmanagerdriver", + "createTime": "2016-10-31 11:08:39", + "description": "" + } resp_body = { "responsedescriptor": { "status": "processing", @@ -241,7 +242,6 @@ class InterfacesTest(TestCase): } r1 = [0, json.JSONEncoder().encode(vnfm_info), '200'] r2 = [0, json.JSONEncoder().encode(resp_body), '200'] - # mock_call_req_aai.side_effect = [r1] mock_call_req.side_effect = [r1, r2] response = self.client.get("/api/ztevmanagerdriver/v1/{vnfmid}/jobs/{jobid}?responseId={responseId}".format( vnfmid=vnfm_info["vnfmId"], @@ -256,12 +256,15 @@ class InterfacesTest(TestCase): @mock.patch.object(restcall, 'call_req') def test_grantvnf_005(self, mock_call_req): - """ - Grant_VNF - """ - ret = [0, - '{"vim":{"accessinfo":{"tenant":"admin"},"vimid":"516cee95-e8ca-4d26-9268-38e343c2e31e"}}', - '201'] + grant_data = { + "vim": { + "accessinfo": { + "tenant": "admin" + }, + "vimid": "516cee95-e8ca-4d26-9268-38e343c2e31e" + } + } + ret = [0, json.JSONEncoder().encode(grant_data), '201'] req_data = { "vnfmid": "13232222", @@ -298,9 +301,6 @@ class InterfacesTest(TestCase): @mock.patch.object(restcall, 'call_req') def test_notify_006(self, mock_call_req): - """ - Notification - """ r1 = [0, json.JSONEncoder().encode( {"vim": { @@ -342,26 +342,26 @@ class InterfacesTest(TestCase): expect_resp_data = None self.assertEqual(expect_resp_data, response.data) - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_scale(self, mock_call_req): job_info = {"jobid": "801", "nfInstanceId": "101"} - vnfm_info = {u'userName': u'admin', - u'vendor': u'ZTE', - u'name': u'ZTE_VNFM_237_62', - u'vimId': u'516cee95-e8ca-4d26-9268-38e343c2e31e', - u'url': u'http://192.168.237.165:2324', - u'certificateUrl': u'', - u'version': u'V1.0', - u'vnfmId': u'b0797c9b-3da9-459c-b25c-3813e9d8fd70', - u'password': u'admin', - u'type': u'ztevmanagerdriver', - u'createTime': u'2016-10-31 11:08:39', - u'description': u''} + vnfm_info = { + "userName": "admin", + "vendor": "ZTE", + "name": "ZTE_VNFM_237_62", + "vimId": "516cee95-e8ca-4d26-9268-38e343c2e31e", + "url": "http://192.168.237.165:2324", + "certificateUrl": "", + "version": "V1.0", + "vnfmId": "b0797c9b-3da9-459c-b25c-3813e9d8fd70", + "password": "admin", + "type": "ztevmanagerdriver", + "createTime": "2016-10-31 11:08:39", + "description": "" + } ret = [0, json.JSONEncoder().encode(job_info), "202"] ret_vnfm = [0, json.JSONEncoder().encode(vnfm_info), "200"] - # mock_call_req_aai.side_effect = [ret_vnfm] mock_call_req.side_effect = [ret_vnfm, ret] vnfd_info = { @@ -423,26 +423,29 @@ class InterfacesTest(TestCase): self.assertEqual(str(status.HTTP_202_ACCEPTED), response.status_code) self.assertDictEqual(job_info, response.data) - # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') def test_heal(self, mock_call_req): - job_info = {"jobid": "12234455", "nfInstanceId": "10144445666"} - vnfm_info = {u'userName': u'admin', - u'vendor': u'ZTE', - u'name': u'ZTE_VNFM_237_62', - u'vimId': u'516cee95-e8ca-4d26-9268-38e343c2e31e', - u'url': u'http://192.168.237.165:2324', - u'certificateUrl': u'', - u'version': u'V1.0', - u'vnfmId': u'b0797c9b-3da9-459c-b25c-3813e9d8fd70', - u'password': u'admin', - u'type': u'ztevmanagerdriver', - u'createTime': u'2016-10-31 11:08:39', - u'description': u''} + job_info = { + "jobid": "12234455", + "nfInstanceId": "10144445666" + } + vnfm_info = { + "userName": "admin", + "vendor": "ZTE", + "name": "ZTE_VNFM_237_62", + "vimId": "516cee95-e8ca-4d26-9268-38e343c2e31e", + "url": "http://192.168.237.165:2324", + "certificateUrl": "", + "version": "V1.0", + "vnfmId": "b0797c9b-3da9-459c-b25c-3813e9d8fd70", + "password": "admin", + "type": "ztevmanagerdriver", + "createTime": "2016-10-31 11:08:39", + "description": "" + } ret = [0, json.JSONEncoder().encode(job_info), "202"] ret_vnfm = [0, json.JSONEncoder().encode(vnfm_info), "200"] - # mock_call_req_aai.side_effect = [ret_vnfm] mock_call_req.side_effect = [ret_vnfm, ret] heal_vnf_data = { diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py index 6b9d71eb..21432b2f 100644 --- a/zte/vmanager/driver/interfaces/views.py +++ b/zte/vmanager/driver/interfaces/views.py @@ -22,7 +22,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from driver.pub.utils import restcall -from driver.pub.utils.restcall import req_by_msb, call_aai +from driver.pub.utils.restcall import req_by_msb from driver.pub.config.config import VNF_FTP logger = logging.getLogger(__name__) @@ -72,12 +72,6 @@ def get_vnfminfo_from_nslcm(vnfmid): return ret -# Query vnfm_info from esr -def vnfm_get(vnfmid): - ret = call_aai("api/aai-esr-server/v1/vnfms/%s" % vnfmid, "GET") - return ret - - # Query vnfd_info from nslcm def vnfd_get(vnfpackageid): ret = req_by_msb("api/nslcm/v1/vnfpackage/%s" % vnfpackageid, "GET") @@ -90,7 +84,6 @@ def vnfpackage_get(csarid): return ret -# ================================================== create_vnf_url = "v1/vnfs" create_vnf_param_mapping = { "packageUrl": "", @@ -188,7 +181,6 @@ def instantiate_vnf(request, *args, **kwargs): return Response(data=resp_data, status=ret[2]) -# ================================================== vnf_delete_url = "v1/vnfs/%s" vnf_delete_param_mapping = { "terminationType": "terminationType", @@ -229,9 +221,6 @@ def terminate_vnf(request, *args, **kwargs): return Response(data=resp_data, status=ret[2]) -# ================================================== - - vnf_detail_url = "v1/vnfs/%s" vnf_detail_resp_mapping = { "VNFInstanseStatus": "status" @@ -442,11 +431,7 @@ def notify(request, *args, **kwargs): for affectedcp in affectedcps: data["affectedCp"].append(affectedcp) - # { - # "virtualLinkInstanceId": ignorcase_get(affectedcp, "virtuallinkinstanceid"), - # "ownerId": ignorcase_get(affectedcp, "ownerId"), - # "ownerType": ignorcase_get(affectedcp, "ownerType") - # } + ret = req_by_msb(notify_url.format(vnfmid=ignorcase_get(data, 'VNFMID'), vnfInstanceId=ignorcase_get(data, 'vnfinstanceid')), "POST", content=json.JSONEncoder().encode(data)) @@ -508,7 +493,6 @@ def scale(request, *args, **kwargs): if ret[0] != 0: return Response(data={'error': 'scale error'}, status=ret[2]) resp_data = json.JSONDecoder().decode(ret[1]) - # jobId = resp_data["jobid"] logger.info("resp_data=%s", resp_data) except Exception as e: logger.error("Error occurred when scaling VNF,error:%s", e.message) @@ -556,7 +540,6 @@ def heal(request, *args, **kwargs): if ret[0] != 0: return Response(data={'error': 'heal error'}, status=ret[2]) resp_data = json.JSONDecoder().decode(ret[1]) - # jobId = resp_data["jobid"] logger.info("resp_data=%s", resp_data) except Exception as e: logger.error("Error occurred when healing VNF,error:%s", e.message) diff --git a/zte/vmanager/driver/pub/config/config.py b/zte/vmanager/driver/pub/config/config.py index e5d90b33..3ccdde3d 100644 --- a/zte/vmanager/driver/pub/config/config.py +++ b/zte/vmanager/driver/pub/config/config.py @@ -12,16 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [AAI] -AAI_SERVICE_IP = '127.0.0.1' -AAI_SERVICE_PORT = '8443' -AAI_BASE_URL = "https://%s:%s/aai/v8" % (AAI_SERVICE_IP, AAI_SERVICE_PORT) -AAI_USER = "AAI" -AAI_PASSWORD = "AAI" -CLOUD_OWNER = "11" -CLOUD_REGION_ID = "" -TENANT_ID = "" - # [VNFFTP] VNF_FTP = "ftp://VMVNFM:Vnfm_1g3T@127.0.0.1:21/" diff --git a/zte/vmanager/driver/pub/utils/restcall.py b/zte/vmanager/driver/pub/utils/restcall.py index 3bf9c2d8..fd0b3ddd 100644 --- a/zte/vmanager/driver/pub/utils/restcall.py +++ b/zte/vmanager/driver/pub/utils/restcall.py @@ -12,14 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import sys import traceback -import logging import urllib2 import uuid + import httplib2 -from driver.pub.config.config import MSB_SERVICE_IP, MSB_SERVICE_PORT, AAI_BASE_URL, AAI_USER, AAI_PASSWORD +from driver.pub.config.config import MSB_SERVICE_IP, MSB_SERVICE_PORT rest_no_auth, rest_oneway_auth, rest_bothway_auth = 0, 1, 2 HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_202_ACCEPTED = '200', '201', '204', '202' @@ -93,56 +94,3 @@ def combine_url(base_url, resource): else: full_url = base_url + '/' + resource return full_url - - -def call_req_aai(base_url, user, passwd, auth_type, resource, method, content=''): - callid = str(uuid.uuid1()) - logger.debug("[%s]call_req('%s','%s','%s',%s,'%s','%s','%s')" % ( - callid, base_url, user, passwd, auth_type, resource, method, content)) - ret = None - resp_status = '' - try: - full_url = combine_url(base_url, resource) - headers = {'content-type': 'application/json', 'accept': 'application/json', - 'X-FromAppId': 'VFC-SVNFM-ZTE-DRIVER', 'X-TransactionId': str(uuid.uuid1())} - if user: - headers['Authorization'] = 'Basic ' + ('%s:%s' % (user, passwd)).encode("base64") - ca_certs = None - for retry_times in range(3): - http = httplib2.Http(ca_certs=ca_certs, disable_ssl_certificate_validation=(auth_type == rest_no_auth)) - http.follow_all_redirects = True - try: - resp, resp_content = http.request(full_url, method=method.upper(), body=content, headers=headers) - resp_status, resp_body = resp['status'], resp_content.decode('UTF-8') - logger.debug("[%s][%d]status=%s,resp_body=%s)" % (callid, retry_times, resp_status, resp_body)) - if resp_status in status_ok_list: - ret = [0, resp_body, resp_status] - else: - ret = [1, resp_body, resp_status] - break - except Exception as ex: - if 'httplib.ResponseNotReady' in str(sys.exc_info()): - logger.debug("retry_times=%d", retry_times) - logger.error(traceback.format_exc()) - ret = [1, "Unable to connect to %s" % full_url, resp_status] - continue - raise ex - except urllib2.URLError as err: - ret = [2, str(err), resp_status] - except Exception as ex: - logger.error(traceback.format_exc()) - logger.error("[%s]ret=%s" % (callid, str(sys.exc_info()))) - res_info = str(sys.exc_info()) - if 'httplib.ResponseNotReady' in res_info: - res_info = "The URL[%s] request failed or is not responding." % full_url - ret = [3, res_info, resp_status] - except: - logger.error(traceback.format_exc()) - ret = [4, str(sys.exc_info()), resp_status] - - logger.debug("[%s]ret=%s" % (callid, str(ret))) - return ret - - -def call_aai(resource, method, data=''): - return call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, method, data) -- cgit 1.2.3-korg