Use LOG.warning instead of deprecated LOG.warn
The LOG.warn method is deprecated[1] and the LOG.warning method should be used instead. [1] https://docs.python.org/3/library/logging.html#logging.warning Change-Id: Id847acd613c27d4e647391c346ab6d3ceced99e4
This commit is contained in:
parent
39c67f09b8
commit
86facea1e4
@ -8,5 +8,6 @@ Blazar Style Commandments
|
|||||||
Blazar Specific Commandments
|
Blazar Specific Commandments
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
- [C312] Validate that logs are not translated.
|
- [Bl301] Validate that logs are not translated.
|
||||||
|
- [Bl302] Use LOG.warning() rather than LOG.warn().
|
||||||
- [H904] Delay string interpolations at logging calls.
|
- [H904] Delay string interpolations at logging calls.
|
||||||
|
@ -31,7 +31,7 @@ _log_translation_hint = re.compile(
|
|||||||
|
|
||||||
@core.flake8ext
|
@core.flake8ext
|
||||||
def no_translate_logs(logical_line):
|
def no_translate_logs(logical_line):
|
||||||
"""C312 - Don't translate logs.
|
"""Bl301 - Don't translate logs.
|
||||||
|
|
||||||
Check for 'LOG.*(_('
|
Check for 'LOG.*(_('
|
||||||
|
|
||||||
@ -46,4 +46,14 @@ def no_translate_logs(logical_line):
|
|||||||
message describe the check validation failure.
|
message describe the check validation failure.
|
||||||
"""
|
"""
|
||||||
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, "Bl301: Log messages should not be translated!")
|
||||||
|
|
||||||
|
|
||||||
|
@core.flake8ext
|
||||||
|
def no_log_warn(logical_line):
|
||||||
|
"""Bl302 - Use LOG.warning() rather than LOG.warn()
|
||||||
|
|
||||||
|
https://bugs.launchpad.net/tempest/+bug/1508442
|
||||||
|
"""
|
||||||
|
if logical_line.startswith('LOG.warn('):
|
||||||
|
yield(0, 'Bl302 Use LOG.warning() rather than LOG.warn()')
|
||||||
|
@ -714,9 +714,9 @@ class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
if new_host_id is None:
|
if new_host_id is None:
|
||||||
for allocation in allocations:
|
for allocation in allocations:
|
||||||
db_api.host_allocation_destroy(allocation['id'])
|
db_api.host_allocation_destroy(allocation['id'])
|
||||||
LOG.warn('Could not find alternative host for '
|
LOG.warning('Could not find alternative host for '
|
||||||
'reservation %s (lease: %s).',
|
'reservation %s (lease: %s).',
|
||||||
reservation['id'], lease['name'])
|
reservation['id'], lease['name'])
|
||||||
ret = False
|
ret = False
|
||||||
else:
|
else:
|
||||||
for allocation in allocations:
|
for allocation in allocations:
|
||||||
@ -735,9 +735,9 @@ class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
|
|
||||||
if new_host_id is None:
|
if new_host_id is None:
|
||||||
db_api.host_allocation_destroy(allocation['id'])
|
db_api.host_allocation_destroy(allocation['id'])
|
||||||
LOG.warn('Could not find alternative host for '
|
LOG.warning('Could not find alternative host for '
|
||||||
'reservation %s (lease: %s).',
|
'reservation %s (lease: %s).',
|
||||||
reservation['id'], lease['name'])
|
reservation['id'], lease['name'])
|
||||||
ret = False
|
ret = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -796,8 +796,8 @@ class VirtualInstancePlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
self.placement_client.update_reservation_inventory(
|
self.placement_client.update_reservation_inventory(
|
||||||
new_host['hypervisor_hostname'], reservation['id'], num,
|
new_host['hypervisor_hostname'], reservation['id'], num,
|
||||||
additional=True)
|
additional=True)
|
||||||
LOG.warn('Resource changed for reservation %s (lease: %s).',
|
LOG.warning('Resource changed for reservation %s (lease: %s).',
|
||||||
reservation['id'], lease['name'])
|
reservation['id'], lease['name'])
|
||||||
|
|
||||||
def _get_extra_capabilities(self, host_id):
|
def _get_extra_capabilities(self, host_id):
|
||||||
extra_capabilities = {}
|
extra_capabilities = {}
|
||||||
|
@ -282,15 +282,15 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||||||
)
|
)
|
||||||
if not new_hostids:
|
if not new_hostids:
|
||||||
db_api.host_allocation_destroy(allocation['id'])
|
db_api.host_allocation_destroy(allocation['id'])
|
||||||
LOG.warn('Could not find alternative host for reservation %s '
|
LOG.warning('Could not find alternative host for reservation %s '
|
||||||
'(lease: %s).', reservation['id'], lease['name'])
|
'(lease: %s).', reservation['id'], lease['name'])
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
new_hostid = new_hostids.pop()
|
new_hostid = new_hostids.pop()
|
||||||
db_api.host_allocation_update(allocation['id'],
|
db_api.host_allocation_update(allocation['id'],
|
||||||
{'compute_host_id': new_hostid})
|
{'compute_host_id': new_hostid})
|
||||||
LOG.warn('Resource changed for reservation %s (lease: %s).',
|
LOG.warning('Resource changed for reservation %s (lease: %s).',
|
||||||
reservation['id'], lease['name'])
|
reservation['id'], lease['name'])
|
||||||
if reservation['status'] == status.reservation.ACTIVE:
|
if reservation['status'] == status.reservation.ACTIVE:
|
||||||
# Add the alternative host into the aggregate.
|
# Add the alternative host into the aggregate.
|
||||||
new_host = db_api.host_get(new_hostid)
|
new_host = db_api.host_get(new_hostid)
|
||||||
@ -802,8 +802,8 @@ class PhysicalHostMonitorPlugin(base.BaseMonitorPlugin,
|
|||||||
failed_hosts = db_api.reservable_host_get_all_by_queries(
|
failed_hosts = db_api.reservable_host_get_all_by_queries(
|
||||||
['hypervisor_hostname == ' + data['host']])
|
['hypervisor_hostname == ' + data['host']])
|
||||||
if failed_hosts:
|
if failed_hosts:
|
||||||
LOG.warn('%s failed.',
|
LOG.warning('%s failed.',
|
||||||
failed_hosts[0]['hypervisor_hostname'])
|
failed_hosts[0]['hypervisor_hostname'])
|
||||||
reservation_flags = self._handle_failures(failed_hosts)
|
reservation_flags = self._handle_failures(failed_hosts)
|
||||||
else:
|
else:
|
||||||
recovered_hosts = db_api.host_get_all_by_queries(
|
recovered_hosts = db_api.host_get_all_by_queries(
|
||||||
@ -812,8 +812,8 @@ class PhysicalHostMonitorPlugin(base.BaseMonitorPlugin,
|
|||||||
if recovered_hosts:
|
if recovered_hosts:
|
||||||
db_api.host_update(recovered_hosts[0]['id'],
|
db_api.host_update(recovered_hosts[0]['id'],
|
||||||
{'reservable': True})
|
{'reservable': True})
|
||||||
LOG.warn('%s recovered.',
|
LOG.warning('%s recovered.',
|
||||||
recovered_hosts[0]['hypervisor_hostname'])
|
recovered_hosts[0]['hypervisor_hostname'])
|
||||||
|
|
||||||
return reservation_flags
|
return reservation_flags
|
||||||
|
|
||||||
@ -838,12 +838,12 @@ class PhysicalHostMonitorPlugin(base.BaseMonitorPlugin,
|
|||||||
failed_hosts, recovered_hosts = self._poll_resource_failures()
|
failed_hosts, recovered_hosts = self._poll_resource_failures()
|
||||||
if failed_hosts:
|
if failed_hosts:
|
||||||
for host in failed_hosts:
|
for host in failed_hosts:
|
||||||
LOG.warn('%s failed.', host['hypervisor_hostname'])
|
LOG.warning('%s failed.', host['hypervisor_hostname'])
|
||||||
reservation_flags = self._handle_failures(failed_hosts)
|
reservation_flags = self._handle_failures(failed_hosts)
|
||||||
if recovered_hosts:
|
if recovered_hosts:
|
||||||
for host in recovered_hosts:
|
for host in recovered_hosts:
|
||||||
db_api.host_update(host['id'], {'reservable': True})
|
db_api.host_update(host['id'], {'reservable': True})
|
||||||
LOG.warn('%s recovered.', host['hypervisor_hostname'])
|
LOG.warning('%s recovered.', host['hypervisor_hostname'])
|
||||||
|
|
||||||
return reservation_flags
|
return reservation_flags
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ class BaseStatus(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if next_status not in cls.NEXT_STATUSES[current_status]:
|
if next_status not in cls.NEXT_STATUSES[current_status]:
|
||||||
LOG.warn('Invalid transition from %s to %s.',
|
LOG.warning('Invalid transition from %s to %s.',
|
||||||
current_status, next_status)
|
current_status, next_status)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -135,7 +135,7 @@ class LeaseStatus(BaseStatus):
|
|||||||
if cls.is_valid_combination(kwargs['lease_id'], next):
|
if cls.is_valid_combination(kwargs['lease_id'], next):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
LOG.warn('Invalid combination of statuses.')
|
LOG.warning('Invalid combination of statuses.')
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -203,10 +203,11 @@ class LeaseStatus(BaseStatus):
|
|||||||
LOG.debug('Status of lease %s changed from %s to %s.',
|
LOG.debug('Status of lease %s changed from %s to %s.',
|
||||||
lease_id, lease['status'], transition)
|
lease_id, lease['status'], transition)
|
||||||
else:
|
else:
|
||||||
LOG.warn('Aborting %s. '
|
LOG.warning('Aborting %s. '
|
||||||
'Invalid lease status transition from %s to %s.',
|
'Invalid lease status transition '
|
||||||
func.__name__, lease['status'],
|
'from %s to %s.',
|
||||||
transition)
|
func.__name__, lease['status'],
|
||||||
|
transition)
|
||||||
raise exceptions.InvalidStatus
|
raise exceptions.InvalidStatus
|
||||||
|
|
||||||
# Executing the wrapped function
|
# Executing the wrapped function
|
||||||
|
@ -25,3 +25,10 @@ class HackingTestCase(tests.TestCase):
|
|||||||
# Catch abuses when used with a variable and not a literal
|
# Catch abuses when used with a variable and not a literal
|
||||||
bad = 'LOG.%s(%s(msg))' % (log, hint)
|
bad = 'LOG.%s(%s(msg))' % (log, hint)
|
||||||
self.assertEqual(1, len(list(checks.no_translate_logs(bad))))
|
self.assertEqual(1, len(list(checks.no_translate_logs(bad))))
|
||||||
|
|
||||||
|
def test_no_log_warn(self):
|
||||||
|
bad = 'LOG.warn("LOG.warn is deprecated")'
|
||||||
|
self.assertEqual(1, len(list(checks.no_log_warn(bad))))
|
||||||
|
|
||||||
|
good = 'LOG.warning("LOG.warn is deprecated")'
|
||||||
|
self.assertEqual(0, len(list(checks.no_log_warn(good))))
|
||||||
|
@ -281,7 +281,7 @@ class ReservationPool(NovaClientWrapper):
|
|||||||
try:
|
try:
|
||||||
agg = self.get_aggregate_from_name_or_id(pool)
|
agg = self.get_aggregate_from_name_or_id(pool)
|
||||||
except manager_exceptions.AggregateNotFound:
|
except manager_exceptions.AggregateNotFound:
|
||||||
LOG.warn("Aggregate '%s' not found, skipping deletion", pool)
|
LOG.warning("Aggregate '%s' not found, skipping deletion", pool)
|
||||||
return
|
return
|
||||||
|
|
||||||
hosts = agg.hosts
|
hosts = agg.hosts
|
||||||
@ -373,12 +373,12 @@ class ReservationPool(NovaClientWrapper):
|
|||||||
pool=pool, host=host, nova_exception=str(e))
|
pool=pool, host=host, nova_exception=str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if added_hosts:
|
if added_hosts:
|
||||||
LOG.warn('Removing hosts added to aggregate %s: %s',
|
LOG.warning('Removing hosts added to aggregate %s: %s',
|
||||||
agg.id, added_hosts)
|
agg.id, added_hosts)
|
||||||
for host in added_hosts:
|
for host in added_hosts:
|
||||||
self.nova.aggregates.remove_host(agg.id, host)
|
self.nova.aggregates.remove_host(agg.id, host)
|
||||||
if removed_hosts:
|
if removed_hosts:
|
||||||
LOG.warn('Adding hosts back to freepool: %s', removed_hosts)
|
LOG.warning('Adding hosts back to freepool: %s', removed_hosts)
|
||||||
for host in removed_hosts:
|
for host in removed_hosts:
|
||||||
self.nova.aggregates.add_host(freepool_agg.id, host)
|
self.nova.aggregates.add_host(freepool_agg.id, host)
|
||||||
raise e
|
raise e
|
||||||
|
3
tox.ini
3
tox.ini
@ -74,7 +74,8 @@ max-complexity=23
|
|||||||
|
|
||||||
[flake8:local-plugins]
|
[flake8:local-plugins]
|
||||||
extension =
|
extension =
|
||||||
C312 = checks:no_translate_logs
|
Bl301 = checks:no_translate_logs
|
||||||
|
Bl302 = checks:no_log_warn
|
||||||
paths = ./blazar/hacking
|
paths = ./blazar/hacking
|
||||||
|
|
||||||
[testenv:pylint]
|
[testenv:pylint]
|
||||||
|
Loading…
Reference in New Issue
Block a user