Update hacking for Python3

The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix found problems.

Change-Id: I78ee32da2b158abda1ca4438c23c5245dd8849b2
This commit is contained in:
Andreas Jaeger 2020-03-28 15:48:17 +01:00 committed by Andreas Jaeger
parent e3652b9c1c
commit 7cf94c6527
28 changed files with 45 additions and 25 deletions

View File

@ -83,7 +83,7 @@ class HTTPClient(object):
"""Truncates url and returns base endpoint""" """Truncates url and returns base endpoint"""
service_endpoint = parse.urlparse(url) service_endpoint = parse.urlparse(url)
service_endpoint_base_path = re.search( service_endpoint_base_path = re.search(
'(.+?)/v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)', service_endpoint.path) r'(.+?)/v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)', service_endpoint.path)
base_path = (service_endpoint_base_path.group(1) base_path = (service_endpoint_base_path.group(1)
if service_endpoint_base_path else '') if service_endpoint_base_path else '')
base_url = service_endpoint._replace(path=base_path) base_url = service_endpoint._replace(path=base_path)

View File

@ -20,7 +20,7 @@ Exception definitions.
from manilaclient.common.apiclient.exceptions import * # noqa from manilaclient.common.apiclient.exceptions import * # noqa
class NoTokenLookupException(ClientException): class NoTokenLookupException(ClientException): # noqa: F405
"""No support for looking up endpoints. """No support for looking up endpoints.
This form of authentication does not support looking up This form of authentication does not support looking up

View File

@ -492,7 +492,6 @@ class ListShare(command.Lister):
'project_id': project_id, 'project_id': project_id,
'user_id': user_id, 'user_id': user_id,
'offset': parsed_args.marker, 'offset': parsed_args.marker,
'limit': parsed_args.limit,
} }
# NOTE(vkmc) We implemented sorting and filtering in manilaclient # NOTE(vkmc) We implemented sorting and filtering in manilaclient

View File

@ -104,17 +104,17 @@ class BaseTestCase(base.ClientTestBase):
deletion_params = res.get("deletion_params") deletion_params = res.get("deletion_params")
with handle_cleanup_exceptions(): with handle_cleanup_exceptions():
# TODO(vponomaryov): add support for other resources # TODO(vponomaryov): add support for other resources
if res["type"] is "share_type": if res["type"] == "share_type":
client.delete_share_type( client.delete_share_type(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
client.wait_for_share_type_deletion( client.wait_for_share_type_deletion(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
elif res["type"] is "share_network": elif res["type"] == "share_network":
client.delete_share_network( client.delete_share_network(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
client.wait_for_share_network_deletion( client.wait_for_share_network_deletion(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
elif res["type"] is "share_network_subnet": elif res["type"] == "share_network_subnet":
client.delete_share_network_subnet( client.delete_share_network_subnet(
share_network_subnet=res_id, share_network_subnet=res_id,
share_network=deletion_params["share_network"], share_network=deletion_params["share_network"],
@ -123,17 +123,17 @@ class BaseTestCase(base.ClientTestBase):
share_network_subnet=res_id, share_network_subnet=res_id,
share_network=deletion_params["share_network"], share_network=deletion_params["share_network"],
microversion=res["microversion"]) microversion=res["microversion"])
elif res["type"] is "share": elif res["type"] == "share":
client.delete_share( client.delete_share(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
client.wait_for_share_deletion( client.wait_for_share_deletion(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
elif res["type"] is "snapshot": elif res["type"] == "snapshot":
client.delete_snapshot( client.delete_snapshot(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
client.wait_for_snapshot_deletion( client.wait_for_snapshot_deletion(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
elif res["type"] is "share_replica": elif res["type"] == "share_replica":
client.delete_share_replica( client.delete_share_replica(
res_id, microversion=res["microversion"]) res_id, microversion=res["microversion"])
client.wait_for_share_replica_deletion( client.wait_for_share_replica_deletion(

View File

@ -46,7 +46,8 @@ def not_found_wrapper(f):
try: try:
return f(self, *args, **kwargs) return f(self, *args, **kwargs)
except tempest_lib_exc.CommandFailed as e: except tempest_lib_exc.CommandFailed as e:
for regexp in ('No (\w+) with a name or ID', 'not(.*){0,5}found'): for regexp in (r'No (\w+) with a name or ID',
r'not(.*){0,5}found'):
if re.search(regexp, six.text_type(e.stderr)): if re.search(regexp, six.text_type(e.stderr)):
# Raise appropriate 'NotFound' error # Raise appropriate 'NotFound' error
raise tempest_lib_exc.NotFound() raise tempest_lib_exc.NotFound()

View File

@ -36,7 +36,7 @@ class ManilaClientTestCommonReadOnly(base.BaseTestCase):
commands = [] commands = []
cmds_start = lines.index('Positional arguments:') cmds_start = lines.index('Positional arguments:')
cmds_end = lines.index('Optional arguments:') cmds_end = lines.index('Optional arguments:')
command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') command_pattern = re.compile(r'^ {4}([a-z0-9\-\_]+)')
for line in lines[cmds_start:cmds_end]: for line in lines[cmds_start:cmds_end]:
match = command_pattern.match(line) match = command_pattern.match(line)
if match: if match:

View File

@ -119,7 +119,7 @@ class ClientTest(utils.TestCase):
**self.TEST_REQUEST_BASE) **self.TEST_REQUEST_BASE)
# Automatic JSON parsing # Automatic JSON parsing
self.assertEqual(body, {"hi": "there"}) self.assertEqual(body, {"hi": "there"})
self.assertEqual(re.split('/v[0-9]+[\.0-9]*', self.assertEqual(re.split(r'/v[0-9]+[\.0-9]*',
endpoint_url)[0] + "/", cl.base_url) endpoint_url)[0] + "/", cl.base_url)
test_get_call() test_get_call()
@ -231,7 +231,7 @@ class ClientTest(utils.TestCase):
headers=headers, headers=headers,
data='[1, 2, 3]', data='[1, 2, 3]',
**self.TEST_REQUEST_BASE) **self.TEST_REQUEST_BASE)
self.assertEqual(re.split('/v[0-9]+[\.0-9]*', self.assertEqual(re.split(r'/v[0-9]+[\.0-9]*',
endpoint_url)[0] + "/", cl.base_url) endpoint_url)[0] + "/", cl.base_url)
test_post_call() test_post_call()

View File

@ -38,6 +38,7 @@ class FakeClient(fakes.FakeClient):
) )
self.client = FakeHTTPClient(**kwargs) self.client = FakeHTTPClient(**kwargs)
fake_share_instance = { fake_share_instance = {
'id': 1234, 'id': 1234,
'share_id': 'fake', 'share_id': 'fake',

View File

@ -31,15 +31,16 @@ def _get_default_RateLimit(verb="verb1", uri="uri1", regex="regex1",
class TestLimits(utils.TestCase): class TestLimits(utils.TestCase):
def test_repr(self): def test_repr(self):
l = limits.Limits(None, {"foo": "bar"}) li = limits.Limits(None, {"foo": "bar"})
self.assertEqual("<Limits>", repr(l)) self.assertEqual("<Limits>", repr(li))
def test_absolute(self): def test_absolute(self):
l = limits.Limits(None, li = limits.Limits(None,
{"absolute": {"name1": "value1", "name2": "value2"}}) {"absolute": {"name1": "value1",
"name2": "value2"}})
l1 = limits.AbsoluteLimit("name1", "value1") l1 = limits.AbsoluteLimit("name1", "value1")
l2 = limits.AbsoluteLimit("name2", "value2") l2 = limits.AbsoluteLimit("name2", "value2")
for item in l.absolute: for item in li.absolute:
self.assertIn(item, [l1, l2]) self.assertIn(item, [l1, l2])
def test_rate(self): def test_rate(self):
@ -67,12 +68,12 @@ class TestLimits(utils.TestCase):
}] }]
}] }]
} }
l = limits.Limits(None, limit_param) li = limits.Limits(None, limit_param)
l1 = limits.RateLimit("verb1", "uri1", "regex1", "value1", "remain1", l1 = limits.RateLimit("verb1", "uri1", "regex1", "value1", "remain1",
"unit1", "next1") "unit1", "next1")
l2 = limits.RateLimit("verb2", "uri2", "regex2", "value2", "remain2", l2 = limits.RateLimit("verb2", "uri2", "regex2", "value2", "remain2",
"unit2", "next2") "unit2", "next2")
for item in l.rate: for item in li.rate:
self.assertIn(item, [l1, l2]) self.assertIn(item, [l1, l2])

View File

@ -27,4 +27,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["maniliaclient.v1"] = MovedModule(v2) sys.modules["maniliaclient.v1"] = MovedModule(v2)

View File

@ -32,5 +32,6 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.contrib.list_extensions"] = MovedModule( sys.modules["manilaclient.v1.contrib.list_extensions"] = MovedModule(
list_extensions) list_extensions)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.limits"] = MovedModule(limits) sys.modules["manilaclient.v1.limits"] = MovedModule(limits)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.quota_classes"] = MovedModule(quota_classes) sys.modules["manilaclient.v1.quota_classes"] = MovedModule(quota_classes)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.quotas"] = MovedModule(quotas) sys.modules["manilaclient.v1.quotas"] = MovedModule(quotas)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.scheduler_stats"] = MovedModule(scheduler_stats) sys.modules["manilaclient.v1.scheduler_stats"] = MovedModule(scheduler_stats)

View File

@ -32,5 +32,6 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules[ sys.modules[
"manilaclient.v1.security_services"] = MovedModule(security_services) "manilaclient.v1.security_services"] = MovedModule(security_services)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.services"] = MovedModule(services) sys.modules["manilaclient.v1.services"] = MovedModule(services)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.share_networks"] = MovedModule(share_networks) sys.modules["manilaclient.v1.share_networks"] = MovedModule(share_networks)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.share_servers"] = MovedModule(share_servers) sys.modules["manilaclient.v1.share_servers"] = MovedModule(share_servers)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.share_snapshots"] = MovedModule(share_snapshots) sys.modules["manilaclient.v1.share_snapshots"] = MovedModule(share_snapshots)

