nova/nova/tests/unit/scheduler/weights/test_weights_hosts.py
Ildiko Vancsa 72ba18468e scheduler: add soft-(anti-)affinity weighers
ServerGroupSoftAffinityWeigher implements the soft-affinity
policy for server groups as it orders the hosts by the number
of instances running on them from the same group in decreasing
order.

ServerGroupSoftAntiAffinityWeigher implements the
soft-anti-affinity policy for server groups as it orders the
hosts by the number of instances running on them from the same
group in increasing order.

Both weigher assumes the the RequestSpec object refers to a valid
InstanceGroup object which has a populated members field. This
will be provided by the subsequent patch.

New configuration options added:
 * soft_affinity_weight_multiplier
 * soft_anti_affinity_multiplier

Add docs about the new weigher classes and change the function
name 'weigh_object' to '_weigh_object' in the Weights section
to match the code.

DocImpact

Co-Authored-By: Balazs Gibizer <balazs.gibizer@ericsson.com>

Implements: blueprint soft-affinity-for-server-group
Change-Id: I3f156d5e5df4d9642bb4b0ffac30a6288459ce61
2016-01-07 10:43:57 +01:00

44 lines
1.7 KiB
Python

# Copyright 2011-2014 IBM
# All Rights Reserved.
#
# 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 weights.
"""
from nova.scheduler import weights
from nova.scheduler.weights import affinity
from nova.scheduler.weights import io_ops
from nova.scheduler.weights import metrics
from nova.scheduler.weights import ram
from nova import test
from nova.tests.unit import matchers
from nova.tests.unit.scheduler import fakes
class TestWeighedHost(test.NoDBTestCase):
def test_dict_conversion(self):
host_state = fakes.FakeHostState('somehost', None, {})
host = weights.WeighedHost(host_state, 'someweight')
expected = {'weight': 'someweight',
'host': 'somehost'}
self.assertThat(host.to_dict(), matchers.DictMatches(expected))
def test_all_weighers(self):
classes = weights.all_weighers()
self.assertIn(ram.RAMWeigher, classes)
self.assertIn(metrics.MetricsWeigher, classes)
self.assertIn(io_ops.IoOpsWeigher, classes)
self.assertIn(affinity.ServerGroupSoftAffinityWeigher, classes)
self.assertIn(affinity.ServerGroupSoftAntiAffinityWeigher, classes)