2727from nova import test
2828
2929
30+ TEST_IMAGE_PREFIX = 'nova-unittest-formatinspector-'
31+
32+
3033def get_size_from_qemu_img (filename ):
3134 output = subprocess .check_output ('qemu-img info "%s"' % filename ,
3235 shell = True )
@@ -41,13 +44,6 @@ def get_size_from_qemu_img(filename):
4144class TestFormatInspectors (test .NoDBTestCase ):
4245 def setUp (self ):
4346 super (TestFormatInspectors , self ).setUp ()
44- # these tests depend on qemu-img being installed
45- # and in the path, if it is not installed, skip
46- try :
47- subprocess .check_output ('qemu-img --version' , shell = True )
48- except Exception :
49- self .skipTest ('qemu-img not installed' )
50-
5147 self ._created_files = []
5248
5349 def tearDown (self ):
@@ -58,16 +54,63 @@ def tearDown(self):
5854 except Exception :
5955 pass
6056
57+ def _create_iso (self , image_size , subformat = 'iso-9660' ):
58+ # these tests depend on mkisofs
59+ # being installed and in the path,
60+ # if it is not installed, skip
61+ try :
62+ subprocess .check_output ('mkisofs --version' , shell = True )
63+ except Exception :
64+ self .skipTest ('mkisofs not installed' )
65+
66+ size = image_size // units .Mi
67+ base_cmd = "mkisofs"
68+ if subformat == 'udf' :
69+ # depending on the distribution mkisofs may not support udf
70+ # and may be provided by genisoimage instead. As a result we
71+ # need to check if the command supports udf via help
72+ # instead of checking the installed version.
73+ # mkisofs --help outputs to stderr so we need to
74+ # redirect it to stdout to use grep.
75+ try :
76+ subprocess .check_output (
77+ 'mkisofs --help 2>&1 | grep udf' , shell = True )
78+ except Exception :
79+ self .skipTest ('mkisofs does not support udf format' )
80+ base_cmd += " -udf"
81+ prefix = TEST_IMAGE_PREFIX
82+ prefix += '-%s-' % subformat
83+ fn = tempfile .mktemp (prefix = prefix , suffix = '.iso' )
84+ self ._created_files .append (fn )
85+ subprocess .check_output (
86+ 'dd if=/dev/zero of=%s bs=1M count=%i' % (fn , size ),
87+ shell = True )
88+ subprocess .check_output (
89+ '%s -o %s -V "TEST" -J -r %s' % (base_cmd , fn , fn ),
90+ shell = True )
91+ return fn
92+
6193 def _create_img (self , fmt , size , subformat = None , options = None ,
6294 backing_file = None ):
95+ if fmt == 'iso' :
96+ return self ._create_iso (size , subformat )
97+
98+ # these tests depend on qemu-img
99+ # being installed and in the path,
100+ # if it is not installed, skip
101+ try :
102+ subprocess .check_output ('qemu-img --version' , shell = True )
103+ except Exception :
104+ self .skipTest ('qemu-img not installed' )
105+
63106 if fmt == 'vhd' :
64107 # QEMU calls the vhd format vpc
65108 fmt = 'vpc'
66109
67110 if options is None :
68111 options = {}
69112 opt = ''
70- prefix = 'nova-unittest-formatinspector-'
113+ prefix = TEST_IMAGE_PREFIX
71114
72115 if subformat :
73116 options ['subformat' ] = subformat
@@ -97,7 +140,8 @@ def _create_allocated_vmdk(self, size_mb, subformat=None):
97140 # Matches qemu-img default, see `qemu-img convert -O vmdk -o help`
98141 subformat = 'monolithicSparse'
99142
100- prefix = 'nova-unittest-formatinspector-%s-' % subformat
143+ prefix = TEST_IMAGE_PREFIX
144+ prefix += '-%s-' % subformat
101145 fn = tempfile .mktemp (prefix = prefix , suffix = '.vmdk' )
102146 self ._created_files .append (fn )
103147 raw = tempfile .mktemp (prefix = prefix , suffix = '.raw' )
@@ -165,6 +209,16 @@ def _test_format(self, format_name, subformat=None):
165209 def test_qcow2 (self ):
166210 self ._test_format ('qcow2' )
167211
212+ def test_iso_9660 (self ):
213+ # reproduce iso-9660 format regression
214+ self .assertRaises (
215+ TypeError , self ._test_format , 'iso' , subformat = 'iso-9660' )
216+
217+ def test_udf (self ):
218+ # reproduce udf format regression
219+ self .assertRaises (
220+ TypeError , self ._test_format , 'iso' , subformat = 'udf' )
221+
168222 def test_vhd (self ):
169223 self ._test_format ('vhd' )
170224
0 commit comments