summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-03-07 15:54:07 +0100
committerNikola Dipanov <ndipanov@redhat.com>2013-03-09 12:23:56 +0100
commit3133096f2bf2c8de04c70c3f3209d727a4c8cfb3 (patch)
tree1e5d6d1a8b994eba329c0f4cde4fc87896c5b324 /nova/tests
parent7477bbfdad9cfa6383a1ef1824f630a2c9938212 (diff)
Libvirt driver create images even without meta
This patch allows the libvirt driver to call _create_image and create instance directory and other needed images even when there is no image metadata specified. As an added bonus, this patch refactors the code of _create_image method a bit to make it more clear to the reader when some of the images will and will not be created, especially with regard to booting from volume. Fixes bug: 1124441 Fixes bug: 1131913 Fixes bug: 1123274 blueprint: improve-boot-from-volume Change-Id: I5a028dc0585876d35be4fb86df3a423d89e054ee
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_libvirt.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 351c6b7dd..55b6aaec4 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2578,7 +2578,7 @@ class LibvirtConnTestCase(test.TestCase):
self.stubs.Set(conn, 'get_info', fake_get_info)
conn.spawn(self.context, instance, None, [], None)
- self.assertFalse(self.create_image_called)
+ self.assertTrue(self.create_image_called)
conn.spawn(self.context,
instance,
@@ -2587,6 +2587,59 @@ class LibvirtConnTestCase(test.TestCase):
None)
self.assertTrue(self.create_image_called)
+ def test_spawn_from_volume_calls_cache(self):
+ self.cache_called_for_disk = False
+
+ def fake_none(*args, **kwargs):
+ return
+
+ def fake_cache(*args, **kwargs):
+ if kwargs.get('image_id') == 'my_fake_image':
+ self.cache_called_for_disk = True
+
+ def fake_get_info(instance):
+ return {'state': power_state.RUNNING}
+
+ conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
+ self.stubs.Set(conn, 'to_xml', fake_none)
+
+ self.stubs.Set(imagebackend.Image, 'cache', fake_cache)
+ self.stubs.Set(conn, '_create_domain_and_network', fake_none)
+ self.stubs.Set(conn, 'get_info', fake_get_info)
+
+ block_device_info = {'root_device_name': '/dev/vda',
+ 'block_device_mapping': [
+ {'mount_device': 'vda'}]}
+
+ # Volume-backed instance created without image
+ instance_ref = self.test_instance
+ instance_ref['image_ref'] = ''
+ instance_ref['root_device_name'] = '/dev/vda'
+ instance = db.instance_create(self.context, instance_ref)
+
+ conn.spawn(self.context, instance, None, [], None,
+ block_device_info=block_device_info)
+ self.assertFalse(self.cache_called_for_disk)
+ db.instance_destroy(self.context, instance['uuid'])
+
+ # Booted from volume but with placeholder image
+ instance_ref = self.test_instance
+ instance_ref['image_ref'] = 'my_fake_image'
+ instance_ref['root_device_name'] = '/dev/vda'
+ instance = db.instance_create(self.context, instance_ref)
+
+ conn.spawn(self.context, instance, None, [], None,
+ block_device_info=block_device_info)
+ self.assertFalse(self.cache_called_for_disk)
+ db.instance_destroy(self.context, instance['uuid'])
+
+ # Booted from an image
+ instance_ref['image_ref'] = 'my_fake_image'
+ instance = db.instance_create(self.context, instance_ref)
+ conn.spawn(self.context, instance, None, [], None)
+ self.assertTrue(self.cache_called_for_disk)
+ db.instance_destroy(self.context, instance['uuid'])
+
def test_create_image_plain(self):
gotFiles = []