27
27
from nova import test
28
28
29
29
30
+ TEST_IMAGE_PREFIX = 'nova-unittest-formatinspector-'
31
+
32
+
30
33
def get_size_from_qemu_img (filename ):
31
34
output = subprocess .check_output ('qemu-img info "%s"' % filename ,
32
35
shell = True )
@@ -41,13 +44,6 @@ def get_size_from_qemu_img(filename):
41
44
class TestFormatInspectors (test .NoDBTestCase ):
42
45
def setUp (self ):
43
46
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
-
51
47
self ._created_files = []
52
48
53
49
def tearDown (self ):
@@ -58,16 +54,63 @@ def tearDown(self):
58
54
except Exception :
59
55
pass
60
56
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
+
61
93
def _create_img (self , fmt , size , subformat = None , options = None ,
62
94
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
+
63
106
if fmt == 'vhd' :
64
107
# QEMU calls the vhd format vpc
65
108
fmt = 'vpc'
66
109
67
110
if options is None :
68
111
options = {}
69
112
opt = ''
70
- prefix = 'nova-unittest-formatinspector-'
113
+ prefix = TEST_IMAGE_PREFIX
71
114
72
115
if subformat :
73
116
options ['subformat' ] = subformat
@@ -97,7 +140,8 @@ def _create_allocated_vmdk(self, size_mb, subformat=None):
97
140
# Matches qemu-img default, see `qemu-img convert -O vmdk -o help`
98
141
subformat = 'monolithicSparse'
99
142
100
- prefix = 'nova-unittest-formatinspector-%s-' % subformat
143
+ prefix = TEST_IMAGE_PREFIX
144
+ prefix += '-%s-' % subformat
101
145
fn = tempfile .mktemp (prefix = prefix , suffix = '.vmdk' )
102
146
self ._created_files .append (fn )
103
147
raw = tempfile .mktemp (prefix = prefix , suffix = '.raw' )
@@ -165,6 +209,16 @@ def _test_format(self, format_name, subformat=None):
165
209
def test_qcow2 (self ):
166
210
self ._test_format ('qcow2' )
167
211
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
+
168
222
def test_vhd (self ):
169
223
self ._test_format ('vhd' )
170
224
0 commit comments