View File

@ -32,5 +32,6 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules[ sys.modules[
"manilaclient.v1.share_type_access"] = MovedModule(share_type_access) "manilaclient.v1.share_type_access"] = MovedModule(share_type_access)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.share_types"] = MovedModule(share_types) sys.modules["manilaclient.v1.share_types"] = MovedModule(share_types)

View File

@ -32,4 +32,5 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v1.shares"] = MovedModule(shares) sys.modules["manilaclient.v1.shares"] = MovedModule(shares)

View File

@ -461,8 +461,8 @@ class ShareManager(base.ManagerWithFind):
''' '''
@staticmethod @staticmethod
def _validate_username(access): def _validate_username(access):
sole_periods_spaces_re = '[\s|\.]+$' sole_periods_spaces_re = r'[\s|\.]+$'
valid_username_re = '.[^\"\/\\\[\]\:\;\|\=\,\+\*\?\<\>]{3,254}$' valid_username_re = r'.[^\"\/\\\[\]\:\;\|\=\,\+\*\?\<\>]{3,254}$'
username = access username = access
if re.match(sole_periods_spaces_re, username): if re.match(sole_periods_spaces_re, username):
@ -473,7 +473,7 @@ class ShareManager(base.ManagerWithFind):
if not re.match(valid_username_re, username): if not re.match(valid_username_re, username):
exc_str = ('Invalid user or group name. Must be 4-255 characters ' exc_str = ('Invalid user or group name. Must be 4-255 characters '
'and consist of alphanumeric characters and ' 'and consist of alphanumeric characters and '
'exclude special characters "/\[]:;|=,+*?<>') 'exclude special characters "/\\[]:;|=,+*?<>')
raise exceptions.CommandError(exc_str) raise exceptions.CommandError(exc_str)
@staticmethod @staticmethod

View File

@ -384,6 +384,7 @@ def do_credentials(cs, args):
} }
cliutils.print_dict(data, "Token") cliutils.print_dict(data, "Token")
_quota_resources = [ _quota_resources = [
'shares', 'shares',
'snapshots', 'snapshots',

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
# hacking should be first # hacking should be first
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 hacking>=3.0,<4.0.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
ddt>=1.0.1 # MIT ddt>=1.0.1 # MIT

View File

@ -247,5 +247,6 @@ def main(argv):
post_process() post_process()
print_help() print_help()
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv) main(sys.argv)

View File

@ -91,7 +91,9 @@ commands =
[flake8] [flake8]
# F821: undefined name # F821: undefined name
ignore = F821 # W503 line break before binary operator
# W504 line break after binary operator
ignore = F821,W503,W504
builtins = _ builtins = _
# [H106] Don't put vim configuration in source files. # [H106] Don't put vim configuration in source files.
# [H203] Use assertIs(Not)None to check for None. # [H203] Use assertIs(Not)None to check for None.