From: Andrew Forrest Date: Sat, 15 Jun 2013 18:45:15 +0000 (-0700) Subject: cinder.schedule: Replace 'locals()' with explicit values X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8cb79dd1278b604e2f0f26216b9add71ecdca904;p=openstack-build%2Fcinder-build.git cinder.schedule: Replace 'locals()' with explicit values Help bring source code into compliance with the Cinder Style Commandments: https://github.com/openstack/cinder/blob/master/HACKING.rst This change covers all affected source in the cinder scheduler module, i.e. cinder/scheduler/*.py and subdirectories. Partially fixes: bug #1190748 Change-Id: I75ad858ee62317bef6c59b9c0896f8a94a989d52 --- diff --git a/cinder/scheduler/filter_scheduler.py b/cinder/scheduler/filter_scheduler.py index 456adeef2..bdeb6178d 100644 --- a/cinder/scheduler/filter_scheduler.py +++ b/cinder/scheduler/filter_scheduler.py @@ -126,7 +126,11 @@ class FilterScheduler(driver.Scheduler): last_host = hosts[-1] msg = _("Error scheduling %(volume_id)s from last vol-service: " - "%(last_host)s : %(exc)s") % locals() + "%(last_host)s : %(exc)s") % { + 'volume_id': volume_id, + 'last_host': last_host, + 'exc': exc, + } LOG.error(msg) def _populate_retry(self, filter_properties, properties): @@ -155,7 +159,10 @@ class FilterScheduler(driver.Scheduler): if retry['num_attempts'] > max_attempts: msg = _("Exceeded max scheduling attempts %(max_attempts)d for " - "volume %(volume_id)s") % locals() + "volume %(volume_id)s") % { + 'max_attempts': max_attempts, + 'volume_id': volume_id, + } raise exception.NoValidHost(reason=msg) def _schedule(self, context, request_spec, filter_properties=None): @@ -202,12 +209,12 @@ class FilterScheduler(driver.Scheduler): if not hosts: return None - LOG.debug(_("Filtered %(hosts)s") % locals()) + LOG.debug(_("Filtered %s") % hosts) # weighted_host = WeightedHost() ... the best # host for the job. weighed_hosts = self.host_manager.get_weighed_hosts(hosts, filter_properties) best_host = weighed_hosts[0] - LOG.debug(_("Choosing %(best_host)s") % locals()) + LOG.debug(_("Choosing %s") % best_host) best_host.obj.consume_from_volume(volume_properties) return best_host diff --git a/cinder/scheduler/filters/retry_filter.py b/cinder/scheduler/filters/retry_filter.py index ae84a4e27..93f16d2cb 100644 --- a/cinder/scheduler/filters/retry_filter.py +++ b/cinder/scheduler/filters/retry_filter.py @@ -39,7 +39,8 @@ class RetryFilter(filters.BaseHostFilter): pass_msg = "passes" if passes else "fails" LOG.debug(_("Host %(host)s %(pass_msg)s. Previously tried hosts: " - "%(hosts)s") % locals()) + "%(hosts)s") % + {'host': host, 'pass_msg': pass_msg, 'hosts': hosts}) # Host passes if it's not in the list of previously attempted hosts: return passes diff --git a/cinder/scheduler/host_manager.py b/cinder/scheduler/host_manager.py index 9e2c394e7..f1f51487b 100644 --- a/cinder/scheduler/host_manager.py +++ b/cinder/scheduler/host_manager.py @@ -238,11 +238,13 @@ class HostManager(object): """Update the per-service capabilities based on this notification.""" if service_name != 'volume': LOG.debug(_('Ignoring %(service_name)s service update ' - 'from %(host)s'), locals()) + 'from %(host)s'), + {'service_name': service_name, 'host': host}) return LOG.debug(_("Received %(service_name)s service update from " - "%(host)s.") % locals()) + "%(host)s.") % + {'service_name': service_name, 'host': host}) # Copy the capabilities, so we don't modify the original dict capab_copy = dict(capabilities) diff --git a/cinder/scheduler/manager.py b/cinder/scheduler/manager.py index 91ba3c5e9..4bef56526 100644 --- a/cinder/scheduler/manager.py +++ b/cinder/scheduler/manager.py @@ -116,7 +116,8 @@ class SchedulerManager(manager.Manager): def _set_volume_state_and_notify(self, method, updates, context, ex, request_spec): - LOG.error(_("Failed to schedule_%(method)s: %(ex)s") % locals()) + LOG.error(_("Failed to schedule_%(method)s: %(ex)s") % + {'method': method, 'ex': ex}) volume_state = updates['volume_state'] properties = request_spec.get('volume_properties', {}) diff --git a/cinder/scheduler/scheduler_options.py b/cinder/scheduler/scheduler_options.py index a8010afc6..2917b3977 100644 --- a/cinder/scheduler/scheduler_options.py +++ b/cinder/scheduler/scheduler_options.py @@ -68,16 +68,16 @@ class SchedulerOptions(object): return os.path.getmtime(filename) except os.error as e: LOG.exception(_("Could not stat scheduler options file " - "%(filename)s: '%(e)s'"), locals()) + "%(filename)s: '%(e)s'"), + {'filename': filename, 'e': e}) raise def _load_file(self, handle): """Decode the JSON file. Broken out for testing.""" try: return json.load(handle) - except ValueError as e: - LOG.exception(_("Could not decode scheduler options: " - "'%(e)s'") % locals()) + except ValueError, e: + LOG.exception(_("Could not decode scheduler options: '%s'") % e) return {} def _get_time_now(self):