Skip to content

Commit 2f5b578

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Delete InstanceMapping in conductor if BuildRequest is already deleted"
2 parents 5005ff9 + 1ff029c commit 2f5b578

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

nova/conductor/manager.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,15 @@ def schedule_and_build_instances(self, context, build_requests,
13571357
'was already deleted.', instance=instance)
13581358
# This is a placeholder in case the quota recheck fails.
13591359
instances.append(None)
1360+
# If the build request was deleted and the instance is not
1361+
# going to be created, there is on point in leaving an orphan
1362+
# instance mapping so delete it.
1363+
try:
1364+
im = objects.InstanceMapping.get_by_instance_uuid(
1365+
context, instance.uuid)
1366+
im.destroy()
1367+
except exception.InstanceMappingNotFound:
1368+
pass
13601369
self.report_client.delete_allocation_for_instance(
13611370
context, instance.uuid)
13621371
continue

nova/tests/unit/conductor/test_conductor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,10 @@ def test_schedule_and_build_delete_before_scheduling(self, inst_create,
21082108
self.assertFalse(bury.called)
21092109
# we don't don't destroy the build request since it's already gone
21102110
self.assertFalse(br_destroy.called)
2111+
# Make sure the instance mapping is gone.
2112+
self.assertRaises(exc.InstanceMappingNotFound,
2113+
objects.InstanceMapping.get_by_instance_uuid,
2114+
self.context, inst_uuid)
21112115

21122116
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
21132117
@mock.patch('nova.scheduler.rpcapi.SchedulerAPI.select_destinations')

0 commit comments

Comments
 (0)