Set instance host field after resource claim
Set the 'host' field on the instance after the resource tracker on the compute node has accepted the build. The field is set after resources are confirmed to be available while the COMPUTE_RESOURCES_SEMAPHORE is held. The semaphore ensures the resources usage values will be consistent even if the update_available_resource periodic task audit runs. bug 1060255 Change-Id: I92105ec14924960ac8ef7ca8c810783085314e10
This commit is contained in:
		@@ -68,7 +68,7 @@ class ChanceScheduler(driver.Scheduler):
 | 
			
		||||
                host = self._schedule(context, 'compute', request_spec,
 | 
			
		||||
                                      filter_properties)
 | 
			
		||||
                updated_instance = driver.instance_update_db(context,
 | 
			
		||||
                        instance_uuid, host)
 | 
			
		||||
                        instance_uuid)
 | 
			
		||||
                self.compute_rpcapi.run_instance(context,
 | 
			
		||||
                        instance=updated_instance, host=host,
 | 
			
		||||
                        requested_networks=requested_networks,
 | 
			
		||||
 
 | 
			
		||||
@@ -101,13 +101,13 @@ def cast_to_volume_host(context, host, method, **kwargs):
 | 
			
		||||
    LOG.debug(_("Casted '%(method)s' to volume '%(host)s'") % locals())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def instance_update_db(context, instance_uuid, host):
 | 
			
		||||
    '''Set the host and scheduled_at fields of an Instance.
 | 
			
		||||
def instance_update_db(context, instance_uuid):
 | 
			
		||||
    '''Clear the host and set the scheduled_at field of an Instance.
 | 
			
		||||
 | 
			
		||||
    :returns: An Instance with the updated fields set properly.
 | 
			
		||||
    '''
 | 
			
		||||
    now = timeutils.utcnow()
 | 
			
		||||
    values = {'host': host, 'scheduled_at': now}
 | 
			
		||||
    values = {'host': None, 'scheduled_at': now}
 | 
			
		||||
    return db.instance_update(context, instance_uuid, values)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -116,7 +116,7 @@ def cast_to_compute_host(context, host, method, **kwargs):
 | 
			
		||||
 | 
			
		||||
    instance_uuid = kwargs.get('instance_uuid', None)
 | 
			
		||||
    if instance_uuid:
 | 
			
		||||
        instance_update_db(context, instance_uuid, host)
 | 
			
		||||
        instance_update_db(context, instance_uuid)
 | 
			
		||||
 | 
			
		||||
    rpc.cast(context,
 | 
			
		||||
             rpc.queue_get_for(context, 'compute', host),
 | 
			
		||||
 
 | 
			
		||||
@@ -142,8 +142,7 @@ class FilterScheduler(driver.Scheduler):
 | 
			
		||||
                        'scheduler.run_instance.scheduled', notifier.INFO,
 | 
			
		||||
                        payload)
 | 
			
		||||
 | 
			
		||||
        updated_instance = driver.instance_update_db(context,
 | 
			
		||||
                instance_uuid, weighted_host.host_state.host)
 | 
			
		||||
        updated_instance = driver.instance_update_db(context, instance_uuid)
 | 
			
		||||
 | 
			
		||||
        self.compute_rpcapi.run_instance(context, instance=updated_instance,
 | 
			
		||||
                host=weighted_host.host_state.host,
 | 
			
		||||
 
 | 
			
		||||
@@ -90,8 +90,8 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase):
 | 
			
		||||
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
 | 
			
		||||
                ['host1', 'host2', 'host3', 'host4'])
 | 
			
		||||
        random.random().AndReturn(.5)
 | 
			
		||||
        driver.instance_update_db(ctxt, instance1['uuid'],
 | 
			
		||||
                'host3').WithSideEffects(inc_launch_index).AndReturn(instance1)
 | 
			
		||||
        driver.instance_update_db(ctxt, instance1['uuid']).WithSideEffects(
 | 
			
		||||
                inc_launch_index).AndReturn(instance1)
 | 
			
		||||
        compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host3',
 | 
			
		||||
                instance=instance1, requested_networks=None,
 | 
			
		||||
                injected_files=None, admin_password=None, is_first_time=None,
 | 
			
		||||
@@ -102,8 +102,8 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase):
 | 
			
		||||
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
 | 
			
		||||
                ['host1', 'host2', 'host3', 'host4'])
 | 
			
		||||
        random.random().AndReturn(.2)
 | 
			
		||||
        driver.instance_update_db(ctxt, instance2['uuid'],
 | 
			
		||||
                'host1').WithSideEffects(inc_launch_index).AndReturn(instance2)
 | 
			
		||||
        driver.instance_update_db(ctxt, instance2['uuid']).WithSideEffects(
 | 
			
		||||
                inc_launch_index).AndReturn(instance2)
 | 
			
		||||
        compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host1',
 | 
			
		||||
                instance=instance2, requested_networks=None,
 | 
			
		||||
                injected_files=None, admin_password=None, is_first_time=None,
 | 
			
		||||
 
 | 
			
		||||
@@ -712,7 +712,7 @@ class SchedulerDriverModuleTestCase(test.TestCase):
 | 
			
		||||
 | 
			
		||||
        timeutils.utcnow().AndReturn('fake-now')
 | 
			
		||||
        db.instance_update(self.context, 'fake_uuid',
 | 
			
		||||
                {'host': host, 'scheduled_at': 'fake-now'})
 | 
			
		||||
                {'host': None, 'scheduled_at': 'fake-now'})
 | 
			
		||||
        rpc.queue_get_for(self.context, 'compute', host).AndReturn(queue)
 | 
			
		||||
        rpc.cast(self.context, queue,
 | 
			
		||||
                {'method': method,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user