From a9913ea35fee4a8c2321718c9217047950e61517 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 28 Mar 2020 15:30:28 +0100 Subject: Update hacking for Python3 The repo is Python 3 now, so update hacking to version 3.1.0 which supports Python 3. Fix problems found. Change-Id: I54f9f7c5f6ee87ee886658388541f45e23c7546d --- barbicanclient/barbican.py | 1 + barbicanclient/barbican_cli/v1/containers.py | 2 +- barbicanclient/client.py | 118 ++++++++++----------- barbicanclient/v1/orders.py | 11 +- functionaltests/cli/v1/behaviors/acl_behaviors.py | 2 +- functionaltests/cli/v1/behaviors/base_behaviors.py | 8 +- test-requirements.txt | 3 +- tox.ini | 2 +- 8 files changed, 74 insertions(+), 73 deletions(-) diff --git a/barbicanclient/barbican.py b/barbicanclient/barbican.py index dbaa3d3..0e58236 100644 --- a/barbicanclient/barbican.py +++ b/barbicanclient/barbican.py @@ -385,5 +385,6 @@ def main(argv=sys.argv[1:]): barbican_app = Barbican() return barbican_app.run(argv) + if __name__ == '__main__': # pragma: no cover sys.exit(main(sys.argv[1:])) diff --git a/barbicanclient/barbican_cli/v1/containers.py b/barbicanclient/barbican_cli/v1/containers.py index 1da349b..ccb541b 100644 --- a/barbicanclient/barbican_cli/v1/containers.py +++ b/barbicanclient/barbican_cli/v1/containers.py @@ -135,5 +135,5 @@ class CreateContainer(show.ShowOne): raise ValueError("Must supply at least one secret.") return dict( (s.split('=')[0], s.split('=')[1]) - for s in secrets if s.count('=') is 1 + for s in secrets if s.count('=') == 1 ) diff --git a/barbicanclient/client.py b/barbicanclient/client.py index f1910e7..dc91003 100644 --- a/barbicanclient/client.py +++ b/barbicanclient/client.py @@ -120,65 +120,65 @@ class _HTTPClient(adapter.Adapter): def Client(version=None, session=None, *args, **kwargs): - """Barbican client used to interact with barbican service. - - :param version: The API version to use. - :param session: An instance of keystoneauth1.session.Session that - can be either authenticated, or not authenticated. When using - a non-authenticated Session, you must provide some additional - parameters. When no session is provided it will default to a - non-authenticated Session. - :param endpoint: Barbican endpoint url. Required when a session is not - given, or when using a non-authenticated session. - When using an authenticated session, the client will attempt - to get an endpoint from the session. - :param project_id: The project ID used for context in Barbican. - Required when a session is not given, or when using a - non-authenticated session. - When using an authenticated session, the project ID will be - provided by the authentication mechanism. - :param verify: When a session is not given, the client will create - a non-authenticated session. This parameter is passed to the - session that is created. If set to False, it allows - barbicanclient to perform "insecure" TLS (https) requests. - The server's certificate will not be verified against any - certificate authorities. - WARNING: This option should be used with caution. - :param service_type: Used as an endpoint filter when using an - authenticated keystone session. Defaults to 'key-manager'. - :param service_name: Used as an endpoint filter when using an - authenticated keystone session. - :param interface: Used as an endpoint filter when using an - authenticated keystone session. Defaults to 'public'. - :param region_name: Used as an endpoint filter when using an - authenticated keystone session. - """ - LOG.debug("Creating Client object") - - if not session: - session = ks_session.Session(verify=kwargs.pop('verify', True)) - - if session.auth is None and kwargs.get('auth') is None: - if not kwargs.get('endpoint'): - raise ValueError('Barbican endpoint url must be provided when ' - 'not using auth in the Keystone Session.') - - if kwargs.get('project_id') is None: - raise ValueError('Project ID must be provided when not using ' - 'auth in the Keystone Session') - if not version: - version = _DEFAULT_API_VERSION - - try: - client_path = _SUPPORTED_API_VERSION_MAP[version] - client_class = importutils.import_class(client_path) - return client_class(session=session, *args, **kwargs) - except (KeyError, ValueError): - supported_versions = ', '.join(_SUPPORTED_API_VERSION_MAP.keys()) - msg = ("Invalid client version %(version)s; must be one of: " - "%(versions)s") % {'version': version, - 'versions': supported_versions} - raise exceptions.UnsupportedVersion(msg) + """Barbican client used to interact with barbican service. + + :param version: The API version to use. + :param session: An instance of keystoneauth1.session.Session that + can be either authenticated, or not authenticated. When using + a non-authenticated Session, you must provide some additional + parameters. When no session is provided it will default to a + non-authenticated Session. + :param endpoint: Barbican endpoint url. Required when a session is not + given, or when using a non-authenticated session. + When using an authenticated session, the client will attempt + to get an endpoint from the session. + :param project_id: The project ID used for context in Barbican. + Required when a session is not given, or when using a + non-authenticated session. + When using an authenticated session, the project ID will be + provided by the authentication mechanism. + :param verify: When a session is not given, the client will create + a non-authenticated session. This parameter is passed to the + session that is created. If set to False, it allows + barbicanclient to perform "insecure" TLS (https) requests. + The server's certificate will not be verified against any + certificate authorities. + WARNING: This option should be used with caution. + :param service_type: Used as an endpoint filter when using an + authenticated keystone session. Defaults to 'key-manager'. + :param service_name: Used as an endpoint filter when using an + authenticated keystone session. + :param interface: Used as an endpoint filter when using an + authenticated keystone session. Defaults to 'public'. + :param region_name: Used as an endpoint filter when using an + authenticated keystone session. + """ + LOG.debug("Creating Client object") + + if not session: + session = ks_session.Session(verify=kwargs.pop('verify', True)) + + if session.auth is None and kwargs.get('auth') is None: + if not kwargs.get('endpoint'): + raise ValueError('Barbican endpoint url must be provided when ' + 'not using auth in the Keystone Session.') + + if kwargs.get('project_id') is None: + raise ValueError('Project ID must be provided when not using ' + 'auth in the Keystone Session') + if not version: + version = _DEFAULT_API_VERSION + + try: + client_path = _SUPPORTED_API_VERSION_MAP[version] + client_class = importutils.import_class(client_path) + return client_class(session=session, *args, **kwargs) + except (KeyError, ValueError): + supported_versions = ', '.join(_SUPPORTED_API_VERSION_MAP.keys()) + msg = ("Invalid client version %(version)s; must be one of: " + "%(versions)s") % {'version': version, + 'versions': supported_versions} + raise exceptions.UnsupportedVersion(msg) def env(*vars, **kwargs): diff --git a/barbicanclient/v1/orders.py b/barbicanclient/v1/orders.py index 15eca81..aee762a 100644 --- a/barbicanclient/v1/orders.py +++ b/barbicanclient/v1/orders.py @@ -417,12 +417,11 @@ class OrderManager(base.BaseEntityManager): # validate key_order meta fields. if resp_type == 'key' and ( set(response['meta'].keys()) - set(KeyOrder._validMeta)): - invalidFields = ', '.join( - map(str, set( - response['meta'].keys()) - - set(KeyOrder._validMeta))) - raise TypeError( - 'Invalid KeyOrder meta field: [%s]' % invalidFields) + invalidFields = ', '.join( + map(str, set(response['meta'].keys()) - + set(KeyOrder._validMeta))) + raise TypeError( + 'Invalid KeyOrder meta field: [%s]' % invalidFields) response.update(response.pop('meta')) diff --git a/functionaltests/cli/v1/behaviors/acl_behaviors.py b/functionaltests/cli/v1/behaviors/acl_behaviors.py index a9fc506..25478fd 100644 --- a/functionaltests/cli/v1/behaviors/acl_behaviors.py +++ b/functionaltests/cli/v1/behaviors/acl_behaviors.py @@ -48,7 +48,7 @@ class ACLBehaviors(base_behaviors.BaseBehaviors): argv.extend(['--project-access']) else: argv.extend(['--no-project-access']) - if operation_type and operation_type is not 'read': + if operation_type and operation_type != 'read': argv.extend([self._args_map_list['operation_type'][index], operation_type]) diff --git a/functionaltests/cli/v1/behaviors/base_behaviors.py b/functionaltests/cli/v1/behaviors/base_behaviors.py index 1c81723..3420cee 100644 --- a/functionaltests/cli/v1/behaviors/base_behaviors.py +++ b/functionaltests/cli/v1/behaviors/base_behaviors.py @@ -104,7 +104,7 @@ class BaseBehaviors(object): """ retval = {} if str is not None and len(str) > 0: - table_body = re.split('\+-*\+-*\+\n', str)[2:-1] + table_body = re.split(r'\+-*\+-*\+\n', str)[2:-1] lines = table_body[0].split('\n') for line in lines: if len(line) > 0: @@ -124,12 +124,12 @@ class BaseBehaviors(object): """ retval = [] if str is not None and len(str) > 0: - rows = re.findall('\|(.*?)\n', str) + rows = re.findall(r'\|(.*?)\n', str) # Remove header header_row = rows.pop(0) - key_names = re.findall('\s*(.*?)\s*\|', header_row) + key_names = re.findall(r'\s*(.*?)\s*\|', header_row) for row in rows: - values = re.findall('\s*(.*?)\s*\|', row) + values = re.findall(r'\s*(.*?)\s*\|', row) entry_dict = dict(zip(key_names, values)) retval.append(entry_dict) return retval diff --git a/test-requirements.txt b/test-requirements.txt index 1491aef..fdc1bc4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,9 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. +hacking>=3.1.0,<3.2.0 # Apache-2.0 + coverage!=4.4,>=4.1 # Apache-2.0 -hacking>=1.1.0,<1.2.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD requests-mock>=1.2.0 # Apache-2.0 mock>=2.0.0 # BSD diff --git a/tox.ini b/tox.ini index 7229a7a..2f9ccc9 100644 --- a/tox.ini +++ b/tox.ini @@ -63,7 +63,7 @@ deps = {[testenv]deps} commands = nosetests {toxinidir}/functionaltests/{posargs} -v [flake8] -ignore = H202 +ignore = H202,W504 show-source = True exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build -- cgit v1.2.1