Merge "Don't verify format with autodetect after image conversion"
This commit is contained in:
commit
9551bf16d1
|
@ -420,16 +420,6 @@ def fetch_to_volume_format(context, image_service,
|
|||
src_format=disk_format,
|
||||
run_as_root=run_as_root)
|
||||
|
||||
data = qemu_img_info(dest, run_as_root=run_as_root)
|
||||
|
||||
if not _validate_file_format(data, volume_format):
|
||||
raise exception.ImageUnacceptable(
|
||||
image_id=image_id,
|
||||
reason=_("Converted to %(vol_format)s, but format is "
|
||||
"now %(file_format)s") % {'vol_format': volume_format,
|
||||
'file_format': data.
|
||||
file_format})
|
||||
|
||||
|
||||
def _validate_file_format(image_data, expected_format):
|
||||
if image_data.file_format == expected_format:
|
||||
|
|
|
@ -365,7 +365,6 @@ class TestVerifyImage(test.TestCase):
|
|||
self.assertIsNone(output)
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
dest, None, None)
|
||||
mock_info.assert_called_once_with(dest, run_as_root=run_as_root)
|
||||
mock_fileutils.remove_path_on_error.assert_called_once_with(dest)
|
||||
(mock_fileutils.remove_path_on_error.return_value.__enter__
|
||||
.assert_called_once_with())
|
||||
|
@ -718,8 +717,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
mock_temp.assert_called_once_with()
|
||||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=True),
|
||||
mock.call(tmp, run_as_root=True),
|
||||
mock.call(dest, run_as_root=True)])
|
||||
mock.call(tmp, run_as_root=True)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, None, None)
|
||||
self.assertFalse(mock_repl_xen.called)
|
||||
|
@ -768,8 +766,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
mock_temp.assert_called_once_with()
|
||||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(dest, run_as_root=run_as_root)])
|
||||
mock.call(tmp, run_as_root=run_as_root)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, user_id, project_id)
|
||||
self.assertFalse(mock_repl_xen.called)
|
||||
|
@ -819,8 +816,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
mock_temp.assert_called_once_with()
|
||||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(dest, run_as_root=run_as_root)])
|
||||
mock.call(tmp, run_as_root=run_as_root)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, user_id, project_id)
|
||||
mock_repl_xen.assert_called_once_with(tmp)
|
||||
|
@ -873,8 +869,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=True),
|
||||
mock.call(dummy, run_as_root=True),
|
||||
mock.call(tmp, run_as_root=True),
|
||||
mock.call(dest, run_as_root=True)])
|
||||
mock.call(tmp, run_as_root=True)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, None, None)
|
||||
self.assertFalse(mock_repl_xen.called)
|
||||
|
@ -1203,73 +1198,6 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
self.assertFalse(mock_copy.called)
|
||||
self.assertFalse(mock_convert.called)
|
||||
|
||||
@mock.patch('cinder.image.image_utils.check_available_space')
|
||||
@mock.patch('cinder.image.image_utils.convert_image')
|
||||
@mock.patch('cinder.image.image_utils.volume_utils.copy_volume')
|
||||
@mock.patch(
|
||||
'cinder.image.image_utils.replace_xenserver_image_with_coalesced_vhd')
|
||||
@mock.patch('cinder.image.image_utils.is_xenserver_format',
|
||||
return_value=False)
|
||||
@mock.patch('cinder.image.image_utils.fetch')
|
||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
||||
@mock.patch('cinder.image.image_utils.temporary_file')
|
||||
@mock.patch('cinder.image.image_utils.CONF')
|
||||
def _test_format_name_mismatch(self, mock_conf, mock_temp, mock_info,
|
||||
mock_fetch, mock_is_xen, mock_repl_xen,
|
||||
mock_copy, mock_convert,
|
||||
mock_check_space,
|
||||
legacy_format_name=False):
|
||||
ctxt = mock.sentinel.context
|
||||
image_service = FakeImageService()
|
||||
image_id = mock.sentinel.image_id
|
||||
dest = mock.sentinel.dest
|
||||
volume_format = 'vhd'
|
||||
blocksize = mock.sentinel.blocksize
|
||||
ctxt.user_id = user_id = mock.sentinel.user_id
|
||||
project_id = mock.sentinel.project_id
|
||||
size = 4321
|
||||
run_as_root = mock.sentinel.run_as_root
|
||||
|
||||
data = mock_info.return_value
|
||||
data.file_format = 'vpc' if legacy_format_name else 'raw'
|
||||
data.backing_file = None
|
||||
data.virtual_size = 1234
|
||||
tmp = mock_temp.return_value.__enter__.return_value
|
||||
|
||||
if legacy_format_name:
|
||||
image_utils.fetch_to_volume_format(
|
||||
ctxt, image_service, image_id, dest, volume_format, blocksize,
|
||||
user_id=user_id, project_id=project_id, size=size,
|
||||
run_as_root=run_as_root)
|
||||
else:
|
||||
self.assertRaises(
|
||||
exception.ImageUnacceptable,
|
||||
image_utils.fetch_to_volume_format,
|
||||
ctxt, image_service, image_id, dest, volume_format, blocksize,
|
||||
user_id=user_id, project_id=project_id, size=size,
|
||||
run_as_root=run_as_root)
|
||||
|
||||
mock_temp.assert_called_once_with()
|
||||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(dest, run_as_root=run_as_root)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, user_id, project_id)
|
||||
self.assertFalse(mock_repl_xen.called)
|
||||
self.assertFalse(mock_copy.called)
|
||||
mock_convert.assert_called_once_with(tmp, dest, volume_format,
|
||||
run_as_root=run_as_root,
|
||||
src_format='raw')
|
||||
|
||||
def test_format_mismatch(self):
|
||||
self._test_format_name_mismatch()
|
||||
|
||||
def test_format_name_mismatch_same_format(self):
|
||||
# Make sure no exception is raised because of qemu-img still using
|
||||
# the legacy 'vpc' format name if 'vhd' is requested.
|
||||
self._test_format_name_mismatch(legacy_format_name=True)
|
||||
|
||||
@mock.patch('cinder.image.image_utils.check_available_space')
|
||||
@mock.patch('cinder.image.image_utils.convert_image')
|
||||
@mock.patch('cinder.image.image_utils.volume_utils.copy_volume')
|
||||
|
@ -1310,8 +1238,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
|||
mock_temp.assert_called_once_with()
|
||||
mock_info.assert_has_calls([
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(tmp, run_as_root=run_as_root),
|
||||
mock.call(dest, run_as_root=run_as_root)])
|
||||
mock.call(tmp, run_as_root=run_as_root)])
|
||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||
tmp, user_id, project_id)
|
||||
mock_repl_xen.assert_called_once_with(tmp)
|
||||
|
|
Loading…
Reference in New Issue