Added unit tests for ensuring VDI are cleaned up upon spawn failures
This commit is contained in:
@@ -251,6 +251,16 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
# Check that the VM is running according to XenAPI.
|
||||
self.assertEquals(vm['power_state'], 'Running')
|
||||
|
||||
def _check_no_unbound_vdi(self):
|
||||
url = FLAGS.xenapi_connection_url
|
||||
username = FLAGS.xenapi_connection_username
|
||||
password = FLAGS.xenapi_connection_password
|
||||
session = xenapi_conn.XenAPISession(url, username, password)
|
||||
vdi_refs = session.call_xenapi('VDI.get_all')
|
||||
for vdi_ref in vdi_refs:
|
||||
vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref)
|
||||
self.assertEquals(vdi_rec['VBDs'], {})
|
||||
|
||||
def _test_spawn(self, image_id, kernel_id, ramdisk_id,
|
||||
instance_type="m1.large"):
|
||||
stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests)
|
||||
@@ -275,6 +285,26 @@ class XenAPIVMTestCase(test.TestCase):
|
||||
self._test_spawn,
|
||||
1, 2, 3, "m1.xlarge")
|
||||
|
||||
def test_spawn_fail_cleanup_1(self):
|
||||
"""Simulates an error while downloading image
|
||||
Verifies VDI create are properly cleaned up"""
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
stubs.stubout_fetch_image_glance_disk(self.stubs)
|
||||
self.assertRaises(Exception,
|
||||
self._test_spawn, 1, 2, 3)
|
||||
#ensure there is no VDI without a VBD
|
||||
self._check_no_unbound_vdi()
|
||||
|
||||
def test_spawn_fail_cleanup_2(self):
|
||||
"""Simulates an error while creating VM record.
|
||||
Verifies VDI create are properly cleaned up"""
|
||||
FLAGS.xenapi_image_service = 'glance'
|
||||
stubs.stubout_create_vm(self.stubs)
|
||||
self.assertRaises(Exception,
|
||||
self._test_spawn, 1, 2, 3)
|
||||
#ensure there is no VDI without a VBD
|
||||
self._check_no_unbound_vdi()
|
||||
|
||||
def test_spawn_raw_objectstore(self):
|
||||
FLAGS.xenapi_image_service = 'objectstore'
|
||||
self._test_spawn(1, None, None)
|
||||
|
||||
@@ -136,6 +136,29 @@ def stubout_is_vdi_pv(stubs):
|
||||
stubs.Set(vm_utils, '_is_vdi_pv', f)
|
||||
|
||||
|
||||
def stubout_lookup_image(stubs):
|
||||
"""Simulates a failure in lookup image"""
|
||||
def f(_1, _2, _3, _4):
|
||||
raise Exception("Test Exception raised by fake lookup_image")
|
||||
stubs.Set(vm_utils, 'lookup_image', f)
|
||||
|
||||
|
||||
def stubout_fetch_image_glance_disk(stubs):
|
||||
"""Simulates a failure in fetch image_glance_disk"""
|
||||
def f(_1, _2, _3, _4, _5, _6):
|
||||
raise Exception("Test Exception raised by " +
|
||||
"fake fetch_image_glance_disk")
|
||||
stubs.Set(vm_utils.VMHelper, '_fetch_image_glance_disk', f)
|
||||
|
||||
|
||||
def stubout_create_vm(stubs):
|
||||
"""Simulates a failure in create_vm"""
|
||||
def f(_1, _2, _3, _4, _5, _6):
|
||||
raise Exception("Test Exception raised by " +
|
||||
"fake create_vm")
|
||||
stubs.Set(vm_utils.VMHelper, 'create_vm', f)
|
||||
|
||||
|
||||
class FakeSessionForVMTests(fake.SessionBase):
|
||||
""" Stubs out a XenAPISession for VM tests """
|
||||
def __init__(self, uri):
|
||||
|
||||
Reference in New Issue
Block a user