Method to download file to VMware server
This patch adds a utility method in image_transfer to download a file to VMware server. Change-Id: Ic378d21d036f5296310697d73dbc6ee284fdd187
This commit is contained in:
parent
0258fe0c6a
commit
03faa1c24b
@ -137,6 +137,36 @@ def download_flat_image(context, timeout_secs, image_service, image_id,
|
||||
image_id)
|
||||
|
||||
|
||||
def download_file(
|
||||
read_handle, host, port, dc_name, ds_name, cookies,
|
||||
upload_file_path, file_size, cacerts, timeout_secs):
|
||||
"""Download file to VMware server.
|
||||
|
||||
:param read_handle: file read handle
|
||||
:param host: VMware server host name or IP address
|
||||
:param port: VMware server port number
|
||||
:param dc_name: name of the datacenter which contains the destination
|
||||
datastore
|
||||
:param ds_name: name of the destination datastore
|
||||
:param cookies: cookies to build the cookie header while establishing
|
||||
http connection with VMware server
|
||||
:param upload_file_path: destination datastore file path
|
||||
:param file_size: source file size
|
||||
:param cacerts: CA bundle file to use for SSL verification
|
||||
:param timeout_secs: timeout in seconds to wait for the download to
|
||||
complete
|
||||
"""
|
||||
write_handle = rw_handles.FileWriteHandle(host,
|
||||
port,
|
||||
dc_name,
|
||||
ds_name,
|
||||
cookies,
|
||||
upload_file_path,
|
||||
file_size,
|
||||
cacerts=cacerts)
|
||||
_start_transfer(read_handle, write_handle, timeout_secs)
|
||||
|
||||
|
||||
def download_stream_optimized_data(context, timeout_secs, read_handle,
|
||||
**kwargs):
|
||||
"""Download stream optimized data to VMware server.
|
||||
|
@ -96,6 +96,32 @@ class ImageTransferUtilityTest(base.TestCase):
|
||||
fake_FileWriteHandle,
|
||||
timeout_secs)
|
||||
|
||||
@mock.patch('oslo_vmware.rw_handles.FileWriteHandle')
|
||||
@mock.patch.object(image_transfer, '_start_transfer')
|
||||
def test_download_file(self, start_transfer, file_write_handle_cls):
|
||||
write_handle = mock.sentinel.write_handle
|
||||
file_write_handle_cls.return_value = write_handle
|
||||
|
||||
read_handle = mock.sentinel.read_handle
|
||||
host = mock.sentinel.host
|
||||
port = mock.sentinel.port
|
||||
dc_name = mock.sentinel.dc_name
|
||||
ds_name = mock.sentinel.ds_name
|
||||
cookies = mock.sentinel.cookies
|
||||
upload_file_path = mock.sentinel.upload_file_path
|
||||
file_size = mock.sentinel.file_size
|
||||
cacerts = mock.sentinel.cacerts
|
||||
timeout_secs = mock.sentinel.timeout_secs
|
||||
image_transfer.download_file(
|
||||
read_handle, host, port, dc_name, ds_name, cookies,
|
||||
upload_file_path, file_size, cacerts, timeout_secs)
|
||||
|
||||
file_write_handle_cls.assert_called_once_with(
|
||||
host, port, dc_name, ds_name, cookies, upload_file_path,
|
||||
file_size, cacerts=cacerts)
|
||||
start_transfer.assert_called_once_with(
|
||||
read_handle, write_handle, timeout_secs)
|
||||
|
||||
@mock.patch('oslo_vmware.rw_handles.VmdkWriteHandle')
|
||||
@mock.patch.object(image_transfer, '_start_transfer')
|
||||
def test_download_stream_optimized_data(self, fake_transfer,
|
||||
|
Loading…
x
Reference in New Issue
Block a user