Merge "Update hacking for Python3"

This commit is contained in:
Zuul 2020-06-16 13:55:17 +00:00 committed by Gerrit Code Review
commit ad2b85b4ed
8 changed files with 69 additions and 68 deletions

View File

@ -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:]))

View File

@ -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
)

View File

@ -120,65 +120,65 @@ class _HTTPClient(adapter.Adapter):
def Client(version=None, session=None, *args, **kwargs):
"""Barbican client used to interact with barbican service.
"""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")
: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 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 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
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)
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):

View File

@ -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'))

View File

@ -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])

View File

@ -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

View File

@ -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
stestr>=2.0.0 # Apache-2.0

View File

@ -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