From a771e45a76161e639d18030ad3cb41fe3f30ba64 Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Mon, 3 Jun 2013 17:36:42 +0400 Subject: [PATCH] Replace FLAGS with cfg.CONF in scheduler Replace all the FLAGS with cfg.CONF in cinder/scheduler Large commit "https://review.openstack.org/31172" was split into several parts Use the common pattern: CONF = cfg.CONF Change-Id: If293d36a9e1552f7af497edf947e82458488bf9c Fixes: bug #1182037 --- cinder/scheduler/chance.py | 7 ++++--- cinder/scheduler/driver.py | 8 ++++---- cinder/scheduler/filter_scheduler.py | 9 +++------ cinder/scheduler/host_manager.py | 12 ++++++------ cinder/scheduler/manager.py | 10 +++++----- cinder/scheduler/rpcapi.py | 7 ++++--- cinder/scheduler/scheduler_options.py | 9 +++++---- cinder/scheduler/simple.py | 10 +++++----- cinder/scheduler/weights/capacity.py | 17 +++++++++-------- cinder/tests/test_rbd.py | 2 ++ cinder/volume/drivers/rbd.py | 2 ++ 11 files changed, 49 insertions(+), 44 deletions(-) diff --git a/cinder/scheduler/chance.py b/cinder/scheduler/chance.py index 876a12d8f..8bb0eb72a 100644 --- a/cinder/scheduler/chance.py +++ b/cinder/scheduler/chance.py @@ -23,12 +23,13 @@ Chance (Random) Scheduler implementation import random +from oslo.config import cfg + from cinder import exception -from cinder import flags from cinder.scheduler import driver -FLAGS = flags.FLAGS +CONF = cfg.CONF class ChanceScheduler(driver.Scheduler): @@ -60,7 +61,7 @@ class ChanceScheduler(driver.Scheduler): def schedule_create_volume(self, context, request_spec, filter_properties): """Picks a host that is up at random.""" - topic = FLAGS.volume_topic + topic = CONF.volume_topic host = self._schedule(context, topic, request_spec, filter_properties=filter_properties) volume_id = request_spec['volume_id'] diff --git a/cinder/scheduler/driver.py b/cinder/scheduler/driver.py index b2e3efe01..9e970a728 100644 --- a/cinder/scheduler/driver.py +++ b/cinder/scheduler/driver.py @@ -24,12 +24,12 @@ Scheduler base class that all Schedulers should inherit from from oslo.config import cfg from cinder import db -from cinder import flags from cinder.openstack.common import importutils from cinder.openstack.common import timeutils from cinder import utils from cinder.volume import rpcapi as volume_rpcapi + scheduler_driver_opts = [ cfg.StrOpt('scheduler_host_manager', default='cinder.scheduler.host_manager.HostManager', @@ -39,8 +39,8 @@ scheduler_driver_opts = [ help='Maximum number of attempts to schedule an volume'), ] -FLAGS = flags.FLAGS -FLAGS.register_opts(scheduler_driver_opts) +CONF = cfg.CONF +CONF.register_opts(scheduler_driver_opts) def volume_update_db(context, volume_id, host): @@ -58,7 +58,7 @@ class Scheduler(object): def __init__(self): self.host_manager = importutils.import_object( - FLAGS.scheduler_host_manager) + CONF.scheduler_host_manager) self.volume_rpcapi = volume_rpcapi.VolumeAPI() def get_host_list(self): diff --git a/cinder/scheduler/filter_scheduler.py b/cinder/scheduler/filter_scheduler.py index 71caf16dc..456adeef2 100644 --- a/cinder/scheduler/filter_scheduler.py +++ b/cinder/scheduler/filter_scheduler.py @@ -20,17 +20,14 @@ You can customize this scheduler by specifying your own volume Filters and Weighing Functions. """ -import operator +from oslo.config import cfg from cinder import exception -from cinder import flags -from cinder.openstack.common import importutils from cinder.openstack.common import log as logging from cinder.scheduler import driver from cinder.scheduler import scheduler_options - -FLAGS = flags.FLAGS +CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -108,7 +105,7 @@ class FilterScheduler(driver.Scheduler): hosts.append(host) def _max_attempts(self): - max_attempts = FLAGS.scheduler_max_attempts + max_attempts = CONF.scheduler_max_attempts if max_attempts < 1: msg = _("Invalid value for 'scheduler_max_attempts', " "must be >=1") diff --git a/cinder/scheduler/host_manager.py b/cinder/scheduler/host_manager.py index acc024f53..9e2c394e7 100644 --- a/cinder/scheduler/host_manager.py +++ b/cinder/scheduler/host_manager.py @@ -23,13 +23,13 @@ from oslo.config import cfg from cinder import db from cinder import exception -from cinder import flags from cinder.openstack.common import log as logging from cinder.openstack.common.scheduler import filters from cinder.openstack.common.scheduler import weights from cinder.openstack.common import timeutils from cinder import utils + host_manager_opts = [ cfg.ListOpt('scheduler_default_filters', default=[ @@ -46,8 +46,8 @@ host_manager_opts = [ help='Which weigher class names to use for weighing hosts.') ] -FLAGS = flags.FLAGS -FLAGS.register_opts(host_manager_opts) +CONF = cfg.CONF +CONF.register_opts(host_manager_opts) LOG = logging.getLogger(__name__) @@ -172,7 +172,7 @@ class HostManager(object): of acceptable filters. """ if filter_cls_names is None: - filter_cls_names = FLAGS.scheduler_default_filters + filter_cls_names = CONF.scheduler_default_filters if not isinstance(filter_cls_names, (list, tuple)): filter_cls_names = [filter_cls_names] good_filters = [] @@ -198,7 +198,7 @@ class HostManager(object): of acceptable weighers. """ if weight_cls_names is None: - weight_cls_names = FLAGS.scheduler_default_weighers + weight_cls_names = CONF.scheduler_default_weighers if not isinstance(weight_cls_names, (list, tuple)): weight_cls_names = [weight_cls_names] @@ -259,7 +259,7 @@ class HostManager(object): """ # Get resource usage across the available volume nodes: - topic = FLAGS.volume_topic + topic = CONF.volume_topic volume_services = db.service_get_all_by_topic(context, topic) for service in volume_services: host = service['host'] diff --git a/cinder/scheduler/manager.py b/cinder/scheduler/manager.py index fa0852d70..91ba3c5e9 100644 --- a/cinder/scheduler/manager.py +++ b/cinder/scheduler/manager.py @@ -26,7 +26,6 @@ from oslo.config import cfg from cinder import context from cinder import db from cinder import exception -from cinder import flags from cinder import manager from cinder.openstack.common import excutils from cinder.openstack.common import importutils @@ -34,15 +33,16 @@ from cinder.openstack.common import log as logging from cinder.openstack.common.notifier import api as notifier from cinder.volume import rpcapi as volume_rpcapi -LOG = logging.getLogger(__name__) scheduler_driver_opt = cfg.StrOpt('scheduler_driver', default='cinder.scheduler.filter_scheduler.' 'FilterScheduler', help='Default scheduler driver to use') -FLAGS = flags.FLAGS -FLAGS.register_opt(scheduler_driver_opt) +CONF = cfg.CONF +CONF.register_opt(scheduler_driver_opt) + +LOG = logging.getLogger(__name__) class SchedulerManager(manager.Manager): @@ -53,7 +53,7 @@ class SchedulerManager(manager.Manager): def __init__(self, scheduler_driver=None, service_name=None, *args, **kwargs): if not scheduler_driver: - scheduler_driver = FLAGS.scheduler_driver + scheduler_driver = CONF.scheduler_driver self.driver = importutils.import_object(scheduler_driver) super(SchedulerManager, self).__init__(*args, **kwargs) diff --git a/cinder/scheduler/rpcapi.py b/cinder/scheduler/rpcapi.py index cadde6189..4d10c1f26 100644 --- a/cinder/scheduler/rpcapi.py +++ b/cinder/scheduler/rpcapi.py @@ -18,12 +18,13 @@ Client side of the scheduler manager RPC API. """ -from cinder import flags +from oslo.config import cfg + from cinder.openstack.common import jsonutils import cinder.openstack.common.rpc.proxy -FLAGS = flags.FLAGS +CONF = cfg.CONF class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy): @@ -41,7 +42,7 @@ class SchedulerAPI(cinder.openstack.common.rpc.proxy.RpcProxy): def __init__(self): super(SchedulerAPI, self).__init__( - topic=FLAGS.scheduler_topic, + topic=CONF.scheduler_topic, default_version=self.RPC_API_VERSION) def create_volume(self, ctxt, topic, volume_id, snapshot_id=None, diff --git a/cinder/scheduler/scheduler_options.py b/cinder/scheduler/scheduler_options.py index 9b05bb717..0b4f1ee9c 100644 --- a/cinder/scheduler/scheduler_options.py +++ b/cinder/scheduler/scheduler_options.py @@ -28,17 +28,18 @@ import os from oslo.config import cfg -from cinder import flags from cinder.openstack.common import log as logging from cinder.openstack.common import timeutils + scheduler_json_config_location_opt = cfg.StrOpt( 'scheduler_json_config_location', default='', help='Absolute path to scheduler configuration JSON file.') -FLAGS = flags.FLAGS -FLAGS.register_opt(scheduler_json_config_location_opt) + +CONF = cfg.CONF +CONF.register_opt(scheduler_json_config_location_opt) LOG = logging.getLogger(__name__) @@ -86,7 +87,7 @@ class SchedulerOptions(object): def get_configuration(self, filename=None): """Check the json file for changes and load it if needed.""" if not filename: - filename = FLAGS.scheduler_json_config_location + filename = CONF.scheduler_json_config_location if not filename: return self.data if self.last_checked: diff --git a/cinder/scheduler/simple.py b/cinder/scheduler/simple.py index c9a7009c7..923c9379a 100644 --- a/cinder/scheduler/simple.py +++ b/cinder/scheduler/simple.py @@ -25,18 +25,18 @@ from oslo.config import cfg from cinder import db from cinder import exception -from cinder import flags from cinder.scheduler import chance from cinder.scheduler import driver from cinder import utils + simple_scheduler_opts = [ cfg.IntOpt("max_gigabytes", default=10000, help="maximum number of volume gigabytes to allow per host"), ] -FLAGS = flags.FLAGS -FLAGS.register_opts(simple_scheduler_opts) +CONF = cfg.CONF +CONF.register_opts(simple_scheduler_opts) class SimpleScheduler(chance.ChanceScheduler): @@ -57,7 +57,7 @@ class SimpleScheduler(chance.ChanceScheduler): if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: - topic = FLAGS.volume_topic + topic = CONF.volume_topic service = db.service_get_by_args(elevated, host, topic) if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) @@ -75,7 +75,7 @@ class SimpleScheduler(chance.ChanceScheduler): if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result - if volume_gigabytes + volume_size > FLAGS.max_gigabytes: + if volume_gigabytes + volume_size > CONF.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: diff --git a/cinder/scheduler/weights/capacity.py b/cinder/scheduler/weights/capacity.py index e2042e9cd..e8914cb65 100644 --- a/cinder/scheduler/weights/capacity.py +++ b/cinder/scheduler/weights/capacity.py @@ -20,28 +20,29 @@ stacking, you can set the 'capacity_weight_multiplier' option to a negative number and the weighing has the opposite effect of the default. """ + import math from oslo.config import cfg -from cinder import flags from cinder.openstack.common.scheduler import weights + capacity_weight_opts = [ - cfg.FloatOpt('capacity_weight_multiplier', - default=1.0, - help='Multiplier used for weighing volume capacity. ' - 'Negative numbers mean to stack vs spread.'), + cfg.FloatOpt('capacity_weight_multiplier', + default=1.0, + help='Multiplier used for weighing volume capacity. ' + 'Negative numbers mean to stack vs spread.'), ] -FLAGS = flags.FLAGS -FLAGS.register_opts(capacity_weight_opts) +CONF = cfg.CONF +CONF.register_opts(capacity_weight_opts) class CapacityWeigher(weights.BaseHostWeigher): def _weight_multiplier(self): """Override the weight multiplier.""" - return FLAGS.capacity_weight_multiplier + return CONF.capacity_weight_multiplier def _weigh_object(self, host_state, weight_properties): """Higher weights win. We want spreading to be the default.""" diff --git a/cinder/tests/test_rbd.py b/cinder/tests/test_rbd.py index d36673b07..995eb8120 100644 --- a/cinder/tests/test_rbd.py +++ b/cinder/tests/test_rbd.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. + import contextlib import mox import os @@ -31,6 +32,7 @@ from cinder.tests.test_volume import DriverTestCase from cinder.volume import configuration as conf import cinder.volume.drivers.rbd as driver + LOG = logging.getLogger(__name__) diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index c765ecfcf..53efc2955 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -15,6 +15,7 @@ RADOS Block Device Driver """ + from __future__ import absolute_import import json @@ -37,6 +38,7 @@ except ImportError: rados = None rbd = None + LOG = logging.getLogger(__name__) rbd_opts = [ -- 2.45.2