Exemplo n.º 1
0
def test_TemporaryVolume_host_path_is_temporary_directory():
    with mock.patch('girder_worker.docker.transforms.tempfile.mkdtemp', return_value='/bogus/path'):
        tv = TemporaryVolume()

        assert tv.host_path is None
        tv.transform()
        assert tv.host_path == '/bogus/path'
Exemplo n.º 2
0
def test_TemporaryVolume_transform_creates_container_path():
    with mock.patch('girder_worker.docker.transforms.uuid.uuid4',
                    return_value=mock.Mock(hex='SOME_UUID')):
        tv = TemporaryVolume()

        assert tv.container_path is None
        assert tv.transform() == '{}/SOME_UUID'.format(TEMP_VOLUME_MOUNT_PREFIX)
        assert tv.container_path == '{}/SOME_UUID'.format(TEMP_VOLUME_MOUNT_PREFIX)
def test_TemporaryVolume_host_dir_prepended_to_host_path():
    with mock.patch('girder_worker.docker.transforms.tempfile.mkdtemp'
                    ) as mock_mkdtemp:
        with mock.patch('girder_worker.docker.transforms.os.path.exists',
                        return_value=True):
            TemporaryVolume(host_dir='/some/preexisting/directory').transform()
            mock_mkdtemp.assert_called_once_with(
                dir='/some/preexisting/directory')
Exemplo n.º 4
0
    def test_docker_run_temporary_volume_root(self, params):
        prefix = params.get('prefix')
        root = os.path.join(tempfile.gettempdir(), prefix)
        # We set the mode to 0o777 because the worker container is
        # running as the 'worker' user and needs to be able to have
        # read/write access to the TemporaryVolume
        volume = TemporaryVolume(host_dir=root, mode=0o777)

        result = docker_run.delay(
            TEST_IMAGE, pull_image=True, container_args=['print_path', '-p', volume],
            remove_container=True, volumes=[volume])

        return result.job