Merge "Handle instance being deleted while in filter scheduler"

This commit is contained in:
Jenkins
2013-07-19 12:33:22 +00:00
committed by Gerrit Code Review
2 changed files with 44 additions and 11 deletions

View File

@@ -200,19 +200,27 @@ class FilterScheduler(driver.Scheduler):
values.update({'group': group})
values = {'system_metadata': values}
updated_instance = driver.instance_update_db(context,
instance_uuid, extra_values=values)
try:
updated_instance = driver.instance_update_db(context,
instance_uuid, extra_values=values)
scheduler_utils.populate_filter_properties(filter_properties,
weighed_host.obj)
except exception.InstanceNotFound:
LOG.warning(_("Instance disappeared during scheduling"),
context=context, instance_uuid=instance_uuid)
self.compute_rpcapi.run_instance(context, instance=updated_instance,
host=weighed_host.obj.host,
request_spec=request_spec, filter_properties=filter_properties,
requested_networks=requested_networks,
injected_files=injected_files,
admin_password=admin_password, is_first_time=is_first_time,
node=weighed_host.obj.nodename)
else:
scheduler_utils.populate_filter_properties(filter_properties,
weighed_host.obj)
self.compute_rpcapi.run_instance(context,
instance=updated_instance,
host=weighed_host.obj.host,
request_spec=request_spec,
filter_properties=filter_properties,
requested_networks=requested_networks,
injected_files=injected_files,
admin_password=admin_password, is_first_time=is_first_time,
node=weighed_host.obj.nodename)
def _get_configuration_options(self):
"""Fetch options dictionary. Broken out for testing."""

View File

@@ -663,3 +663,28 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
self.assertRaises(exception.NoValidHost,
self.driver.select_destinations, self.context,
{'num_instances': 1}, {})
def test_handles_deleted_instance(self):
"""Test instance deletion while being scheduled."""
def _raise_instance_not_found(*args, **kwargs):
raise exception.InstanceNotFound(instance_id='123')
self.stubs.Set(driver, 'instance_update_db',
_raise_instance_not_found)
sched = fakes.FakeFilterScheduler()
fake_context = context.RequestContext('user', 'project')
host_state = host_manager.HostState('host2', 'node2')
weighted_host = weights.WeighedHost(host_state, 1.42)
filter_properties = {}
uuid = 'fake-uuid1'
instance_properties = {'project_id': 1, 'os_type': 'Linux'}
request_spec = {'instance_type': {'memory_mb': 1, 'local_gb': 1},
'instance_properties': instance_properties,
'instance_uuids': [uuid]}
sched._provision_resource(fake_context, weighted_host,
request_spec, filter_properties,
None, None, None, None)