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