Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by $ pyupgrade --py3-only $(git ls-files | grep ".py$") to modernize the code according to Python 3 syntaxes. pep8 errors are fixed by $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place oslo_vmware Also add the pyupgrade hook to pre-commit to avoid merging additional Python 2 syntaxes. Change-Id: I1b34f8026d69db4485b2eec03767e54331e7817c
This commit is contained in:
@@ -28,3 +28,8 @@ repos:
|
||||
hooks:
|
||||
- id: bandit
|
||||
args: ['-x', 'tests']
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.18.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py3-only]
|
||||
|
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2020 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@@ -46,7 +46,7 @@ def _trunc_id(session_id):
|
||||
|
||||
|
||||
# TODO(vbala) Move this class to excutils.py.
|
||||
class RetryDecorator(object):
|
||||
class RetryDecorator:
|
||||
"""Decorator for retrying a function upon suggested exceptions.
|
||||
|
||||
The decorated function is retried for the given number of times, and the
|
||||
@@ -124,7 +124,7 @@ class RetryDecorator(object):
|
||||
return func
|
||||
|
||||
|
||||
class VMwareAPISession(object):
|
||||
class VMwareAPISession:
|
||||
"""Setup a session with the server and handles all calls made to it.
|
||||
|
||||
Example:
|
||||
|
@@ -43,7 +43,7 @@ class LoopingCallDone(Exception):
|
||||
self.retvalue = retvalue
|
||||
|
||||
|
||||
class LoopingCallBase(object):
|
||||
class LoopingCallBase:
|
||||
def __init__(self, f=None, *args, **kw):
|
||||
self.args = args
|
||||
self.kw = kw
|
||||
|
@@ -82,7 +82,7 @@ class VMwareDriverException(Exception):
|
||||
message = self.msg_fmt
|
||||
|
||||
self.message = message
|
||||
super(VMwareDriverException, self).__init__(message)
|
||||
super().__init__(message)
|
||||
|
||||
@property
|
||||
def msg(self):
|
||||
@@ -103,7 +103,7 @@ class VimException(VMwareDriverException):
|
||||
"""The base exception class for all VIM related exceptions."""
|
||||
|
||||
def __init__(self, message=None, cause=None, details=None, **kwargs):
|
||||
super(VimException, self).__init__(message, details, **kwargs)
|
||||
super().__init__(message, details, **kwargs)
|
||||
self.cause = cause
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ class VimSessionOverLoadException(VMwareDriverException):
|
||||
"""Thrown when there is an API call overload at the VMware server."""
|
||||
|
||||
def __init__(self, message, cause=None):
|
||||
super(VimSessionOverLoadException, self).__init__(message)
|
||||
super().__init__(message)
|
||||
self.cause = cause
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class VimConnectionException(VMwareDriverException):
|
||||
"""Thrown when there is a connection problem."""
|
||||
|
||||
def __init__(self, message, cause=None):
|
||||
super(VimConnectionException, self).__init__(message)
|
||||
super().__init__(message)
|
||||
self.cause = cause
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class VimAttributeException(VMwareDriverException):
|
||||
"""Thrown when a particular attribute cannot be found."""
|
||||
|
||||
def __init__(self, message, cause=None):
|
||||
super(VimAttributeException, self).__init__(message)
|
||||
super().__init__(message)
|
||||
self.cause = cause
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class VimFaultException(VimException):
|
||||
"""Exception thrown when there are unrecognized VIM faults."""
|
||||
|
||||
def __init__(self, fault_list, message, cause=None, details=None):
|
||||
super(VimFaultException, self).__init__(message, cause, details)
|
||||
super().__init__(message, cause, details)
|
||||
if not isinstance(fault_list, list):
|
||||
raise ValueError(_("fault_list must be a list"))
|
||||
self.fault_list = fault_list
|
||||
@@ -148,7 +148,7 @@ class VimFaultException(VimException):
|
||||
descr += '\nFaults: ' + str(self.fault_list)
|
||||
if self.details:
|
||||
# details may contain non-ASCII values
|
||||
details = '{%s}' % ', '.join(["'%s': '%s'" % (k, v) for k, v in
|
||||
details = '{%s}' % ', '.join(["'{}': '{}'".format(k, v) for k, v in
|
||||
self.details.items()])
|
||||
descr += '\nDetails: ' + details
|
||||
return descr
|
||||
@@ -158,7 +158,7 @@ class ImageTransferException(VMwareDriverException):
|
||||
"""Thrown when there is an error during image transfer."""
|
||||
|
||||
def __init__(self, message, cause=None):
|
||||
super(ImageTransferException, self).__init__(message)
|
||||
super().__init__(message)
|
||||
self.cause = cause
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ class VMwareDriverConfigurationException(VMwareDriverException):
|
||||
msg_fmt = _("VMware Driver configuration fault.")
|
||||
|
||||
def __init__(self, message=None, details=None, **kwargs):
|
||||
super(VMwareDriverConfigurationException, self).__init__(
|
||||
super().__init__(
|
||||
message, details, **kwargs)
|
||||
_print_deprecation_warning(self.__class__)
|
||||
|
||||
@@ -186,7 +186,7 @@ class MissingParameter(VMwareDriverException):
|
||||
msg_fmt = _("Missing parameter : %(param)s")
|
||||
|
||||
def __init__(self, message=None, details=None, **kwargs):
|
||||
super(MissingParameter, self).__init__(message, details, **kwargs)
|
||||
super().__init__(message, details, **kwargs)
|
||||
_print_deprecation_warning(self.__class__)
|
||||
|
||||
|
||||
|
@@ -24,10 +24,10 @@ _all_log_levels = {'critical', 'error', 'exception', 'info',
|
||||
_all_hints = {'_'}
|
||||
|
||||
_log_translation_hint = re.compile(
|
||||
r".*LOG\.(%(levels)s)\(\s*(%(hints)s)\(" % {
|
||||
'levels': '|'.join(_all_log_levels),
|
||||
'hints': '|'.join(_all_hints),
|
||||
})
|
||||
r".*LOG\.({levels})\(\s*({hints})\(".format(
|
||||
levels='|'.join(_all_log_levels),
|
||||
hints='|'.join(_all_hints),
|
||||
))
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
|
@@ -106,8 +106,8 @@ def download_image(image, image_meta, session, datastore, rel_path,
|
||||
conn = ds_url.connect(method, image_size, cookie)
|
||||
else:
|
||||
ds_url = datastore.build_url(session._scheme, session._host, rel_path)
|
||||
cookie = '%s=%s' % (constants.SOAP_COOKIE_KEY,
|
||||
session.vim.get_http_cookie().strip("\""))
|
||||
cookie = '{}={}'.format(constants.SOAP_COOKIE_KEY,
|
||||
session.vim.get_http_cookie().strip("\""))
|
||||
conn = ds_url.connect(method, image_size, cookie)
|
||||
conn.write = conn.send
|
||||
|
||||
|
@@ -19,10 +19,10 @@ from defusedxml.lxml import parse
|
||||
def _get_vmdk_name_from_ovf(root):
|
||||
ns_ovf = "{{{0}}}".format(root.nsmap["ovf"])
|
||||
disk = root.find("./{0}DiskSection/{0}Disk".format(ns_ovf))
|
||||
file_id = disk.get("{0}fileRef".format(ns_ovf))
|
||||
file_id = disk.get("{}fileRef".format(ns_ovf))
|
||||
f = root.find('./{0}References/{0}File[@{0}id="{1}"]'.format(ns_ovf,
|
||||
file_id))
|
||||
return f.get("{0}href".format(ns_ovf))
|
||||
return f.get("{}href".format(ns_ovf))
|
||||
|
||||
|
||||
def get_vmdk_name_from_ovf(ovf_handle):
|
||||
|
@@ -15,7 +15,7 @@
|
||||
from oslo_vmware._i18n import _
|
||||
|
||||
|
||||
class Datacenter(object):
|
||||
class Datacenter:
|
||||
|
||||
def __init__(self, ref, name):
|
||||
"""Datacenter object holds ref and name together for convenience."""
|
||||
|
@@ -149,7 +149,7 @@ def sdrs_enabled(session, dsc_ref):
|
||||
return pod_sdrs_entry.storageDrsConfig.podConfig.enabled
|
||||
|
||||
|
||||
class Datastore(object):
|
||||
class Datastore:
|
||||
|
||||
def __init__(self, ref, name, capacity=None, freespace=None,
|
||||
uncommitted=None, type=None, datacenter=None):
|
||||
@@ -276,7 +276,7 @@ class Datastore(object):
|
||||
return hosts[i]
|
||||
|
||||
|
||||
class DatastorePath(object):
|
||||
class DatastorePath:
|
||||
|
||||
"""Class for representing a directory or file path in a vSphere datatore.
|
||||
|
||||
@@ -312,7 +312,7 @@ class DatastorePath(object):
|
||||
def __str__(self):
|
||||
"""Full datastore path to the file or directory."""
|
||||
if self._rel_path != '':
|
||||
return "[%s] %s" % (self._datastore_name, self.rel_path)
|
||||
return "[{}] {}".format(self._datastore_name, self.rel_path)
|
||||
return "[%s]" % self._datastore_name
|
||||
|
||||
@property
|
||||
@@ -372,7 +372,7 @@ class DatastorePath(object):
|
||||
return cls(datastore_name, path.strip())
|
||||
|
||||
|
||||
class DatastoreURL(object):
|
||||
class DatastoreURL:
|
||||
|
||||
"""Class for representing a URL to HTTP access a file in a datastore.
|
||||
|
||||
@@ -420,8 +420,8 @@ class DatastoreURL(object):
|
||||
return self._datastore_name
|
||||
|
||||
def __str__(self):
|
||||
return '%s://%s/folder/%s?%s' % (self._scheme, self._server,
|
||||
self.path, self._query)
|
||||
return '{}://{}/folder/{}?{}'.format(self._scheme, self._server,
|
||||
self.path, self._query)
|
||||
|
||||
def connect(self, method, content_length, cookie):
|
||||
try:
|
||||
@@ -434,7 +434,8 @@ class DatastoreURL(object):
|
||||
excep_msg = _("Invalid scheme: %s.") % self._scheme
|
||||
LOG.error(excep_msg)
|
||||
raise ValueError(excep_msg)
|
||||
conn.putrequest(method, '/folder/%s?%s' % (self.path, self._query))
|
||||
conn.putrequest(
|
||||
method, '/folder/{}?{}'.format(self.path, self._query))
|
||||
conn.putheader('User-Agent', constants.USER_AGENT)
|
||||
conn.putheader('Content-Length', content_length)
|
||||
conn.putheader('Cookie', cookie)
|
||||
@@ -458,4 +459,4 @@ class DatastoreURL(object):
|
||||
'AcquireGenericServiceTicket',
|
||||
session.vim.service_content.sessionManager,
|
||||
spec=spec)
|
||||
return '%s="%s"' % (constants.CGI_COOKIE_KEY, ticket.id)
|
||||
return '{}="{}"'.format(constants.CGI_COOKIE_KEY, ticket.id)
|
||||
|
@@ -59,9 +59,9 @@ class Pbm(service.Service):
|
||||
"""
|
||||
base_url = service.Service.build_base_url(protocol, host, port)
|
||||
soap_url = base_url + '/pbm'
|
||||
super(Pbm, self).__init__(wsdl_url, soap_url, cacert, insecure,
|
||||
pool_maxsize, connection_timeout,
|
||||
op_id_prefix)
|
||||
super().__init__(wsdl_url, soap_url, cacert, insecure,
|
||||
pool_maxsize, connection_timeout,
|
||||
op_id_prefix)
|
||||
|
||||
def set_soap_cookie(self, cookie):
|
||||
"""Set the specified vCenter session cookie in the SOAP header
|
||||
@@ -193,7 +193,7 @@ def get_pbm_wsdl_location(vc_version):
|
||||
ver = vc_version.split('.')
|
||||
major_minor = ver[0]
|
||||
if len(ver) >= 2:
|
||||
major_minor = '%s.%s' % (major_minor, ver[1])
|
||||
major_minor = '{}.{}'.format(major_minor, ver[1])
|
||||
curr_dir = os.path.abspath(os.path.dirname(__file__))
|
||||
pbm_service_wsdl = os.path.join(curr_dir, 'wsdl', major_minor,
|
||||
'pbmService.wsdl')
|
||||
|
@@ -44,7 +44,7 @@ READ_CHUNKSIZE = 65536
|
||||
USER_AGENT = 'OpenStack-ESX-Adapter'
|
||||
|
||||
|
||||
class FileHandle(object):
|
||||
class FileHandle:
|
||||
"""Base class for VMware server file (including VMDK) access over HTTP.
|
||||
|
||||
This class wraps a backing file handle and provides utility methods
|
||||
@@ -184,7 +184,7 @@ class FileHandle(object):
|
||||
"""returns the integer file descriptor
|
||||
by default this is not supported and raises IOError
|
||||
"""
|
||||
raise IOError()
|
||||
raise OSError()
|
||||
|
||||
def seek(self, offset):
|
||||
"""sets the file's current position at the offset
|
||||
@@ -243,7 +243,7 @@ class FileWriteHandle(FileHandle):
|
||||
else:
|
||||
soap_url = self._get_soap_url(scheme, host_or_url, port)
|
||||
param_list = {'dcPath': data_center_name, 'dsName': datastore_name}
|
||||
self._url = '%s/folder/%s' % (soap_url, file_path)
|
||||
self._url = '{}/folder/{}'.format(soap_url, file_path)
|
||||
self._url = self._url + '?' + urlparse.urlencode(param_list)
|
||||
|
||||
self._conn = self._create_write_connection('PUT',
|
||||
@@ -284,7 +284,7 @@ class FileWriteHandle(FileHandle):
|
||||
except Exception:
|
||||
LOG.warning("Error occurred while reading the HTTP response.",
|
||||
exc_info=True)
|
||||
super(FileWriteHandle, self).close()
|
||||
super().close()
|
||||
|
||||
def __str__(self):
|
||||
return "File write handle for %s" % self._url
|
||||
@@ -319,7 +319,7 @@ class FileReadHandle(FileHandle):
|
||||
else:
|
||||
soap_url = self._get_soap_url(scheme, host_or_url, port)
|
||||
param_list = {'dcPath': data_center_name, 'dsName': datastore_name}
|
||||
self._url = '%s/folder/%s' % (soap_url, file_path)
|
||||
self._url = '{}/folder/{}'.format(soap_url, file_path)
|
||||
self._url = self._url + '?' + urlparse.urlencode(param_list)
|
||||
|
||||
self._conn = self._create_read_connection(self._url,
|
||||
@@ -353,7 +353,7 @@ class FileReadHandle(FileHandle):
|
||||
"""Closes the connection.
|
||||
"""
|
||||
self._conn.close()
|
||||
super(FileReadHandle, self).close()
|
||||
super().close()
|
||||
LOG.debug("Closed File read handle for %s.", self._url)
|
||||
|
||||
def get_size(self):
|
||||
@@ -373,7 +373,7 @@ class VmdkHandle(FileHandle):
|
||||
self._last_logged_progress = 0
|
||||
self._last_progress_udpate = 0
|
||||
|
||||
super(VmdkHandle, self).__init__(file_handle)
|
||||
super().__init__(file_handle)
|
||||
|
||||
def _log_progress(self, progress):
|
||||
"""Log data transfer progress."""
|
||||
@@ -586,7 +586,7 @@ class VmdkWriteHandle(VmdkHandle):
|
||||
overwrite=overwrite,
|
||||
content_type=content_type,
|
||||
ssl_thumbprint=thumbprint)
|
||||
super(VmdkWriteHandle, self).__init__(session, lease, url, self._conn)
|
||||
super().__init__(session, lease, url, self._conn)
|
||||
|
||||
def get_imported_vm(self):
|
||||
""""Get managed object reference of the VM created for import.
|
||||
@@ -642,7 +642,7 @@ class VmdkWriteHandle(VmdkHandle):
|
||||
"for %s.",
|
||||
self._url,
|
||||
exc_info=True)
|
||||
super(VmdkWriteHandle, self).close()
|
||||
super().close()
|
||||
LOG.debug("Closed VMDK write handle for %s.", self._url)
|
||||
|
||||
def _get_progress(self):
|
||||
@@ -685,8 +685,8 @@ class VmdkReadHandle(VmdkHandle):
|
||||
self._conn = self._create_read_connection(url,
|
||||
cookies=cookies,
|
||||
ssl_thumbprint=thumbprint)
|
||||
super(VmdkReadHandle, self).__init__(session, lease, url,
|
||||
self._conn.getresponse())
|
||||
super().__init__(session, lease, url,
|
||||
self._conn.getresponse())
|
||||
|
||||
def read(self, chunk_size=READ_CHUNKSIZE):
|
||||
"""Read a chunk of data from the VMDK file.
|
||||
@@ -731,7 +731,7 @@ class VmdkReadHandle(VmdkHandle):
|
||||
exc_info=True)
|
||||
raise
|
||||
finally:
|
||||
super(VmdkReadHandle, self).close()
|
||||
super().close()
|
||||
LOG.debug("Closed VMDK read handle for %s.", self._url)
|
||||
|
||||
def _get_progress(self):
|
||||
@@ -741,7 +741,7 @@ class VmdkReadHandle(VmdkHandle):
|
||||
return "VMDK read handle for %s" % self._url
|
||||
|
||||
|
||||
class ImageReadHandle(object):
|
||||
class ImageReadHandle:
|
||||
"""Read handle for glance images."""
|
||||
|
||||
def __init__(self, glance_read_iter):
|
||||
@@ -767,8 +767,7 @@ class ImageReadHandle(object):
|
||||
|
||||
def get_next(self):
|
||||
"""Get the next item from the image iterator."""
|
||||
for data in self._glance_read_iter:
|
||||
yield data
|
||||
yield from self._glance_read_iter
|
||||
|
||||
def close(self):
|
||||
"""Close the read handle.
|
||||
|
@@ -138,8 +138,8 @@ class LocalFileAdapter(requests.adapters.HTTPAdapter):
|
||||
See http://stackoverflow.com/a/22989322
|
||||
"""
|
||||
def __init__(self, pool_maxsize=10):
|
||||
super(LocalFileAdapter, self).__init__(pool_connections=pool_maxsize,
|
||||
pool_maxsize=pool_maxsize)
|
||||
super().__init__(pool_connections=pool_maxsize,
|
||||
pool_maxsize=pool_maxsize)
|
||||
|
||||
def _build_response_from_file(self, request):
|
||||
file_path = request.url[7:]
|
||||
@@ -216,7 +216,7 @@ class CompatibilitySudsClient(client.Client):
|
||||
underlying transport.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CompatibilitySudsClient, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def cookiejar(self):
|
||||
@@ -228,7 +228,7 @@ class CompatibilitySudsClient(client.Client):
|
||||
self.options.transport.cookiejar = cookies
|
||||
|
||||
|
||||
class Service(object):
|
||||
class Service:
|
||||
"""Base class containing common functionality for invoking vSphere
|
||||
services
|
||||
"""
|
||||
@@ -366,8 +366,8 @@ class Service(object):
|
||||
if not skip_op_id:
|
||||
# Generate opID. It will appear in vCenter and ESX logs for
|
||||
# this particular remote call.
|
||||
op_id = '%s-%s' % (self.op_id_prefix,
|
||||
uuidutils.generate_uuid())
|
||||
op_id = '{}-{}'.format(self.op_id_prefix,
|
||||
uuidutils.generate_uuid())
|
||||
LOG.debug('Invoking %s.%s with opID=%s',
|
||||
vim_util.get_moref_type(managed_object),
|
||||
attr_name,
|
||||
|
@@ -30,7 +30,7 @@ class TestCase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
"""Run before each test method to initialize test environment."""
|
||||
|
||||
super(TestCase, self).setUp()
|
||||
super().setUp()
|
||||
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
|
||||
try:
|
||||
test_timeout = int(test_timeout)
|
||||
|
@@ -23,14 +23,14 @@ from oslo_vmware.tests import base
|
||||
from oslo_vmware import vim_util
|
||||
|
||||
|
||||
class HostMount(object):
|
||||
class HostMount:
|
||||
|
||||
def __init__(self, key, mountInfo):
|
||||
self.key = key
|
||||
self.mountInfo = mountInfo
|
||||
|
||||
|
||||
class MountInfo(object):
|
||||
class MountInfo:
|
||||
|
||||
def __init__(self, accessMode, mounted, accessible):
|
||||
self.accessMode = accessMode
|
||||
@@ -111,21 +111,21 @@ class DatastoreTestCase(base.TestCase):
|
||||
m4 = HostMount("m4", MountInfo('readWrite', True, False))
|
||||
ds.get_summary.assert_called_once_with(session)
|
||||
|
||||
class Prop(object):
|
||||
class Prop:
|
||||
DatastoreHostMount = [m1, m2, m3, m4]
|
||||
|
||||
class HostRuntime(object):
|
||||
class HostRuntime:
|
||||
inMaintenanceMode = in_maintenance_mode
|
||||
|
||||
class HostProp(object):
|
||||
class HostProp:
|
||||
name = 'runtime'
|
||||
val = HostRuntime()
|
||||
|
||||
class Object(object):
|
||||
class Object:
|
||||
obj = "m1"
|
||||
propSet = [HostProp()]
|
||||
|
||||
class Runtime(object):
|
||||
class Runtime:
|
||||
objects = [Object()]
|
||||
|
||||
session.invoke_api = mock.Mock(side_effect=[Prop(), Runtime()])
|
||||
@@ -366,7 +366,7 @@ class DatastoreURLTestCase(base.TestCase):
|
||||
params = {'dcPath': dc_path, 'dsName': ds_name}
|
||||
query = urlparse.urlencode(params)
|
||||
url = datastore.DatastoreURL(scheme, server, path, dc_path, ds_name)
|
||||
expected_url = '%s://%s/folder/%s?%s' % (
|
||||
expected_url = '{}://{}/folder/{}?{}'.format(
|
||||
scheme, server, path, query)
|
||||
self.assertEqual(expected_url, str(url))
|
||||
|
||||
@@ -379,7 +379,7 @@ class DatastoreURLTestCase(base.TestCase):
|
||||
params = {'dcPath': dc_path, 'dsName': ds_name}
|
||||
query = urlparse.urlencode(params)
|
||||
url = datastore.DatastoreURL(scheme, server, path, dc_path, ds_name)
|
||||
expected_url = '%s://%s/folder/%s?%s' % (
|
||||
expected_url = '{}://{}/folder/{}?{}'.format(
|
||||
scheme, server, path.lstrip('/'), query)
|
||||
self.assertEqual(expected_url, str(url))
|
||||
|
||||
@@ -392,7 +392,7 @@ class DatastoreURLTestCase(base.TestCase):
|
||||
params = {'dcPath': dc_path, 'dsName': ds_name}
|
||||
query = urlparse.urlencode(params)
|
||||
url = datastore.DatastoreURL(scheme, server, path, dc_path, ds_name)
|
||||
expected_url = '%s://%s/folder/%s?%s' % (
|
||||
expected_url = '{}://{}/folder/{}?{}'.format(
|
||||
scheme, server, path.rstrip('/'), query)
|
||||
self.assertEqual(expected_url, str(url))
|
||||
|
||||
@@ -429,7 +429,7 @@ class DatastoreURLTestCase(base.TestCase):
|
||||
params = {'dcPath': dc_path, 'dsName': ds_name}
|
||||
path = 'images/aa.vmdk'
|
||||
query = urlparse.urlencode(params)
|
||||
url = 'https://13.37.73.31/folder/%s?%s' % (path, query)
|
||||
url = 'https://13.37.73.31/folder/{}?{}'.format(path, query)
|
||||
ds_url = datastore.DatastoreURL.urlparse(url)
|
||||
self.assertEqual(path, ds_url.path)
|
||||
|
||||
@@ -454,12 +454,12 @@ class DatastoreURLTestCase(base.TestCase):
|
||||
session = mock.Mock()
|
||||
session.invoke_api = mock.Mock()
|
||||
|
||||
class Ticket(object):
|
||||
class Ticket:
|
||||
id = 'fake_id'
|
||||
session.invoke_api.return_value = Ticket()
|
||||
ds_url = datastore.DatastoreURL.urlparse(url)
|
||||
ticket = ds_url.get_transfer_ticket(session, 'PUT')
|
||||
self.assertEqual('%s="%s"' % (constants.CGI_COOKIE_KEY, 'fake_id'),
|
||||
self.assertEqual('{}="{}"'.format(constants.CGI_COOKIE_KEY, 'fake_id'),
|
||||
ticket)
|
||||
|
||||
def test_get_datastore_by_ref(self):
|
||||
|
@@ -1,4 +1,3 @@
|
||||
# coding=utf-8
|
||||
# Copyright (c) 2014 VMware, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
@@ -105,7 +104,7 @@ class VMwareAPISessionTest(base.TestCase):
|
||||
POOL_SIZE = 15
|
||||
|
||||
def setUp(self):
|
||||
super(VMwareAPISessionTest, self).setUp()
|
||||
super().setUp()
|
||||
patcher = mock.patch('oslo_vmware.vim.Vim')
|
||||
self.addCleanup(patcher.stop)
|
||||
self.VimMock = patcher.start()
|
||||
@@ -318,7 +317,7 @@ class VMwareAPISessionTest(base.TestCase):
|
||||
api_session = self._create_api_session(True)
|
||||
fault_string = 'Invalid property.'
|
||||
fault_list = [exceptions.INVALID_PROPERTY]
|
||||
details = {u'name': suds.sax.text.Text(u'фира')}
|
||||
details = {'name': suds.sax.text.Text('фира')}
|
||||
|
||||
module = mock.Mock()
|
||||
module.api.side_effect = exceptions.VimFaultException(fault_list,
|
||||
@@ -328,10 +327,10 @@ class VMwareAPISessionTest(base.TestCase):
|
||||
api_session.invoke_api,
|
||||
module,
|
||||
'api')
|
||||
details_str = u"{'name': 'фира'}"
|
||||
expected_str = "%s\nFaults: %s\nDetails: %s" % (fault_string,
|
||||
fault_list,
|
||||
details_str)
|
||||
details_str = "{'name': 'фира'}"
|
||||
expected_str = "{}\nFaults: {}\nDetails: {}".format(fault_string,
|
||||
fault_list,
|
||||
details_str)
|
||||
self.assertEqual(expected_str, str(e))
|
||||
self.assertEqual(details, e.details)
|
||||
|
||||
|
@@ -22,8 +22,8 @@ class HackingTestCase(base.TestCase):
|
||||
def test_no_log_translations(self):
|
||||
for log, hint in itertools.product(checks._all_log_levels,
|
||||
checks._all_hints):
|
||||
bad = 'LOG.%s(%s("Bad"))' % (log, hint)
|
||||
bad = 'LOG.{}({}("Bad"))'.format(log, hint)
|
||||
self.assertEqual(1, len(list(checks.no_translate_logs(bad, 'f'))))
|
||||
# Catch abuses when used with a variable and not a literal
|
||||
bad = 'LOG.%s(%s(msg))' % (log, hint)
|
||||
bad = 'LOG.{}({}(msg))'.format(log, hint)
|
||||
self.assertEqual(1, len(list(checks.no_translate_logs(bad, 'f'))))
|
||||
|
@@ -97,7 +97,7 @@ class FileWriteHandleTest(base.TestCase):
|
||||
"""Tests for FileWriteHandle."""
|
||||
|
||||
def setUp(self):
|
||||
super(FileWriteHandleTest, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
vim_cookie = mock.Mock()
|
||||
vim_cookie.name = 'name'
|
||||
@@ -188,7 +188,7 @@ class VmdkWriteHandleTest(base.TestCase):
|
||||
"""Tests for VmdkWriteHandle."""
|
||||
|
||||
def setUp(self):
|
||||
super(VmdkWriteHandleTest, self).setUp()
|
||||
super().setUp()
|
||||
self._conn = mock.Mock()
|
||||
patcher = mock.patch(
|
||||
'urllib3.connection.HTTPConnection')
|
||||
@@ -308,7 +308,7 @@ class VmdkReadHandleTest(base.TestCase):
|
||||
"""Tests for VmdkReadHandle."""
|
||||
|
||||
def setUp(self):
|
||||
super(VmdkReadHandleTest, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def _mock_connection(self, read_data='fake-data'):
|
||||
self._resp = mock.Mock()
|
||||
@@ -436,7 +436,7 @@ class ImageReadHandleTest(base.TestCase):
|
||||
max_items = 10
|
||||
item = [1] * 10
|
||||
|
||||
class ImageReadIterator(object):
|
||||
class ImageReadIterator:
|
||||
|
||||
def __init__(self):
|
||||
self.num_items = 0
|
||||
|
@@ -32,7 +32,7 @@ class ServiceMessagePluginTest(base.TestCase):
|
||||
"""Test class for ServiceMessagePlugin."""
|
||||
|
||||
def setUp(self):
|
||||
super(ServiceMessagePluginTest, self).setUp()
|
||||
super().setUp()
|
||||
self.plugin = service.ServiceMessagePlugin()
|
||||
|
||||
@ddt.data(('value', 'foo', 'string'), ('removeKey', '1', 'int'),
|
||||
@@ -59,7 +59,7 @@ class ServiceMessagePluginTest(base.TestCase):
|
||||
class ServiceTest(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ServiceTest, self).setUp()
|
||||
super().setUp()
|
||||
patcher = mock.patch('oslo_vmware.service.CompatibilitySudsClient')
|
||||
self.addCleanup(patcher.stop)
|
||||
self.SudsClientMock = patcher.start()
|
||||
@@ -536,7 +536,7 @@ class SudsLogFilterTest(base.TestCase):
|
||||
"""Tests for SudsLogFilter."""
|
||||
|
||||
def setUp(self):
|
||||
super(SudsLogFilterTest, self).setUp()
|
||||
super().setUp()
|
||||
self.log_filter = service.SudsLogFilter()
|
||||
|
||||
self.login = mock.Mock(spec=suds.sax.element.Element)
|
||||
|
@@ -30,7 +30,7 @@ class VimTest(base.TestCase):
|
||||
"""Test class for Vim."""
|
||||
|
||||
def setUp(self):
|
||||
super(VimTest, self).setUp()
|
||||
super().setUp()
|
||||
patcher = mock.patch('oslo_vmware.service.CompatibilitySudsClient')
|
||||
self.addCleanup(patcher.stop)
|
||||
self.SudsClientMock = patcher.start()
|
||||
@@ -78,7 +78,7 @@ class VimTest(base.TestCase):
|
||||
|
||||
class VMwareSudsTest(base.TestCase):
|
||||
def setUp(self):
|
||||
super(VMwareSudsTest, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def new_client_init(self, url, **kwargs):
|
||||
return
|
||||
@@ -89,7 +89,7 @@ class VMwareSudsTest(base.TestCase):
|
||||
self.vim = self._vim_create()
|
||||
|
||||
def _mock_getattr(self, attr_name):
|
||||
class fake_service_content(object):
|
||||
class fake_service_content:
|
||||
def __init__(self):
|
||||
self.ServiceContent = {}
|
||||
self.ServiceContent.fake = 'fake'
|
||||
|
@@ -44,9 +44,9 @@ class Vim(service.Service):
|
||||
soap_url = base_url + '/sdk'
|
||||
if wsdl_url is None:
|
||||
wsdl_url = soap_url + '/vimService.wsdl'
|
||||
super(Vim, self).__init__(wsdl_url, soap_url, cacert, insecure,
|
||||
pool_maxsize, connection_timeout,
|
||||
op_id_prefix)
|
||||
super().__init__(wsdl_url, soap_url, cacert, insecure,
|
||||
pool_maxsize, connection_timeout,
|
||||
op_id_prefix)
|
||||
|
||||
def retrieve_service_content(self):
|
||||
return self.RetrieveServiceContent(service.SERVICE_INSTANCE)
|
||||
|
@@ -433,7 +433,7 @@ def continue_retrieval(vim, retrieve_result):
|
||||
return vim.ContinueRetrievePropertiesEx(collector, token=token)
|
||||
|
||||
|
||||
class WithRetrieval(object):
|
||||
class WithRetrieval:
|
||||
"""Context to retrieve results.
|
||||
|
||||
This context provides an iterator to retrieve results and cancel (when
|
||||
@@ -447,7 +447,7 @@ class WithRetrieval(object):
|
||||
"""
|
||||
|
||||
def __init__(self, vim, retrieve_result):
|
||||
super(WithRetrieval, self).__init__()
|
||||
super().__init__()
|
||||
self.vim = vim
|
||||
self.retrieve_result = retrieve_result
|
||||
|
||||
@@ -460,8 +460,7 @@ class WithRetrieval(object):
|
||||
|
||||
def __iter__(self):
|
||||
while self.retrieve_result:
|
||||
for obj in self.retrieve_result.objects:
|
||||
yield obj
|
||||
yield from self.retrieve_result.objects
|
||||
self.retrieve_result = continue_retrieval(
|
||||
self.vim, self.retrieve_result)
|
||||
|
||||
@@ -577,13 +576,13 @@ def get_inventory_path(vim, entity_ref, max_objects=100):
|
||||
if len(propSet) >= 1 and not entity_name:
|
||||
entity_name = propSet[0].val
|
||||
elif len(propSet) >= 1:
|
||||
path = '%s/%s' % (propSet[0].val, path)
|
||||
path = '{}/{}'.format(propSet[0].val, path)
|
||||
# NOTE(arnaud): slice to exclude the root folder from the result.
|
||||
if propSet is not None and len(propSet) > 0:
|
||||
path = path[len(propSet[0].val):]
|
||||
if entity_name is None:
|
||||
entity_name = ""
|
||||
return '%s%s' % (path, entity_name)
|
||||
return '{}{}'.format(path, entity_name)
|
||||
|
||||
|
||||
def get_http_service_request_spec(client_factory, method, uri):
|
||||
|
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2020 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
Reference in New Issue
Block a user