-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AllocatedCapacityWeigher is a weigher that weigh hosts by their allocated capacity. The main purpose of this weigher is to simulate the SimpleScheduler's behavior, which sorts hosts by the size of all volumes on them. So by allocated capacity, it equals to the sum of size of all volumes on target host. In order to keep track of 'allocated' capacity, host state is updated to add a 'allocated_capacity_gb' attribute to record the value, which means each back-end must report one extra stats to scheduler. Fortunately, the 'allocated' capacity we are interested in here is pure Cinder level capacity, the volume manager can take all the burden to calculate this value without having to query back-ends. The volume manager does the initial calculation in init_host() by the time when it has to query all existing volumes from DB for ensure_export(). After initial calculation, volume manager/scheduler will keep track of every new request that changes 'allocated_capacity' and make sure this value is up to date. !DriverImpact! Cinder driver developers, please read on: This patch contains a change that might IMPACT volume drivers: volume manager now uses 'stats' attribute to save 'allocated_capacity_gb'. And this information will be merged with those stats drivers provide as a whole for scheduler to consume. If you plan to report any form of allocated space other than the apparent Cinder level value, (e.g. actual capacity allocated), Please choose a key name other than 'allocated_capacity_gb', otherwise it will *OVERWRITE* the value volume manager has calculated and confuse scheduler. Partially implements bp: deprecate-chance-and-simple-schedulers Change-Id: I306230b8973c2d1ad77bcab14ccde68e997ea816
- Loading branch information
Zhiteng Huang
committed
Dec 30, 2013
1 parent
2d6a903
commit 254e37a
Showing
12 changed files
with
176 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2013 eBay Inc. | ||
# | ||
# 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 Allocated Capacity Weigher. | ||
""" | ||
|
||
import mock | ||
from oslo.config import cfg | ||
|
||
from cinder import context | ||
from cinder.openstack.common.scheduler.weights import HostWeightHandler | ||
from cinder.scheduler.weights.capacity import AllocatedCapacityWeigher as ACW | ||
from cinder import test | ||
from cinder.tests.scheduler import fakes | ||
|
||
CONF = cfg.CONF | ||
|
||
|
||
class AllocatedCapacityWeigherTestCase(test.TestCase): | ||
def setUp(self): | ||
super(AllocatedCapacityWeigherTestCase, self).setUp() | ||
self.host_manager = fakes.FakeHostManager() | ||
self.weight_handler = HostWeightHandler('cinder.scheduler.weights') | ||
|
||
def _get_weighed_host(self, hosts, weight_properties=None): | ||
if weight_properties is None: | ||
weight_properties = {} | ||
return self.weight_handler.get_weighed_objects([ACW], hosts, | ||
weight_properties)[0] | ||
|
||
@mock.patch('cinder.db.sqlalchemy.api.service_get_all_by_topic') | ||
def _get_all_hosts(self, _mock_service_get_all_by_topic): | ||
ctxt = context.get_admin_context() | ||
fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic) | ||
host_states = self.host_manager.get_all_host_states(ctxt) | ||
_mock_service_get_all_by_topic.assert_called_once_with( | ||
ctxt, CONF.volume_topic) | ||
return host_states | ||
|
||
def test_default_of_spreading_first(self): | ||
hostinfo_list = self._get_all_hosts() | ||
|
||
# host1: allocated_capacity_gb=0, weight=0 | ||
# host2: allocated_capacity_gb=1748, weight=-1748 | ||
# host3: allocated_capacity_gb=256, weight=-256 | ||
# host4: allocated_capacity_gb=1848, weight=-1848 | ||
|
||
# so, host1 should win: | ||
weighed_host = self._get_weighed_host(hostinfo_list) | ||
self.assertEqual(weighed_host.weight, 0) | ||
self.assertEqual(weighed_host.obj.host, 'host1') | ||
|
||
def test_capacity_weight_multiplier1(self): | ||
self.flags(allocated_capacity_weight_multiplier=1.0) | ||
hostinfo_list = self._get_all_hosts() | ||
|
||
# host1: allocated_capacity_gb=0, weight=0 | ||
# host2: allocated_capacity_gb=1748, weight=1748 | ||
# host3: allocated_capacity_gb=256, weight=256 | ||
# host4: allocated_capacity_gb=1848, weight=1848 | ||
|
||
# so, host4 should win: | ||
weighed_host = self._get_weighed_host(hostinfo_list) | ||
self.assertEqual(weighed_host.weight, 1848.0) | ||
self.assertEqual(weighed_host.obj.host, 'host4') | ||
|
||
def test_capacity_weight_multiplier2(self): | ||
self.flags(allocated_capacity_weight_multiplier=-2.0) | ||
hostinfo_list = self._get_all_hosts() | ||
|
||
# host1: allocated_capacity_gb=0, weight=0 | ||
# host2: allocated_capacity_gb=1748, weight=-3496 | ||
# host3: allocated_capacity_gb=256, weight=-512 | ||
# host4: allocated_capacity_gb=1848, weight=-3696 | ||
|
||
# so, host1 should win: | ||
weighed_host = self._get_weighed_host(hostinfo_list) | ||
self.assertEqual(weighed_host.weight, 0) | ||
self.assertEqual(weighed_host.obj.host, 'host1') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.