Add helper method for checking if VM is booting from a volume
Add a _is_booted_from_value method which determines whether the disk mapping indicates that the VM is booting from a volume Update the _create_image method to use this helper API. Related-Bug: #1271528 Change-Id: Iaa92f84ad3de9e84ba49bb255add043f3c8e4c8f
This commit is contained in:
parent
e7e0e955c0
commit
b1a8b39bfb
|
@ -8284,6 +8284,17 @@ class LibvirtDriverTestCase(test.TestCase):
|
|||
self.assertEqual(['/dev/vols/fake-uuid_foo',
|
||||
'/dev/vols/instance-00000001_bar'], disks)
|
||||
|
||||
def test_is_booted_from_volume(self):
|
||||
func = libvirt_driver.LibvirtDriver._is_booted_from_volume
|
||||
instance, disk_mapping = {}, {}
|
||||
|
||||
self.assertTrue(func(instance, disk_mapping))
|
||||
disk_mapping['disk'] = 'map'
|
||||
self.assertTrue(func(instance, disk_mapping))
|
||||
|
||||
instance['image_ref'] = 'uuid'
|
||||
self.assertFalse(func(instance, disk_mapping))
|
||||
|
||||
|
||||
class LibvirtVolumeUsageTestCase(test.TestCase):
|
||||
"""Test for LibvirtDriver.get_all_volume_usage."""
|
||||
|
|
|
@ -2454,6 +2454,16 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
if os.path.exists(disk_config):
|
||||
libvirt_utils.chown(disk_config, os.getuid())
|
||||
|
||||
@staticmethod
|
||||
def _is_booted_from_volume(instance, disk_mapping):
|
||||
"""Determines whether the VM is booting from volume
|
||||
|
||||
Determines whether the disk mapping indicates that the VM
|
||||
is booting from a volume.
|
||||
"""
|
||||
return ((not bool(instance.get('image_ref')))
|
||||
or 'disk' not in disk_mapping)
|
||||
|
||||
def _create_image(self, context, instance,
|
||||
disk_mapping, suffix='',
|
||||
disk_images=None, network_info=None,
|
||||
|
@ -2462,10 +2472,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
if not suffix:
|
||||
suffix = ''
|
||||
|
||||
booted_from_volume = (
|
||||
(not bool(instance.get('image_ref')))
|
||||
or 'disk' not in disk_mapping
|
||||
)
|
||||
booted_from_volume = self._is_booted_from_volume(
|
||||
instance, disk_mapping)
|
||||
|
||||
def image(fname, image_type=CONF.libvirt.images_type):
|
||||
return self.image_backend.image(instance,
|
||||
|
|
Loading…
Reference in New Issue