diff --git a/nova/conf/compute.py b/nova/conf/compute.py index 7cfd1a1a01aa..47e790fd2d6c 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -189,6 +189,7 @@ allocation_ratio_opts = [ # TODO(sfinucan): Add min parameter 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 @@ Possible values: # TODO(sfinucan): Add min parameter 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 @@ Possible values: # TODO(sfinucan): Add min parameter 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 fcc623ec502b..319ad1fa2055 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, @@ -2273,3 +2275,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.