Ejemplo n.º 1
0
    def test_start_transfer(self, fake_BlockingQueue, fake_FileReadWriteTask,
                            fake_ImageWriter, fake_Timeout):

        context = mock.Mock()
        read_file_handle = mock.Mock()
        read_file_handle.close = mock.Mock()
        image_service = mock.Mock()
        image_id = mock.Mock()
        blocking_queue = mock.Mock()

        write_file_handle1 = mock.Mock()
        write_file_handle1.close = mock.Mock()
        write_file_handle2 = None
        write_file_handles = [write_file_handle1, write_file_handle2]

        timeout_secs = 10
        blocking_queue_size = 10
        image_meta = {}
        max_data_size = 30

        fake_BlockingQueue.return_value = blocking_queue
        fake_timer = mock.Mock()
        fake_timer.cancel = mock.Mock()
        fake_Timeout.return_value = fake_timer

        for write_file_handle in write_file_handles:
            image_transfer._start_transfer(context,
                                           timeout_secs,
                                           read_file_handle,
                                           max_data_size,
                                           write_file_handle=write_file_handle,
                                           image_service=image_service,
                                           image_id=image_id,
                                           image_meta=image_meta)

        exp_calls = [mock.call(blocking_queue_size, max_data_size)
                     ] * len(write_file_handles)
        self.assertEqual(exp_calls, fake_BlockingQueue.call_args_list)

        exp_calls2 = [
            mock.call(read_file_handle, blocking_queue),
            mock.call(blocking_queue, write_file_handle1),
            mock.call(read_file_handle, blocking_queue)
        ]
        self.assertEqual(exp_calls2, fake_FileReadWriteTask.call_args_list)

        exp_calls3 = mock.call(context, blocking_queue, image_service,
                               image_id, image_meta)
        self.assertEqual(exp_calls3, fake_ImageWriter.call_args)

        exp_calls4 = [mock.call(timeout_secs)] * len(write_file_handles)
        self.assertEqual(exp_calls4, fake_Timeout.call_args_list)

        self.assertEqual(len(write_file_handles), fake_timer.cancel.call_count)

        self.assertEqual(len(write_file_handles),
                         read_file_handle.close.call_count)

        write_file_handle1.close.assert_called_once_with()
Ejemplo n.º 2
0
 def _upload_vmdk(self, read_handle, host, port, dc_name, ds_name, cookies,
                  upload_file_path, file_size, cacerts, timeout_secs):
     write_handle = rw_handles.FileWriteHandle(host,
                                               port,
                                               dc_name,
                                               ds_name,
                                               cookies,
                                               upload_file_path,
                                               file_size,
                                               cacerts=cacerts)
     image_transfer._start_transfer(read_handle, write_handle, timeout_secs)
Ejemplo n.º 3
0
 def _upload_vmdk(
         self, read_handle, host, port, dc_name, ds_name, cookies,
         upload_file_path, file_size, cacerts, timeout_secs):
     write_handle = rw_handles.FileWriteHandle(host,
                                               port,
                                               dc_name,
                                               ds_name,
                                               cookies,
                                               upload_file_path,
                                               file_size,
                                               cacerts=cacerts)
     image_transfer._start_transfer(read_handle, write_handle, timeout_secs)
Ejemplo n.º 4
0
 def test_start_transfer(self):
     data = b'image-data-here'
     read_handle = six.BytesIO(data)
     write_handle = mock.Mock()
     image_transfer._start_transfer(read_handle, write_handle, None)
     write_handle.write.assert_called_once_with(data)
Ejemplo n.º 5
0
    def test_start_transfer(self, fake_BlockingQueue, fake_FileReadWriteTask,
                            fake_ImageWriter, fake_Timeout):

        context = mock.Mock()
        read_file_handle = mock.Mock()
        read_file_handle.close = mock.Mock()
        image_service = mock.Mock()
        image_id = mock.Mock()
        blocking_queue = mock.Mock()

        write_file_handle1 = mock.Mock()
        write_file_handle1.close = mock.Mock()
        write_file_handle2 = None
        write_file_handles = [write_file_handle1, write_file_handle2]

        timeout_secs = 10
        blocking_queue_size = 10
        image_meta = {}
        max_data_size = 30

        fake_BlockingQueue.return_value = blocking_queue
        fake_timer = mock.Mock()
        fake_timer.cancel = mock.Mock()
        fake_Timeout.return_value = fake_timer

        for write_file_handle in write_file_handles:
            new_image_transfer._start_transfer(
                context,
                timeout_secs,
                read_file_handle,
                max_data_size,
                write_file_handle=write_file_handle,
                image_service=image_service,
                image_id=image_id,
                image_meta=image_meta)

        exp_calls = [mock.call(blocking_queue_size,
                               max_data_size)] * len(write_file_handles)
        self.assertEqual(exp_calls,
                         fake_BlockingQueue.call_args_list)

        exp_calls2 = [mock.call(read_file_handle, blocking_queue),
                      mock.call(blocking_queue, write_file_handle1),
                      mock.call(read_file_handle, blocking_queue)]
        self.assertEqual(exp_calls2,
                         fake_FileReadWriteTask.call_args_list)

        exp_calls3 = mock.call(context, blocking_queue, image_service,
                               image_id, image_meta)
        self.assertEqual(exp_calls3,
                         fake_ImageWriter.call_args)

        exp_calls4 = [mock.call(timeout_secs)] * len(write_file_handles)
        self.assertEqual(exp_calls4,
                         fake_Timeout.call_args_list)

        self.assertEqual(len(write_file_handles),
                         fake_timer.cancel.call_count)

        self.assertEqual(len(write_file_handles),
                         read_file_handle.close.call_count)

        write_file_handle1.close.assert_called_once()
Ejemplo n.º 6
0
 def test_start_transfer(self):
     data = b'image-data-here'
     read_handle = six.BytesIO(data)
     write_handle = mock.Mock()
     image_transfer._start_transfer(read_handle, write_handle, None)
     write_handle.write.assert_called_once_with(data)