summaryrefslogtreecommitdiffstats
path: root/zte/vmanager
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-30 11:00:47 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-30 11:00:47 +0800
commit47fd33356d8ae5d709fdb1759a3fcfdb3a8c06a2 (patch)
tree4386f2b941c73d40b2b7d32728f19ac82514586e /zte/vmanager
parent910d4b904de77e9be7beb64bebc7b4cf99f97050 (diff)
Fix vfc-svnfm-ztedriver pep8 issues
Change-Id: Iaa7f1293f036652f9825a40e41b58da0794e85d7 Issue-ID: VFC-478 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte/vmanager')
-rw-r--r--zte/vmanager/driver/interfaces/tests.py134
-rw-r--r--zte/vmanager/driver/interfaces/views.py37
-rw-r--r--zte/vmanager/driver/pub/utils/restcall.py2
-rw-r--r--zte/vmanager/driver/settings.py4
-rw-r--r--zte/vmanager/driver/swagger/tests.py3
-rw-r--r--zte/vmanager/driver/urls.py4
6 files changed, 106 insertions, 78 deletions
diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py
index daacdb6a..3dde266b 100644
--- a/zte/vmanager/driver/interfaces/tests.py
+++ b/zte/vmanager/driver/interfaces/tests.py
@@ -112,18 +112,22 @@ class InterfacesTest(TestCase):
# mock_call_req_aai.side_effect =[r1]
mock_call_req.side_effect = [r1, r2, r3, ret]
- req_data = {'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367',
- 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a',
- 'vnfDescriptorId': 'vcpe_vfw_zte_1_0',
- 'additionalParam': {'sdncontroller': 'e4d637f1-a4ec-4c59-8b20-4e8ab34daba9',
- 'NatIpRange': '192.167.0.10-192.168.0.20',
- 'm6000_mng_ip': '192.168.11.11',
- 'externalPluginManageNetworkName': 'plugin_net_2014',
- 'location': '516cee95-e8ca-4d26-9268-38e343c2e31e',
- 'externalManageNetworkName': 'mng_net_2017',
- 'sfc_data_network': 'sfc_data_net_2016',
- 'externalDataNetworkName': 'Flow_out_net',
- 'inputs':{}}}
+ req_data = {
+ 'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367',
+ 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a',
+ 'vnfDescriptorId': 'vcpe_vfw_zte_1_0',
+ 'additionalParam': {
+ 'sdncontroller': 'e4d637f1-a4ec-4c59-8b20-4e8ab34daba9',
+ 'NatIpRange': '192.167.0.10-192.168.0.20',
+ 'm6000_mng_ip': '192.168.11.11',
+ 'externalPluginManageNetworkName': 'plugin_net_2014',
+ 'location': '516cee95-e8ca-4d26-9268-38e343c2e31e',
+ 'externalManageNetworkName': 'mng_net_2017',
+ 'sfc_data_network': 'sfc_data_net_2016',
+ 'externalDataNetworkName': 'Flow_out_net',
+ 'inputs': {}
+ }
+ }
response = self.client.post("/api/ztevmanagerdriver/v1/ztevnfmid/vnfs",
data=json.dumps(req_data), content_type="application/json")
@@ -210,27 +214,34 @@ class InterfacesTest(TestCase):
u'type': u'ztevmanagerdriver',
u'createTime': u'2016-10-31 11:08:39',
u'description': u''}
- resp_body = {"responsedescriptor":
- {"status": "processing", "responsehistorylist": [
- {"status": "error",
- "progress": 255,
- "errorcode": "",
- "responseid": 20,
- "statusdescription": "'JsonParser' object has no attribute 'parser_info'"}],
- "responseid": 21,
- "errorcode": "",
- "progress": 40,
- "statusdescription": "Create nf apply resource failed"},
- "jobid": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9"}
+ resp_body = {
+ "responsedescriptor": {
+ "status": "processing",
+ "responsehistorylist": [
+ {
+ "status": "error",
+ "progress": 255,
+ "errorcode": "",
+ "responseid": 20,
+ "statusdescription": "'JsonParser' object has no attribute 'parser_info'"
+ }
+ ],
+ "responseid": 21,
+ "errorcode": "",
+ "progress": 40,
+ "statusdescription": "Create nf apply resource failed"
+ },
+ "jobid": "NF-CREATE-11-ec6c2f2a-9f48-11e6-9405-fa163e91c2f9"
+ }
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(
+ response = self.client.get("/api/ztevmanagerdriver/v1/{vnfmid}/jobs/{jobid}?responseId={responseId}".format(
vnfmid=vnfm_info["vnfmId"],
jobid=resp_body["jobid"],
- responseId=resp_body["responsedescriptor"]["responseid"]))
+ responseId=resp_body["responsedescriptor"]["responseid"])
+ )
self.assertEqual(str(status.HTTP_200_OK), response.status_code)
@@ -250,19 +261,23 @@ class InterfacesTest(TestCase):
"vnfmid": "13232222",
"nfvoid": "03212234",
"vimid": "12345678",
- "exvimidlist ":
- ["exvimid"],
+ "exvimidlist ": [
+ "exvimid"
+ ],
"tenant": " tenant1",
"vnfistanceid": "1234",
"operationright": "0",
"vmlist": [
{
"vmflavor": "SMP",
- "vmnumber": "3"},
+ "vmnumber": "3"
+ },
{
"vmflavor": "CMP",
- "vmnumber": "3"}
- ]}
+ "vmnumber": "3"
+ }
+ ]
+ }
mock_call_req.return_value = ret
response = self.client.put("/api/ztevmanagerdriver/v1/resource/grant",
@@ -341,7 +356,7 @@ class InterfacesTest(TestCase):
# @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"}
+ job_info = {"jobid": "801", "nfInstanceId": "101"}
vnfm_info = {u'userName': u'admin',
u'vendor': u'ZTE',
u'name': u'ZTE_VNFM_237_62',
@@ -356,29 +371,30 @@ class InterfacesTest(TestCase):
u'description': u''}
ret = [0, json.JSONEncoder().encode(job_info), "202"]
- ret_vnfm = [0,json.JSONEncoder().encode(vnfm_info), "200"]
+ 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 = {
- "vnf_flavours":[
+ "vnf_flavours": [
{
- "flavour_id":"flavour1",
- "description":"",
- "vdu_profiles":[
+ "flavour_id": "flavour1",
+ "description": "",
+ "vdu_profiles": [
{
- "vdu_id":"vdu1Id",
+ "vdu_id": "vdu1Id",
"instances_minimum_number": 1,
"instances_maximum_number": 4,
- "local_affinity_antiaffinity_rule":[
+ "local_affinity_antiaffinity_rule": [
{
- "affinity_antiaffinity":"affinity",
- "scope":"node",
+ "affinity_antiaffinity": "affinity",
+ "scope": "node",
+
}
]
}
],
- "scaling_aspects":[
+ "scaling_aspects": [
{
"id": "demo_aspect",
"name": "demo_aspect",
@@ -390,29 +406,31 @@ class InterfacesTest(TestCase):
}
],
"element_groups": [
- {
- "group_id": "elementGroup1",
- "description": "",
- "properties":{
- "name": "elementGroup1",
- },
- "members": ["gsu_vm","pfu_vm"],
- }
+ {
+ "group_id": "elementGroup1",
+ "description": "",
+ "properties": {
+ "name": "elementGroup1"
+ },
+ "members": [
+ "gsu_vm",
+ "pfu_vm"
+ ]
+ }
]
}
scale_vnf_data = {
- "type":"SCALE_OUT",
- "aspectId":"demo_aspect",
- "numberOfSteps":"3",
- "additionalParam":{
- "vnfdModel":vnfd_info
+ "type": "SCALE_OUT",
+ "aspectId": "demo_aspect",
+ "numberOfSteps": "3",
+ "additionalParam": {
+ "vnfdModel": vnfd_info
}
}
-
response = self.client.post("/api/ztevmanagerdriver/v1/100/vnfs/101/scale",
- data=json.dumps(scale_vnf_data), content_type='application/json')
+ data=json.dumps(scale_vnf_data), content_type='application/json')
self.assertEqual(str(status.HTTP_202_ACCEPTED), response.status_code)
self.assertDictEqual(job_info, response.data)
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 3f4a4baf..a9a430d2 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -55,21 +55,25 @@ query_vnfd_url = "api/nslcm/v1/vnfpackage/%s"
query_vnfm_url = "api/extsys/v1/vnfms/%s"
query_package_url = "api/nslcm/v1/vnfpackage/%s"
-#Query vnfm_info from nslcm
+
+# Query vnfm_info from nslcm
def get_vnfminfo_from_nslcm(vnfmid):
ret = req_by_msb("api/nslcm/v1/vnfms/%s" % vnfmid, "GET")
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")
return ret
+
# Query vnfpackage_info from nslcm
def vnfpackage_get(csarid):
ret = req_by_msb("api/nslcm/v1/vnfpackage/%s" % csarid, "GET")
@@ -91,7 +95,8 @@ create_vnf_param_mapping = {
"additionalParam": ""}
create_vnf_resp_mapping = {
"VNFInstanceID": "vnfInstanceId",
- "JobId": "jobid",}
+ "JobId": "jobid"
+}
@api_view(http_method_names=['POST'])
@@ -214,7 +219,8 @@ def terminate_vnf(request, *args, **kwargs):
vnf_detail_url = "v1/vnfs/%s"
vnf_detail_resp_mapping = {
- "VNFInstanseStatus": "status",}
+ "VNFInstanseStatus": "status"
+}
@api_view(http_method_names=['GET'])
@@ -258,7 +264,8 @@ operation_status_resp_map = {
"ErrorCode": "errorCode",
"ResponseId": "responseId",
"ResponseHistoryList": "responseHistoryList",
- "ResponseDescriptor": "responseDescriptor",}
+ "ResponseDescriptor": "responseDescriptor"
+}
@api_view(http_method_names=['GET'])
@@ -366,7 +373,8 @@ notify_param_map = {
"VMFlavor": "",
"VMNumber": "",
"VMIDlist": "",
- "VMUUID": "",}
+ "VMUUID": ""
+}
@api_view(http_method_names=['POST'])
@@ -447,14 +455,14 @@ def scale(request, *args, **kwargs):
scale_type = ignorcase_get(request.data, "type")
aspect_id = ignorcase_get(request.data, "aspectId")
number_of_steps = ignorcase_get(request.data, "numberOfSteps")
- extension = ignorcase_get(request.data, "additionalParam")
- vnfd_model = ignorcase_get(extension, "vnfdModel")
+ # extension = ignorcase_get(request.data, "additionalParam")
+ # vnfd_model = ignorcase_get(extension, "vnfdModel")
data = {
'vnfmid': vnfm_id,
'nfvoid': 1,
'scaletype': '0' if scale_type == 'SCALE_OUT' else '1',
- 'vmlist': [{'VMNumber':number_of_steps,'VMFlavor':aspect_id}],
- 'extension':''
+ 'vmlist': [{'VMNumber': number_of_steps, 'VMFlavor': aspect_id}],
+ 'extension': ''
}
'''
for vdu_id in get_vdus(vnfd_model, aspect_id):
@@ -474,19 +482,20 @@ def scale(request, *args, **kwargs):
content=json.JSONEncoder().encode(data))
logger.info("ret=%s", ret)
if ret[0] != 0:
- return Response(data={'error':'scale error'}, status=ret[2])
+ 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")
+ logger.error("Error occurred when scaling VNF,error:%s", e.message)
logger.error(traceback.format_exc())
- return Response(data={'error':'scale expection'}, status='500')
+ return Response(data={'error': 'scale expection'}, status='500')
return Response(data=resp_data, status=ret[2])
nf_healing_url = '/api/v1/nf_m_i/nfs/{vnfInstanceID}/vms/operation'
+
@api_view(http_method_names=['POST'])
def heal(request, *args, **kwargs):
logger.info("====heal_vnf===")
@@ -519,12 +528,12 @@ def heal(request, *args, **kwargs):
# jobId = resp_data["jobid"]
logger.info("resp_data=%s", resp_data)
except Exception as e:
- logger.error("Error occurred when healing VNF")
+ logger.error("Error occurred when healing VNF,error:%s", e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'heal expection'}, status='500')
return Response(data=resp_data, status=ret[2])
-#@staticmethod
+
def get_vdus(nf_model, aspect_id):
associated_group = ''
members = []
diff --git a/zte/vmanager/driver/pub/utils/restcall.py b/zte/vmanager/driver/pub/utils/restcall.py
index 8efe0afb..3bf9c2d8 100644
--- a/zte/vmanager/driver/pub/utils/restcall.py
+++ b/zte/vmanager/driver/pub/utils/restcall.py
@@ -94,6 +94,7 @@ def combine_url(base_url, resource):
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')" % (
@@ -142,5 +143,6 @@ def call_req_aai(base_url, user, passwd, auth_type, resource, method, content=''
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)
diff --git a/zte/vmanager/driver/settings.py b/zte/vmanager/driver/settings.py
index 6af1f267..f5923e22 100644
--- a/zte/vmanager/driver/settings.py
+++ b/zte/vmanager/driver/settings.py
@@ -44,7 +44,7 @@ INSTALLED_APPS = [
'rest_framework',
'driver.pub.database',
'driver.interfaces'
- ]
+]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
@@ -55,7 +55,7 @@ MIDDLEWARE_CLASSES = [
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
- ]
+]
ROOT_URLCONF = 'driver.urls'
diff --git a/zte/vmanager/driver/swagger/tests.py b/zte/vmanager/driver/swagger/tests.py
index 20fe9805..157b92a2 100644
--- a/zte/vmanager/driver/swagger/tests.py
+++ b/zte/vmanager/driver/swagger/tests.py
@@ -13,7 +13,7 @@
# limitations under the License.
import unittest
-import json
+
from django.test import Client
from rest_framework import status
@@ -28,4 +28,3 @@ class SwaggerViewTest(unittest.TestCase):
def test_sample(self):
response = self.client.get("/api/ztevmanagerdriver/v1/swagger.json")
self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-
diff --git a/zte/vmanager/driver/urls.py b/zte/vmanager/driver/urls.py
index 0e61dabb..fad242e1 100644
--- a/zte/vmanager/driver/urls.py
+++ b/zte/vmanager/driver/urls.py
@@ -15,8 +15,8 @@
from driver.pub.config.config import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG_TO_MSB_REG_PARAM
from django.conf.urls import include, url
urlpatterns = [
- url(r'^', include('driver.interfaces.urls')),
- url(r'^', include('driver.swagger.urls')),
+ url(r'^', include('driver.interfaces.urls')),
+ url(r'^', include('driver.swagger.urls')),
]
# regist to MSB when startup