Merge "Reduce redundant call of image show"
This commit is contained in:
commit
8758d35946
@ -297,7 +297,7 @@ def fetch_to_volume_format(context, image_service,
|
||||
else:
|
||||
fetch(context, image_service, image_id, tmp, user_id, project_id)
|
||||
|
||||
if is_xenserver_image(context, image_service, image_id):
|
||||
if is_xenserver_format(image_meta):
|
||||
replace_xenserver_image_with_coalesced_vhd(tmp)
|
||||
|
||||
if not qemu_img:
|
||||
@ -432,11 +432,6 @@ def check_virtual_size(virtual_size, volume_size, image_id):
|
||||
return virtual_size
|
||||
|
||||
|
||||
def is_xenserver_image(context, image_service, image_id):
|
||||
image_meta = image_service.show(context, image_id)
|
||||
return is_xenserver_format(image_meta)
|
||||
|
||||
|
||||
def is_xenserver_format(image_meta):
|
||||
return (
|
||||
image_meta['disk_format'] == 'vhd'
|
||||
|
@ -631,7 +631,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -675,7 +675,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -723,7 +723,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -775,7 +775,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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',
|
||||
@ -821,7 +821,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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',
|
||||
@ -864,7 +864,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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',
|
||||
@ -907,7 +907,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -954,7 +954,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -1002,7 +1002,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -1050,7 +1050,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@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')
|
||||
@ -1115,7 +1115,7 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
@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_image',
|
||||
@mock.patch('cinder.image.image_utils.is_xenserver_format',
|
||||
return_value=True)
|
||||
@mock.patch('cinder.image.image_utils.fetch')
|
||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
||||
@ -1162,18 +1162,6 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||
|
||||
|
||||
class TestXenserverUtils(test.TestCase):
|
||||
@mock.patch('cinder.image.image_utils.is_xenserver_format')
|
||||
def test_is_xenserver_image(self, mock_format):
|
||||
ctxt = mock.sentinel.context
|
||||
image_service = mock.Mock()
|
||||
image_id = mock.sentinel.image_id
|
||||
|
||||
output = image_utils.is_xenserver_image(ctxt, image_service, image_id)
|
||||
|
||||
image_service.show.assert_called_once_with(ctxt, image_id)
|
||||
mock_format.assert_called_once_with(image_service.show.return_value)
|
||||
self.assertEqual(mock_format.return_value, output)
|
||||
|
||||
def test_is_xenserver_format(self):
|
||||
image_meta1 = {'disk_format': 'vhd', 'container_format': 'ovf'}
|
||||
self.assertTrue(image_utils.is_xenserver_format(image_meta1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user