diff --git a/oslo_vmware/image_transfer.py b/oslo_vmware/image_transfer.py index c4e35bf..e84f806 100644 --- a/oslo_vmware/image_transfer.py +++ b/oslo_vmware/image_transfer.py @@ -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. diff --git a/oslo_vmware/tests/test_image_transfer.py b/oslo_vmware/tests/test_image_transfer.py index 1cb6da9..0d902d0 100644 --- a/oslo_vmware/tests/test_image_transfer.py +++ b/oslo_vmware/tests/test_image_transfer.py @@ -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,