From e1d46b3770b3974e7d8cc69361a014e3af9f7b94 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Sat, 7 Sep 2013 10:46:42 +0200 Subject: [PATCH] Fix and enable gating on H703 - string localisation Avoid using multi positional strings for localisation, as those are hard to translate to various languages. Also enable gating on H231 (which does not trigger). Change-Id: Ie22cf781bcd5ce7562a5e61cf08fde816e7af86a --- tox.ini | 4 ++-- trove/db/models.py | 8 ++++---- trove/dns/models.py | 8 ++++---- trove/extensions/account/service.py | 4 ++-- trove/extensions/mysql/models.py | 4 ++-- trove/extensions/security_group/models.py | 3 +-- trove/guestagent/api.py | 11 ++++++++--- trove/guestagent/models.py | 4 ++-- trove/instance/models.py | 17 ++++++++++------- trove/taskmanager/models.py | 7 ++++--- 10 files changed, 39 insertions(+), 31 deletions(-) diff --git a/tox.ini b/tox.ini index c42b9dc037..66f8efa4c9 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ commands = {posargs} [flake8] show-source = True -ignore = E125,F401,F403,F811,F821,F841,H102,H103,H201,H23,H301,H306,H401,H402,H403,H404,H702,H703 +ignore = E125,F401,F403,F811,F821,F841,H102,H103,H201,H233,H301,H306,H401,H402,H403,H404,H702 builtins = _ exclude=.venv,.tox,dist,doc,openstack,*egg,rsdns,tools,etc -filename=*.py,trove-* \ No newline at end of file +filename=*.py,trove-* diff --git a/trove/db/models.py b/trove/db/models.py index 01e87e2484..8584baa7db 100644 --- a/trove/db/models.py +++ b/trove/db/models.py @@ -55,14 +55,14 @@ class DatabaseModelBase(models.ModelBase): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) self['updated'] = utils.utcnow() - LOG.debug(_("Saving %s: %s") % - (self.__class__.__name__, self.__dict__)) + LOG.debug(_("Saving %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) return self.db_api.save(self) def delete(self): self['updated'] = utils.utcnow() - LOG.debug(_("Deleting %s: %s") % - (self.__class__.__name__, self.__dict__)) + LOG.debug(_("Deleting %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) if self.preserve_on_delete: self['deleted_at'] = utils.utcnow() diff --git a/trove/dns/models.py b/trove/dns/models.py index 967eae4fa5..7c8db86533 100644 --- a/trove/dns/models.py +++ b/trove/dns/models.py @@ -54,13 +54,13 @@ class DnsRecord(ModelBase): def save(self): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) - LOG.debug(_("Saving %s: %s") % - (self.__class__.__name__, self.__dict__)) + LOG.debug(_("Saving %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) return get_db_api().save(self) def delete(self): - LOG.debug(_("Deleting %s: %s") % - (self.__class__.__name__, self.__dict__)) + LOG.debug(_("Deleting %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) return get_db_api().delete(self) @classmethod diff --git a/trove/extensions/account/service.py b/trove/extensions/account/service.py index 8c2e5e6eaa..8bce8f5bb6 100644 --- a/trove/extensions/account/service.py +++ b/trove/extensions/account/service.py @@ -39,8 +39,8 @@ class AccountController(wsgi.Controller): def show(self, req, tenant_id, id): """Return a account and instances associated with a single account.""" LOG.info(_("req : '%s'\n\n") % req) - LOG.info(_("Showing account information for '%s' to '%s'") % - (id, tenant_id)) + LOG.info(_("Showing account information for '%(account)s' " + "to '%(tenant)s'") % {'account': id, 'tenant': tenant_id}) context = req.environ[wsgi.CONTEXT_KEY] account = models.Account.load(context, id) diff --git a/trove/extensions/mysql/models.py b/trove/extensions/mysql/models.py index ee6eca6c61..d1fc29b97d 100644 --- a/trove/extensions/mysql/models.py +++ b/trove/extensions/mysql/models.py @@ -209,8 +209,8 @@ class RootHistory(object): self.created = utils.utcnow() def save(self): - LOG.debug(_("Saving %s: %s") % (self.__class__.__name__, - self.__dict__)) + LOG.debug(_("Saving %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) return get_db_api().save(self) @classmethod diff --git a/trove/extensions/security_group/models.py b/trove/extensions/security_group/models.py index 9969b881ad..a7add7cf96 100644 --- a/trove/extensions/security_group/models.py +++ b/trove/extensions/security_group/models.py @@ -76,8 +76,7 @@ class SecurityGroup(DatabaseModelBase): @classmethod def create_for_instance(cls, instance_id, context): # Create a new security group - name = _("%s_%s") %\ - (CONF.trove_security_group_name_prefix, instance_id) + name = "%s_%s" % (CONF.trove_security_group_name_prefix, instance_id) description = _("Security Group for %s") % instance_id sec_group = cls.create_sec_group(name, description, context) diff --git a/trove/guestagent/api.py b/trove/guestagent/api.py index ef3f3086dd..aee259e2d5 100644 --- a/trove/guestagent/api.py +++ b/trove/guestagent/api.py @@ -160,7 +160,8 @@ class API(proxy.RpcProxy): def delete_user(self, user): """Make an asynchronous call to delete an existing database user""" - LOG.debug(_("Deleting user %s for Instance %s"), user, self.id) + LOG.debug(_("Deleting user %(user)s for Instance %(instance_id)s") % + {'user': user, 'instance_id': self.id}) self._cast("delete_user", user=user) def create_database(self, databases): @@ -178,7 +179,9 @@ class API(proxy.RpcProxy): def delete_database(self, database): """Make an asynchronous call to delete an existing database within the specified container""" - LOG.debug(_("Deleting database %s for Instance %s"), database, self.id) + LOG.debug(_("Deleting database %(database)s for " + "Instance %(instance_id)s") % {'database': database, + 'instance_id': self.id}) self._cast("delete_database", database=database) def enable_root(self): @@ -265,5 +268,7 @@ class API(proxy.RpcProxy): def create_backup(self, backup_id): """Make async call to create a full backup of this instance""" - LOG.debug(_("Create Backup %s for Instance %s"), backup_id, self.id) + LOG.debug(_("Create Backup %(backup_id)s " + "for Instance %(instance_id)s") % {'backup_id': backup_id, + 'instance_id': self.id}) self._cast("create_backup", backup_id=backup_id) diff --git a/trove/guestagent/models.py b/trove/guestagent/models.py index a0cbb9a4c5..4468f12eee 100644 --- a/trove/guestagent/models.py +++ b/trove/guestagent/models.py @@ -55,8 +55,8 @@ class AgentHeartBeat(dbmodels.DatabaseModelBase): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) self['updated_at'] = utils.utcnow() - LOG.debug(_("Saving %s: %s") % - (self.__class__.__name__, self.__dict__)) + LOG.debug(_("Saving %(name)s: %(dict)s") % + {'name': self.__class__.__name__, 'dict': self.__dict__}) return get_db_api().save(self) @staticmethod diff --git a/trove/instance/models.py b/trove/instance/models.py index d6db114d15..05b76926a9 100644 --- a/trove/instance/models.py +++ b/trove/instance/models.py @@ -193,9 +193,10 @@ class SimpleInstance(object): if self.db_info.server_status in ["ACTIVE", "SHUTDOWN", "DELETED"]: return InstanceStatus.SHUTDOWN else: - msg = _("While shutting down instance (%s): server had " - "status (%s).") - LOG.error(msg % (self.id, self.db_info.server_status)) + LOG.error(_("While shutting down instance (%(instance)s): " + "server had status (%(status)s).") % + {'instance': self.id, + 'status': self.db_info.server_status}) return InstanceStatus.ERROR ### Check against the service status. @@ -455,8 +456,9 @@ class Instance(BuiltInstance): volume_size=volume_size, service_type=service_type, task_status=InstanceTasks.BUILDING) - LOG.debug(_("Tenant %s created new Trove instance %s...") - % (context.tenant, db_info.id)) + LOG.debug(_("Tenant %(tenant)s created new " + "Trove instance %(db)s...") % + {'tenant': context.tenant, 'db': db_info.id}) service_status = InstanceServiceStatus.create( instance_id=db_info.id, @@ -611,8 +613,9 @@ def create_server_list_matcher(server_list): instance_id=instance_id, server_id=server_id) else: # Should never happen, but never say never. - LOG.error(_("Server %s for instance %s was found twice!") % - (server_id, instance_id)) + LOG.error(_("Server %(server)s for instance %(instance)s was" + "found twice!") % {'server': server_id, + 'instance': instance_id}) raise exception.TroveError(uuid=instance_id) return find_server diff --git a/trove/taskmanager/models.py b/trove/taskmanager/models.py index 6d2fee937a..118579c459 100644 --- a/trove/taskmanager/models.py +++ b/trove/taskmanager/models.py @@ -438,9 +438,10 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): return False elif (server.addresses == {} and server.status == InstanceStatus.ERROR): - msg = _("Instance IP not available, instance (%s): " - "server had status (%s).") - LOG.error(msg % (self.id, server.status)) + LOG.error(_("Instance IP not available, " + "instance (%(instance)s): " + "server had status (%(status)s)." % + {'instance': self.id, 'status': server.status})) raise TroveError(status=server.status) poll_until(get_server, ip_is_available,