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