Merge "Include launch_index when creating instances."
This commit is contained in:
		
							
								
								
									
										1
									
								
								Authors
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Authors
									
									
									
									
									
								
							@@ -123,6 +123,7 @@ Michael Basnight <mbasnigh@rackspace.com>
 | 
				
			|||||||
Michael Gundlach <michael.gundlach@rackspace.com>
 | 
					Michael Gundlach <michael.gundlach@rackspace.com>
 | 
				
			||||||
Michael Still <mikal@stillhq.com>
 | 
					Michael Still <mikal@stillhq.com>
 | 
				
			||||||
Mike Lundy <mike@pistoncloud.com>
 | 
					Mike Lundy <mike@pistoncloud.com>
 | 
				
			||||||
 | 
					Mike Milner <mike.milner@canonical.com>
 | 
				
			||||||
Mike Pittaro <mikeyp@lahondaresearch.org>
 | 
					Mike Pittaro <mikeyp@lahondaresearch.org>
 | 
				
			||||||
Mike Scherbakov <mihgen@gmail.com>
 | 
					Mike Scherbakov <mihgen@gmail.com>
 | 
				
			||||||
Mikyung Kang <mkkang@isi.edu>
 | 
					Mikyung Kang <mkkang@isi.edu>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -84,6 +84,7 @@ class DistributedScheduler(driver.Scheduler):
 | 
				
			|||||||
                break
 | 
					                break
 | 
				
			||||||
            weighted_host = weighted_hosts.pop(0)
 | 
					            weighted_host = weighted_hosts.pop(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            request_spec['instance_properties']['launch_index'] = num
 | 
				
			||||||
            instance = self._provision_resource(elevated, weighted_host,
 | 
					            instance = self._provision_resource(elevated, weighted_host,
 | 
				
			||||||
                                                request_spec, kwargs)
 | 
					                                                request_spec, kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,6 +97,7 @@ class SimpleScheduler(chance.ChanceScheduler):
 | 
				
			|||||||
        for num in xrange(num_instances):
 | 
					        for num in xrange(num_instances):
 | 
				
			||||||
            host = self._schedule_instance(context,
 | 
					            host = self._schedule_instance(context,
 | 
				
			||||||
                    request_spec['instance_properties'], *_args, **_kwargs)
 | 
					                    request_spec['instance_properties'], *_args, **_kwargs)
 | 
				
			||||||
 | 
					            request_spec['instance_properties']['launch_index'] = num
 | 
				
			||||||
            instance_ref = self.create_instance_db_entry(context,
 | 
					            instance_ref = self.create_instance_db_entry(context,
 | 
				
			||||||
                    request_spec)
 | 
					                    request_spec)
 | 
				
			||||||
            driver.cast_to_compute_host(context, host, 'run_instance',
 | 
					            driver.cast_to_compute_host(context, host, 'run_instance',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,21 +16,26 @@
 | 
				
			|||||||
Tests For Distributed Scheduler.
 | 
					Tests For Distributed Scheduler.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mox
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from nova import context
 | 
					from nova import context
 | 
				
			||||||
from nova import exception
 | 
					from nova import exception
 | 
				
			||||||
from nova.scheduler import least_cost
 | 
					from nova.scheduler import least_cost
 | 
				
			||||||
from nova.scheduler import host_manager
 | 
					from nova.scheduler import host_manager
 | 
				
			||||||
 | 
					from nova.scheduler import distributed_scheduler
 | 
				
			||||||
from nova import test
 | 
					from nova import test
 | 
				
			||||||
from nova.tests.scheduler import fakes
 | 
					from nova.tests.scheduler import fakes, test_scheduler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def fake_filter_hosts(hosts, filter_properties):
 | 
					def fake_filter_hosts(hosts, filter_properties):
 | 
				
			||||||
    return list(hosts)
 | 
					    return list(hosts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DistributedSchedulerTestCase(test.TestCase):
 | 
					class DistributedSchedulerTestCase(test_scheduler.SchedulerTestCase):
 | 
				
			||||||
    """Test case for Distributed Scheduler."""
 | 
					    """Test case for Distributed Scheduler."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    driver_cls = distributed_scheduler.DistributedScheduler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_instance_no_hosts(self):
 | 
					    def test_run_instance_no_hosts(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Ensure empty hosts & child_zones result in NoValidHosts exception.
 | 
					        Ensure empty hosts & child_zones result in NoValidHosts exception.
 | 
				
			||||||
@@ -76,6 +81,51 @@ class DistributedSchedulerTestCase(test.TestCase):
 | 
				
			|||||||
        self.assertRaises(NotImplementedError, sched._schedule, fake_context,
 | 
					        self.assertRaises(NotImplementedError, sched._schedule, fake_context,
 | 
				
			||||||
                          "foo", {})
 | 
					                          "foo", {})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_scheduler_includes_launch_index(self):
 | 
				
			||||||
 | 
					        ctxt = "fake-context"
 | 
				
			||||||
 | 
					        fake_kwargs = {'fake_kwarg1': 'fake_value1',
 | 
				
			||||||
 | 
					                       'fake_kwarg2': 'fake_value2'}
 | 
				
			||||||
 | 
					        instance_opts = {'fake_opt1': 'meow'}
 | 
				
			||||||
 | 
					        request_spec = {'num_instances': 2,
 | 
				
			||||||
 | 
					                        'instance_properties': instance_opts}
 | 
				
			||||||
 | 
					        instance1 = {'uuid': 'fake-uuid1'}
 | 
				
			||||||
 | 
					        instance2 = {'uuid': 'fake-uuid2'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def _has_launch_index(expected_index):
 | 
				
			||||||
 | 
					            """Return a function that verifies the expected index."""
 | 
				
			||||||
 | 
					            def _check_launch_index(value):
 | 
				
			||||||
 | 
					                if 'instance_properties' in value:
 | 
				
			||||||
 | 
					                    if 'launch_index' in value['instance_properties']:
 | 
				
			||||||
 | 
					                        index = value['instance_properties']['launch_index']
 | 
				
			||||||
 | 
					                        if index == expected_index:
 | 
				
			||||||
 | 
					                            return True
 | 
				
			||||||
 | 
					                return False
 | 
				
			||||||
 | 
					            return _check_launch_index
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        class ContextFake(object):
 | 
				
			||||||
 | 
					            def elevated(self):
 | 
				
			||||||
 | 
					                return ctxt
 | 
				
			||||||
 | 
					        context_fake = ContextFake()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.mox.StubOutWithMock(self.driver, '_schedule')
 | 
				
			||||||
 | 
					        self.mox.StubOutWithMock(self.driver, '_provision_resource')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.driver._schedule(context_fake, 'compute',
 | 
				
			||||||
 | 
					                              request_spec, **fake_kwargs
 | 
				
			||||||
 | 
					                              ).AndReturn(['host1', 'host2'])
 | 
				
			||||||
 | 
					        # instance 1
 | 
				
			||||||
 | 
					        self.driver._provision_resource(
 | 
				
			||||||
 | 
					            ctxt, 'host1',
 | 
				
			||||||
 | 
					            mox.Func(_has_launch_index(0)), fake_kwargs).AndReturn(instance1)
 | 
				
			||||||
 | 
					        # instance 2
 | 
				
			||||||
 | 
					        self.driver._provision_resource(
 | 
				
			||||||
 | 
					            ctxt, 'host2',
 | 
				
			||||||
 | 
					            mox.Func(_has_launch_index(1)), fake_kwargs).AndReturn(instance2)
 | 
				
			||||||
 | 
					        self.mox.ReplayAll()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.driver.schedule_run_instance(context_fake, request_spec,
 | 
				
			||||||
 | 
					                                          **fake_kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_schedule_happy_day(self):
 | 
					    def test_schedule_happy_day(self):
 | 
				
			||||||
        """Make sure there's nothing glaringly wrong with _schedule()
 | 
					        """Make sure there's nothing glaringly wrong with _schedule()
 | 
				
			||||||
        by doing a happy day pass through."""
 | 
					        by doing a happy day pass through."""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,7 +80,8 @@ def rpc_call_wrapper(context, topic, msg, do_cast=True):
 | 
				
			|||||||
        scheduler = scheduler_driver.Scheduler
 | 
					        scheduler = scheduler_driver.Scheduler
 | 
				
			||||||
        num_instances = request_spec.get('num_instances', 1)
 | 
					        num_instances = request_spec.get('num_instances', 1)
 | 
				
			||||||
        instances = []
 | 
					        instances = []
 | 
				
			||||||
        for x in xrange(num_instances):
 | 
					        for num in xrange(num_instances):
 | 
				
			||||||
 | 
					            request_spec['instance_properties']['launch_index'] = num
 | 
				
			||||||
            instance = scheduler().create_instance_db_entry(
 | 
					            instance = scheduler().create_instance_db_entry(
 | 
				
			||||||
                    context, request_spec)
 | 
					                    context, request_spec)
 | 
				
			||||||
            encoded = scheduler_driver.encode_instance(instance)
 | 
					            encoded = scheduler_driver.encode_instance(instance)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user