diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-10-09 15:37:17 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-10-10 09:47:50 +0000 |
commit | 276cfa63b5aec4760b171b0c4a60962b2a9ba819 (patch) | |
tree | 97df3d122ac5b9e82b98bbab71a743614223f998 /tests | |
parent | d71b8080ab009d7428cf99601f2e1aec50c76772 (diff) | |
download | buildstream-276cfa63b5aec4760b171b0c4a60962b2a9ba819.tar.gz |
_sourcecache: Fallback to fetch source when remote has missing blobs
If a remote has some missing blobs for a source, we should not fail
abruptly but instead continue to the next remote, and, in the worst
case, fetch the source again.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sourcecache/fetch.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/sourcecache/fetch.py b/tests/sourcecache/fetch.py index 8d6d5dcf4..a5863b867 100644 --- a/tests/sourcecache/fetch.py +++ b/tests/sourcecache/fetch.py @@ -180,3 +180,50 @@ def test_pull_fail(cli, tmpdir, datafiles): res.assert_task_error(ErrorDomain.PLUGIN, None) assert "Remote source service ({}) does not have source {} cached".format( share.repo, source._get_brief_display_key()) in res.stderr + + +@pytest.mark.datafiles(DATA_DIR) +def test_source_pull_partial_fallback_fetch(cli, tmpdir, datafiles): + project_dir = str(datafiles) + element_name, repo, ref = create_test_element(tmpdir, project_dir) + cache_dir = os.path.join(str(tmpdir), 'cache') + + # use artifact cache for sources for now, they should work the same + with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share: + with context_with_source_cache(cli, cache_dir, share, tmpdir) as context: + project = Project(project_dir, context) + project.ensure_fully_loaded() + + element = project.load_elements([element_name])[0] + assert not element._source_cached() + source = list(element.sources())[0] + + cas = context.get_cascache() + assert not cas.contains(source._get_source_name()) + + # Just check that we sensibly fetch and build the element + res = cli.run(project=project_dir, args=['build', element_name]) + res.assert_success() + + assert os.listdir(os.path.join(str(tmpdir), 'cache', 'sources', 'git')) != [] + + # get root digest of source + sourcecache = context.sourcecache + digest = sourcecache.export(source)._get_digest() + + move_local_cas_to_remote_source_share(str(cache_dir), share.directory) + + # Remove the cas content, only keep the proto and such around + shutil.rmtree(os.path.join(str(tmpdir), "sourceshare", "repo", "cas", "objects")) + # check the share doesn't have the object + assert not share.has_object(digest) + + state = cli.get_element_state(project_dir, element_name) + assert state == 'fetch needed' + + # Now fetch the source and check + res = cli.run(project=project_dir, args=['source', 'fetch', element_name]) + res.assert_success() + + assert ("SUCCESS Fetching from {}" + .format(repo.source_config(ref=ref)['url'])) in res.stderr |