From dce9bc03c4753b8acd5ce722c1adcfee7540af0e Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Wed, 12 Feb 2020 19:45:12 +0000 Subject: [PATCH] images: Remove Libvirt specific configurable use from qemu_img_info This change addresses an old TODO in the images module by dropping the use of a Libvirt specific configurable from the qemu_img_info function. We can identify RBD based volumes by checking for 'rbd:' at the start of the path provided to the function instead of using the configurable. Change-Id: Ife9e67d5c71f4cca825dff713f54ec955508f6e6 --- nova/tests/unit/virt/test_images.py | 9 +++++++++ nova/virt/images.py | 8 ++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nova/tests/unit/virt/test_images.py b/nova/tests/unit/virt/test_images.py index 9dacc828addd..296aa24b09d7 100644 --- a/nova/tests/unit/virt/test_images.py +++ b/nova/tests/unit/virt/test_images.py @@ -49,6 +49,15 @@ class QemuTestCase(test.NoDBTestCase): self.assertTrue(image_info) self.assertTrue(str(image_info)) + @mock.patch('oslo_concurrency.processutils.execute', + return_value=('stdout', None)) + def test_qemu_info_with_rbd_path(self, utils_execute): + # Assert that the use of a RBD URI as the path doesn't raise + # exception.DiskNotFound + image_info = images.qemu_img_info('rbd:volume/pool') + self.assertTrue(image_info) + self.assertTrue(str(image_info)) + @mock.patch.object(compute_utils, 'disk_ops_semaphore') @mock.patch('nova.privsep.utils.supports_direct_io', return_value=True) @mock.patch.object(processutils, 'execute', diff --git a/nova/virt/images.py b/nova/virt/images.py index 85ce6ce2fbe6..54db59df5ccd 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -45,9 +45,7 @@ IMAGE_API = glance.API() def qemu_img_info(path, format=None, output_format=None): """Return an object containing the parsed output from qemu-img info.""" - # TODO(mikal): this code should not be referring to a libvirt specific - # flag. - if not os.path.exists(path) and CONF.libvirt.images_type != 'rbd': + if not os.path.exists(path) and not path.startswith('rbd:'): raise exception.DiskNotFound(location=path) info = nova.privsep.qemu.unprivileged_qemu_img_info( @@ -61,9 +59,7 @@ def qemu_img_info(path, format=None, output_format=None): def privileged_qemu_img_info(path, format=None, output_format=None): """Return an object containing the parsed output from qemu-img info.""" - # TODO(mikal): this code should not be referring to a libvirt specific - # flag. - if not os.path.exists(path) and CONF.libvirt.images_type != 'rbd': + if not os.path.exists(path) and not path.startswith('rbd:'): raise exception.DiskNotFound(location=path) info = nova.privsep.qemu.privileged_qemu_img_info(