From 2cd20613e3237754df7c4e73995ac5fdc10a1298 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 5 Nov 2017 15:32:01 -0800 Subject: [PATCH] Clean up allocations if instance deleted during build When we notice that an instance was deleted after scheduling, we punt on instance creation. When that happens, the scheduler will have created allocations already so we need to delete those to avoid leaking resources. Related-Bug: #1679750 Change-Id: I54806fe43257528fbec7d44c841ee4abb14c9dff (cherry picked from commit 57a3af6921dea72b3b2972f66e089578331dbb63) --- nova/conductor/manager.py | 2 ++ nova/tests/unit/conductor/test_conductor.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index fa9ac3ac960d..702fe658d979 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -1071,6 +1071,8 @@ class ComputeTaskManager(base.Base): 'was already deleted.', instance=instance) # This is a placeholder in case the quota recheck fails. instances.append(None) + rc = self.scheduler_client.reportclient + rc.delete_allocation_for_instance(instance.uuid) continue else: instance.availability_zone = ( diff --git a/nova/tests/unit/conductor/test_conductor.py b/nova/tests/unit/conductor/test_conductor.py index e4633d987eac..0ff34def5c7c 100644 --- a/nova/tests/unit/conductor/test_conductor.py +++ b/nova/tests/unit/conductor/test_conductor.py @@ -1759,7 +1759,11 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase): select_destinations.return_value = [{'host': 'fake-host', 'nodename': 'nodesarestupid', 'limits': None}] - self.conductor.schedule_and_build_instances(**self.params) + with mock.patch.object(self.conductor.scheduler_client, + 'reportclient') as mock_rc: + self.conductor.schedule_and_build_instances(**self.params) + mock_rc.delete_allocation_for_instance.assert_called_once_with( + inst_uuid) # 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