Allow older versions of libvirt to delete vms
Libvirt < 0.9.4 doesn't support undefineFlags, so the vms can't be deleted. This patch adds a workaround to fallback to the old style of undefine if undefineFlags throws an Attribute error. It also attempts to remove any managed save images that exist. Fixes bug 1051010 Change-Id: I155fe2ab3be347b1515c5aab4a9233921bd722ca
This commit is contained in:
@@ -2165,8 +2165,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
instance = db.instance_create(self.context, self.test_instance)
|
instance = db.instance_create(self.context, self.test_instance)
|
||||||
conn.destroy(instance, {})
|
conn.destroy(instance, {})
|
||||||
|
|
||||||
def test_destroy(self):
|
def test_destroy_undefines(self):
|
||||||
"""Ensure destroy calls virDomain.undefineFlags"""
|
|
||||||
mock = self.mox.CreateMock(libvirt.virDomain)
|
mock = self.mox.CreateMock(libvirt.virDomain)
|
||||||
mock.destroy()
|
mock.destroy()
|
||||||
mock.undefineFlags(1).AndReturn(1)
|
mock.undefineFlags(1).AndReturn(1)
|
||||||
@@ -2186,9 +2185,7 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||||
conn.destroy(instance, [])
|
conn.destroy(instance, [])
|
||||||
|
|
||||||
def test_destroy_noflag(self):
|
def test_destroy_undefines_no_undefine_flags(self):
|
||||||
"""Ensure destroy calls virDomain.undefine
|
|
||||||
if mock.undefineFlags raises an error"""
|
|
||||||
mock = self.mox.CreateMock(libvirt.virDomain)
|
mock = self.mox.CreateMock(libvirt.virDomain)
|
||||||
mock.destroy()
|
mock.destroy()
|
||||||
mock.undefineFlags(1).AndRaise(libvirt.libvirtError('Err'))
|
mock.undefineFlags(1).AndRaise(libvirt.libvirtError('Err'))
|
||||||
@@ -2209,6 +2206,51 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||||
conn.destroy(instance, [])
|
conn.destroy(instance, [])
|
||||||
|
|
||||||
|
def test_destroy_undefines_no_attribute_with_managed_save(self):
|
||||||
|
mock = self.mox.CreateMock(libvirt.virDomain)
|
||||||
|
mock.destroy()
|
||||||
|
mock.undefineFlags(1).AndRaise(AttributeError())
|
||||||
|
mock.hasManagedSaveImage(0).AndReturn(True)
|
||||||
|
mock.managedSaveRemove(0)
|
||||||
|
mock.undefine()
|
||||||
|
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
def fake_lookup_by_name(instance_name):
|
||||||
|
return mock
|
||||||
|
|
||||||
|
def fake_get_info(instance_name):
|
||||||
|
return {'state': power_state.SHUTDOWN}
|
||||||
|
|
||||||
|
conn = libvirt_driver.LibvirtDriver(False)
|
||||||
|
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||||
|
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||||
|
instance = {"name": "instancename", "id": "instanceid",
|
||||||
|
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||||
|
conn.destroy(instance, [])
|
||||||
|
|
||||||
|
def test_destroy_undefines_no_attribute_no_managed_save(self):
|
||||||
|
mock = self.mox.CreateMock(libvirt.virDomain)
|
||||||
|
mock.destroy()
|
||||||
|
mock.undefineFlags(1).AndRaise(AttributeError())
|
||||||
|
mock.hasManagedSaveImage(0).AndRaise(AttributeError())
|
||||||
|
mock.undefine()
|
||||||
|
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
def fake_lookup_by_name(instance_name):
|
||||||
|
return mock
|
||||||
|
|
||||||
|
def fake_get_info(instance_name):
|
||||||
|
return {'state': power_state.SHUTDOWN}
|
||||||
|
|
||||||
|
conn = libvirt_driver.LibvirtDriver(False)
|
||||||
|
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
|
||||||
|
self.stubs.Set(conn, 'get_info', fake_get_info)
|
||||||
|
instance = {"name": "instancename", "id": "instanceid",
|
||||||
|
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
|
||||||
|
conn.destroy(instance, [])
|
||||||
|
|
||||||
def test_private_destroy(self):
|
def test_private_destroy(self):
|
||||||
"""Ensure Instance not found skips undefine"""
|
"""Ensure Instance not found skips undefine"""
|
||||||
mock = self.mox.CreateMock(libvirt.virDomain)
|
mock = self.mox.CreateMock(libvirt.virDomain)
|
||||||
|
|||||||
Reference in New Issue
Block a user