diff --git a/nova/tests/unit/volume/encryptors/test_cryptsetup.py b/nova/tests/unit/volume/encryptors/test_cryptsetup.py index 5e523068cd7f..b26d0aa293ae 100644 --- a/nova/tests/unit/volume/encryptors/test_cryptsetup.py +++ b/nova/tests/unit/volume/encryptors/test_cryptsetup.py @@ -78,7 +78,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase): mock_execute.assert_has_calls([ mock.call('cryptsetup', 'remove', self.dev_name, - run_as_root=True, check_exit_code=True), + run_as_root=True, check_exit_code=[0, 4]), ]) self.assertEqual(1, mock_execute.call_count) @@ -88,7 +88,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase): mock_execute.assert_has_calls([ mock.call('cryptsetup', 'remove', self.dev_name, - run_as_root=True, check_exit_code=True), + run_as_root=True, check_exit_code=[0, 4]), ]) self.assertEqual(1, mock_execute.call_count) diff --git a/nova/volume/encryptors/cryptsetup.py b/nova/volume/encryptors/cryptsetup.py index 3b5bcadd5a6c..3e37d645a0af 100644 --- a/nova/volume/encryptors/cryptsetup.py +++ b/nova/volume/encryptors/cryptsetup.py @@ -103,8 +103,11 @@ class CryptsetupEncryptor(base.VolumeEncryptor): def _close_volume(self, **kwargs): """Closes the device (effectively removes the dm-crypt mapping).""" LOG.debug("closing encrypted volume %s", self.dev_path) + # cryptsetup returns 4 when attempting to destroy a non-active + # dm-crypt device. We are going to ignore this error code to make + # nova deleting that instance successfully. utils.execute('cryptsetup', 'remove', self.dev_name, - run_as_root=True, check_exit_code=True) + run_as_root=True, check_exit_code=[0, 4]) def detach_volume(self, **kwargs): """Removes the dm-crypt mapping for the device."""