Undefine libvirt saved instances

Fixes bug 814561

Adding a call to managedSaveRemove if the instance has a
saved instance, so they are now undefined in addition to running
instances during destroy
With test case

Also added myself to Authors

Change-Id: If93e8ac6972116152f38e187bd1a61c652855814
This commit is contained in:
Derek Higgins 2011-11-04 00:25:34 +00:00
parent 7a2e8a1d67
commit ad7fcf225e
3 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,7 @@ Dave Walker <DaveWalker@ubuntu.com>
David Pravec <David.Pravec@danix.org>
David Subiros <david.perez5@hp.com>
Dean Troyer <dtroyer@gmail.com>
Derek Higgins <higginsd@gmail.com>
Devendra Modium <dmodium@isi.edu>
Devin Carlen <devin.carlen@gmail.com>
Donal Lafferty <donal.lafferty@citrix.com>

View File

@ -1063,6 +1063,25 @@ class LibvirtConnTestCase(test.TestCase):
instance = db.instance_create(self.context, self.test_instance)
conn.destroy(instance, {})
@test.skip_if(missing_libvirt(), "Test requires libvirt")
def test_destroy_saved(self):
"""Ensure destroy calls managedSaveRemove for saved instance"""
mock = self.mox.CreateMock(libvirt.virDomain)
mock.destroy()
mock.hasManagedSaveImage(0).AndReturn(1)
mock.managedSaveRemove(0)
mock.undefine()
self.mox.ReplayAll()
def fake_lookup_by_name(instance_name):
return mock
conn = connection.LibvirtConnection(False)
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
instance = {"name": "instancename", "id": "instanceid"}
conn.destroy(instance, [])
class HostStateTestCase(test.TestCase):

View File

@ -310,6 +310,17 @@ class LibvirtConnection(driver.ComputeDriver):
locals())
raise
try:
# NOTE(derekh): we can switch to undefineFlags and
# VIR_DOMAIN_UNDEFINE_MANAGED_SAVE once we require 0.9.4
if virt_dom.hasManagedSaveImage(0):
virt_dom.managedSaveRemove(0)
except libvirt.libvirtError as e:
errcode = e.get_error_code()
LOG.warning(_("Error from libvirt during saved instance "
"removal %(instance_name)s. Code=%(errcode)s"
" Error=%(e)s") % locals())
try:
# NOTE(justinsb): We remove the domain definition. We probably
# would do better to keep it if cleanup=False (e.g. volumes?)