Update hacking for Python3

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

Fix problems found.

Update local hacking checks for new flake8.

Remove hacking and friends from lower-constraints, they are not needed
to be installed at run-time.

Move hacking tests to another subdir, import hacking failed since the
subdir was called hacking as well.

Change-Id: I684f0e4be28e529ae2c9d6f4bef5bd840adc8787
This commit is contained in:
Andreas Jaeger 2020-04-02 07:23:34 +02:00 committed by Pierre Riteau
parent eb5cef0bf5
commit 0b8d264171
11 changed files with 21 additions and 19 deletions

View File

@ -49,5 +49,6 @@ def main():
return upgradecheck.main( return upgradecheck.main(
cfg.CONF, project='blazar', upgrade_command=Checks()) cfg.CONF, project='blazar', upgrade_command=Checks())
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View File

@ -78,6 +78,7 @@ def run_migrations_online(config):
finally: finally:
connection.close() connection.close()
if context.is_offline_mode(): if context.is_offline_mode():
run_migrations_offline(config.blazar_config) run_migrations_offline(config.blazar_config)
else: else:

View File

@ -48,4 +48,5 @@ def datetime_to_str(dct, attr_name):
if dct.get(attr_name) is not None: if dct.get(attr_name) is not None:
dct[attr_name] = dct[attr_name].isoformat(' ') dct[attr_name] = dct[attr_name].isoformat(' ')
BlazarBase = declarative.declarative_base(cls=_BlazarBase) BlazarBase = declarative.declarative_base(cls=_BlazarBase)

View File

@ -14,6 +14,7 @@
import re import re
from hacking import core
_all_log_levels = {'critical', 'error', 'exception', 'info', _all_log_levels = {'critical', 'error', 'exception', 'info',
'warning', 'debug'} 'warning', 'debug'}
@ -28,6 +29,7 @@ _log_translation_hint = re.compile(
}) })
@core.flake8ext
def no_translate_logs(logical_line): def no_translate_logs(logical_line):
"""C312 - Don't translate logs. """C312 - Don't translate logs.
@ -45,7 +47,3 @@ def no_translate_logs(logical_line):
""" """
if _log_translation_hint.match(logical_line): if _log_translation_hint.match(logical_line):
yield (0, "C312: Log messages should not be translated!") yield (0, "C312: Log messages should not be translated!")
def factory(register):
register(no_translate_logs)

View File

@ -195,7 +195,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
host_reservation['aggregate_id']): host_reservation['aggregate_id']):
for server in client.servers.list( for server in client.servers.list(
search_opts={"host": host, "all_tenants": 1}): search_opts={"host": host, "all_tenants": 1}):
client.servers.create_image(server=server) client.servers.create_image(server=server)
def on_end(self, resource_id): def on_end(self, resource_id):
"""Remove the hosts from the pool.""" """Remove the hosts from the pool."""

View File

@ -194,18 +194,18 @@ class LeaseStatus(BaseStatus):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
# Update a lease status # Update a lease status
lease_id = kwargs['lease_id'] lease_id = kwargs['lease_id']
l = db_api.lease_get(lease_id) lease = db_api.lease_get(lease_id)
if cls.is_valid_transition(l['status'], if cls.is_valid_transition(lease['status'],
transition, transition,
lease_id=lease_id): lease_id=lease_id):
db_api.lease_update(lease_id, db_api.lease_update(lease_id,
{'status': transition}) {'status': transition})
LOG.debug('Status of lease %s changed from %s to %s.', LOG.debug('Status of lease %s changed from %s to %s.',
lease_id, l['status'], transition) lease_id, lease['status'], transition)
else: else:
LOG.warn('Aborting %s. ' LOG.warn('Aborting %s. '
'Invalid lease status transition from %s to %s.', 'Invalid lease status transition from %s to %s.',
func.__name__, l['status'], func.__name__, lease['status'],
transition) transition)
raise exceptions.InvalidStatus raise exceptions.InvalidStatus

View File

@ -22,11 +22,9 @@ eventlet==0.18.2
extras==1.0.0 extras==1.0.0
fasteners==0.14.1 fasteners==0.14.1
fixtures==3.0.0 fixtures==3.0.0
flake8==2.5.5
Flask==0.10 Flask==0.10
futurist==1.6.0 futurist==1.6.0
greenlet==0.4.13 greenlet==0.4.13
hacking==0.12.0
idna==2.6 idna==2.6
imagesize==1.0.0 imagesize==1.0.0
iso8601==0.1.11 iso8601==0.1.11
@ -70,12 +68,10 @@ Paste==2.0.3
PasteDeploy==1.5.2 PasteDeploy==1.5.2
pbr==2.0.0 pbr==2.0.0
pecan==1.0.0 pecan==1.0.0
pep8==1.5.7
pika-pool==0.1.3 pika-pool==0.1.3
pika==0.10.0 pika==0.10.0
prettytable==0.7.2 prettytable==0.7.2
pycadf==2.7.0 pycadf==2.7.0
pyflakes==0.8.1
Pygments==2.2.0 Pygments==2.2.0
pyinotify==0.9.6 pyinotify==0.9.6
pylint==1.9.1 pylint==1.9.1

View File

@ -1,7 +1,7 @@
# The order of packages is significant, because pip processes them in the order # 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 # of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 hacking>=3.0,<3.1.0 # Apache-2.0
ddt>=1.0.1 # MIT ddt>=1.0.1 # MIT
mock>=2.0.0 # BSD mock>=2.0.0 # BSD

15
tox.ini
View File

@ -61,17 +61,22 @@ commands = oslo-config-generator --config-file=etc/blazar/blazar-config-generato
show-source = true show-source = true
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,api-ref exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,api-ref
# NOTE(tonyb): Ignore a few errors/warnings that are now "on by default". # NOTE(tonyb): Ignore a few errors/warnings that are now "on by default".
ignore=H105,H238,E123 # W503 line break before binary operator
# W504 line break after binary operator
# E402 module level import not at top of file
ignore=H105,H238,E123,E402,W503,W504
# [H904] Delay string interpolations at logging calls. # [H904] Delay string interpolations at logging calls.
enable-extensions=H904 enable-extensions=H904
# To get a list of functions that have a complexity of 17 or more, set # To get a list of functions that have a complexity of 17 or more, set
# max-complexity to 17 and run 'tox -epep8'. # max-complexity to 17 and run 'tox -epep8'.
# 16 is currently the most complex thing we have: # 23 is currently the most complex thing we have:
# 'ManagerService.update_lease' - blazar/manager/service.py # 'ManagerService.update_lease' - blazar/manager/service.py
max-complexity=17 max-complexity=23
[hacking] [flake8:local-plugins]
local-check-factory = blazar.hacking.checks.factory extension =
C312 = checks:no_translate_logs
paths = ./blazar/hacking
[testenv:pylint] [testenv:pylint]
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt