summaryrefslogtreecommitdiffstats
path: root/gvnfmadapter
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-22 17:21:48 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-22 17:21:48 +0800
commit6813ac186ad710b48a4573b9345ee8205f965836 (patch)
treea92eed57081ade034262b8c92a74b2878b71c9b5 /gvnfmadapter
parent47bfb11ebbdfd0257238caeb6a6924cee9d2d7a5 (diff)
Fix vfc-gvnfmadapter unit tests
Change-Id: I4e28bac6e6a7d69b5cbc982eb86b62ceb83cdfab Issue-ID: VFC-418 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'gvnfmadapter')
-rw-r--r--gvnfmadapter/driver/interfaces/tests.py98
-rw-r--r--gvnfmadapter/driver/interfaces/views.py87
2 files changed, 90 insertions, 95 deletions
diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py
index a05ea80..68e84b5 100644
--- a/gvnfmadapter/driver/interfaces/tests.py
+++ b/gvnfmadapter/driver/interfaces/tests.py
@@ -31,27 +31,26 @@ class InterfacesTest(TestCase):
def test_instantiate_vnf(self, mock_call_req):
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': ''
+ '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-3111: 08: 39',
+ 'description': ''
}
job_info = {
- "vnfInstanceId":"8",
- "jobId":"NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9"
+ "vnfInstanceId": "8",
+ "jobId": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9"
}
vnflcm_info = {
- "vnfInstanceId":"8",
- "vnfLcOpId":"NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
+ "vnfInstanceId": "8",
+ "vnfLcOpId": "NF-INST-8-6ffa8083-6705-49b3-ae54-cbd6265fbe7a"
}
-
r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
ret = [0, json.JSONEncoder().encode(job_info), '200']
ret2 = [0, json.JSONEncoder().encode(vnflcm_info), '200']
@@ -69,7 +68,7 @@ class InterfacesTest(TestCase):
'externalManageNetworkName': 'mng_net_2017',
'sfc_data_network': 'sfc_data_net_2016',
'externalDataNetworkName': 'Flow_out_net',
- 'inputs':{}
+ 'inputs': {}
}
}
response = self.client.post("/api/gvnfmdriver/v1/1/vnfs",
@@ -98,7 +97,6 @@ class InterfacesTest(TestCase):
"createTime": "2016-07-06 15:33:18"
}
job_info = {"vnfInstanceId": "1", "vnfLcOpId": "1"}
- # job_status_info = {"responseDescriptor":{"progress":"100"}}
job_status_info = {
"jobId": "1",
"responseDescriptor": {
@@ -142,47 +140,59 @@ class InterfacesTest(TestCase):
"password": "admin",
"createTime": "2016-07-06 15:33:18"
}
- job_info = {"ResponseInfo": {"vnfInstanceId":"88","instantiationState":"INSTANTIATED","vnfSoftwareVersion":"v1.2.3"}}
+ job_info = {
+ "ResponseInfo": {
+ "vnfInstanceId": "88",
+ "instantiationState": "INSTANTIATED",
+ "vnfSoftwareVersion": "v1.2.3"
+ }
+ }
r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"]
r2 = [0, json.JSONEncoder().encode(job_info), "200"]
mock_call_req.side_effect = [r1, r2]
response = self.client.get("/api/gvnfmdriver/v1/19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee/vnfs/88")
self.assertEqual(status.HTTP_200_OK, response.status_code)
- expect_resp_data = {"vnfInfo": {"vnfInstanceId": "88", "vnfStatus": "ACTIVE","version":"v1.2.3"}}
+ expect_resp_data = {
+ "vnfInfo": {
+ "vnfInstanceId": "88",
+ "vnfStatus": "ACTIVE",
+ "version": "v1.2.3"
+ }
+ }
self.assertEqual(expect_resp_data, response.data)
@mock.patch.object(restcall, 'call_req')
def test_operation_status(self, mock_call_req):
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': ''
+ '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-3111: 08: 39',
+ 'description': ''
}
expected_body = {
"jobId": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9",
- "responseDescriptor":{
+ "responseDescriptor": {
"responseId": 3,
"progress": 40,
"status": "PROCESSING",
"statusDescription": "OMC VMs are decommissioned in VIM",
"errorCode": "null",
"responseHistoryList": [
- {
- "status": "error",
- "progress": 255,
- "errorcode": "",
- "responseid": 20,
- "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
- }
+ {
+ "status": "error",
+ "progress": 255,
+ "errorcode": "",
+ "responseid": 20,
+ "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
+ }
]
}
}
@@ -207,9 +217,8 @@ class InterfacesTest(TestCase):
r1 = [0, json.JSONEncoder().encode(vnfm_info), '200']
r2 = [0, json.JSONEncoder().encode(resp_body), '200']
mock_call_req.side_effect = [r1, r2]
- response = self.client.get("/api/gvnfmdriver/v1/{vnfmid}/jobs/{jobid}?responseId={responseId}".
- format(vnfmid=vnfm_info["vnfmId"],jobid=resp_body["ResponseInfo"]["vnfLcOpId"],
- responseId=resp_body["ResponseInfo"]["responseDescriptor"]["responseId"]))
+ response = self.client.get("/api/gvnfmdriver/v1/%s/jobs/%s?responseId=0"
+ %(vnfm_info["vnfmId"], expected_body["jobId"]))
self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertDictEqual(expected_body, response.data)
@@ -243,7 +252,7 @@ class InterfacesTest(TestCase):
@mock.patch.object(restcall, 'call_req')
def test_notify(self, mock_call_req):
vim_info = {
- "vim":{
+ "vim": {
"vimInfoId": "111111",
"vimId": "12345678",
"interfaceInfo": {
@@ -295,7 +304,8 @@ class InterfacesTest(TestCase):
]
}
response = self.client.post("/api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification",
- data=json.dumps(req_data), content_type='application/json')
+ data=json.dumps(req_data),
+ content_type='application/json')
self.assertEqual(str(status.HTTP_200_OK), response.status_code)
expect_resp_data = None
self.assertEqual(expect_resp_data, response.data)
diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py
index bfb91e7..a96a510 100644
--- a/gvnfmadapter/driver/interfaces/views.py
+++ b/gvnfmadapter/driver/interfaces/views.py
@@ -184,20 +184,25 @@ def operation_status(request, *args, **kwargs):
def grantvnf(request, *args, **kwargs):
logger.info("=====grantvnf=====")
try:
- resp_data = {}
logger.info("req_data = %s", request.data)
ret = req_by_msb('api/nslcm/v1/grantvnf', "POST", content=json.JSONEncoder().encode(request.data))
logger.info("ret = %s", ret)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise GvnfmDriverException('Failed to grant vnf.')
resp = json.JSONDecoder().decode(ret[1])
- resp_data['vimid'] = ignorcase_get(resp['vim'], 'vimid')
- resp_data['tenant'] = ignorcase_get(ignorcase_get(resp['vim'], 'accessinfo'), 'tenant')
+ resp_data = {
+ 'vimid': ignorcase_get(resp['vim'], 'vimid'),
+ 'tenant': ignorcase_get(ignorcase_get(resp['vim'], 'accessinfo'), 'tenant')
+ }
logger.info("[%s]resp_data=%s", fun_name(), resp_data)
- except Exception as e:
- logger.error("Error occurred in Grant VNF.")
- raise e
- return Response(data=resp_data, status=ret[2])
+ return Response(data=resp_data, status=ret[2])
+ except GvnfmDriverException as e:
+ logger.error('Grant vnf failed, detail message: %s' % e.message)
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@api_view(http_method_names=['POST'])
@@ -208,21 +213,33 @@ def notify(request, *args, **kwargs):
ret = req_by_msb("api/nslcm/v1/vnfs/%s/Notify" % vnfinstanceid, "POST", json.JSONEncoder().encode(request.data))
logger.info("[%s]data = %s", fun_name(), ret)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- except Exception as e:
- logger.error("Error occurred in LCM notification.")
- raise e
- return Response(data=None, status=ret[2])
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise GvnfmDriverException('Failed to notify vnf.')
+ return Response(data=None, status=ret[2])
+ except GvnfmDriverException as e:
+ logger.error('Grant vnf failed, detail message: %s' % e.message)
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@api_view(http_method_names=['GET'])
def get_vnfpkgs(request, *args, **kwargs):
- logger.info("Enter %s", fun_name())
- ret = req_by_msb("api/nslcm/v1/vnfpackage", "GET")
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- resp = json.JSONDecoder().decode(ret[1])
- return Response(data=resp, status=status.HTTP_200_OK)
+ try:
+ logger.info("Enter %s", fun_name())
+ ret = req_by_msb("api/nslcm/v1/vnfpackage", "GET")
+ if ret[0] != 0:
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise GvnfmDriverException('Failed to get vnfpkgs.')
+ resp = json.JSONDecoder().decode(ret[1])
+ return Response(data=resp, status=status.HTTP_200_OK)
+ except GvnfmDriverException as e:
+ logger.error('Get vnfpkgs failed, detail message: %s' % e.message)
+ return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ except:
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def call_vnfm(resource, method, vnfm_info, data=""):
@@ -273,37 +290,6 @@ def get_vnfminfo_from_nslcm(vnfm_id):
return json.JSONDecoder().decode(ret[1])
-# def wait4job(vnfm_id, jobId, gracefulTerminationTimeout):
-# begin_time = time.time()
-# try:
-# logger.debug("[wait4job] vnfm_id=[%s],jobId=[%s],gracefulTerminationTimeout=[%s]",
-# vnfm_id, jobId, gracefulTerminationTimeout)
-# vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
-# logger.debug("[do_terminatevnf] vnfm_info=[%s]", vnfm_info)
-#
-# ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
-# if ret != 0:
-# return 255, Response(data={"error":"Fail to get VNFM!"}, status=status.HTTP_412_PRECONDITION_FAILED)
-#
-# responseId = None
-# while ret == 0:
-# cur_time = time.time()
-# if gracefulTerminationTimeout and (cur_time - begin_time > gracefulTerminationTimeout):
-# return 255, Response(data={"error":"Fail to terminate VNF!"}, status=status.HTTP_408_REQUEST_TIMEOUT)
-# ret = call_vnfm("api/vnflcm/v1/vnf_lc_ops/%s?responseId=%s" % (jobId, responseId), "GET", vnfm_info)
-# if ret[0] != 0:
-# return 255, Response(data={"error":"Fail to get job status!"}, status=status.HTTP_412_PRECONDITION_FAILED)
-# if json.JSONDecoder().decode(ret[2]) != 200:
-# return 255, Response(data={"error":"Fail to get job status!"}, status=status.HTTP_412_PRECONDITION_FAILED)
-# job_info = json.JSONDecoder().decode(ret[1])
-# responseId = ignorcase_get(ignorcase_get(job_info, "VnfLcOpResponseDescriptor"), "responseId")
-# progress = ignorcase_get(ignorcase_get(job_info, "VnfLcOpResponseDescriptor"), "progress")
-# if progress == "100":
-# return 0, Response(data={"success":"success"}, status=status.HTTP_204_NO_CONTENT)
-# except Exception as e:
-# logger.error("Error occurred when do_createvnf")
-# return 255, Response(data={"error":"Exception caught! Fail to get job status!"}, status=status.HTTP_412_PRECONDITION_FAILED)
-
def wait4job(vnfm_id, job_id, gracefulTerminationTimeout=1200, retry_count=60, interval_second=3):
logger.debug("[wait4job] vnfm_id=[%s],jobId=[%s],gracefulTerminationTimeout=[%s]",
vnfm_id, job_id, gracefulTerminationTimeout)
@@ -312,7 +298,6 @@ def wait4job(vnfm_id, job_id, gracefulTerminationTimeout=1200, retry_count=60, i
job_end_normal, job_timeout = False, True
vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
logger.debug("[do_terminatevnf] vnfm_info=[%s]", vnfm_info)
-
while count < retry_count:
count = count + 1
time.sleep(interval_second)