From fcf2a644fbe6efc2bfd2810add36a099cadd959e Mon Sep 17 00:00:00 2001 From: Vu Tran Date: Mon, 29 Aug 2016 14:05:25 -0400 Subject: [PATCH] Not allow overcommit ratios to be negative Currently the three overcommit ratios: ram_allocation_ratio, cpu_allocation_ratio, and disk_allocation_ratio can be set to negative values. It's up to the scheduler filters to impose the checks on these ratios. It makes more sense to make sure these 3 ratios are not negative when nova-compute is started. If any of these ratios is negative then nova-compute service will fail to start. Closes-Bug: #1604116 Change-Id: Ic960e319b59910c0178e81259b2e35435f2db592 --- nova/conf/compute.py | 3 +++ .../unit/compute/test_resource_tracker.py | 19 +++++++++++++++++++ .../notes/bug-1604116-87a823c3c165d057.yaml | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 releasenotes/notes/bug-1604116-87a823c3c165d057.yaml diff --git a/nova/conf/compute.py b/nova/conf/compute.py index c1ad0e7f60a9..290266ffcbe1 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -189,6 +189,7 @@ Possible values allocation_ratio_opts = [ cfg.FloatOpt('cpu_allocation_ratio', default=0.0, + min=0.0, help=""" This option helps you specify virtual CPU to physical CPU allocation ratio which affects all CPU filters. @@ -208,6 +209,7 @@ and defaulted to 16.0'. """), cfg.FloatOpt('ram_allocation_ratio', default=0.0, + min=0.0, help=""" This option helps you specify virtual RAM to physical RAM allocation ratio which affects all RAM filters. @@ -227,6 +229,7 @@ defaulted to 1.5. """), cfg.FloatOpt('disk_allocation_ratio', default=0.0, + min=0.0, help=""" This option helps you specify virtual disk to physical disk allocation ratio used by the disk_filter.py script to determine if diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index fb5bef8e5df1..21ca50a88b30 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -14,6 +14,7 @@ import copy import datetime import mock +from oslo_config import cfg from oslo_utils import timeutils from oslo_utils import units @@ -38,6 +39,7 @@ from nova.tests import uuidsentinel as uuids _HOSTNAME = 'fake-host' _NODENAME = 'fake-node' +CONF = cfg.CONF _VIRT_DRIVER_AVAIL_RESOURCES = { 'vcpus': 4, @@ -2270,3 +2272,20 @@ class TestIsTrackableMigration(test.NoDBTestCase): mig.migration_type = mig_type self.assertFalse(resource_tracker._is_trackable_migration(mig)) + + +class OverCommitTestCase(BaseTestCase): + def test_cpu_allocation_ratio_none_negative(self): + self.assertRaises(ValueError, + CONF.set_default, 'cpu_allocation_ratio', -1.0, + enforce_type=True) + + def test_ram_allocation_ratio_none_negative(self): + self.assertRaises(ValueError, + CONF.set_default, 'ram_allocation_ratio', -1.0, + enforce_type=True) + + def test_disk_allocation_ratio_none_negative(self): + self.assertRaises(ValueError, + CONF.set_default, 'disk_allocation_ratio', -1.0, + enforce_type=True) diff --git a/releasenotes/notes/bug-1604116-87a823c3c165d057.yaml b/releasenotes/notes/bug-1604116-87a823c3c165d057.yaml new file mode 100644 index 000000000000..46ae12a08ee5 --- /dev/null +++ b/releasenotes/notes/bug-1604116-87a823c3c165d057.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - The three configuration options ``cpu_allocation_ratio``, + ``ram_allocation_ratio`` and ``disk_allocation_ratio`` for + the nova compute are now checked against negative values. + If any of these three options is set to negative value + then nova compute service will fail to start.