~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/scheduler/test_weights.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011-2012 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
"""
 
16
Tests For Scheduler weights.
 
17
"""
 
18
 
 
19
from nova import context
 
20
from nova.scheduler import weights
 
21
from nova import test
 
22
from nova.tests import matchers
 
23
from nova.tests.scheduler import fakes
 
24
 
 
25
 
 
26
class TestWeighedHost(test.TestCase):
 
27
    def test_dict_conversion(self):
 
28
        host_state = fakes.FakeHostState('somehost', None, {})
 
29
        host = weights.WeighedHost(host_state, 'someweight')
 
30
        expected = {'weight': 'someweight',
 
31
                    'host': 'somehost'}
 
32
        self.assertThat(host.to_dict(), matchers.DictMatches(expected))
 
33
 
 
34
    def test_all_weighers(self):
 
35
        classes = weights.all_weighers()
 
36
        class_names = [cls.__name__ for cls in classes]
 
37
        self.assertEqual(len(classes), 1)
 
38
        self.assertIn('RAMWeigher', class_names)
 
39
 
 
40
    def test_all_weighers_with_deprecated_config1(self):
 
41
        self.flags(compute_fill_first_cost_fn_weight=-1.0)
 
42
        classes = weights.all_weighers()
 
43
        class_names = [cls.__name__ for cls in classes]
 
44
        self.assertEqual(len(classes), 1)
 
45
        self.assertIn('_LeastCostWeigher', class_names)
 
46
 
 
47
    def test_all_weighers_with_deprecated_config2(self):
 
48
        self.flags(least_cost_functions=['something'])
 
49
        classes = weights.all_weighers()
 
50
        class_names = [cls.__name__ for cls in classes]
 
51
        self.assertEqual(len(classes), 1)
 
52
        self.assertIn('_LeastCostWeigher', class_names)
 
53
 
 
54
 
 
55
class RamWeigherTestCase(test.TestCase):
 
56
    def setUp(self):
 
57
        super(RamWeigherTestCase, self).setUp()
 
58
        self.host_manager = fakes.FakeHostManager()
 
59
        self.weight_handler = weights.HostWeightHandler()
 
60
        self.weight_classes = self.weight_handler.get_matching_classes(
 
61
                ['nova.scheduler.weights.ram.RAMWeigher'])
 
62
 
 
63
    def _get_weighed_host(self, hosts, weight_properties=None):
 
64
        if weight_properties is None:
 
65
            weight_properties = {}
 
66
        return self.weight_handler.get_weighed_objects(self.weight_classes,
 
67
                hosts, weight_properties)[0]
 
68
 
 
69
    def _get_all_hosts(self):
 
70
        ctxt = context.get_admin_context()
 
71
        fakes.mox_host_manager_db_calls(self.mox, ctxt)
 
72
        self.mox.ReplayAll()
 
73
        host_states = self.host_manager.get_all_host_states(ctxt)
 
74
        self.mox.VerifyAll()
 
75
        self.mox.ResetAll()
 
76
        return host_states
 
77
 
 
78
    def test_default_of_spreading_first(self):
 
79
        hostinfo_list = self._get_all_hosts()
 
80
 
 
81
        # host1: free_ram_mb=512
 
82
        # host2: free_ram_mb=1024
 
83
        # host3: free_ram_mb=3072
 
84
        # host4: free_ram_mb=8192
 
85
 
 
86
        # so, host4 should win:
 
87
        weighed_host = self._get_weighed_host(hostinfo_list)
 
88
        self.assertEqual(weighed_host.weight, 8192)
 
89
        self.assertEqual(weighed_host.obj.host, 'host4')
 
90
 
 
91
    def test_ram_filter_multiplier1(self):
 
92
        self.flags(ram_weight_multiplier=-1.0)
 
93
        hostinfo_list = self._get_all_hosts()
 
94
 
 
95
        # host1: free_ram_mb=-512
 
96
        # host2: free_ram_mb=-1024
 
97
        # host3: free_ram_mb=-3072
 
98
        # host4: free_ram_mb=-8192
 
99
 
 
100
        # so, host1 should win:
 
101
        weighed_host = self._get_weighed_host(hostinfo_list)
 
102
        self.assertEqual(weighed_host.weight, -512)
 
103
        self.assertEqual(weighed_host.obj.host, 'host1')
 
104
 
 
105
    def test_ram_filter_multiplier2(self):
 
106
        self.flags(ram_weight_multiplier=2.0)
 
107
        hostinfo_list = self._get_all_hosts()
 
108
 
 
109
        # host1: free_ram_mb=512 * 2
 
110
        # host2: free_ram_mb=1024 * 2
 
111
        # host3: free_ram_mb=3072 * 2
 
112
        # host4: free_ram_mb=8192 * 2
 
113
 
 
114
        # so, host4 should win:
 
115
        weighed_host = self._get_weighed_host(hostinfo_list)
 
116
        self.assertEqual(weighed_host.weight, 8192 * 2)
 
117
        self.assertEqual(weighed_host.obj.host, 'host4')