Example #1
0
def get(galaxy_context, repository_spec):
    """determine how to download a repo, builds a fetch instance, and returns the instance"""

    fetcher = None

    # FIXME: note that ignore_certs for the galaxy
    # server(galaxy_context.server['ignore_certs'])
    # does not really imply that the repo archive download should ignore certs as well
    # (galaxy api server vs cdn) but for now, we use the value for both

    if repository_spec.fetch_method == FetchMethods.EDITABLE:
        fetcher = editable.EditableFetch(repository_spec=repository_spec,
                                         galaxy_context=galaxy_context)
    elif repository_spec.fetch_method == FetchMethods.SCM_URL:
        fetcher = scm_url.ScmUrlFetch(repository_spec=repository_spec)
    elif repository_spec.fetch_method == FetchMethods.LOCAL_FILE:
        # the file is a tar, so open it that way and extract it
        # to the specified (or default) content directory
        fetcher = local_file.LocalFileFetch(repository_spec)
    elif repository_spec.fetch_method == FetchMethods.REMOTE_URL:
        fetcher = remote_url.RemoteUrlFetch(
            repository_spec=repository_spec,
            validate_certs=not galaxy_context.server['ignore_certs'])
    elif repository_spec.fetch_method == FetchMethods.GALAXY_URL:
        fetcher = galaxy_url.GalaxyUrlFetch(repository_spec=repository_spec,
                                            galaxy_context=galaxy_context)
    else:
        raise exceptions.GalaxyError(
            'No approriate content fetcher found for %s %s',
            repository_spec.scm, repository_spec.src)

    log.debug('Using fetcher: %s for repository_spec: %r', fetcher,
              repository_spec)

    return fetcher
Example #2
0
def test_local_file_fetch(mocker):
    tmp_file = tempfile.NamedTemporaryFile(prefix='tmp',
                                           suffix='.tar.gz',
                                           delete=True)
    log.debug('tmp_file.name=%s tmp_file=%s', tmp_file.name, tmp_file)

    repository_spec_ = repository_spec.repository_spec_from_string(
        tmp_file.name)

    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository_archive',
        return_value=mocker.Mock(name='mockRepoArchive'))
    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository',
        return_value=mocker.Mock(name='mockRepo'))
    local_fetch = local_file.LocalFileFetch(repository_spec_)

    find_results = local_fetch.find()
    results = local_fetch.fetch(find_results=find_results)

    log.debug('results: %s', results)
    local_fetch.cleanup()

    # LocalFileFetch is acting directly on an existing file, so it's cleanup
    # should _not_ delete the file
    assert os.path.isfile(tmp_file.name)

    # results = {'archive_path': '/tmp/tmpcle_fdtp.tar.gz', 'fetch_method': 'local_file',
    # 'custom': {'local_path': '/tmp/tmpcle_fdtp.tar.gz'},
    # 'content': {'galaxy_namespace': None, 'repo_name': '/tmp/tmpcle_fdtp.tar',
    # 'fetched_name': <Mock name='mockRepo.repository_spec.name' id='139946600228288'>}}
    assert results['archive_path'] == tmp_file.name
    assert results['fetch_method'] == 'local_file'
    assert results['custom']['local_path'] == tmp_file.name
Example #3
0
def test_local_file_fetch(mocker):
    tmp_file_fo = tempfile.NamedTemporaryFile(prefix='tmp',
                                              suffix='.tar.gz',
                                              delete=True)
    log.debug('tmp_file_fo.name=%s tmp_file=%s', tmp_file_fo.name, tmp_file_fo)

    tar_file = tarfile.open(mode='w:gz', fileobj=tmp_file_fo)

    _repo_archive_info = RepositoryArchiveInfo(archive_type='foo',
                                               top_dir='namespace-name-1.2.3',
                                               archive_path=tmp_file_fo.name)
    _repo_archive = RepositoryArchive(info=_repo_archive_info,
                                      tar_file=tar_file)
    mocker.patch(
        'ansible_galaxy.repository_spec.repository_archive.load_archive',
        return_value=_repo_archive)

    repository_spec_ = RepositorySpec(namespace='namespace',
                                      name='name',
                                      version='1.2.3',
                                      fetch_method=FetchMethods.LOCAL_FILE,
                                      src=tmp_file_fo.name)

    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository_archive',
        return_value=mocker.Mock(name='mockRepoArchive'))
    mocker.patch(
        'ansible_galaxy.fetch.local_file.LocalFileFetch._load_repository',
        return_value=mocker.Mock(name='mockRepo'))
    local_fetch = local_file.LocalFileFetch(repository_spec_)

    find_results = local_fetch.find()
    results = local_fetch.fetch(find_results=find_results)

    log.debug('results: %s', results)
    local_fetch.cleanup()

    # LocalFileFetch is acting directly on an existing file, so it's cleanup
    # should _not_ delete the file
    assert os.path.isfile(tmp_file_fo.name)

    # results = {'archive_path': '/tmp/tmpcle_fdtp.tar.gz', 'fetch_method': 'local_file',
    # 'custom': {'local_path': '/tmp/tmpcle_fdtp.tar.gz'},
    # 'content': {'galaxy_namespace': None, 'repo_name': '/tmp/tmpcle_fdtp.tar',
    # 'fetched_name': <Mock name='mockRepo.repository_spec.name' id='139946600228288'>}}
    assert results['archive_path'] == tmp_file_fo.name
    assert results['fetch_method'] == 'local_file'
    assert results['custom']['local_path'] == tmp_file_fo.name

    log.debug('should unlink %s here', tmp_file_fo.name)
Example #4
0
def test_local_file_fetch():
    tmp_file = tempfile.NamedTemporaryFile(prefix='tmp', delete=True)
    log.debug('tmp_file.name=%s tmp_file=%s', tmp_file.name, tmp_file)

    content_spec_ = content_spec.content_spec_from_string(tmp_file.name)

    local_fetch = local_file.LocalFileFetch(content_spec_)

    find_results = local_fetch.find()
    results = local_fetch.fetch(find_results=find_results)

    log.debug('results: %s', results)
    local_fetch.cleanup()

    # LocalFileFetch is acting directly on an existing file, so it's cleanup
    # should _not_ delete the file
    assert os.path.isfile(tmp_file.name)