From f20ca36d1552651b41db44e6c7432969a9aaed15 Mon Sep 17 00:00:00 2001 From: "sonu.kumar" Date: Fri, 27 Nov 2015 12:22:49 +0530 Subject: [PATCH] Improving info level log messages String interpolation should be delayed to be handled by the logging code, rather than being done at the point of the logging call. So we should use- LOG.info(_LI('some message: variable=%s'), variable) instead of LOG.info(_LI('some message: variable=%s') % variable) Change-Id: I6b3e578f2a0b66f253d49fe44766b6a31196a7c4 link: http://docs.openstack.org/developer/oslo.i18n/guidelines.html --- designate/backend/agent.py | 2 +- designate/backend/impl_dynect.py | 6 +++--- designate/backend/impl_fake.py | 4 ++-- designate/backend/impl_infoblox/__init__.py | 4 ++-- designate/central/rpcapi.py | 2 +- designate/central/service.py | 6 +++--- designate/context.py | 4 ++-- designate/manage/akamai.py | 4 ++-- designate/manage/tlds.py | 4 ++-- designate/mdns/handler.py | 4 ++-- designate/mdns/notify.py | 4 ++-- designate/mdns/rpcapi.py | 8 ++++---- designate/utils.py | 4 ++-- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/designate/backend/agent.py b/designate/backend/agent.py index d5945b98b..cc6ff5c04 100644 --- a/designate/backend/agent.py +++ b/designate/backend/agent.py @@ -119,7 +119,7 @@ class AgentPoolBackend(base.Backend): response = None LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:" - "%(port)d'.") % + "%(port)d'."), {'msg': str(opcode), 'zone': zone_name, 'server': dest_ip, 'port': dest_port}) diff --git a/designate/backend/impl_dynect.py b/designate/backend/impl_dynect.py index ed9b3ae21..d09b2617a 100644 --- a/designate/backend/impl_dynect.py +++ b/designate/backend/impl_dynect.py @@ -345,7 +345,7 @@ class DynECTBackend(base.Backend): timings=CONF[CFG_GROUP].timings) def create_zone(self, context, zone): - LOG.info(_LI('Creating zone %(d_id)s / %(d_name)s') % + LOG.info(_LI('Creating zone %(d_id)s / %(d_name)s'), {'d_id': zone['id'], 'd_name': zone['name']}) url = '/Secondary/%s' % zone['name'].rstrip('.') @@ -368,7 +368,7 @@ class DynECTBackend(base.Backend): if emsg['ERR_CD'] == 'TARGET_EXISTS': msg = _LI("Zone already exists, updating existing " "zone instead %s") - LOG.info(msg % zone['name']) + LOG.info(msg, zone['name']) client.put(url, data=data) break else: @@ -378,7 +378,7 @@ class DynECTBackend(base.Backend): client.logout() def delete_zone(self, context, zone): - LOG.info(_LI('Deleting zone %(d_id)s / %(d_name)s') % + LOG.info(_LI('Deleting zone %(d_id)s / %(d_name)s'), {'d_id': zone['id'], 'd_name': zone['name']}) url = '/Zone/%s' % zone['name'].rstrip('.') client = self.get_client() diff --git a/designate/backend/impl_fake.py b/designate/backend/impl_fake.py index d961dfda4..82d7d4f8b 100644 --- a/designate/backend/impl_fake.py +++ b/designate/backend/impl_fake.py @@ -26,7 +26,7 @@ class FakeBackend(base.Backend): __plugin_name__ = 'fake' def create_zone(self, context, zone): - LOG.info(_LI('Create Zone %r') % zone) + LOG.info(_LI('Create Zone %r'), zone) def delete_zone(self, context, zone): - LOG.info(_LI('Delete Zone %r') % zone) + LOG.info(_LI('Delete Zone %r'), zone) diff --git a/designate/backend/impl_infoblox/__init__.py b/designate/backend/impl_infoblox/__init__.py index cd5956b53..28eb081d9 100644 --- a/designate/backend/impl_infoblox/__init__.py +++ b/designate/backend/impl_infoblox/__init__.py @@ -43,7 +43,7 @@ class InfobloxBackend(base.Backend): "Infoblox only supports mDNS instances on port 53") def create_zone(self, context, zone): - LOG.info(_LI('Create Zone %r') % zone) + LOG.info(_LI('Create Zone %r'), zone) dns_net_view = self.infoblox.get_dns_view(context.tenant) self.infoblox.create_zone_auth( @@ -52,7 +52,7 @@ class InfobloxBackend(base.Backend): ) def delete_zone(self, context, zone): - LOG.info(_LI('Delete Zone %r') % zone) + LOG.info(_LI('Delete Zone %r'), zone) self.infoblox.delete_zone_auth(zone['name'][0:-1]) def ping(self, context): diff --git a/designate/central/rpcapi.py b/designate/central/rpcapi.py index 007628852..62830b9be 100644 --- a/designate/central/rpcapi.py +++ b/designate/central/rpcapi.py @@ -411,7 +411,7 @@ class CentralAPI(object): # Pool Manager Integration Methods def update_status(self, context, zone_id, status, serial): LOG.info(_LI("update_status: Calling central's update_status " - "for %(zone_id)s : %(status)s : %(serial)s") % + "for %(zone_id)s : %(status)s : %(serial)s"), {'zone_id': zone_id, 'status': status, 'serial': serial}) self.client.cast(context, 'update_status', zone_id=zone_id, status=status, serial=serial) diff --git a/designate/central/service.py b/designate/central/service.py index e2d586b67..9adf933bc 100644 --- a/designate/central/service.py +++ b/designate/central/service.py @@ -1091,7 +1091,7 @@ class Service(service.RPCService, service.Service): 'before deleting this zone') if hasattr(context, 'abandon') and context.abandon: - LOG.info(_LW("Abandoning zone '%(zone)s'") % {'zone': zone.name}) + LOG.info(_LW("Abandoning zone '%(zone)s'"), {'zone': zone.name}) zone = self.storage.delete_zone(context, zone.id) else: zone = self._delete_zone_in_storage(context, zone) @@ -1151,7 +1151,7 @@ class Service(service.RPCService, service.Service): "Serial %(srv_serial)d is not equal to zone's %(serial)d," " performing AXFR") LOG.info( - msg % {"srv_serial": serial, "serial": zone.serial}) + msg, {"srv_serial": serial, "serial": zone.serial}) self.mdns_api.perform_zone_xfr(context, zone) def count_zones(self, context, criterion=None): @@ -1977,7 +1977,7 @@ class Service(service.RPCService, service.Service): except exceptions.ZoneNotFound: msg = _LI( 'Creating zone for %(fip_id)s:%(region)s - ' - '%(fip_addr)s zone %(zonename)s') % \ + '%(fip_addr)s zone %(zonename)s'), \ {'fip_id': floatingip_id, 'region': region, 'fip_addr': fip['address'], 'zonename': zone_name} LOG.info(msg) diff --git a/designate/context.py b/designate/context.py index 5f4465648..a2204ef78 100644 --- a/designate/context.py +++ b/designate/context.py @@ -124,8 +124,8 @@ class DesignateContext(context.RequestContext): policy.check('use_sudo', self) - LOG.info(_LI('Accepted sudo from user %(user)s to tenant %(tenant)s') - % {'user': self.user, 'tenant': tenant}) + LOG.info(_LI('Accepted sudo from user %(user)s to tenant %(tenant)s'), + {'user': self.user, 'tenant': tenant}) self.original_tenant = self.tenant self.tenant = tenant diff --git a/designate/manage/akamai.py b/designate/manage/akamai.py index 767b1bfc0..2af0c0125 100644 --- a/designate/manage/akamai.py +++ b/designate/manage/akamai.py @@ -79,7 +79,7 @@ class AkamaiCommands(base.Commands): client = impl_akamai.EnhancedDNSClient( target.options.get("username"), target.options.get("password")) - LOG.info(_LI("Doing batches of %i") % batch_size) + LOG.info(_LI("Doing batches of %i"), batch_size) criterion = {"pool_id": pool_id} marker = None @@ -103,6 +103,6 @@ class AkamaiCommands(base.Commands): z = impl_akamai.build_zone(client, target, zone) update.append(z) - LOG.info(_LI('Uploading %d Zones') % len(update)) + LOG.info(_LI('Uploading %d Zones'), len(update)) client.setZones(update) diff --git a/designate/manage/tlds.py b/designate/manage/tlds.py index d9072ab0e..6fe0aadff 100644 --- a/designate/manage/tlds.py +++ b/designate/manage/tlds.py @@ -113,7 +113,7 @@ class TLDCommands(base.Commands): if not os.path.exists(input_file): raise Exception('TLD Input file Not Found') - LOG.info(_LI("Importing TLDs from %s") % input_file) + LOG.info(_LI("Importing TLDs from %s"), input_file) error_lines = [] tlds_added = 0 @@ -133,7 +133,7 @@ class TLDCommands(base.Commands): tlds_added += self._validate_and_create_tld(line, error_lines) - LOG.info(_LI("Number of tlds added: %d") % tlds_added) + LOG.info(_LI("Number of tlds added: %d"), tlds_added) errors = len(error_lines) if errors > 0: diff --git a/designate/mdns/handler.py b/designate/mdns/handler.py index 8a61c4320..9690421bc 100644 --- a/designate/mdns/handler.py +++ b/designate/mdns/handler.py @@ -145,11 +145,11 @@ class RequestHandler(xfr.XFRMixin): if soa_serial == zone.serial: msg = _LI("Serial %(serial)s is the same for master and us for " "%(zone_id)s") - LOG.info(msg % {"serial": soa_serial, "zone_id": zone.id}) + LOG.info(msg, {"serial": soa_serial, "zone_id": zone.id}) else: msg = _LI("Scheduling AXFR for %(zone_id)s from %(master_addr)s") info = {"zone_id": zone.id, "master_addr": master_addr} - LOG.info(msg % info) + LOG.info(msg, info) self.tg.add_thread(self.zone_sync, context, zone, [master_addr]) diff --git a/designate/mdns/notify.py b/designate/mdns/notify.py index 1df8b2f27..9665bd045 100644 --- a/designate/mdns/notify.py +++ b/designate/mdns/notify.py @@ -176,7 +176,7 @@ class NotifyEndpoint(base.BaseEndpoint): while retry < max_retries: retry = retry + 1 LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:" - "%(port)d'.") % + "%(port)d'."), {'msg': 'NOTIFY' if notify else 'SOA', 'zone': zone.name, 'server': host, 'port': port}) @@ -209,7 +209,7 @@ class NotifyEndpoint(base.BaseEndpoint): # authoritative answer elif response.rcode() in (dns.rcode.NXDOMAIN, dns.rcode.REFUSED, dns.rcode.SERVFAIL): - LOG.info(_LI("%(zone)s not found on %(server)s:%(port)d") % + LOG.info(_LI("%(zone)s not found on %(server)s:%(port)d"), {'zone': zone.name, 'server': host, 'port': port}) break diff --git a/designate/mdns/rpcapi.py b/designate/mdns/rpcapi.py index e71dea4a5..98fcce08d 100644 --- a/designate/mdns/rpcapi.py +++ b/designate/mdns/rpcapi.py @@ -72,7 +72,7 @@ class MdnsAPI(object): def notify_zone_changed(self, context, zone, host, port, timeout, retry_interval, max_retries, delay): LOG.info(_LI("notify_zone_changed: Calling mdns for zone '%(zone)s', " - "serial '%(serial)s' to nameserver '%(host)s:%(port)s'") % + "serial '%(serial)s' to nameserver '%(host)s:%(port)s'"), {'zone': zone.name, 'serial': zone.serial, 'host': host, 'port': port}) # The notify_zone_changed method is a cast rather than a call since the @@ -87,7 +87,7 @@ class MdnsAPI(object): retry_interval, max_retries, delay): LOG.info( _LI("poll_for_serial_number: Calling mdns for zone '%(zone)s', " - "serial '%(serial)s' on nameserver '%(host)s:%(port)s'") % + "serial '%(serial)s' on nameserver '%(host)s:%(port)s'"), {'zone': zone.name, 'serial': zone.serial, 'host': nameserver.host, 'port': nameserver.port}) # The poll_for_serial_number method is a cast rather than a call since @@ -103,7 +103,7 @@ class MdnsAPI(object): retry_interval, max_retries, delay): LOG.info( _LI("get_serial_number: Calling mdns for zone '%(zone)s', serial " - "%(serial)s' on nameserver '%(host)s:%(port)s'") % + "%(serial)s' on nameserver '%(host)s:%(port)s'"), {'zone': zone.name, 'serial': zone.serial, 'host': host, 'port': port}) cctxt = self.notify_client.prepare() @@ -114,6 +114,6 @@ class MdnsAPI(object): delay=delay) def perform_zone_xfr(self, context, zone): - LOG.info(_LI("perform_zone_xfr: Calling mdns for zone %(zone)s") % + LOG.info(_LI("perform_zone_xfr: Calling mdns for zone %(zone)s"), {"zone": zone.name}) return self.xfr_client.cast(context, 'perform_zone_xfr', zone=zone) diff --git a/designate/utils.py b/designate/utils.py index 38bd9e320..4a9d1ac84 100644 --- a/designate/utils.py +++ b/designate/utils.py @@ -453,7 +453,7 @@ def get_paging_params(params, sort_keys): def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None): # Bind to the TCP port - LOG.info(_LI('Opening TCP Listening Socket on %(host)s:%(port)d') % + LOG.info(_LI('Opening TCP Listening Socket on %(host)s:%(port)d'), {'host': host, 'port': port}) sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -480,7 +480,7 @@ def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None): def bind_udp(host, port): # Bind to the UDP port - LOG.info(_LI('Opening UDP Listening Socket on %(host)s:%(port)d') % + LOG.info(_LI('Opening UDP Listening Socket on %(host)s:%(port)d'), {'host': host, 'port': port}) sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)