Merge lp:~klmitch/nova/weigh-instances into lp:~hudson-openstack/nova/trunk

Proposed by Kevin L. Mitchell
Status: Merged
Approved by: Monty Taylor
Approved revision: 1533
Merged at revision: 1534
Proposed branch: lp:~klmitch/nova/weigh-instances
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 78 lines (+47/-2)
2 files modified
nova/scheduler/base_scheduler.py (+14/-2)
nova/tests/scheduler/test_abstract_scheduler.py (+33/-0)
To merge this branch: bzr merge lp:~klmitch/nova/weigh-instances
Reviewer Review Type Date Requested Status
Josh Kearney (community) Approve
Sandy Walsh (community) Approve
Review via email: mp+74501@code.launchpad.net

Description of the change

Make weigh_hosts() return a host per instance, instead of just a list of hosts.

To post a comment you must log in.
Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

lgtm

review: Approve
lp:~klmitch/nova/weigh-instances updated
1531. By Kevin L. Mitchell

fix a couple of typos in the added unit test

1532. By Kevin L. Mitchell

pull-up from trunk

1533. By Kevin L. Mitchell

pull-up from trunk

Revision history for this message
Josh Kearney (jk0) wrote :

LGTM

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

The attempt to merge lp:~klmitch/nova/weigh-instances into lp:nova failed. Below is the output from the failed tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/scheduler/base_scheduler.py'
2--- nova/scheduler/base_scheduler.py 2011-08-15 22:09:39 +0000
3+++ nova/scheduler/base_scheduler.py 2011-09-08 15:51:28 +0000
4@@ -55,5 +55,17 @@
5 scheduling objectives
6 """
7 # NOTE(sirp): The default logic is the same as the NoopCostFunction
8- return [dict(weight=1, hostname=hostname, capabilities=capabilities)
9- for hostname, capabilities in hosts]
10+ hosts = [dict(weight=1, hostname=hostname, capabilities=capabilities)
11+ for hostname, capabilities in hosts]
12+
13+ # NOTE(Vek): What we actually need to return is enough hosts
14+ # for all the instances!
15+ num_instances = request_spec.get('num_instances', 1)
16+ instances = []
17+ while num_instances > len(hosts):
18+ instances.extend(hosts)
19+ num_instances -= len(hosts)
20+ if num_instances > 0:
21+ instances.extend(hosts[:num_instances])
22+
23+ return instances
24
25=== modified file 'nova/tests/scheduler/test_abstract_scheduler.py'
26--- nova/tests/scheduler/test_abstract_scheduler.py 2011-08-12 18:58:26 +0000
27+++ nova/tests/scheduler/test_abstract_scheduler.py 2011-09-08 15:51:28 +0000
28@@ -26,6 +26,7 @@
29 from nova.compute import api as compute_api
30 from nova.scheduler import driver
31 from nova.scheduler import abstract_scheduler
32+from nova.scheduler import base_scheduler
33 from nova.scheduler import zone_manager
34
35
36@@ -65,6 +66,11 @@
37 pass
38
39
40+class FakeBaseScheduler(base_scheduler.BaseScheduler):
41+ # No need to stub anything at the moment
42+ pass
43+
44+
45 class FakeZoneManager(zone_manager.ZoneManager):
46 def __init__(self):
47 self.service_states = {
48@@ -365,3 +371,30 @@
49
50 self.assertEqual(fixture._decrypt_blob(test_data),
51 json.dumps(test_data))
52+
53+
54+class BaseSchedulerTestCase(test.TestCase):
55+ """Test case for Base Scheduler."""
56+
57+ def test_weigh_hosts(self):
58+ """
59+ Try to weigh a short list of hosts and make sure enough
60+ entries for a larger number instances are returned.
61+ """
62+
63+ sched = FakeBaseScheduler()
64+
65+ # Fake out a list of hosts
66+ zm = FakeZoneManager()
67+ hostlist = [(host, services['compute'])
68+ for host, services in zm.service_states.items()
69+ if 'compute' in services]
70+
71+ # Call weigh_hosts()
72+ num_instances = len(hostlist) * 2 + len(hostlist) / 2
73+ instlist = sched.weigh_hosts('compute',
74+ dict(num_instances=num_instances),
75+ hostlist)
76+
77+ # Should be enough entries to cover all instances
78+ self.assertEqual(len(instlist), num_instances)