From 7cf94c6527418b1f2cbf130c4607f81e98eb83e8 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 28 Mar 2020 15:48:17 +0100 Subject: [PATCH] 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 --- manilaclient/common/httpclient.py | 2 +- manilaclient/exceptions.py | 2 +- manilaclient/osc/v2/share.py | 1 - manilaclient/tests/functional/base.py | 12 ++++++------ manilaclient/tests/functional/client.py | 3 ++- manilaclient/tests/functional/test_common.py | 2 +- manilaclient/tests/unit/common/test_httpclient.py | 4 ++-- manilaclient/tests/unit/v2/fakes.py | 1 + manilaclient/tests/unit/v2/test_limits.py | 15 ++++++++------- manilaclient/v1/__init__.py | 1 + manilaclient/v1/contrib/list_extensions.py | 1 + manilaclient/v1/limits.py | 1 + manilaclient/v1/quota_classes.py | 1 + manilaclient/v1/quotas.py | 1 + manilaclient/v1/scheduler_stats.py | 1 + manilaclient/v1/security_services.py | 1 + manilaclient/v1/services.py | 1 + manilaclient/v1/share_networks.py | 1 + manilaclient/v1/share_servers.py | 1 + manilaclient/v1/share_snapshots.py | 1 + manilaclient/v1/share_type_access.py | 1 + manilaclient/v1/share_types.py | 1 + manilaclient/v1/shares.py | 1 + manilaclient/v2/shares.py | 6 +++--- manilaclient/v2/shell.py | 1 + test-requirements.txt | 2 +- tools/install_venv.py | 1 + tox.ini | 4 +++- 28 files changed, 45 insertions(+), 25 deletions(-) diff --git a/manilaclient/common/httpclient.py b/manilaclient/common/httpclient.py index 56067db61..2ed2f2d05 100644 --- a/manilaclient/common/httpclient.py +++ b/manilaclient/common/httpclient.py @@ -83,7 +83,7 @@ class HTTPClient(object): """Truncates url and returns base endpoint""" service_endpoint = parse.urlparse(url) 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) if service_endpoint_base_path else '') base_url = service_endpoint._replace(path=base_path) diff --git a/manilaclient/exceptions.py b/manilaclient/exceptions.py index b1ce03b54..c8ecc5c17 100644 --- a/manilaclient/exceptions.py +++ b/manilaclient/exceptions.py @@ -20,7 +20,7 @@ Exception definitions. from manilaclient.common.apiclient.exceptions import * # noqa -class NoTokenLookupException(ClientException): +class NoTokenLookupException(ClientException): # noqa: F405 """No support for looking up endpoints. This form of authentication does not support looking up diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index c0529e9dd..05ec88fa5 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -492,7 +492,6 @@ class ListShare(command.Lister): 'project_id': project_id, 'user_id': user_id, 'offset': parsed_args.marker, - 'limit': parsed_args.limit, } # NOTE(vkmc) We implemented sorting and filtering in manilaclient diff --git a/manilaclient/tests/functional/base.py b/manilaclient/tests/functional/base.py index 66c6e7a7b..81476edb1 100644 --- a/manilaclient/tests/functional/base.py +++ b/manilaclient/tests/functional/base.py @@ -104,17 +104,17 @@ class BaseTestCase(base.ClientTestBase): deletion_params = res.get("deletion_params") with handle_cleanup_exceptions(): # TODO(vponomaryov): add support for other resources - if res["type"] is "share_type": + if res["type"] == "share_type": client.delete_share_type( res_id, microversion=res["microversion"]) client.wait_for_share_type_deletion( res_id, microversion=res["microversion"]) - elif res["type"] is "share_network": + elif res["type"] == "share_network": client.delete_share_network( res_id, microversion=res["microversion"]) client.wait_for_share_network_deletion( res_id, microversion=res["microversion"]) - elif res["type"] is "share_network_subnet": + elif res["type"] == "share_network_subnet": client.delete_share_network_subnet( share_network_subnet=res_id, share_network=deletion_params["share_network"], @@ -123,17 +123,17 @@ class BaseTestCase(base.ClientTestBase): share_network_subnet=res_id, share_network=deletion_params["share_network"], microversion=res["microversion"]) - elif res["type"] is "share": + elif res["type"] == "share": client.delete_share( res_id, microversion=res["microversion"]) client.wait_for_share_deletion( res_id, microversion=res["microversion"]) - elif res["type"] is "snapshot": + elif res["type"] == "snapshot": client.delete_snapshot( res_id, microversion=res["microversion"]) client.wait_for_snapshot_deletion( res_id, microversion=res["microversion"]) - elif res["type"] is "share_replica": + elif res["type"] == "share_replica": client.delete_share_replica( res_id, microversion=res["microversion"]) client.wait_for_share_replica_deletion( diff --git a/manilaclient/tests/functional/client.py b/manilaclient/tests/functional/client.py index 0787bd8db..15c45a3cf 100644 --- a/manilaclient/tests/functional/client.py +++ b/manilaclient/tests/functional/client.py @@ -46,7 +46,8 @@ def not_found_wrapper(f): try: return f(self, *args, **kwargs) 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)): # Raise appropriate 'NotFound' error raise tempest_lib_exc.NotFound() diff --git a/manilaclient/tests/functional/test_common.py b/manilaclient/tests/functional/test_common.py index dc1cf7f8e..2b552a170 100644 --- a/manilaclient/tests/functional/test_common.py +++ b/manilaclient/tests/functional/test_common.py @@ -36,7 +36,7 @@ class ManilaClientTestCommonReadOnly(base.BaseTestCase): commands = [] cmds_start = lines.index('Positional 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]: match = command_pattern.match(line) if match: diff --git a/manilaclient/tests/unit/common/test_httpclient.py b/manilaclient/tests/unit/common/test_httpclient.py index a71bb8260..ccbb1943e 100644 --- a/manilaclient/tests/unit/common/test_httpclient.py +++ b/manilaclient/tests/unit/common/test_httpclient.py @@ -119,7 +119,7 @@ class ClientTest(utils.TestCase): **self.TEST_REQUEST_BASE) # Automatic JSON parsing 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) test_get_call() @@ -231,7 +231,7 @@ class ClientTest(utils.TestCase): headers=headers, data='[1, 2, 3]', **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) test_post_call() diff --git a/manilaclient/tests/unit/v2/fakes.py b/manilaclient/tests/unit/v2/fakes.py index 2ba810bfd..34315ec16 100644 --- a/manilaclient/tests/unit/v2/fakes.py +++ b/manilaclient/tests/unit/v2/fakes.py @@ -38,6 +38,7 @@ class FakeClient(fakes.FakeClient): ) self.client = FakeHTTPClient(**kwargs) + fake_share_instance = { 'id': 1234, 'share_id': 'fake', diff --git a/manilaclient/tests/unit/v2/test_limits.py b/manilaclient/tests/unit/v2/test_limits.py index ca78ba45d..d4265f7b5 100644 --- a/manilaclient/tests/unit/v2/test_limits.py +++ b/manilaclient/tests/unit/v2/test_limits.py @@ -31,15 +31,16 @@ def _get_default_RateLimit(verb="verb1", uri="uri1", regex="regex1", class TestLimits(utils.TestCase): def test_repr(self): - l = limits.Limits(None, {"foo": "bar"}) - self.assertEqual("", repr(l)) + li = limits.Limits(None, {"foo": "bar"}) + self.assertEqual("", repr(li)) def test_absolute(self): - l = limits.Limits(None, - {"absolute": {"name1": "value1", "name2": "value2"}}) + li = limits.Limits(None, + {"absolute": {"name1": "value1", + "name2": "value2"}}) l1 = limits.AbsoluteLimit("name1", "value1") l2 = limits.AbsoluteLimit("name2", "value2") - for item in l.absolute: + for item in li.absolute: self.assertIn(item, [l1, l2]) 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", "unit1", "next1") l2 = limits.RateLimit("verb2", "uri2", "regex2", "value2", "remain2", "unit2", "next2") - for item in l.rate: + for item in li.rate: self.assertIn(item, [l1, l2]) diff --git a/manilaclient/v1/__init__.py b/manilaclient/v1/__init__.py index 35670b721..56c143bed 100644 --- a/manilaclient/v1/__init__.py +++ b/manilaclient/v1/__init__.py @@ -27,4 +27,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["maniliaclient.v1"] = MovedModule(v2) diff --git a/manilaclient/v1/contrib/list_extensions.py b/manilaclient/v1/contrib/list_extensions.py index e5f7a58c7..7c9508cd2 100644 --- a/manilaclient/v1/contrib/list_extensions.py +++ b/manilaclient/v1/contrib/list_extensions.py @@ -32,5 +32,6 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.contrib.list_extensions"] = MovedModule( list_extensions) diff --git a/manilaclient/v1/limits.py b/manilaclient/v1/limits.py index 6ca081e05..06c557663 100644 --- a/manilaclient/v1/limits.py +++ b/manilaclient/v1/limits.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.limits"] = MovedModule(limits) diff --git a/manilaclient/v1/quota_classes.py b/manilaclient/v1/quota_classes.py index f983e1c40..32e22a003 100644 --- a/manilaclient/v1/quota_classes.py +++ b/manilaclient/v1/quota_classes.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.quota_classes"] = MovedModule(quota_classes) diff --git a/manilaclient/v1/quotas.py b/manilaclient/v1/quotas.py index e400c0971..d0b79b6a9 100644 --- a/manilaclient/v1/quotas.py +++ b/manilaclient/v1/quotas.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.quotas"] = MovedModule(quotas) diff --git a/manilaclient/v1/scheduler_stats.py b/manilaclient/v1/scheduler_stats.py index f62dbab99..d30a96d46 100644 --- a/manilaclient/v1/scheduler_stats.py +++ b/manilaclient/v1/scheduler_stats.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.scheduler_stats"] = MovedModule(scheduler_stats) diff --git a/manilaclient/v1/security_services.py b/manilaclient/v1/security_services.py index 8885cc0e6..1819b0550 100644 --- a/manilaclient/v1/security_services.py +++ b/manilaclient/v1/security_services.py @@ -32,5 +32,6 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules[ "manilaclient.v1.security_services"] = MovedModule(security_services) diff --git a/manilaclient/v1/services.py b/manilaclient/v1/services.py index c2d8879f2..7dfbc10c6 100644 --- a/manilaclient/v1/services.py +++ b/manilaclient/v1/services.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.services"] = MovedModule(services) diff --git a/manilaclient/v1/share_networks.py b/manilaclient/v1/share_networks.py index 308c9126f..076fbd307 100644 --- a/manilaclient/v1/share_networks.py +++ b/manilaclient/v1/share_networks.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.share_networks"] = MovedModule(share_networks) diff --git a/manilaclient/v1/share_servers.py b/manilaclient/v1/share_servers.py index 442971c4a..7440b915e 100644 --- a/manilaclient/v1/share_servers.py +++ b/manilaclient/v1/share_servers.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.share_servers"] = MovedModule(share_servers) diff --git a/manilaclient/v1/share_snapshots.py b/manilaclient/v1/share_snapshots.py index b522bbc2f..96070a403 100644 --- a/manilaclient/v1/share_snapshots.py +++ b/manilaclient/v1/share_snapshots.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.share_snapshots"] = MovedModule(share_snapshots) diff --git a/manilaclient/v1/share_type_access.py b/manilaclient/v1/share_type_access.py index f77502d77..2da0873f4 100644 --- a/manilaclient/v1/share_type_access.py +++ b/manilaclient/v1/share_type_access.py @@ -32,5 +32,6 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules[ "manilaclient.v1.share_type_access"] = MovedModule(share_type_access) diff --git a/manilaclient/v1/share_types.py b/manilaclient/v1/share_types.py index 58d11ff7f..793766f79 100644 --- a/manilaclient/v1/share_types.py +++ b/manilaclient/v1/share_types.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.share_types"] = MovedModule(share_types) diff --git a/manilaclient/v1/shares.py b/manilaclient/v1/shares.py index dce2a190b..cc007fb91 100644 --- a/manilaclient/v1/shares.py +++ b/manilaclient/v1/shares.py @@ -32,4 +32,5 @@ class MovedModule(object): def __getattr__(self, attr): return getattr(self.new_module, attr) + sys.modules["manilaclient.v1.shares"] = MovedModule(shares) diff --git a/manilaclient/v2/shares.py b/manilaclient/v2/shares.py index dd2b7ebb8..d8ab75359 100644 --- a/manilaclient/v2/shares.py +++ b/manilaclient/v2/shares.py @@ -461,8 +461,8 @@ class ShareManager(base.ManagerWithFind): ''' @staticmethod def _validate_username(access): - sole_periods_spaces_re = '[\s|\.]+$' - valid_username_re = '.[^\"\/\\\[\]\:\;\|\=\,\+\*\?\<\>]{3,254}$' + sole_periods_spaces_re = r'[\s|\.]+$' + valid_username_re = r'.[^\"\/\\\[\]\:\;\|\=\,\+\*\?\<\>]{3,254}$' username = access if re.match(sole_periods_spaces_re, username): @@ -473,7 +473,7 @@ class ShareManager(base.ManagerWithFind): if not re.match(valid_username_re, username): exc_str = ('Invalid user or group name. Must be 4-255 characters ' 'and consist of alphanumeric characters and ' - 'exclude special characters "/\[]:;|=,+*?<>') + 'exclude special characters "/\\[]:;|=,+*?<>') raise exceptions.CommandError(exc_str) @staticmethod diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index dc5e023ea..c27eaa9ec 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -384,6 +384,7 @@ def do_credentials(cs, args): } cliutils.print_dict(data, "Token") + _quota_resources = [ 'shares', 'snapshots', diff --git a/test-requirements.txt b/test-requirements.txt index 45b827dcf..e6f34e755 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,7 +3,7 @@ # process, which may cause wedges in the gate later. # 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 ddt>=1.0.1 # MIT diff --git a/tools/install_venv.py b/tools/install_venv.py index e8ed7465f..4ce06b8bb 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -247,5 +247,6 @@ def main(argv): post_process() print_help() + if __name__ == '__main__': main(sys.argv) diff --git a/tox.ini b/tox.ini index 155e10978..536ff81cb 100644 --- a/tox.ini +++ b/tox.ini @@ -91,7 +91,9 @@ commands = [flake8] # F821: undefined name -ignore = F821 +# W503 line break before binary operator +# W504 line break after binary operator +ignore = F821,W503,W504 builtins = _ # [H106] Don't put vim configuration in source files. # [H203] Use assertIs(Not)None to check for None.