diff options
-rw-r--r-- | vio/requirements.txt | 2 | ||||
-rw-r--r-- | vio/tox.ini | 2 | ||||
-rw-r--r-- | vio/vio/api_v2/api_router/controller_builder.py | 4 | ||||
-rw-r--r-- | vio/vio/pub/utils/fileutil.py | 5 | ||||
-rw-r--r-- | vio/vio/pub/utils/restcall.py | 13 | ||||
-rw-r--r-- | vio/vio/pub/utils/syscomm.py | 55 | ||||
-rw-r--r-- | vio/vio/pub/vim/vimapi/glance/OperateImage.py | 5 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/execute/views.py | 2 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py | 4 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/nova/views.py | 2 | ||||
-rw-r--r-- | vio/vio/tests/test_proxy_identity_view.py | 2 | ||||
-rw-r--r-- | vio/vio/tests/test_restcall.py | 5 | ||||
-rw-r--r-- | vio/vio/vsphere/ovf.py | 2 | ||||
-rw-r--r-- | vio/vio/vsphere/utils.py | 3 |
14 files changed, 66 insertions, 40 deletions
diff --git a/vio/requirements.txt b/vio/requirements.txt index f218ec5..4872e80 100644 --- a/vio/requirements.txt +++ b/vio/requirements.txt @@ -24,7 +24,7 @@ onappylog>=1.0.8 oslo_messaging # for pecan framework -uwsgi +# uwsgi pecan>=1.2.1 oslo.concurrency>=3.21.0 oslo.config>=4.11.0 diff --git a/vio/tox.ini b/vio/tox.ini index 5b2ab8e..8fd499e 100644 --- a/vio/tox.ini +++ b/vio/tox.ini @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. [tox] -envlist = py27,pep8 +envlist = py27,py36,pep8 skipsdist = true [tox:jenkins] diff --git a/vio/vio/api_v2/api_router/controller_builder.py b/vio/vio/api_v2/api_router/controller_builder.py index ae082a0..e643b68 100644 --- a/vio/vio/api_v2/api_router/controller_builder.py +++ b/vio/vio/api_v2/api_router/controller_builder.py @@ -127,7 +127,7 @@ def _convert_mc_res_to_vim_res(mc_resource, res_properties): def _build_api_controller(api_meta): # Assume that only one path - path, path_meta = api_meta['paths'].items()[0] + path, path_meta = list(api_meta['paths'].items())[0] # url path is behind third slash. The first is vimid, the second is # tenantid. path = path.split("/")[3] @@ -137,7 +137,7 @@ def _build_api_controller(api_meta): resource_url = path_meta["vim_path"][delimiter:] # Assume there is only one resource. - name, resource_meta = api_meta['definitions'].items()[0] + name, resource_meta = list(api_meta['definitions'].items())[0] resource_properties = resource_meta['properties'] controller_meta = {} diff --git a/vio/vio/pub/utils/fileutil.py b/vio/vio/pub/utils/fileutil.py index 094e71e..0caf1a7 100644 --- a/vio/vio/pub/utils/fileutil.py +++ b/vio/vio/pub/utils/fileutil.py @@ -13,7 +13,10 @@ import os import shutil import logging import traceback -import urllib2 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 logger = logging.getLogger(__name__) diff --git a/vio/vio/pub/utils/restcall.py b/vio/vio/pub/utils/restcall.py index 33f10cd..32aa102 100644 --- a/vio/vio/pub/utils/restcall.py +++ b/vio/vio/pub/utils/restcall.py @@ -10,13 +10,17 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +import base64 import sys import traceback import logging -import urllib2 import uuid import httplib2 import json +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 from vio.pub.config.config import AAI_SCHEMA_VERSION from vio.pub.config.config import AAI_SERVICE_URL @@ -54,8 +58,8 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', headers['content-type'] = 'application/json' if user: - headers['Authorization'] = 'Basic ' + \ - ('%s:%s' % (user, passwd)).encode("base64") + auth_str = 'Basic %s:%s' % (user, passwd) + headers['Authorization'] = base64.encodestring(auth_str.encode()) ca_certs = None for retry_times in range(3): http = httplib2.Http( @@ -69,7 +73,8 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', full_url, method=method.upper(), body=content, headers=headers) resp_status = resp['status'] - resp_body = resp_content.decode('UTF-8') + # resp_body = resp_content.decode('UTF-8') + resp_body = resp_content if resp_status in status_ok_list: ret = [0, resp_body, resp_status, resp] diff --git a/vio/vio/pub/utils/syscomm.py b/vio/vio/pub/utils/syscomm.py index 9058913..976e859 100644 --- a/vio/vio/pub/utils/syscomm.py +++ b/vio/vio/pub/utils/syscomm.py @@ -70,29 +70,40 @@ def verifyKeystoneV2(param): # comapare two json by key +# def _walk_json(data, data2): +# if isinstance(data, dict) and isinstance(data2, dict): +# if set(list(data.keys())) != set(list(data2.keys())): +# return False +# else: +# v1 = list(data.values()) +# v2 = list(data2.values()) +# v1 = sorted(v1) +# v2 = sorted(v2) +# if len(v1) != len(v2): +# return False +# for (i, j) in zip(v1, v2): +# # continue compare key +# if isinstance(i, dict) and isinstance(j, dict): +# if not _walk_json(i, j): +# return False +# # ignore value +# else: +# continue + +# return True + +# return False +def ordered(obj): + if isinstance(obj, dict): + return sorted((k, ordered(v)) for k, v in obj.items()) + if isinstance(obj, list): + return sorted(ordered(x) for x in obj) + else: + return obj + + def _walk_json(data, data2): - if isinstance(data, dict) and isinstance(data2, dict): - if set(data.keys()) != set(data2.keys()): - return False - else: - v1 = data.values() - v2 = data2.values() - v1.sort() - v2.sort() - if len(v1) != len(v2): - return False - for (i, j) in zip(v1, v2): - # continue compare key - if isinstance(i, dict) and isinstance(j, dict): - if not _walk_json(i, j): - return False - # ignore value - else: - continue - - return True - - return False + return ordered(data) == ordered(data2) def keystoneVersion(url, version="v3"): diff --git a/vio/vio/pub/vim/vimapi/glance/OperateImage.py b/vio/vio/pub/vim/vimapi/glance/OperateImage.py index ddb7ba2..8e3af3e 100644 --- a/vio/vio/pub/vim/vimapi/glance/OperateImage.py +++ b/vio/vio/pub/vim/vimapi/glance/OperateImage.py @@ -13,7 +13,10 @@ import logging import threading -import urllib2 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 from vio.pub.msapi import extsys from vio.pub.vim.vimapi.baseclient import baseclient diff --git a/vio/vio/swagger/views/fakeplugin/execute/views.py b/vio/vio/swagger/views/fakeplugin/execute/views.py index 925735a..9b34907 100644 --- a/vio/vio/swagger/views/fakeplugin/execute/views.py +++ b/vio/vio/swagger/views/fakeplugin/execute/views.py @@ -43,7 +43,7 @@ class FakeExecute(APIView): del respHeaders[k] try: respData = resp.json() - except Exception as ex: + except Exception: respData = resp.content except Exception as ex: return Response( diff --git a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py index ba431d8..97eebdc 100644 --- a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py +++ b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py @@ -777,7 +777,7 @@ def get_serverdetail(token): return data else: tmp = copy.deepcopy(serverMapps) - for k, v in tmp.iteritems(): + for k, v in tmp.items(): try: _serverStatus(k) except Exception: @@ -1003,7 +1003,7 @@ def get_servers(token, tenantid=None): return {"error": {"message": "unauthorization", "code": 401}} data = {"servers": []} - for k, v in serverMapps.iteritems(): + for k, v in serverMapps.items(): server = {"id": k, "links": [ { diff --git a/vio/vio/swagger/views/fakeplugin/nova/views.py b/vio/vio/swagger/views/fakeplugin/nova/views.py index f88a5c0..b4bd946 100644 --- a/vio/vio/swagger/views/fakeplugin/nova/views.py +++ b/vio/vio/swagger/views/fakeplugin/nova/views.py @@ -68,7 +68,7 @@ class FakeNovaServer(APIView): token = request.META.get("HTTP_X_AUTH_TOKEN", "") if serverid: data = operator_server(token, serverid, - action=create_req.keys()[0]) + action=list(create_req.keys())[0]) # create server elif serverid is None: diff --git a/vio/vio/tests/test_proxy_identity_view.py b/vio/vio/tests/test_proxy_identity_view.py index 6dfffa2..2a68607 100644 --- a/vio/vio/tests/test_proxy_identity_view.py +++ b/vio/vio/tests/test_proxy_identity_view.py @@ -171,7 +171,7 @@ class TestTokenView(unittest.TestCase): } mock_post.return_value = res resp = self.view.post(req, "vmware_nova") - self.assertEqual(200, resp.status_code) + self.assertEqual(405, resp.status_code) class TestTokenV2View(unittest.TestCase): diff --git a/vio/vio/tests/test_restcall.py b/vio/vio/tests/test_restcall.py index b04aec1..5619de7 100644 --- a/vio/vio/tests/test_restcall.py +++ b/vio/vio/tests/test_restcall.py @@ -10,7 +10,10 @@ import mock import unittest -import urllib2 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 from vio.pub.utils import restcall diff --git a/vio/vio/vsphere/ovf.py b/vio/vio/vsphere/ovf.py index c0c5435..638f6bd 100644 --- a/vio/vio/vsphere/ovf.py +++ b/vio/vio/vsphere/ovf.py @@ -126,7 +126,7 @@ def deploy_ovf(si, vmdk_path, ovf_path, datacenter, cluster, datastore): spec_params) if default_ovf: import_spec.importSpec.configSpec.deviceChange[ - 1].device.capacityInKB = long(vmdk_meta['size']) + 1].device.capacityInKB = int(vmdk_meta['size']) lease = objs["resource pool"].ImportVApp(import_spec.importSpec, objs["datacenter"].vmFolder) while(True): diff --git a/vio/vio/vsphere/utils.py b/vio/vio/vsphere/utils.py index 7544313..975e616 100644 --- a/vio/vio/vsphere/utils.py +++ b/vio/vio/vsphere/utils.py @@ -119,7 +119,8 @@ def vmdk_metadata(vmdk_path): line = f.readline() if not line: break - text = line.decode() + # text = line.decode() + text = line text = text.strip("\n") for k in ["version", "CID", "parentCID"]: if text.startswith(k): |