diff options
Diffstat (limited to 'nova')
-rw-r--r-- | nova/conf/scheduler.py | 43 | ||||
-rw-r--r-- | nova/scheduler/weights/hypervisor_version.py | 39 | ||||
-rw-r--r-- | nova/tests/unit/scheduler/weights/test_weights_hypervisor_version.py | 97 |
3 files changed, 179 insertions, 0 deletions
diff --git a/nova/conf/scheduler.py b/nova/conf/scheduler.py index c75bd07c5b..c7aa2ad76d 100644 --- a/nova/conf/scheduler.py +++ b/nova/conf/scheduler.py @@ -464,6 +464,49 @@ Possible values: * An integer or float value, where the value corresponds to the multipler ratio for this weigher. """), + cfg.FloatOpt("hypervisor_version_weight_multiplier", + default=1.0, + help=""" +Hypervisor Version weight multiplier ratio. + +The multiplier is used for weighting hosts based on the reported +hypervisor version. +Negative numbers indicate preferring older hosts, +the default is to prefer newer hosts to aid with upgrades. + +Possible values: + +* An integer or float value, where the value corresponds to the multiplier + ratio for this weigher. + +Example: + +* Strongly prefer older hosts + + .. code-block:: ini + + [filter_scheduler] + hypervisor_version_weight_multiplier=-1000 + + +* Moderately prefer new hosts + + .. code-block:: ini + + [filter_scheduler] + hypervisor_version_weight_multiplier=2.5 + +* Disable weigher influence + + .. code-block:: ini + + [filter_scheduler] + hypervisor_version_weight_multiplier=0 + +Related options: + +* ``[filter_scheduler] weight_classes`` +"""), cfg.FloatOpt("io_ops_weight_multiplier", default=-1.0, help=""" diff --git a/nova/scheduler/weights/hypervisor_version.py b/nova/scheduler/weights/hypervisor_version.py new file mode 100644 index 0000000000..0cd7b0a824 --- /dev/null +++ b/nova/scheduler/weights/hypervisor_version.py @@ -0,0 +1,39 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Hypervisor Version Weigher. Weigh hosts by their relative hypervior version. + +The default is to select newer hosts. If you prefer +to invert the behavior set the 'hypervisor_version_weight_multiplier' option +to a negative number and the weighing has the opposite effect of the default. +""" + +import nova.conf +from nova.scheduler import utils +from nova.scheduler import weights + +CONF = nova.conf.CONF + + +class HypervisorVersionWeigher(weights.BaseHostWeigher): + + def weight_multiplier(self, host_state): + """Override the weight multiplier.""" + return utils.get_weight_multiplier( + host_state, 'hypervisor_version_weight_multiplier', + CONF.filter_scheduler.hypervisor_version_weight_multiplier) + + def _weigh_object(self, host_state, weight_properties): + """Higher weights win. We want newer hosts by default.""" + # convert None to 0 + return host_state.hypervisor_version or 0 diff --git a/nova/tests/unit/scheduler/weights/test_weights_hypervisor_version.py b/nova/tests/unit/scheduler/weights/test_weights_hypervisor_version.py new file mode 100644 index 0000000000..c6e4abd4cd --- /dev/null +++ b/nova/tests/unit/scheduler/weights/test_weights_hypervisor_version.py @@ -0,0 +1,97 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +Tests For Scheduler hypervisor version weights. +""" + +from nova.scheduler import weights +from nova.scheduler.weights import hypervisor_version +from nova import test +from nova.tests.unit.scheduler import fakes + + +class HypervisorVersionWeigherTestCase(test.NoDBTestCase): + def setUp(self): + super().setUp() + self.weight_handler = weights.HostWeightHandler() + self.weighers = [hypervisor_version.HypervisorVersionWeigher()] + + def _get_weighed_host(self, hosts, weight_properties=None): + if weight_properties is None: + weight_properties = {} + return self.weight_handler.get_weighed_objects(self.weighers, + hosts, weight_properties)[0] + + def _get_all_hosts(self): + host_values = [ + ('host1', 'node1', {'hypervisor_version': 1}), + ('host2', 'node2', {'hypervisor_version': 200}), + ('host3', 'node3', {'hypervisor_version': 100}), + ('host4', 'node4', {'hypervisor_version': 1000}), + ] + return [fakes.FakeHostState(host, node, values) + for host, node, values in host_values] + + def test_multiplier_default(self): + hostinfo_list = self._get_all_hosts() + weighed_host = self._get_weighed_host(hostinfo_list) + self.assertEqual(1.0, weighed_host.weight) + self.assertEqual('host4', weighed_host.obj.host) + + def test_multiplier_default_full_ordering(self): + hostinfo_list = self._get_all_hosts() + weighed_hosts = self.weight_handler.get_weighed_objects( + self.weighers, hostinfo_list, {} + ) + expected_hosts = [fakes.FakeHostState(host, node, values) + for host, node, values in [ + ('host4', 'node4', {'hypervisor_version': 1000}), + ('host2', 'node2', {'hypervisor_version': 200}), + ('host3', 'node3', {'hypervisor_version': 100}), + ('host1', 'node1', {'hypervisor_version': 1}), + ]] + for actual, expected in zip( + weighed_hosts, + expected_hosts + ): + self.assertEqual(actual.obj.host, expected.host) + + def test_multiplier_none(self): + multi = 0.0 + self.flags( + hypervisor_version_weight_multiplier=multi, + group='filter_scheduler' + ) + hostinfo_list = self._get_all_hosts() + weighed_host = self._get_weighed_host(hostinfo_list) + self.assertEqual(multi, weighed_host.weight) + + def test_multiplier_positive(self): + multi = 2.0 + self.flags( + hypervisor_version_weight_multiplier=multi, + group='filter_scheduler' + ) + hostinfo_list = self._get_all_hosts() + weighed_host = self._get_weighed_host(hostinfo_list) + self.assertEqual(1.0 * multi, weighed_host.weight) + self.assertEqual('host4', weighed_host.obj.host) + + def test_multiplier_negative(self): + multi = -1.0 + self.flags( + hypervisor_version_weight_multiplier=multi, + group='filter_scheduler' + ) + hostinfo_list = self._get_all_hosts() + weighed_host = self._get_weighed_host(hostinfo_list) + self.assertEqual('host1', weighed_host.obj.host) |