From ee65afeda6427706f4dbea125dd80fcecdb1bea7 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Tue, 28 Jan 2014 23:25:32 +0800 Subject: [PATCH] I18N support for error message The error message should support i18n. Change-Id: Iaa1f860f37a66ae11cdaead566f4a2439739d225 --- heat/engine/resources/autoscaling.py | 2 +- heat/engine/resources/neutron/loadbalancer.py | 12 ++++++++---- heat/engine/resources/neutron/neutron.py | 7 ++++--- heat/engine/resources/volume.py | 3 +-- heat/tests/test_neutron_loadbalancer.py | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 14baba147..e178ff804 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -398,7 +398,7 @@ class InstanceGroup(stack_resource.StackResource): id_list) else: raise exception.Error( - "Unsupported resource '%s' in LoadBalancerNames" % + _("Unsupported resource '%s' in LoadBalancerNames") % (lb,)) resolved_snippet = self.stack.resolve_static_data( lb_resource.json_snippet) diff --git a/heat/engine/resources/neutron/loadbalancer.py b/heat/engine/resources/neutron/loadbalancer.py index 158079d1e..3a9228766 100644 --- a/heat/engine/resources/neutron/loadbalancer.py +++ b/heat/engine/resources/neutron/loadbalancer.py @@ -352,11 +352,15 @@ class Pool(neutron.NeutronResource): elif vip_attributes['status'] == 'ACTIVE': return True raise exception.Error( - 'neutron reported unexpected vip resource[%s] status[%s]' % - (vip_attributes['name'], vip_attributes['status'])) + _('neutron reported unexpected vip resource[%(name)s] ' + 'status[%(status)s]') % + {'name': vip_attributes['name'], + 'status': vip_attributes['status']}) raise exception.Error( - 'neutron report unexpected pool resource[%s] status[%s]' % - (attributes['name'], attributes['status'])) + _('neutron reported unexpected pool resource[%(name)s] ' + 'status[%(status)s]') % + {'name': attributes['name'], + 'status': attributes['status']}) def handle_update(self, json_snippet, tmpl_diff, prop_diff): if prop_diff: diff --git a/heat/engine/resources/neutron/neutron.py b/heat/engine/resources/neutron/neutron.py index c7c7dd34e..0948f859e 100644 --- a/heat/engine/resources/neutron/neutron.py +++ b/heat/engine/resources/neutron/neutron.py @@ -114,9 +114,10 @@ class NeutronResource(resource.Resource): if attributes['status'] in ('ACTIVE', 'DOWN'): return True else: - raise exception.Error('%s resource[%s] status[%s]' % - ('neutron reported unexpected', - attributes['name'], attributes['status'])) + raise exception.Error(_('neutron reported unexpected ' + 'resource[%(name)s] status[%(status)s]') % + {'name': attributes['name'], + 'status': attributes['status']}) def _resolve_attribute(self, name): try: diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 5850707bf..22ef23bb5 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -107,8 +107,7 @@ class Volume(resource.Resource): cinder = self.cinder() if backup_id is not None: if volume_backups is None: - raise exception.Error( - '%s not supported' % self.BACKUP_ID) + raise exception.Error(_('Backups not supported.')) vol_id = cinder.restores.restore(backup_id).volume_id vol = cinder.volumes.get(vol_id) diff --git a/heat/tests/test_neutron_loadbalancer.py b/heat/tests/test_neutron_loadbalancer.py index dc36485cd..f5081e1b5 100644 --- a/heat/tests/test_neutron_loadbalancer.py +++ b/heat/tests/test_neutron_loadbalancer.py @@ -370,7 +370,7 @@ class PoolTest(HeatTestCase): error = self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(rsrc.create)) self.assertEqual( - 'Error: neutron report unexpected pool ' + 'Error: neutron reported unexpected pool ' 'resource[5678] status[ERROR]', str(error)) self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)