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
=== modified file 'nova/scheduler/base_scheduler.py'
--- nova/scheduler/base_scheduler.py 2011-08-15 22:09:39 +0000
+++ nova/scheduler/base_scheduler.py 2011-09-08 15:51:28 +0000
@@ -55,5 +55,17 @@
55 scheduling objectives55 scheduling objectives
56 """56 """
57 # NOTE(sirp): The default logic is the same as the NoopCostFunction57 # NOTE(sirp): The default logic is the same as the NoopCostFunction
58 return [dict(weight=1, hostname=hostname, capabilities=capabilities)58 hosts = [dict(weight=1, hostname=hostname, capabilities=capabilities)
59 for hostname, capabilities in hosts]59 for hostname, capabilities in hosts]
60
61 # NOTE(Vek): What we actually need to return is enough hosts
62 # for all the instances!
63 num_instances = request_spec.get('num_instances', 1)
64 instances = []
65 while num_instances > len(hosts):
66 instances.extend(hosts)
67 num_instances -= len(hosts)
68 if num_instances > 0:
69 instances.extend(hosts[:num_instances])
70
71 return instances
6072
=== modified file 'nova/tests/scheduler/test_abstract_scheduler.py'
--- nova/tests/scheduler/test_abstract_scheduler.py 2011-08-12 18:58:26 +0000
+++ nova/tests/scheduler/test_abstract_scheduler.py 2011-09-08 15:51:28 +0000
@@ -26,6 +26,7 @@
26from nova.compute import api as compute_api26from nova.compute import api as compute_api
27from nova.scheduler import driver27from nova.scheduler import driver
28from nova.scheduler import abstract_scheduler28from nova.scheduler import abstract_scheduler
29from nova.scheduler import base_scheduler
29from nova.scheduler import zone_manager30from nova.scheduler import zone_manager
3031
3132
@@ -65,6 +66,11 @@
65 pass66 pass
6667
6768
69class FakeBaseScheduler(base_scheduler.BaseScheduler):
70 # No need to stub anything at the moment
71 pass
72
73
68class FakeZoneManager(zone_manager.ZoneManager):74class FakeZoneManager(zone_manager.ZoneManager):
69 def __init__(self):75 def __init__(self):
70 self.service_states = {76 self.service_states = {
@@ -365,3 +371,30 @@
365371
366 self.assertEqual(fixture._decrypt_blob(test_data),372 self.assertEqual(fixture._decrypt_blob(test_data),
367 json.dumps(test_data))373 json.dumps(test_data))
374
375
376class BaseSchedulerTestCase(test.TestCase):
377 """Test case for Base Scheduler."""
378
379 def test_weigh_hosts(self):
380 """
381 Try to weigh a short list of hosts and make sure enough
382 entries for a larger number instances are returned.
383 """
384
385 sched = FakeBaseScheduler()
386
387 # Fake out a list of hosts
388 zm = FakeZoneManager()
389 hostlist = [(host, services['compute'])
390 for host, services in zm.service_states.items()
391 if 'compute' in services]
392
393 # Call weigh_hosts()
394 num_instances = len(hostlist) * 2 + len(hostlist) / 2
395 instlist = sched.weigh_hosts('compute',
396 dict(num_instances=num_instances),
397 hostlist)
398
399 # Should be enough entries to cover all instances
400 self.assertEqual(len(instlist), num_instances)