From 8aba6d96d4e080edf699aa63608ab7919641db24 Mon Sep 17 00:00:00 2001 From: Pushkar Umaranikar Date: Thu, 17 Mar 2016 17:58:44 +0000 Subject: [PATCH] Config options: Centralize resource tracker options The config options of the section "nova/compute/resource_tracker" got moved to the new central location "nova/conf/compute.py" Change-Id: I0da2ad7daa942b85c3395dc4861c6e18368ece88 Implements: blueprint centralize-config-options-newton --- nova/compute/opts.py | 3 -- nova/compute/resource_tracker.py | 66 +-------------------------- nova/conf/compute.py | 74 ++++++++++++++++++++++++++++++- nova/objects/compute_node.py | 8 ++-- nova/tests/unit/db/test_db_api.py | 7 ++- 5 files changed, 80 insertions(+), 78 deletions(-) diff --git a/nova/compute/opts.py b/nova/compute/opts.py index d3658fddf7ef..8f90ff662c56 100644 --- a/nova/compute/opts.py +++ b/nova/compute/opts.py @@ -15,7 +15,6 @@ import itertools import nova.compute.flavors import nova.compute.manager import nova.compute.monitors -import nova.compute.resource_tracker import nova.compute.rpcapi import nova.conf @@ -30,8 +29,6 @@ def list_opts(): nova.compute.manager.interval_opts, nova.compute.manager.running_deleted_opts, nova.compute.manager.timeout_opts, - nova.compute.resource_tracker.resource_tracker_opts, - nova.compute.resource_tracker.allocation_ratio_opts, nova.compute.rpcapi.rpcapi_opts, )), ('upgrade_levels', diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index 42ecd5fa37aa..76a1a6caa4d3 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -20,7 +20,6 @@ model. """ import copy -from oslo_config import cfg from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import importutils @@ -30,6 +29,7 @@ from nova.compute import monitors from nova.compute import resources as ext_resources from nova.compute import task_states from nova.compute import vm_states +import nova.conf from nova import exception from nova.i18n import _, _LE, _LI, _LW from nova import objects @@ -41,69 +41,7 @@ from nova.scheduler import client as scheduler_client from nova import utils from nova.virt import hardware -resource_tracker_opts = [ - cfg.IntOpt('reserved_host_disk_mb', default=0, - help='Amount of disk in MB to reserve for the host'), - cfg.IntOpt('reserved_host_memory_mb', default=512, - help='Amount of memory in MB to reserve for the host'), - cfg.StrOpt('compute_stats_class', - default='nova.compute.stats.Stats', - help='DEPRECATED: Class that will manage stats for the ' - 'local compute host', - deprecated_for_removal=True), - cfg.ListOpt('compute_resources', - default=[], - help='DEPRECATED: The names of the extra resources to track. ' - 'The Extensible Resource Tracker is deprecated and will ' - 'be removed in the 14.0.0 release. If you ' - 'use this functionality and have custom resources that ' - 'are managed by the Extensible Resource Tracker, please ' - 'contact the Nova development team by posting to the ' - 'openstack-dev mailing list. There is no future planned ' - 'support for the tracking of custom resources.', - deprecated_for_removal=True), -] - -allocation_ratio_opts = [ - cfg.FloatOpt('cpu_allocation_ratio', - default=0.0, - help='Virtual CPU to physical CPU allocation ratio which affects ' - 'all CPU filters. This configuration specifies a global ratio ' - 'for CoreFilter. For AggregateCoreFilter, it will fall back to ' - 'this configuration value if no per-aggregate setting found. ' - 'NOTE: This can be set per-compute, or if set to 0.0, the value ' - 'set on the scheduler node(s) will be used ' - 'and defaulted to 16.0'), - cfg.FloatOpt('ram_allocation_ratio', - default=0.0, - help='Virtual ram to physical ram allocation ratio which affects ' - 'all ram filters. This configuration specifies a global ratio ' - 'for RamFilter. For AggregateRamFilter, it will fall back to ' - 'this configuration value if no per-aggregate setting found. ' - 'NOTE: This can be set per-compute, or if set to 0.0, the value ' - 'set on the scheduler node(s) will be used ' - 'and defaulted to 1.5'), - cfg.FloatOpt('disk_allocation_ratio', - default=0.0, - help='This is the virtual disk to physical disk allocation ratio used ' - 'by the disk_filter.py script to determine if a host has ' - 'sufficient disk space to fit a requested instance. A ratio ' - 'greater than 1.0 will result in over-subscription of the ' - 'available physical disk, which can be useful for more ' - 'efficiently packing instances created with images that do not ' - 'use the entire virtual disk,such as sparse or compressed ' - 'images. It can be set to a value between 0.0 and 1.0 in order ' - 'to preserve a percentage of the disk for uses other than ' - 'instances.' - 'NOTE: This can be set per-compute, or if set to 0.0, the value ' - 'set on the scheduler node(s) will be used ' - 'and defaulted to 1.0'), -] - - -CONF = cfg.CONF -CONF.register_opts(resource_tracker_opts) -CONF.register_opts(allocation_ratio_opts) +CONF = nova.conf.CONF LOG = logging.getLogger(__name__) COMPUTE_RESOURCE_SEMAPHORE = "compute_resources" diff --git a/nova/conf/compute.py b/nova/conf/compute.py index 07056ff49e4f..c2bfe4be6072 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +import itertools + from oslo_config import cfg compute_opts = [ @@ -74,10 +76,78 @@ compute_opts = [ '["cpu.virt_driver", "numa_mem_bw.virt_driver"]'), ] +resource_tracker_opts = [ + cfg.IntOpt('reserved_host_disk_mb', + default=0, + help='Amount of disk in MB to reserve for the host'), + cfg.IntOpt('reserved_host_memory_mb', + default=512, + help='Amount of memory in MB to reserve for the host'), + cfg.StrOpt('compute_stats_class', + default='nova.compute.stats.Stats', + help='DEPRECATED: Class that will manage stats for the ' + 'local compute host', + deprecated_for_removal=True), + cfg.ListOpt('compute_resources', + default=[], + help='DEPRECATED:The names of the extra resources to track. ' + 'The Extensible Resource Tracker is deprecated and will ' + 'be removed in the 14.0.0 release. If you ' + 'use this functionality and have custom resources that ' + 'are managed by the Extensible Resource Tracker, please ' + 'contact the Nova development team by posting to the ' + 'openstack-dev mailing list. There is no future planned ' + 'support for the tracking of custom resources.', + deprecated_for_removal=True), + +] + +allocation_ratio_opts = [ + cfg.FloatOpt('cpu_allocation_ratio', + default=0.0, + help='Virtual CPU to physical CPU allocation ratio which affects ' + 'all CPU filters. This configuration specifies a global ratio ' + 'for CoreFilter. For AggregateCoreFilter, it will fall back to ' + 'this configuration value if no per-aggregate setting found. ' + 'NOTE: This can be set per-compute, or if set to 0.0, the value ' + 'set on the scheduler node(s) will be used ' + 'and defaulted to 16.0'), + cfg.FloatOpt('ram_allocation_ratio', + default=0.0, + help='Virtual ram to physical ram allocation ratio which affects ' + 'all ram filters. This configuration specifies a global ratio ' + 'for RamFilter. For AggregateRamFilter, it will fall back to ' + 'this configuration value if no per-aggregate setting found. ' + 'NOTE: This can be set per-compute, or if set to 0.0, the value ' + 'set on the scheduler node(s) will be used ' + 'and defaulted to 1.5'), + cfg.FloatOpt('disk_allocation_ratio', + default=0.0, + help='This is the virtual disk to physical disk allocation ratio used ' + 'by the disk_filter.py script to determine if a host has ' + 'sufficient disk space to fit a requested instance. A ratio ' + 'greater than 1.0 will result in over-subscription of the ' + 'available physical disk, which can be useful for more ' + 'efficiently packing instances created with images that do not ' + 'use the entire virtual disk,such as sparse or compressed ' + 'images. It can be set to a value between 0.0 and 1.0 in order ' + 'to preserve a percentage of the disk for uses other than ' + 'instances.' + 'NOTE: This can be set per-compute, or if set to 0.0, the value ' + 'set on the scheduler node(s) will be used ' + 'and defaulted to 1.0'), +] + +ALL_OPTS = itertools.chain( + compute_opts, + resource_tracker_opts, + allocation_ratio_opts + ) + def register_opts(conf): - conf.register_opts(compute_opts) + conf.register_opts(ALL_OPTS) def list_opts(): - return {'DEFAULT': compute_opts} + return {'DEFAULT': ALL_OPTS} diff --git a/nova/objects/compute_node.py b/nova/objects/compute_node.py index a4f99e10c68e..aed5b6a8e226 100644 --- a/nova/objects/compute_node.py +++ b/nova/objects/compute_node.py @@ -12,12 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_config import cfg + from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import uuidutils from oslo_utils import versionutils +import nova.conf from nova import db from nova import exception from nova import objects @@ -25,10 +26,7 @@ from nova.objects import base from nova.objects import fields from nova.objects import pci_device_pool -CONF = cfg.CONF -CONF.import_opt('cpu_allocation_ratio', 'nova.compute.resource_tracker') -CONF.import_opt('ram_allocation_ratio', 'nova.compute.resource_tracker') -CONF.import_opt('disk_allocation_ratio', 'nova.compute.resource_tracker') +CONF = nova.conf.CONF LOG = logging.getLogger(__name__) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 933905d2bc16..85cd569ddf56 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -25,7 +25,7 @@ import uuid as stdlib_uuid import iso8601 import mock import netaddr -from oslo_config import cfg + from oslo_db import api as oslo_db_api from oslo_db import exception as db_exc from oslo_db.sqlalchemy import enginefacade @@ -53,6 +53,7 @@ from nova import block_device from nova.compute import arch from nova.compute import task_states from nova.compute import vm_states +import nova.conf from nova import context from nova import db from nova.db.sqlalchemy import api as sqlalchemy_api @@ -68,9 +69,7 @@ from nova.tests.unit import matchers from nova.tests import uuidsentinel from nova import utils -CONF = cfg.CONF -CONF.import_opt('reserved_host_memory_mb', 'nova.compute.resource_tracker') -CONF.import_opt('reserved_host_disk_mb', 'nova.compute.resource_tracker') +CONF = nova.conf.CONF get_engine = sqlalchemy_api.get_engine