Merge "libvirt: Allow delete to complete when a volume disconnect fails"

This commit is contained in:
Jenkins 2013-11-25 12:20:34 +00:00 committed by Gerrit Code Review
commit 58abeee708
2 changed files with 37 additions and 5 deletions

View File

@ -3998,10 +3998,12 @@ class LibvirtConnTestCase(test.TestCase):
instance = db.instance_create(self.context, self.test_instance)
conn.destroy(self.context, instance, {})
def test_destroy_removes_disk(self):
def _test_destroy_removes_disk(self, volume_fail=False):
instance = {"name": "instancename", "id": "42",
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64",
"cleaned": 0, 'info_cache': None, 'security_groups': []}
vol = {'block_device_mapping': [
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}]}
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver,
'_undefine_domain')
@ -4012,6 +4014,18 @@ class LibvirtConnTestCase(test.TestCase):
'security_groups'],
use_slave=False
).AndReturn(instance)
self.mox.StubOutWithMock(driver, "block_device_info_get_mapping")
driver.block_device_info_get_mapping(vol
).AndReturn(vol['block_device_mapping'])
self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver,
"volume_driver_method")
if volume_fail:
libvirt_driver.LibvirtDriver.volume_driver_method(
mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).\
AndRaise(exception.VolumeNotFound('vol'))
else:
libvirt_driver.LibvirtDriver.volume_driver_method(
mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self.mox.StubOutWithMock(shutil, "rmtree")
shutil.rmtree(os.path.join(CONF.instances_path,
'instance-%08x' % int(instance['id'])))
@ -4053,7 +4067,13 @@ class LibvirtConnTestCase(test.TestCase):
fake_obj_load_attr)
self.stubs.Set(instance_obj.Instance, 'save', fake_save)
conn.destroy(self.context, instance, [])
conn.destroy(self.context, instance, [], vol)
def test_destroy_removes_disk(self):
self._test_destroy_removes_disk(volume_fail=False)
def test_destroy_removes_disk_volume_fails(self):
self._test_destroy_removes_disk(volume_fail=True)
def test_destroy_not_removes_disk(self):
instance = {"name": "instancename", "id": "instanceid",

View File

@ -992,9 +992,21 @@ class LibvirtDriver(driver.ComputeDriver):
encryption)
encryptor.detach_volume(**encryption)
self.volume_driver_method('disconnect_volume',
connection_info,
disk_dev)
try:
self.volume_driver_method('disconnect_volume',
connection_info,
disk_dev)
except Exception as exc:
with excutils.save_and_reraise_exception() as ctxt:
if destroy_disks:
# Don't block on Volume errors if we're trying to
# delete the instance as we may be patially created
# or deleted
ctxt.reraise = False
LOG.warn(_("Ignoring Volume Error on vol %(vol_id)s "
"during delete %(exc)s"),
{'vol_id': vol.get('volume_id'), 'exc': exc},
instance=instance)
if destroy_disks:
#NOTE(GuanQiang): teardown lxc container to avoid resource leak