summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2020-02-27 11:47:41 +0000
committerStephen Finucane <stephenfin@redhat.com>2020-04-01 15:29:02 +0100
commitbd9bea5690e14b252bd13921268bf2e976351c2e (patch)
tree2fa0610ba16c70cf1f1ca2ed3b0429ce2c4804f7
parentdce9bc03c4753b8acd5ce722c1adcfee7540af0e (diff)
downloadnova-bd9bea5690e14b252bd13921268bf2e976351c2e.tar.gz
libvirt: Remove QEMU_VERSION_REQ_SHARED
The updated minimum required libvirt (4.0.0) and QEMU (2.11) for "Ussuri" satisfy the version requirements; this was done in Change-Id: Ia18e9be4d (22c1916b49 — libvirt: Bump MIN_{LIBVIRT,QEMU}_VERSION for "Ussuri", 2019-11-19). Drop the version constant QEMU_VERSION_REQ_SHARED and now-needless compatibility code; adjust/remove tests. Change-Id: If878a023c69f25a9ea45b7de2ff9eb1976aaeb8c Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
-rw-r--r--nova/privsep/qemu.py21
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py18
-rw-r--r--nova/tests/unit/virt/libvirt/test_utils.py43
-rw-r--r--nova/virt/images.py10
-rw-r--r--nova/virt/libvirt/driver.py6
5 files changed, 20 insertions, 78 deletions
diff --git a/nova/privsep/qemu.py b/nova/privsep/qemu.py
index 55bdfe2a77..2b2acfd3e8 100644
--- a/nova/privsep/qemu.py
+++ b/nova/privsep/qemu.py
@@ -16,7 +16,6 @@
Helpers for qemu tasks.
"""
-import operator
import os
from oslo_concurrency import processutils
@@ -33,8 +32,6 @@ QEMU_IMG_LIMITS = processutils.ProcessLimits(
cpu_time=30,
address_space=1 * units.Gi)
-QEMU_VERSION_REQ_SHARED = 2010000
-
@nova.privsep.sys_admin_pctxt.entrypoint
def convert_image(source, dest, in_format, out_format, instances_path,
@@ -85,20 +82,17 @@ def unprivileged_convert_image(source, dest, in_format, out_format,
@nova.privsep.sys_admin_pctxt.entrypoint
-def privileged_qemu_img_info(path, format=None, qemu_version=None,
- output_format=None):
+def privileged_qemu_img_info(path, format=None, output_format=None):
"""Return an oject containing the parsed output from qemu-img info
This is a privileged call to qemu-img info using the sys_admin_pctxt
entrypoint allowing host block devices etc to be accessed.
"""
return unprivileged_qemu_img_info(
- path, format=format, qemu_version=qemu_version,
- output_format=output_format)
+ path, format=format, output_format=output_format)
-def unprivileged_qemu_img_info(path, format=None, qemu_version=None,
- output_format=None):
+def unprivileged_qemu_img_info(path, format=None, output_format=None):
"""Return an object containing the parsed output from qemu-img info."""
try:
# The following check is about ploop images that reside within
@@ -107,15 +101,14 @@ def unprivileged_qemu_img_info(path, format=None, qemu_version=None,
os.path.exists(os.path.join(path, "DiskDescriptor.xml"))):
path = os.path.join(path, "root.hds")
- cmd = ('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path)
+ cmd = (
+ 'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
+ '--force-share',
+ )
if format is not None:
cmd = cmd + ('-f', format)
if output_format is not None:
cmd = cmd + ("--output=%s" % (output_format),)
- # Check to see if the qemu version is >= 2.10 because if so, we need
- # to add the --force-share flag.
- if qemu_version and operator.ge(qemu_version, QEMU_VERSION_REQ_SHARED):
- cmd = cmd + ('--force-share',)
out, err = processutils.execute(*cmd, prlimit=QEMU_IMG_LIMITS)
except processutils.ProcessExecutionError as exp:
if exp.exit_code == -9:
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index bb16260c25..671b65f763 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -105,7 +105,6 @@ from nova.virt import driver
from nova.virt import fake
from nova.virt import hardware
from nova.virt.image import model as imgmodel
-from nova.virt import images
from nova.virt.libvirt import blockinfo
from nova.virt.libvirt import config as vconfig
from nova.virt.libvirt import designer
@@ -1310,23 +1309,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
break
self.assertFalse(version_arg_found)
- # NOTE(sdague): python2.7 and python3.5 have different behaviors
- # when it comes to comparing against the sentinel, so
- # has_min_version is needed to pass python3.5.
- @mock.patch.object(nova.virt.libvirt.host.Host, "has_min_version",
- return_value=True)
- @mock.patch.object(fakelibvirt.Connection, 'getVersion',
- return_value=mock.sentinel.qemu_version)
- def test_qemu_image_version(self, mock_get_libversion, min_ver):
- """Test that init_host sets qemu image version
-
- A sentinel is used here so that we aren't chasing this value
- against minimums that get raised over time.
- """
- drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
- drvr.init_host("dummyhost")
- self.assertEqual(images.QEMU_VERSION, mock.sentinel.qemu_version)
-
@mock.patch.object(fields.Architecture, "from_host",
return_value=fields.Architecture.PPC64)
def test_min_version_ppc_ok(self, mock_arch):
diff --git a/nova/tests/unit/virt/libvirt/test_utils.py b/nova/tests/unit/virt/libvirt/test_utils.py
index 24a7f375f6..97b1386145 100644
--- a/nova/tests/unit/virt/libvirt/test_utils.py
+++ b/nova/tests/unit/virt/libvirt/test_utils.py
@@ -110,7 +110,7 @@ disk size: 96K
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=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--force-share', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
mock_exists.assert_called_once_with(path)
self.assertIsNone(d_backing)
@@ -119,7 +119,7 @@ disk size: 96K
self.assertEqual(expected_size, d_size)
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--force-share', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
@mock.patch('os.path.exists', return_value=True)
def test_disk_size(self, mock_exists):
@@ -167,29 +167,7 @@ disk size: 96K
image_info = images.qemu_img_info(path, output_format='json')
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- '--output=json', 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)
- self.assertEqual(67108864, image_info.virtual_size)
- self.assertEqual(98304, image_info.disk_size)
- self.assertEqual(65536, image_info.cluster_size)
-
- @mock.patch('os.path.exists', return_value=True)
- @mock.patch('oslo_concurrency.processutils.execute')
- def test_qemu_info_canon(self, mock_execute, mock_exists):
- path = "disk.config"
- example_output = """image: disk.config
-file format: raw
-virtual size: 64M (67108864 bytes)
-cluster_size: 65536
-disk size: 96K
-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', '--output=json',
prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
mock_exists.assert_called_once_with(path)
self.assertEqual('disk.config', image_info.image)
@@ -200,8 +178,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 = nova.privsep.qemu.QEMU_VERSION_REQ_SHARED
+ def test_qemu_info_canon(self, mock_execute, mock_exists):
path = "disk.config"
example_output = """image: disk.config
file format: raw
@@ -237,7 +214,7 @@ backing file: /var/lib/nova/a328c7998805951a_2
image_info = images.qemu_img_info(path)
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--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('qcow2', image_info.file_format)
@@ -261,7 +238,7 @@ disk size: 706M
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'),
+ os.path.join(path, 'root.hds'), '--force-share',
prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
mock_isdir.assert_called_once_with(path)
self.assertEqual(2, mock_exists.call_count)
@@ -292,7 +269,7 @@ backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
image_info = images.qemu_img_info(path)
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--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)
@@ -321,7 +298,7 @@ junk stuff: bbb
image_info = images.qemu_img_info(path)
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--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)
@@ -346,7 +323,7 @@ ID TAG VM SIZE DATE VM CLOCK
image_info = images.qemu_img_info(path)
mock_execute.assert_called_once_with(
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
- prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--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)
@@ -503,7 +480,7 @@ disk size: 4.4M
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=nova.privsep.qemu.QEMU_IMG_LIMITS)
+ '--force-share', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
mock_exists.assert_called_once_with(path)
def test_copy_image(self):
diff --git a/nova/virt/images.py b/nova/virt/images.py
index 54db59df5c..800ebca3c7 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -33,10 +33,6 @@ from nova.i18n import _
from nova.image import glance
import nova.privsep.qemu
-# This is set by the libvirt driver on startup. The version is used to
-# determine what flags need to be set on the command line.
-QEMU_VERSION = None
-
LOG = logging.getLogger(__name__)
CONF = nova.conf.CONF
@@ -49,8 +45,7 @@ def qemu_img_info(path, format=None, output_format=None):
raise exception.DiskNotFound(location=path)
info = nova.privsep.qemu.unprivileged_qemu_img_info(
- path, format=format, qemu_version=QEMU_VERSION,
- output_format=output_format)
+ path, format=format, output_format=output_format)
if output_format:
return imageutils.QemuImgInfo(info, format=output_format)
else:
@@ -63,8 +58,7 @@ def privileged_qemu_img_info(path, format=None, output_format=None):
raise exception.DiskNotFound(location=path)
info = nova.privsep.qemu.privileged_qemu_img_info(
- path, format=format, qemu_version=QEMU_VERSION,
- output_format=output_format)
+ path, format=format, output_format=output_format)
if output_format:
return imageutils.QemuImgInfo(info, format=output_format)
else:
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index b4b561dee7..8f7dadf8cf 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -658,11 +658,7 @@ class LibvirtDriver(driver.ComputeDriver):
libvirt_utils.version_to_string(MIN_LIBVIRT_VERSION))
if CONF.libvirt.virt_type in ("qemu", "kvm"):
- if self._host.has_min_version(hv_ver=MIN_QEMU_VERSION):
- # "qemu-img info" calls are version dependent, so we need to
- # store the version in the images module.
- images.QEMU_VERSION = self._host.get_connection().getVersion()
- else:
+ if not self._host.has_min_version(hv_ver=MIN_QEMU_VERSION):
raise exception.InternalError(
_('Nova requires QEMU version %s or greater.') %
libvirt_utils.version_to_string(MIN_QEMU_VERSION))