@@ -172,6 +172,53 @@ def test_image_convert_inspection_reports_error(self):
172
172
# Make sure we did not update the image
173
173
self .img_repo .save .assert_not_called ()
174
174
175
+ def test_image_convert_invalid_qcow (self ):
176
+ data = {'format' : 'qcow2' ,
177
+ 'backing-filename' : '/etc/hosts' }
178
+
179
+ convert = self ._setup_image_convert_info_fail ()
180
+ with mock .patch .object (processutils , 'execute' ) as exc_mock :
181
+ exc_mock .return_value = json .dumps (data ), ''
182
+ e = self .assertRaises (RuntimeError ,
183
+ convert .execute , 'file:///test/path.qcow' )
184
+ self .assertEqual ('QCOW images with backing files are not allowed' ,
185
+ str (e ))
186
+
187
+ def _test_image_convert_invalid_vmdk (self ):
188
+ data = {'format' : 'vmdk' ,
189
+ 'format-specific' : {
190
+ 'data' : {
191
+ 'create-type' : 'monolithicFlat' ,
192
+ }}}
193
+
194
+ convert = self ._setup_image_convert_info_fail ()
195
+ with mock .patch .object (processutils , 'execute' ) as exc_mock :
196
+ exc_mock .return_value = json .dumps (data ), ''
197
+ convert .execute ('file:///test/path.vmdk' )
198
+
199
+ def test_image_convert_invalid_vmdk (self ):
200
+ e = self .assertRaises (RuntimeError ,
201
+ self ._test_image_convert_invalid_vmdk )
202
+ self .assertEqual ('Invalid VMDK create-type specified' , str (e ))
203
+
204
+ def test_image_convert_valid_vmdk_no_types (self ):
205
+ with mock .patch .object (CONF .image_format , 'vmdk_allowed_types' ,
206
+ new = []):
207
+ # We make it past the VMDK check and fail because our file
208
+ # does not exist
209
+ e = self .assertRaises (RuntimeError ,
210
+ self ._test_image_convert_invalid_vmdk )
211
+ self .assertEqual ('Image is a VMDK, but no VMDK createType is '
212
+ 'specified' , str (e ))
213
+
214
+ def test_image_convert_valid_vmdk (self ):
215
+ with mock .patch .object (CONF .image_format , 'vmdk_allowed_types' ,
216
+ new = ['monolithicSparse' , 'monolithicFlat' ]):
217
+ # We make it past the VMDK check and fail because our file
218
+ # does not exist
219
+ self .assertRaises (FileNotFoundError ,
220
+ self ._test_image_convert_invalid_vmdk )
221
+
175
222
def test_image_convert_fails (self ):
176
223
convert = self ._setup_image_convert_info_fail ()
177
224
with mock .patch .object (processutils , 'execute' ) as exc_mock :
0 commit comments