@@ -112,6 +112,37 @@ def test_fetch_to_raw_errors(self, convert_image, qemu_img_info, fetch):
112
112
images .fetch_to_raw ,
113
113
None , 'href123' , '/no/path' )
114
114
115
+ @mock .patch .object (images , 'convert_image' ,
116
+ side_effect = exception .ImageUnacceptable )
117
+ @mock .patch .object (images , 'qemu_img_info' )
118
+ @mock .patch .object (images , 'fetch' )
119
+ def test_fetch_to_raw_data_file (self , convert_image , qemu_img_info_fn ,
120
+ fetch ):
121
+ # NOTE(danms): the above test needs the following line as well, as it
122
+ # is broken without it.
123
+ qemu_img_info = qemu_img_info_fn .return_value
124
+ qemu_img_info .backing_file = None
125
+ qemu_img_info .file_format = 'qcow2'
126
+ qemu_img_info .virtual_size = 20
127
+ qemu_img_info .format_specific = {'data' : {'data-file' : 'somefile' }}
128
+ self .assertRaisesRegex (exception .ImageUnacceptable ,
129
+ 'Image href123 is unacceptable.*somefile' ,
130
+ images .fetch_to_raw ,
131
+ None , 'href123' , '/no/path' )
132
+
133
+ @mock .patch ('os.rename' )
134
+ @mock .patch .object (images , 'qemu_img_info' )
135
+ @mock .patch .object (images , 'fetch' )
136
+ def test_fetch_to_raw_from_raw (self , fetch , qemu_img_info_fn , mock_rename ):
137
+ # Make sure we support a case where we fetch an already-raw image and
138
+ # qemu-img returns None for "format_specific".
139
+ qemu_img_info = qemu_img_info_fn .return_value
140
+ qemu_img_info .file_format = 'raw'
141
+ qemu_img_info .backing_file = None
142
+ qemu_img_info .format_specific = None
143
+ images .fetch_to_raw (None , 'href123' , '/no/path' )
144
+ mock_rename .assert_called_once_with ('/no/path.part' , '/no/path' )
145
+
115
146
@mock .patch .object (compute_utils , 'disk_ops_semaphore' )
116
147
@mock .patch ('nova.privsep.utils.supports_direct_io' , return_value = True )
117
148
@mock .patch ('oslo_concurrency.processutils.execute' )
0 commit comments