Merge "Support for copying streamOptimized disk to file"
This commit is contained in:
commit
48847a5857
@ -494,6 +494,35 @@ def download_stream_optimized_image(context, timeout_secs, image_service,
|
||||
return imported_vm
|
||||
|
||||
|
||||
def copy_stream_optimized_disk(
|
||||
context, timeout_secs, write_handle, **kwargs):
|
||||
"""Copy virtual disk from VMware server to the given write handle.
|
||||
|
||||
:param context: context
|
||||
:param timeout_secs: time in seconds to wait for the copy to complete
|
||||
:param write_handle: copy destination
|
||||
:param kwargs: keyword arguments to configure the source
|
||||
VMDK read handle
|
||||
:raises: VimException, VimFaultException, VimAttributeException,
|
||||
VimSessionOverLoadException, VimConnectionException,
|
||||
ImageTransferException, ValueError
|
||||
"""
|
||||
vmdk_file_path = kwargs.get('vmdk_file_path')
|
||||
LOG.debug("Copying virtual disk: %(vmdk_path)s to %(dest)s.",
|
||||
{'vmdk_path': vmdk_file_path,
|
||||
'dest': write_handle.name})
|
||||
file_size = kwargs.get('vmdk_size')
|
||||
read_handle = rw_handles.VmdkReadHandle(kwargs.get('session'),
|
||||
kwargs.get('host'),
|
||||
kwargs.get('port'),
|
||||
kwargs.get('vm'),
|
||||
kwargs.get('vmdk_file_path'),
|
||||
file_size)
|
||||
_start_transfer(context, timeout_secs, read_handle, file_size,
|
||||
write_file_handle=write_handle)
|
||||
LOG.debug("Downloaded virtual disk: %s.", vmdk_file_path)
|
||||
|
||||
|
||||
def upload_image(context, timeout_secs, image_service, image_id, owner_id,
|
||||
**kwargs):
|
||||
"""Upload the VM's disk file to image service.
|
||||
|
@ -452,6 +452,35 @@ class ImageTransferUtilityTest(base.TestCase):
|
||||
vm_import_spec=vm_import_spec,
|
||||
image_size=image_size)
|
||||
|
||||
@mock.patch.object(image_transfer, '_start_transfer')
|
||||
@mock.patch('oslo.vmware.rw_handles.VmdkReadHandle')
|
||||
def test_copy_stream_optimized_disk(
|
||||
self, vmdk_read_handle, start_transfer):
|
||||
|
||||
read_handle = mock.sentinel.read_handle
|
||||
vmdk_read_handle.return_value = read_handle
|
||||
|
||||
context = mock.sentinel.context
|
||||
timeout = mock.sentinel.timeout
|
||||
write_handle = mock.Mock(name='/cinder/images/tmpAbcd.vmdk')
|
||||
session = mock.sentinel.session
|
||||
host = mock.sentinel.host
|
||||
port = mock.sentinel.port
|
||||
vm = mock.sentinel.vm
|
||||
vmdk_file_path = mock.sentinel.vmdk_file_path
|
||||
vmdk_size = mock.sentinel.vmdk_size
|
||||
|
||||
image_transfer.copy_stream_optimized_disk(
|
||||
context, timeout, write_handle, session=session, host=host,
|
||||
port=port, vm=vm, vmdk_file_path=vmdk_file_path,
|
||||
vmdk_size=vmdk_size)
|
||||
|
||||
vmdk_read_handle.assert_called_once_with(
|
||||
session, host, port, vm, vmdk_file_path, vmdk_size)
|
||||
start_transfer.assert_called_once_with(
|
||||
context, timeout, read_handle, vmdk_size,
|
||||
write_file_handle=write_handle)
|
||||
|
||||
@mock.patch('oslo.vmware.rw_handles.VmdkReadHandle')
|
||||
@mock.patch.object(image_transfer, '_start_transfer')
|
||||
def test_upload_image(self, fake_transfer, fake_rw_handles_VmdkReadHandle):
|
||||
|
Loading…
x
Reference in New Issue
Block a user