Skip to content

Commit

Permalink
Reproduce iso regression with deep format inspection
Browse files Browse the repository at this point in the history
This change adds a reproducer for the regression in iso
file support when
workarounds.disable_deep_image_inspection = False

Change-Id: I56d8b9980b4871941ba5de91e60a7df6a40106a8
(cherry picked from commit b5a1d3b)
  • Loading branch information
SeanMooney committed Jul 9, 2024
1 parent 66205be commit 3a6d9a0
Showing 1 changed file with 63 additions and 9 deletions.
72 changes: 63 additions & 9 deletions nova/tests/unit/image/test_format_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from nova import test


TEST_IMAGE_PREFIX = 'nova-unittest-formatinspector-'


def get_size_from_qemu_img(filename):
output = subprocess.check_output('qemu-img info "%s"' % filename,
shell=True)
Expand All @@ -41,13 +44,6 @@ def get_size_from_qemu_img(filename):
class TestFormatInspectors(test.NoDBTestCase):
def setUp(self):
super(TestFormatInspectors, self).setUp()
# these tests depend on qemu-img being installed
# and in the path, if it is not installed, skip
try:
subprocess.check_output('qemu-img --version', shell=True)
except Exception:
self.skipTest('qemu-img not installed')

self._created_files = []

def tearDown(self):
Expand All @@ -58,16 +54,63 @@ def tearDown(self):
except Exception:
pass

def _create_iso(self, image_size, subformat='iso-9660'):
# these tests depend on mkisofs
# being installed and in the path,
# if it is not installed, skip
try:
subprocess.check_output('mkisofs --version', shell=True)
except Exception:
self.skipTest('mkisofs not installed')

size = image_size // units.Mi
base_cmd = "mkisofs"
if subformat == 'udf':
# depending on the distribution mkisofs may not support udf
# and may be provided by genisoimage instead. As a result we
# need to check if the command supports udf via help
# instead of checking the installed version.
# mkisofs --help outputs to stderr so we need to
# redirect it to stdout to use grep.
try:
subprocess.check_output(
'mkisofs --help 2>&1 | grep udf', shell=True)
except Exception:
self.skipTest('mkisofs does not support udf format')
base_cmd += " -udf"
prefix = TEST_IMAGE_PREFIX
prefix += '-%s-' % subformat
fn = tempfile.mktemp(prefix=prefix, suffix='.iso')
self._created_files.append(fn)
subprocess.check_output(
'dd if=/dev/zero of=%s bs=1M count=%i' % (fn, size),
shell=True)
subprocess.check_output(
'%s -o %s -V "TEST" -J -r %s' % (base_cmd, fn, fn),
shell=True)
return fn

def _create_img(self, fmt, size, subformat=None, options=None,
backing_file=None):
if fmt == 'iso':
return self._create_iso(size, subformat)

# these tests depend on qemu-img
# being installed and in the path,
# if it is not installed, skip
try:
subprocess.check_output('qemu-img --version', shell=True)
except Exception:
self.skipTest('qemu-img not installed')

if fmt == 'vhd':
# QEMU calls the vhd format vpc
fmt = 'vpc'

if options is None:
options = {}
opt = ''
prefix = 'nova-unittest-formatinspector-'
prefix = TEST_IMAGE_PREFIX

if subformat:
options['subformat'] = subformat
Expand Down Expand Up @@ -97,7 +140,8 @@ def _create_allocated_vmdk(self, size_mb, subformat=None):
# Matches qemu-img default, see `qemu-img convert -O vmdk -o help`
subformat = 'monolithicSparse'

prefix = 'nova-unittest-formatinspector-%s-' % subformat
prefix = TEST_IMAGE_PREFIX
prefix += '-%s-' % subformat
fn = tempfile.mktemp(prefix=prefix, suffix='.vmdk')
self._created_files.append(fn)
raw = tempfile.mktemp(prefix=prefix, suffix='.raw')
Expand Down Expand Up @@ -165,6 +209,16 @@ def _test_format(self, format_name, subformat=None):
def test_qcow2(self):
self._test_format('qcow2')

def test_iso_9660(self):
# reproduce iso-9660 format regression
self.assertRaises(
TypeError, self._test_format, 'iso', subformat='iso-9660')

def test_udf(self):
# reproduce udf format regression
self.assertRaises(
TypeError, self._test_format, 'iso', subformat='udf')

def test_vhd(self):
self._test_format('vhd')

Expand Down

0 comments on commit 3a6d9a0

Please sign in to comment.