From b419fa0796ac70b3ee409f9174cfea3002660da4 Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Mon, 8 Oct 2012 18:35:14 +0000 Subject: [PATCH] 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 --- nova/scheduler/chance.py | 2 +- nova/scheduler/driver.py | 8 ++++---- nova/scheduler/filter_scheduler.py | 3 +-- nova/tests/scheduler/test_chance_scheduler.py | 8 ++++---- nova/tests/scheduler/test_scheduler.py | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py index f6a289f26..65806d4d5 100644 --- a/nova/scheduler/chance.py +++ b/nova/scheduler/chance.py @@ -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, diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index a72f3c26d..0ca1d7b89 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -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), diff --git a/nova/scheduler/filter_scheduler.py b/nova/scheduler/filter_scheduler.py index eddd745db..7b13ab215 100644 --- a/nova/scheduler/filter_scheduler.py +++ b/nova/scheduler/filter_scheduler.py @@ -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, diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index 4fb9ab617..26cde055b 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -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, diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 83e9cffc8..af297b589 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -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,