Merge "Ensure build request exists before creating instance"
This commit is contained in:
commit
df1cd10db2
@ -898,6 +898,18 @@ class ComputeTaskManager(base.Base):
|
|||||||
|
|
||||||
cell = host_mapping.cell_mapping
|
cell = host_mapping.cell_mapping
|
||||||
|
|
||||||
|
# Before we create the instance, let's make one final check that
|
||||||
|
# the build request is still around and wasn't deleted by the user
|
||||||
|
# already.
|
||||||
|
try:
|
||||||
|
objects.BuildRequest.get_by_instance_uuid(
|
||||||
|
context, instance.uuid)
|
||||||
|
except exception.BuildRequestNotFound:
|
||||||
|
# the build request is gone so we're done for this instance
|
||||||
|
LOG.debug('While scheduling instance, the build request '
|
||||||
|
'was already deleted.', instance=instance)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
with obj_target_cell(instance, cell):
|
with obj_target_cell(instance, cell):
|
||||||
instance.create()
|
instance.create()
|
||||||
|
|
||||||
|
@ -1556,6 +1556,36 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
|||||||
self.assertFalse(bury.called)
|
self.assertFalse(bury.called)
|
||||||
self.assertTrue(br_destroy.called)
|
self.assertTrue(br_destroy.called)
|
||||||
|
|
||||||
|
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
||||||
|
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
||||||
|
@mock.patch('nova.objects.BuildRequest.get_by_instance_uuid')
|
||||||
|
@mock.patch('nova.objects.BuildRequest.destroy')
|
||||||
|
@mock.patch('nova.conductor.manager.ComputeTaskManager._bury_in_cell0')
|
||||||
|
@mock.patch('nova.objects.Instance.create')
|
||||||
|
def test_schedule_and_build_delete_before_scheduling(self, inst_create,
|
||||||
|
bury, br_destroy,
|
||||||
|
br_get_by_inst,
|
||||||
|
select_destinations,
|
||||||
|
build_and_run):
|
||||||
|
"""Tests the case that the build request is deleted before the instance
|
||||||
|
is created, so we do not create the instance.
|
||||||
|
"""
|
||||||
|
inst_uuid = self.params['build_requests'][0].instance.uuid
|
||||||
|
br_get_by_inst.side_effect = exc.BuildRequestNotFound(uuid=inst_uuid)
|
||||||
|
self.start_service('compute', host='fake-host')
|
||||||
|
select_destinations.return_value = [{'host': 'fake-host',
|
||||||
|
'nodename': 'nodesarestupid',
|
||||||
|
'limits': None}]
|
||||||
|
self.conductor.schedule_and_build_instances(**self.params)
|
||||||
|
# we don't create the instance since the build request is gone
|
||||||
|
self.assertFalse(inst_create.called)
|
||||||
|
# we don't build the instance since we didn't create it
|
||||||
|
self.assertFalse(build_and_run.called)
|
||||||
|
# we don't bury the instance in cell0 since it's already deleted
|
||||||
|
self.assertFalse(bury.called)
|
||||||
|
# we don't don't destroy the build request since it's already gone
|
||||||
|
self.assertFalse(br_destroy.called)
|
||||||
|
|
||||||
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
||||||
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')
|
||||||
@mock.patch('nova.objects.BuildRequest.destroy')
|
@mock.patch('nova.objects.BuildRequest.destroy')
|
||||||
|
Loading…
Reference in New Issue
Block a user