diff options
author | Lee Yarwood <lyarwood@redhat.com> | 2020-02-05 12:36:40 +0000 |
---|---|---|
committer | Lee Yarwood <lyarwood@redhat.com> | 2020-03-16 09:45:31 +0000 |
commit | 03d6eb500f85a417f84a7bf4a9f4ceb275c9a67e (patch) | |
tree | b46243948ae660066840be465adc336ab345f092 /nova/tests/unit/virt/libvirt/test_utils.py | |
parent | e483ca1cd9a5db5856f87fc69ca07c42d2be5def (diff) | |
download | nova-03d6eb500f85a417f84a7bf4a9f4ceb275c9a67e.tar.gz |
images: Move qemu-img info calls into privsep
This is mostly code motion from the nova.virt.images module into privsep
to allow for both privileged and unprivileged calls to be made.
A privileged_qemu_img_info function is introduced allowing QEMU to
access devices requiring root privileges, such as host block devices.
Change-Id: I5ac03f923d9d181d22d44d8ec8fbc31eb0c3999e
Diffstat (limited to 'nova/tests/unit/virt/libvirt/test_utils.py')
-rw-r--r-- | nova/tests/unit/virt/libvirt/test_utils.py | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_utils.py b/nova/tests/unit/virt/libvirt/test_utils.py index 2888078cde..1c3b3df0ac 100644 --- a/nova/tests/unit/virt/libvirt/test_utils.py +++ b/nova/tests/unit/virt/libvirt/test_utils.py @@ -32,6 +32,7 @@ from nova import exception from nova import objects from nova.objects import fields as obj_fields import nova.privsep.fs +import nova.privsep.qemu from nova import test from nova.tests import fixtures as nova_fixtures from nova.tests.unit import fake_instance @@ -107,18 +108,18 @@ disk size: 96K }) mock_execute.return_value = (output, '') d_backing = libvirt_utils.get_disk_backing_file(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertIsNone(d_backing) def _test_disk_size(self, mock_execute, path, expected_size): d_size = libvirt_utils.get_disk_size(path) self.assertEqual(expected_size, d_size) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) @mock.patch('os.path.exists', return_value=True) def test_disk_size(self, mock_exists): @@ -163,9 +164,9 @@ blah BLAH: bb """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('raw', image_info.file_format) @@ -176,7 +177,7 @@ blah BLAH: bb @mock.patch('os.path.exists', return_value=True) @mock.patch('oslo_concurrency.processutils.execute') def test_qemu_info_canon_qemu_2_10(self, mock_execute, mock_exists): - images.QEMU_VERSION = images.QEMU_VERSION_REQ_SHARED + images.QEMU_VERSION = nova.privsep.qemu.QEMU_VERSION_REQ_SHARED path = "disk.config" example_output = """image: disk.config file format: raw @@ -187,10 +188,9 @@ blah BLAH: bb """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - '--force-share', - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + '--force-share', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('raw', image_info.file_format) @@ -211,9 +211,9 @@ backing file: /var/lib/nova/a328c7998805951a_2 """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('qcow2', image_info.file_format) @@ -235,10 +235,10 @@ disk size: 706M """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', - os.path.join(path, 'root.hds'), - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', + os.path.join(path, 'root.hds'), + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_isdir.assert_called_once_with(path) self.assertEqual(2, mock_exists.call_count) self.assertEqual(path, mock_exists.call_args_list[0][0][0]) @@ -266,9 +266,9 @@ backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2) """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('raw', image_info.file_format) @@ -295,9 +295,9 @@ junk stuff: bbb """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('raw', image_info.file_format) @@ -320,9 +320,9 @@ ID TAG VM SIZE DATE VM CLOCK """ mock_execute.return_value = (example_output, '') image_info = images.qemu_img_info(path) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) self.assertEqual('disk.config', image_info.image) self.assertEqual('raw', image_info.file_format) @@ -477,9 +477,9 @@ disk size: 4.4M """ mock_execute.return_value = (example_output, '') self.assertEqual(4592640, disk.get_disk_size('/some/path')) - mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path, - prlimit=images.QEMU_IMG_LIMITS) + mock_execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path, + prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS) mock_exists.assert_called_once_with(path) def test_copy_image(self): |