summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorDerek Higgins <derekh@redhat.com>2012-09-04 11:50:36 +0100
committerDerek Higgins <derekh@redhat.com>2012-09-05 23:36:51 +0100
commitaeacea16a30f85dfb307803a4b46a602cabc8eb5 (patch)
tree35819f424cae7ec550014bd3470f05cd034472b5 /nova/tests
parent06dec8ec1e518c33d00df2e88ffea92cf236a8dc (diff)
Fixing call to hasManagedSaveImage
Fixes bug #1044090 hasManagedSaveImage is not implmented in the LXC libvirt driver, resulting in the following error when a vm is deleted "Error from libvirt during saved instance removal. Code=3 Error=this function is not supported by the connection driver: virDomainHasManagedSaveImage" This commit replaces the use of hasManagedSaveImage, managedSaveRemove and undefine with undefineFlags which does the work of all 3 calls and is implemented in versions of libvirt > 0.9.4. We also revert back to calling undefine if undefineFlags raises an error. Change-Id: Ib8d451aeff7767f835c3c1aab99ee4ab5e299852
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/fakelibvirt.py7
-rw-r--r--nova/tests/test_libvirt.py29
2 files changed, 32 insertions, 4 deletions
diff --git a/nova/tests/fakelibvirt.py b/nova/tests/fakelibvirt.py
index 4e337aa51..2dfc30970 100644
--- a/nova/tests/fakelibvirt.py
+++ b/nova/tests/fakelibvirt.py
@@ -69,6 +69,7 @@ VIR_DOMAIN_SHUTOFF = 5
VIR_DOMAIN_CRASHED = 6
VIR_DOMAIN_XML_SECURE = 1
+VIR_DOMAIN_UNDEFINE_MANAGED_SAVE = 1
VIR_CPU_COMPARE_ERROR = -1
VIR_CPU_COMPARE_INCOMPATIBLE = 0
@@ -276,6 +277,12 @@ class Domain(object):
def undefine(self):
self._connection._undefine(self)
+ def undefineFlags(self, flags):
+ self.undefine()
+ if flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE:
+ if self.hasManagedSaveImage(0):
+ self.managedSaveRemove()
+
def destroy(self):
self._state = VIR_DOMAIN_SHUTOFF
self._connection._mark_not_running(self)
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index e652e6d0b..a1b99388d 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2160,12 +2160,33 @@ class LibvirtConnTestCase(test.TestCase):
instance = db.instance_create(self.context, self.test_instance)
conn.destroy(instance, {})
- def test_destroy_saved(self):
- """Ensure destroy calls managedSaveRemove for saved instance"""
+ def test_destroy(self):
+ """Ensure destroy calls virDomain.undefineFlags"""
+ mock = self.mox.CreateMock(libvirt.virDomain)
+ mock.destroy()
+ mock.undefineFlags(1).AndReturn(1)
+
+ 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_noflag(self):
+ """Ensure destroy calls virDomain.undefine
+ if mock.undefineFlags raises an error"""
mock = self.mox.CreateMock(libvirt.virDomain)
mock.destroy()
- mock.hasManagedSaveImage(0).AndReturn(1)
- mock.managedSaveRemove(0)
+ mock.undefineFlags(1).AndRaise(libvirt.libvirtError('Err'))
mock.undefine()
self.mox.ReplayAll()