libvirt: refactor _create_domain_setup_lxc to use Image.get_model
Instead of trying to figure out what the proper ImageModel is for the instance's image, just use the get_model function. The resulting ImageModel will actually represent the proper ImageModel for the instance, and downstream mounting functions will be able to make intelligent decisions on how to mount the instance's disks. It is not possible to use get_model for an instance booted from volume, but we can still use LocalBlockImage in it's case because it is simply exposed as a block device. Partial-Bug: #1287754 Change-Id: I0f4456731c9d6f64affbf6924f4a7a4c34df4fd1
This commit is contained in:
parent
c49093866e
commit
faeae32a7e
|
@ -7797,8 +7797,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
group='libvirt')
|
||||
|
||||
def check_setup_container(image, container_dir=None):
|
||||
self.assertIsInstance(image, imgmodel.LocalBlockImage)
|
||||
self.assertEqual(image.path, '/dev/path/to/dev')
|
||||
self.assertEqual(image.format, imgmodel.FORMAT_QCOW2)
|
||||
return '/dev/nbd1'
|
||||
|
||||
bdm = {
|
||||
|
@ -7856,7 +7856,6 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
instance_ref['root_device_name'] = '/dev/sda'
|
||||
instance_ref['ephemeral_gb'] = 0
|
||||
instance_ref['uuid'] = uuidutils.generate_uuid()
|
||||
instance_ref['system_metadata']['image_disk_format'] = 'qcow2'
|
||||
inst_obj = objects.Instance(**instance_ref)
|
||||
image_meta = {}
|
||||
|
||||
|
@ -10684,12 +10683,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
drvr.image_backend.image.assert_has_calls([mock.call(mock_instance,
|
||||
'disk')])
|
||||
|
||||
fmt = imgmodel.FORMAT_RAW
|
||||
if CONF.use_cow_images:
|
||||
fmt = imgmodel.FORMAT_QCOW2
|
||||
|
||||
setup_container_call = mock.call(
|
||||
imgmodel.LocalFileImage('/tmp/test.img', fmt),
|
||||
mock_image.get_model(),
|
||||
container_dir='/tmp/rootfs')
|
||||
mock_setup_container.assert_has_calls([setup_container_call])
|
||||
mock_get_info.assert_has_calls([mock.call(mock_instance)])
|
||||
|
@ -10758,12 +10753,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
drvr.image_backend.image.assert_has_calls([mock.call(mock_instance,
|
||||
'disk')])
|
||||
|
||||
fmt = imgmodel.FORMAT_RAW
|
||||
if CONF.use_cow_images:
|
||||
fmt = imgmodel.FORMAT_QCOW2
|
||||
|
||||
setup_container_call = mock.call(
|
||||
imgmodel.LocalFileImage('/tmp/test.img', fmt),
|
||||
mock_image.get_model(),
|
||||
container_dir='/tmp/rootfs')
|
||||
mock_setup_container.assert_has_calls([setup_container_call])
|
||||
mock_get_info.assert_has_calls([mock.call(mock_instance)])
|
||||
|
@ -10812,12 +10803,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
drvr.image_backend.image.assert_has_calls([mock.call(mock_instance,
|
||||
'disk')])
|
||||
|
||||
fmt = imgmodel.FORMAT_RAW
|
||||
if CONF.use_cow_images:
|
||||
fmt = imgmodel.FORMAT_QCOW2
|
||||
|
||||
setup_container_call = mock.call(
|
||||
imgmodel.LocalFileImage('/tmp/test.img', fmt),
|
||||
mock_image.get_model(),
|
||||
container_dir='/tmp/rootfs')
|
||||
mock_setup_container.assert_has_calls([setup_container_call])
|
||||
mock_get_info.assert_has_calls([mock.call(mock_instance)])
|
||||
|
|
|
@ -4422,20 +4422,18 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
self._connect_volume(root_disk['connection_info'], disk_info)
|
||||
disk_path = root_disk['connection_info']['data']['device_path']
|
||||
|
||||
# Get the system metadata from the instance
|
||||
use_cow = instance.system_metadata['image_disk_format'] == 'qcow2'
|
||||
# NOTE(apmelton) - Even though the instance is being booted from a
|
||||
# cinder volume, it is still presented as a local block device.
|
||||
# LocalBlockImage is used here to indicate that the instance's
|
||||
# disk is backed by a local block device.
|
||||
image_model = imgmodel.LocalBlockImage(disk_path)
|
||||
else:
|
||||
image = self.image_backend.image(instance, 'disk')
|
||||
disk_path = image.path
|
||||
use_cow = CONF.use_cow_images
|
||||
image_model = image.get_model(self._conn)
|
||||
|
||||
container_dir = os.path.join(inst_path, 'rootfs')
|
||||
fileutils.ensure_tree(container_dir)
|
||||
fmt = imgmodel.FORMAT_RAW
|
||||
if use_cow:
|
||||
fmt = imgmodel.FORMAT_QCOW2
|
||||
image = imgmodel.LocalFileImage(disk_path, fmt)
|
||||
rootfs_dev = disk.setup_container(image,
|
||||
rootfs_dev = disk.setup_container(image_model,
|
||||
container_dir=container_dir)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue