summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-09-14 20:49:49 +0000
committerGerrit Code Review <review@openstack.org>2012-09-14 20:49:49 +0000
commitd41b93267f2c0e31fa94c8ea185864b631142df4 (patch)
treee92c956ed1d62c61c6de8ffebe62e58fbd1b3650 /nova/tests
parent0c47b74b84a274a7380ace9596b8b1fce62576df (diff)
parentc6ddff821fef8d9edfc7498dbe19d5794d9adc8f (diff)
Merge "Allow older versions of libvirt to delete vms"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_libvirt.py52
1 files changed, 47 insertions, 5 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index d0b89f78f..060a8445a 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2165,8 +2165,7 @@ class LibvirtConnTestCase(test.TestCase):
instance = db.instance_create(self.context, self.test_instance)
conn.destroy(instance, {})
- def test_destroy(self):
- """Ensure destroy calls virDomain.undefineFlags"""
+ def test_destroy_undefines(self):
mock = self.mox.CreateMock(libvirt.virDomain)
mock.destroy()
mock.undefineFlags(1).AndReturn(1)
@@ -2186,9 +2185,7 @@ class LibvirtConnTestCase(test.TestCase):
"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"""
+ def test_destroy_undefines_no_undefine_flags(self):
mock = self.mox.CreateMock(libvirt.virDomain)
mock.destroy()
mock.undefineFlags(1).AndRaise(libvirt.libvirtError('Err'))
@@ -2209,6 +2206,51 @@ class LibvirtConnTestCase(test.TestCase):
"uuid": "875a8070-d0b9-4949-8b31-104d125c9a64"}
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):
"""Ensure Instance not found skips undefine"""
mock = self.mox.CreateMock(libvirt.virDomain)