From d0cbd371308f987a38c48730b9276b37c8d83d0d Mon Sep 17 00:00:00 2001 From: "Jay S. Bryant" Date: Mon, 23 Feb 2015 17:14:57 -0600 Subject: [PATCH] Sync scheduler.filters module from oslo-incubator The scheduler.filters module hasn't been updated since January of 2014. As a result there are a number of changes that we should pull into Cinder's copy. Current HEAD in OSLO: --------------------- commit e589dde0721a0a67e4030813e582afec6e70d042 Date: Wed Feb 18 03:08:12 2015 +0000 Merge "Have a little fun with release notes" Changes merged with this patch by file: __init__.py - be81d6ba - Cleanup unused log related code availability_zone_filter.py - 4a47188e - Allow filters to only run once per request if their data is static capabilities_filter.py - 2fbf5065 - Remove oslo.log code and clean up versionutils API - dacc065a - Merge "Update oslo log messages with translation domains" - 86707cd5 - Remove None for dict.get() - fcf517d7 - Update oslo log messages with translation domains extra_specs_ops.py - ac17de97 - Use oslo_utils instead of deprecated oslo.utils - 6ff6b4b4 - Switch oslo-incubator to use oslo.utils and remove old modules ignore_attempted_hosts_filter.py - 2fbf5065 - Remove oslo.log code and clean up versionutils API - 39625e18 - Set pbr 'warnerrors' option for doc build - dacc065a - Merge "Update oslo log messages with translation domains" - 86707cd5 - Remove None for dict.get() - fcf517d7 - Update oslo log messages with translation domains json_filter - 262279b1 - switch to oslo_serialization - 6c706c5c - Delete graduated serialization files - 86707cd5 - Remove None for dict.get() Change-Id: Ida01f1a6518dcd3a977c524c15dfe9f6979a4ead --- .../common/scheduler/filters/__init__.py | 3 --- .../filters/availability_zone_filter.py | 4 ++- .../scheduler/filters/capabilities_filter.py | 15 ++++++----- .../scheduler/filters/extra_specs_ops.py | 2 +- .../filters/ignore_attempted_hosts_filter.py | 27 ++++++++++--------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/cinder/openstack/common/scheduler/filters/__init__.py b/cinder/openstack/common/scheduler/filters/__init__.py index 7c77d9cdf..dbd87a299 100644 --- a/cinder/openstack/common/scheduler/filters/__init__.py +++ b/cinder/openstack/common/scheduler/filters/__init__.py @@ -17,11 +17,8 @@ Scheduler host filters """ -from cinder.openstack.common import log as logging from cinder.openstack.common.scheduler import base_filter -LOG = logging.getLogger(__name__) - class BaseHostFilter(base_filter.BaseFilter): """Base class for host filters.""" diff --git a/cinder/openstack/common/scheduler/filters/availability_zone_filter.py b/cinder/openstack/common/scheduler/filters/availability_zone_filter.py index 1afc64c03..8e7f1f03c 100644 --- a/cinder/openstack/common/scheduler/filters/availability_zone_filter.py +++ b/cinder/openstack/common/scheduler/filters/availability_zone_filter.py @@ -13,13 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. - from cinder.openstack.common.scheduler import filters class AvailabilityZoneFilter(filters.BaseHostFilter): """Filters Hosts by availability zone.""" + # Availability zones do not change within a request + run_filter_once_per_request = True + def host_passes(self, host_state, filter_properties): spec = filter_properties.get('request_spec', {}) props = spec.get('resource_properties', {}) diff --git a/cinder/openstack/common/scheduler/filters/capabilities_filter.py b/cinder/openstack/common/scheduler/filters/capabilities_filter.py index 7e7953c14..9f4d50a33 100644 --- a/cinder/openstack/common/scheduler/filters/capabilities_filter.py +++ b/cinder/openstack/common/scheduler/filters/capabilities_filter.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import logging + import six -from cinder.openstack.common.gettextutils import _ # noqa -from cinder.openstack.common import log as logging from cinder.openstack.common.scheduler import filters from cinder.openstack.common.scheduler.filters import extra_specs_ops @@ -45,14 +45,15 @@ class CapabilitiesFilter(filters.BaseHostFilter): cap = capabilities for index in range(len(scope)): try: - cap = cap.get(scope[index], None) + cap = cap.get(scope[index]) except AttributeError: return False if cap is None: return False if not extra_specs_ops.match(cap, req): - LOG.debug(_("extra_spec requirement '%(req)s' does not match " - "'%(cap)s'"), {'req': req, 'cap': cap}) + LOG.debug("extra_spec requirement '%(req)s' " + "does not match '%(cap)s'", + {'req': req, 'cap': cap}) return False return True @@ -64,7 +65,7 @@ class CapabilitiesFilter(filters.BaseHostFilter): resource_type = filter_properties.get('resource_type') if not self._satisfies_extra_specs(host_state.capabilities, resource_type): - LOG.debug(_("%(host_state)s fails resource_type extra_specs " - "requirements"), {'host_state': host_state}) + LOG.debug("%(host_state)s fails resource_type extra_specs " + "requirements", {'host_state': host_state}) return False return True diff --git a/cinder/openstack/common/scheduler/filters/extra_specs_ops.py b/cinder/openstack/common/scheduler/filters/extra_specs_ops.py index b3730f5af..54450d36c 100644 --- a/cinder/openstack/common/scheduler/filters/extra_specs_ops.py +++ b/cinder/openstack/common/scheduler/filters/extra_specs_ops.py @@ -15,7 +15,7 @@ import operator -from cinder.openstack.common import strutils +from oslo.utils import strutils # 1. The following operations are supported: # =, s==, s!=, s>=, s>, s<=, s<, , , , ==, !=, >=, <= diff --git a/cinder/openstack/common/scheduler/filters/ignore_attempted_hosts_filter.py b/cinder/openstack/common/scheduler/filters/ignore_attempted_hosts_filter.py index d288ead20..33cdd3fee 100644 --- a/cinder/openstack/common/scheduler/filters/ignore_attempted_hosts_filter.py +++ b/cinder/openstack/common/scheduler/filters/ignore_attempted_hosts_filter.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from cinder.openstack.common.gettextutils import _ # noqa -from cinder.openstack.common import log as logging +import logging + from cinder.openstack.common.scheduler import filters LOG = logging.getLogger(__name__) @@ -26,21 +26,22 @@ class IgnoreAttemptedHostsFilter(filters.BaseHostFilter): A host passes this filter if it has not already been attempted for scheduling. The scheduler needs to add previously attempted hosts to the 'retry' key of filter_properties in order for this to work - correctly. For example: - { - 'retry': { + correctly. For example:: + + { + 'retry': { 'hosts': ['host1', 'host2'], 'num_attempts': 3, - } - } + } + } """ def host_passes(self, host_state, filter_properties): """Skip nodes that have already been attempted.""" - attempted = filter_properties.get('retry', None) + attempted = filter_properties.get('retry') if not attempted: # Re-scheduling is disabled - LOG.debug(_("Re-scheduling is disabled.")) + LOG.debug("Re-scheduling is disabled.") return True hosts = attempted.get('hosts', []) @@ -49,8 +50,8 @@ class IgnoreAttemptedHostsFilter(filters.BaseHostFilter): passes = host not in hosts pass_msg = "passes" if passes else "fails" - LOG.debug(_("Host %(host)s %(pass_msg)s. Previously tried hosts: " - "%(hosts)s") % {'host': host, - 'pass_msg': pass_msg, - 'hosts': hosts}) + LOG.debug("Host %(host)s %(pass_msg)s. Previously tried hosts: " + "%(hosts)s" % {'host': host, + 'pass_msg': pass_msg, + 'hosts': hosts}) return passes -- 2.45.2