Merge "libvirt: Skip fetching the virtual size of block devices" into stable/ocata

This commit is contained in:
Zuul 2018-06-07 03:21:10 +00:00 committed by Gerrit Code Review
commit 7af016cd02
2 changed files with 57 additions and 3 deletions

View File

@ -12982,6 +12982,52 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.assertRaises(exception.DiskNotFound,
drvr._get_disk_over_committed_size_total)
@mock.patch('nova.virt.libvirt.storage.lvm.get_volume_size')
@mock.patch('nova.virt.disk.api.get_disk_size',
new_callable=mock.NonCallableMock)
def test_get_instance_disk_info_block_devices(self,
mock_disk_api, mock_get_volume_size):
"""Test that for block devices the actual and virtual sizes are
reported as the same and that the disk_api is not used.
"""
c = context.get_admin_context()
instance = objects.Instance(root_device_name='/dev/vda',
**self.test_instance)
bdms = objects.BlockDeviceMappingList(objects=[
fake_block_device.fake_bdm_object(c, {
'device_name': '/dev/mapper/vg-lv',
'source_type': 'image',
'destination_type': 'local'
}),
])
block_device_info = driver.get_block_device_info(instance, bdms)
config = vconfig.LibvirtConfigGuest()
config.virt_type = 'kvm'
disk_config = vconfig.LibvirtConfigGuestDisk()
disk_config.driver_name = 'qemu'
disk_config.driver_format = 'raw'
disk_config.driver_cache = 'none'
disk_config.source_type = 'block'
disk_config.source_path = '/dev/sda'
disk_config.bus = 'scsi'
disk_config.target_dev = '/dev/xda'
disk_config.target_bus = 'scsi'
disk_config.serial = uuids.serial
config.devices.append(disk_config)
mock_get_volume_size.return_value = mock.sentinel.volume_size
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
disk_info = drvr._get_instance_disk_info(instance.name,
config.to_xml(), block_device_info=block_device_info)
mock_get_volume_size.assert_called_once_with('/dev/sda')
self.assertEqual(disk_info[0]['disk_size'],
disk_info[0]['virt_disk_size'])
def test_cpu_info(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)

View File

@ -7186,17 +7186,25 @@ class LibvirtDriver(driver.ComputeDriver):
dk_size += os.path.getsize(fp)
else:
dk_size = disk_api.get_allocated_disk_size(path)
# NOTE(lyarwood): Fetch the virtual size for all file disks.
virt_size = disk_api.get_disk_size(path)
elif disk_type == 'block' and block_device_info:
# FIXME(lyarwood): There's no reason to use a separate call
# here, once disk_api uses privsep this should be removed along
# with the surrounding conditionals to simplify this mess.
dk_size = lvm.get_volume_size(path)
# NOTE(lyarwood): As above, we should be using disk_api to
# fetch the virt-size but can't as it currently runs qemu-img
# as an unprivileged user, causing a failure for block devices.
virt_size = dk_size
else:
LOG.debug('skipping disk %(path)s (%(target)s) - unable to '
'determine if volume',
{'path': path, 'target': target})
continue
# NOTE(lyarwood): Always fetch the virtual size for all disk types.
virt_size = disk_api.get_disk_size(path)
disk_type = driver_nodes[cnt].get('type')
if disk_type in ("qcow2", "ploop"):