Install global lazy _()

The patch installs the lazy _() function, which returns translatable
Message objects, globally via the enable_lazy() method such that
translation works in all modules.

Since Messages objects can't be str()'d and native exceptions str()
their messages the patch also removes passing Messages to native
exceptions.

Change-Id: I8a4ecd904e393c4bd0308cdeafa3cf1d8f0e70fe
Closes-Bug: #1275901
This commit is contained in:
Luis A. Garcia 2014-03-06 14:23:32 -07:00
parent b5945037a7
commit 66e10a6c88
10 changed files with 57 additions and 57 deletions

View File

@ -36,9 +36,9 @@ class CPUPollster(plugin.ComputePollster):
instance_name = util.instance_name(instance)
try:
cpu_info = manager.inspector.inspect_cpus(instance_name)
LOG.info(_("CPUTIME USAGE: %(instance)s %(time)d") % (
LOG.info(_("CPUTIME USAGE: %(instance)s %(time)d"),
{'instance': instance.__dict__,
'time': cpu_info.time}))
'time': cpu_info.time})
cpu_num = {'cpu_number': cpu_info.number}
yield util.make_sample_from_instance(
instance,

View File

@ -113,6 +113,7 @@ def prepare_service(argv=None):
# or select()
eventlet.monkey_patch(socket=True, select=True)
gettextutils.install('ceilometer', lazy=True)
gettextutils.enable_lazy()
rpc.set_defaults(control_exchange='ceilometer')
cfg.set_defaults(log.log_opts,
default_log_levels=['amqplib=WARN',

View File

@ -173,7 +173,7 @@ class Connection(object):
All timestamps must be naive utc datetime object.
"""
raise NotImplementedError(_('Projects not implemented'))
raise NotImplementedError('Projects not implemented')
@staticmethod
def clear_expired_metering_data(ttl):
@ -183,7 +183,7 @@ class Connection(object):
:param ttl: Number of seconds to keep records for.
"""
raise NotImplementedError(_('Clearing samples not implemented'))
raise NotImplementedError('Clearing samples not implemented')
@staticmethod
def get_users(source=None):
@ -191,7 +191,7 @@ class Connection(object):
:param source: Optional source filter.
"""
raise NotImplementedError(_('Users not implemented'))
raise NotImplementedError('Users not implemented')
@staticmethod
def get_projects(source=None):
@ -199,7 +199,7 @@ class Connection(object):
:param source: Optional source filter.
"""
raise NotImplementedError(_('Projects not implemented'))
raise NotImplementedError('Projects not implemented')
@staticmethod
def get_resources(user=None, project=None, source=None,
@ -220,7 +220,7 @@ class Connection(object):
:param resource: Optional resource filter.
:param pagination: Optional pagination query.
"""
raise NotImplementedError(_('Resources not implemented'))
raise NotImplementedError('Resources not implemented')
@staticmethod
def get_meters(user=None, project=None, resource=None, source=None,
@ -235,7 +235,7 @@ class Connection(object):
:param metaquery: Optional dict with metadata to match on.
:param pagination: Optional pagination query.
"""
raise NotImplementedError(_('Meters not implemented'))
raise NotImplementedError('Meters not implemented')
@staticmethod
def get_samples(sample_filter, limit=None):
@ -244,7 +244,7 @@ class Connection(object):
:param sample_filter: Filter.
:param limit: Maximum number of results to return.
"""
raise NotImplementedError(_('Samples not implemented'))
raise NotImplementedError('Samples not implemented')
@staticmethod
def get_meter_statistics(sample_filter, period=None, groupby=None,
@ -253,13 +253,13 @@ class Connection(object):
The filter must have a meter value set.
"""
raise NotImplementedError(_('Statistics not implemented'))
raise NotImplementedError('Statistics not implemented')
@staticmethod
def get_alarms(name=None, user=None,
project=None, enabled=None, alarm_id=None, pagination=None):
"""Yields a lists of alarms that match filters."""
raise NotImplementedError(_('Alarms not implemented'))
raise NotImplementedError('Alarms not implemented')
@staticmethod
def create_alarm(alarm):
@ -267,17 +267,17 @@ class Connection(object):
:param alarm: The alarm to create.
"""
raise NotImplementedError(_('Alarms not implemented'))
raise NotImplementedError('Alarms not implemented')
@staticmethod
def update_alarm(alarm):
"""Update alarm."""
raise NotImplementedError(_('Alarms not implemented'))
raise NotImplementedError('Alarms not implemented')
@staticmethod
def delete_alarm(alarm_id):
"""Delete an alarm."""
raise NotImplementedError(_('Alarms not implemented'))
raise NotImplementedError('Alarms not implemented')
@staticmethod
def get_alarm_changes(alarm_id, on_behalf_of,
@ -307,12 +307,12 @@ class Connection(object):
:param end_timestamp: Optional modified timestamp end range
:param end_timestamp_op: Optional timestamp end range operation
"""
raise NotImplementedError(_('Alarm history not implemented'))
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def record_alarm_change(alarm_change):
"""Record alarm change event."""
raise NotImplementedError(_('Alarm history not implemented'))
raise NotImplementedError('Alarm history not implemented')
@staticmethod
def clear():
@ -324,19 +324,19 @@ class Connection(object):
:param events: a list of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
raise NotImplementedError('Events not implemented.')
@staticmethod
def get_events(event_filter):
"""Return an iterable of model.Event objects.
"""
raise NotImplementedError(_('Events not implemented.'))
raise NotImplementedError('Events not implemented.')
@staticmethod
def get_event_types():
"""Return all event types as an iterable of strings.
"""
raise NotImplementedError(_('Events not implemented.'))
raise NotImplementedError('Events not implemented.')
@staticmethod
def get_trait_types(event_type):
@ -346,7 +346,7 @@ class Connection(object):
:param event_type: the type of the Event
"""
raise NotImplementedError(_('Events not implemented.'))
raise NotImplementedError('Events not implemented.')
@staticmethod
def get_traits(event_type, trait_type=None):
@ -357,7 +357,7 @@ class Connection(object):
:param trait_type: the name of the Trait to filter by
"""
raise NotImplementedError(_('Events not implemented.'))
raise NotImplementedError('Events not implemented.')
@staticmethod
def query_samples(filter_expr=None, orderby=None, limit=None):
@ -368,8 +368,8 @@ class Connection(object):
:param limit: Maximum number of results to return.
"""
raise NotImplementedError(_('Complex query for samples \
is not implemented.'))
raise NotImplementedError('Complex query for samples \
is not implemented.')
@staticmethod
def query_alarms(filter_expr=None, orderby=None, limit=None):
@ -380,8 +380,8 @@ class Connection(object):
:param limit: Maximum number of results to return.
"""
raise NotImplementedError(_('Complex query for alarms \
is not implemented.'))
raise NotImplementedError('Complex query for alarms \
is not implemented.')
@staticmethod
def query_alarm_history(filter_expr=None, orderby=None, limit=None):
@ -392,11 +392,11 @@ class Connection(object):
:param limit: Maximum number of results to return.
"""
raise NotImplementedError(_('Complex query for alarms \
history is not implemented.'))
raise NotImplementedError('Complex query for alarms \
history is not implemented.')
@staticmethod
def get_capabilities():
"""Return an dictionary representing the capabilities of this driver.
"""
raise NotImplementedError(_('Capabilities not implemented.'))
raise NotImplementedError('Capabilities not implemented.')

View File

@ -302,7 +302,7 @@ class Connection(pymongo_base.Connection):
:param pagination: Optional pagination query.
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
q = {}
if user is not None:
@ -364,8 +364,7 @@ class Connection(pymongo_base.Connection):
raise NotImplementedError("Unable to group by these fields")
if aggregate:
msg = _('Selectable aggregates not implemented')
raise NotImplementedError(msg)
raise NotImplementedError('Selectable aggregates not implemented')
q = pymongo_base.make_query_from_filter(sample_filter)

View File

@ -228,7 +228,7 @@ class Connection(base.Connection):
project=None, enabled=None, alarm_id=None, pagination=None):
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
alarm_table = self.conn.table(self.ALARM_TABLE)
@ -373,7 +373,7 @@ class Connection(base.Connection):
:param pagination: Optional pagination query.
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
meter_table = self.conn.table(self.METER_TABLE)
@ -427,7 +427,7 @@ class Connection(base.Connection):
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
resource_table = self.conn.table(self.RESOURCE_TABLE)
q = make_query(metaquery=metaquery, user_id=user, project_id=project,
resource_id=resource, source=source)
@ -516,8 +516,7 @@ class Connection(base.Connection):
raise NotImplementedError("Group by not implemented.")
if aggregate:
msg = _('Selectable aggregates not implemented')
raise NotImplementedError(msg)
raise NotImplementedError('Selectable aggregates not implemented')
meter_table = self.conn.table(self.METER_TABLE)
q, start, stop = make_sample_query_from_filter(sample_filter)

View File

@ -834,7 +834,7 @@ class Connection(pymongo_base.Connection):
:param pagination: Optional pagination query.
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
query = {}
if user is not None:
@ -878,8 +878,8 @@ class Connection(pymongo_base.Connection):
params = dict(aggregate_param=a.param)
fragments += (fragment_map[a.func] % params)
else:
raise NotImplementedError(_('Selectable aggregate function %s'
' is not supported') % a.func)
raise NotImplementedError('Selectable aggregate function %s'
' is not supported' % a.func)
return fragments

View File

@ -177,8 +177,8 @@ def apply_metaquery_filter(session, query, metaquery):
try:
_model = META_TYPE_MAP[type(v)]
except KeyError:
raise NotImplementedError(_('Query on %(key)s is of %(value)s '
'type and is not supported') %
raise NotImplementedError('Query on %(key)s is of %(value)s '
'type and is not supported' %
{"key": k, "value": type(v)})
else:
meta_q = session.query(_model).\
@ -201,7 +201,7 @@ def make_query_from_filter(session, query, sample_filter, require_meter=True):
if sample_filter.meter:
query = query.filter(models.Meter.name == sample_filter.meter)
elif require_meter:
raise RuntimeError(_('Missing required meter specifier'))
raise RuntimeError('Missing required meter specifier')
if sample_filter.source:
query = query.filter(models.Sample.sources.any(
id=sample_filter.source))
@ -466,7 +466,7 @@ class Connection(base.Connection):
# if they will be handled. We don't want extra wait or work for it to
# just fail.
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
session = self._get_db_session()
@ -559,7 +559,7 @@ class Connection(base.Connection):
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
session = self._get_db_session()
@ -711,8 +711,8 @@ class Connection(base.Connection):
compute = PARAMETERIZED_AGGREGATES['compute'][a.func]
functions.append(compute(a.param))
else:
raise NotImplementedError(_('Selectable aggregate function %s'
' is not supported') % a.func)
raise NotImplementedError('Selectable aggregate function %s'
' is not supported' % a.func)
return functions
@ -784,8 +784,8 @@ class Connection(base.Connection):
if groupby:
for group in groupby:
if group not in ['user_id', 'project_id', 'resource_id']:
raise NotImplementedError(
_("Unable to group by these fields"))
raise NotImplementedError('Unable to group by '
'these fields')
if not period:
for res in self._make_stats_query(sample_filter,
@ -861,7 +861,7 @@ class Connection(base.Connection):
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
session = self._get_db_session()
query = session.query(models.Alarm)
@ -1343,8 +1343,8 @@ class QueryTransformer(object):
def _handle_metadata(self, op, field_name, value):
if op == self.operators["in"]:
raise NotImplementedError(
_("Metadata query with in operator is not implemented"))
raise NotImplementedError('Metadata query with in '
'operator is not implemented')
field_name = field_name[len('resource_metadata.'):]
meta_table = META_TYPE_MAP[type(value)]

View File

@ -169,7 +169,7 @@ class Connection(base.Connection):
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
q = {}
if user is not None:
@ -250,7 +250,7 @@ class Connection(base.Connection):
:param pagination: Optional pagination query.
"""
if pagination:
raise NotImplementedError(_('Pagination not implemented'))
raise NotImplementedError('Pagination not implemented')
q = {}
if user is not None:

View File

@ -20,6 +20,7 @@
"""
import functools
import os.path
import six
from testtools import testcase
@ -59,10 +60,10 @@ def _skip_decorator(func):
try:
return func(*args, **kwargs)
except NotImplementedError as e:
raise testcase.TestSkipped(str(e))
raise testcase.TestSkipped(six.text_type(e))
except Exception as e:
if 'not implemented' in str(e):
raise testcase.TestSkipped(str(e))
if 'not implemented' in six.text_type(e):
raise testcase.TestSkipped(six.text_type(e))
raise
return skip_if_not_implemented

View File

@ -49,7 +49,7 @@ class TestBase(test_base.BaseTestCase):
try:
self.conn = storage.get_connection(self.CONF)
except storage.StorageBadVersion as e:
self.skipTest(str(e))
self.skipTest(six.text_type(e))
self.conn.upgrade()
self.useFixture(oslo_mock.Patch('ceilometer.storage.get_connection',