Ejemplo n.º 1
0
    def test_fetch_image_stream_optimized(self, mock_write_class,
                                          mock_read_class):
        """Test fetching streamOptimized disk image."""
        session = mock.MagicMock()

        with test.nested(
                mock.patch.object(images.IMAGE_API, 'get'),
                mock.patch.object(images.IMAGE_API, 'download'),
                mock.patch.object(images, 'start_transfer'),
                mock.patch.object(images, '_build_shadow_vm_config_spec'),
                mock.patch.object(session, '_call_method'),
                mock.patch.object(
                    vm_util,
                    'get_vmdk_info')) as (mock_image_api_get,
                                          mock_image_api_download,
                                          mock_start_transfer,
                                          mock_build_shadow_vm_config_spec,
                                          mock_call_method,
                                          mock_get_vmdk_info):
            image_data = {'id': 'fake-id', 'disk_format': 'vmdk', 'size': 512}
            instance = mock.MagicMock()
            instance.image_ref = image_data['id']
            mock_image_api_get.return_value = image_data

            vm_folder_ref = mock.MagicMock()
            res_pool_ref = mock.MagicMock()
            context = mock.MagicMock()

            mock_read_handle = mock.MagicMock()
            mock_read_class.return_value = mock_read_handle
            mock_write_handle = mock.MagicMock()
            mock_write_class.return_value = mock_write_handle
            mock_write_handle.get_imported_vm.return_value = \
                mock.sentinel.vm_ref

            images.fetch_image_stream_optimized(context, instance, session,
                                                'fake-vm', 'fake-datastore',
                                                vm_folder_ref, res_pool_ref)

            mock_start_transfer.assert_called_once_with(
                context,
                mock_read_handle,
                512,
                write_file_handle=mock_write_handle)

            mock_call_method.assert_called_once_with(session.vim,
                                                     "UnregisterVM",
                                                     mock.sentinel.vm_ref)
            mock_get_vmdk_info.assert_called_once_with(session,
                                                       mock.sentinel.vm_ref,
                                                       'fake-vm')
Ejemplo n.º 2
0
    def test_fetch_image_stream_optimized(self,
                                          mock_write_class,
                                          mock_read_class):
        """Test fetching streamOptimized disk image."""
        session = mock.MagicMock()

        with test.nested(
             mock.patch.object(images.IMAGE_API, 'get'),
             mock.patch.object(images.IMAGE_API, 'download'),
             mock.patch.object(images, 'start_transfer'),
             mock.patch.object(images, '_build_shadow_vm_config_spec'),
             mock.patch.object(session, '_call_method'),
             mock.patch.object(vm_util, 'get_vmdk_info')
        ) as (mock_image_api_get,
              mock_image_api_download,
              mock_start_transfer,
              mock_build_shadow_vm_config_spec,
              mock_call_method,
              mock_get_vmdk_info):
            image_data = {'id': 'fake-id',
                          'disk_format': 'vmdk',
                          'size': 512}
            instance = mock.MagicMock()
            instance.image_ref = image_data['id']
            mock_image_api_get.return_value = image_data

            vm_folder_ref = mock.MagicMock()
            res_pool_ref = mock.MagicMock()
            context = mock.MagicMock()

            mock_read_handle = mock.MagicMock()
            mock_read_class.return_value = mock_read_handle
            mock_write_handle = mock.MagicMock()
            mock_write_class.return_value = mock_write_handle
            mock_write_handle.get_imported_vm.return_value = \
                mock.sentinel.vm_ref

            images.fetch_image_stream_optimized(
                    context, instance, session, 'fake-vm', 'fake-datastore',
                    vm_folder_ref, res_pool_ref)

            mock_start_transfer.assert_called_once_with(context,
                    mock_read_handle, 512, write_file_handle=mock_write_handle)

            mock_call_method.assert_called_once_with(
                    session.vim, "UnregisterVM", mock.sentinel.vm_ref)
            mock_get_vmdk_info.assert_called_once_with(
                    session, mock.sentinel.vm_ref, 'fake-vm')