From b3506fa3ebdd48806d80e42f15c612412412a160 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Cuong Date: Thu, 6 Jul 2017 03:59:23 -0400 Subject: [PATCH] Enable H904 check H904 allows the logging package to skip creating the formatted log message if the message is not going to be emitted because of the current log level. Change-Id: Id6e27d8fefacd93bde41db21a20c8eaf3d3d6880 See: https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages --- .../drivers/haproxy/rest_api_driver.py | 6 ++++-- .../controller/housekeeping/house_keeping.py | 9 ++++----- octavia/controller/queue/endpoint.py | 18 +++++++++--------- octavia/controller/worker/controller_worker.py | 4 ++-- .../drivers/neutron/allowed_address_pairs.py | 2 +- tox.ini | 2 ++ 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/octavia/amphorae/drivers/haproxy/rest_api_driver.py b/octavia/amphorae/drivers/haproxy/rest_api_driver.py index 7738502787..4b81b92018 100644 --- a/octavia/amphorae/drivers/haproxy/rest_api_driver.py +++ b/octavia/amphorae/drivers/haproxy/rest_api_driver.py @@ -284,8 +284,10 @@ class AmphoraAPIClient(object): # amphora is not yet up, in which case retry. # Otherwise return the response quickly. if r.status_code == 404: - LOG.debug('Got a 404 (content-type: %s) -- connection ' - 'data: %s' % (content_type, r.content)) + LOG.debug('Got a 404 (content-type: %(content_type)s) -- ' + 'connection data: %(content)s', + {'content_type': content_type, + 'content': r.content}) if content_type.find("application/json") == -1: LOG.debug("Amphora agent not ready.") raise requests.ConnectionError diff --git a/octavia/controller/housekeeping/house_keeping.py b/octavia/controller/housekeeping/house_keeping.py index 6a46be56aa..46a4f9b145 100644 --- a/octavia/controller/housekeeping/house_keeping.py +++ b/octavia/controller/housekeeping/house_keeping.py @@ -47,7 +47,7 @@ class SpareAmphora(object): # When the current spare amphora is less than required if diff_count > 0: - LOG.info("Initiating creation of %d spare amphora." % diff_count) + LOG.info("Initiating creation of %d spare amphora.", diff_count) # Call Amphora Create Flow diff_count times for i in range(1, diff_count + 1): @@ -81,7 +81,7 @@ class DatabaseCleanup(object): self.amp_health_repo.delete(session, amphora_id=amp.id) except sqlalchemy_exceptions.NoResultFound: pass # Best effort delete, this record might not exist - LOG.info('Deleted Amphora id : %s' % amp.id) + LOG.info('Deleted Amphora id : %s', amp.id) def cleanup_load_balancers(self): """Checks the DB for old load balancers and triggers their removal.""" @@ -97,7 +97,7 @@ class DatabaseCleanup(object): exp_age): LOG.info('Attempting to delete load balancer id : %s', lb.id) self.lb_repo.delete(session, id=lb.id) - LOG.info('Deleted load balancer id : %s' % lb.id) + LOG.info('Deleted load balancer id : %s', lb.id) class CertRotation(object): @@ -120,5 +120,4 @@ class CertRotation(object): LOG.debug("Cert expired amphora's id is: %s", amp.id) executor.submit(self.cw.amphora_cert_rotation, amp.id) if rotation_count > 0: - LOG.info("Rotated certificates for %s amphora" % - rotation_count) + LOG.info("Rotated certificates for %s amphora", rotation_count) diff --git a/octavia/controller/queue/endpoint.py b/octavia/controller/queue/endpoint.py index 0f736a3c79..07956a586c 100644 --- a/octavia/controller/queue/endpoint.py +++ b/octavia/controller/queue/endpoint.py @@ -92,37 +92,37 @@ class Endpoint(object): self.worker.delete_health_monitor(health_monitor_id) def create_member(self, context, member_id): - LOG.info('Creating member \'%s\'...' % member_id) + LOG.info('Creating member \'%s\'...', member_id) self.worker.create_member(member_id) def update_member(self, context, member_id, member_updates): - LOG.info('Updating member \'%s\'...' % member_id) + LOG.info('Updating member \'%s\'...', member_id) self.worker.update_member(member_id, member_updates) def delete_member(self, context, member_id): - LOG.info('Deleting member \'%s\'...' % member_id) + LOG.info('Deleting member \'%s\'...', member_id) self.worker.delete_member(member_id) def create_l7policy(self, context, l7policy_id): - LOG.info('Creating l7policy \'%s\'...' % l7policy_id) + LOG.info('Creating l7policy \'%s\'...', l7policy_id) self.worker.create_l7policy(l7policy_id) def update_l7policy(self, context, l7policy_id, l7policy_updates): - LOG.info('Updating l7policy \'%s\'...' % l7policy_id) + LOG.info('Updating l7policy \'%s\'...', l7policy_id) self.worker.update_l7policy(l7policy_id, l7policy_updates) def delete_l7policy(self, context, l7policy_id): - LOG.info('Deleting l7policy \'%s\'...' % l7policy_id) + LOG.info('Deleting l7policy \'%s\'...', l7policy_id) self.worker.delete_l7policy(l7policy_id) def create_l7rule(self, context, l7rule_id): - LOG.info('Creating l7rule \'%s\'...' % l7rule_id) + LOG.info('Creating l7rule \'%s\'...', l7rule_id) self.worker.create_l7rule(l7rule_id) def update_l7rule(self, context, l7rule_id, l7rule_updates): - LOG.info('Updating l7rule \'%s\'...' % l7rule_id) + LOG.info('Updating l7rule \'%s\'...', l7rule_id) self.worker.update_l7rule(l7rule_id, l7rule_updates) def delete_l7rule(self, context, l7rule_id): - LOG.info('Deleting l7rule \'%s\'...' % l7rule_id) + LOG.info('Deleting l7rule \'%s\'...', l7rule_id) self.worker.delete_l7rule(l7rule_id) diff --git a/octavia/controller/worker/controller_worker.py b/octavia/controller/worker/controller_worker.py index 09640a742d..113ceac6a1 100644 --- a/octavia/controller/worker/controller_worker.py +++ b/octavia/controller/worker/controller_worker.py @@ -651,7 +651,7 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine): except Exception as e: with excutils.save_and_reraise_exception(): - LOG.error("Failover exception: %s" % e) + LOG.error("Failover exception: %s", e) def amphora_cert_rotation(self, amphora_id): """Perform cert rotation for an amphora. @@ -663,7 +663,7 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine): amp = self._amphora_repo.get(db_apis.get_session(), id=amphora_id) - LOG.info("Start amphora cert rotation, amphora's id is: %s" % amp.id) + LOG.info("Start amphora cert rotation, amphora's id is: %s", amp.id) certrotation_amphora_tf = self._taskflow_load( self._amphora_flows.cert_rotate_amphora_flow(), diff --git a/octavia/network/drivers/neutron/allowed_address_pairs.py b/octavia/network/drivers/neutron/allowed_address_pairs.py index 8a66ad35b7..e9263fd858 100644 --- a/octavia/network/drivers/neutron/allowed_address_pairs.py +++ b/octavia/network/drivers/neutron/allowed_address_pairs.py @@ -500,7 +500,7 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver): raise base.PlugNetworkException(e.message) except nova_client_exceptions.Conflict: LOG.info('Port %(portid)s is already plugged, ' - 'skipping' % {'portid': port.id}) + 'skipping', {'portid': port.id}) plugged_interface = n_data_models.Interface( compute_id=amphora.compute_id, network_id=port.network_id, diff --git a/tox.ini b/tox.ini index 09c70935fa..4a571cc3cd 100644 --- a/tox.ini +++ b/tox.ini @@ -116,6 +116,8 @@ ignore = show-source = true builtins = _ exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build +# [H904] Delay string interpolations at logging calls. +enable-extensions=H904 [hacking] import_exceptions = octavia.i18n