From 2fd50ab75a7bcb77fcc0c5cd18d077eafd1219bb Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Thu, 14 Aug 2014 17:58:58 -0400 Subject: [PATCH] VMWare: Check for rescue disk during destroy If an instance is destroyed while a rescue disk exists that disk will be orphaned and never cleaned up. It's not enough to check the vm_state because a rescued instance can be suspended. So the check should be for the presence of the rescue disk. Change-Id: I3a5b2f48983344de21b06ccdadc6268dcc3bbb30 Closes-Bug: #1338830 --- nova/tests/virt/vmwareapi/test_driver_api.py | 7 +++++-- nova/virt/vmwareapi/vmops.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/nova/tests/virt/vmwareapi/test_driver_api.py b/nova/tests/virt/vmwareapi/test_driver_api.py index 58a7c27..2dff61f 100644 --- a/nova/tests/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/virt/vmwareapi/test_driver_api.py @@ -1613,8 +1613,11 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): self.conn.destroy(self.context, self.instance, self.network_info, None, True) - mock_get.assert_called_once_with(self.conn._vmops._session, - self.instance['uuid']) + calls = [mock.call(self.conn._vmops._session, + self.instance['uuid'] + '-rescue'), + mock.call(self.conn._vmops._session, + self.instance['uuid'])] + mock_get.assert_has_calls(calls) self.assertFalse(mock_call.called) def _rescue(self, config_drive=False): diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index b27f255..9b61365 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -952,7 +952,11 @@ class VMwareVMOps(object): """ # If there is a rescue VM then we need to destroy that one too. LOG.debug("Destroying instance", instance=instance) - if instance['vm_state'] == vm_states.RESCUED: + + instance_rescue_name = instance.uuid + self._rescue_suffix + vm_rescue_ref = vm_util.get_vm_ref_from_name(self._session, + instance_rescue_name) + if vm_rescue_ref: LOG.debug("Rescue VM configured", instance=instance) try: self.unrescue(instance, power_on=False) -- 1.7.9.5