From a6b56e65cac38fd1f367d469f2079b2f703dabc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 24 Mar 2021 11:02:20 +0100 Subject: [PATCH 1/2] _stream.py: Do not connect artifact remote caches if pull is disabled If artifact remote caches are available, elements are marked as pull pending in non-strict mode if the strict artifact is not in the local cache. Fixes #1469. --- src/buildstream/_stream.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index 8ff60df54..d03480ebd 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -271,7 +271,7 @@ def shell( elements = self.load_selection( (target,), selection=selection, - connect_artifact_cache=True, + connect_artifact_cache=pull_, connect_source_cache=True, artifact_remotes=artifact_remotes, source_remotes=source_remotes, @@ -670,7 +670,7 @@ def checkout( selection=selection, load_artifacts=True, attempt_artifact_metadata=True, - connect_artifact_cache=True, + connect_artifact_cache=pull, artifact_remotes=artifact_remotes, ignore_project_artifact_remotes=ignore_project_artifact_remotes, ) @@ -685,7 +685,7 @@ def checkout( self.query_cache(elements) - uncached_elts = [elt for elt in elements if not elt._cached()] + uncached_elts = [elt for elt in elements if elt._pull_pending()] if uncached_elts and pull: self._context.messenger.info("Attempting to fetch missing or incomplete artifact") self._reset() From 05b217bca1c6d292dff412b5e2133478688e839c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Wed, 24 Mar 2021 11:23:15 +0100 Subject: [PATCH 2/2] tests/frontend/buildcheckout.py: Add test_non_strict_checkout_uncached This is a regression test for #1469. --- tests/frontend/buildcheckout.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 628e886ef..72587b31f 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -148,6 +148,27 @@ def test_non_strict_pull_build_strict_checkout(datafiles, cli, tmpdir): assert os.path.exists(filename) +# Regression test for https://github.com/apache/buildstream/issues/1469 +# Test that artifact checkout without pull doesn't trigger a BUG in non-strict mode. +@pytest.mark.datafiles(DATA_DIR) +def test_non_strict_checkout_uncached(datafiles, cli, tmpdir): + project = str(datafiles) + checkout = os.path.join(cli.directory, "checkout") + + element_name = "target.bst" + + with create_artifact_share(os.path.join(str(tmpdir), "artifactshare")) as share: + + cli.configure({"artifacts": {"servers": [{"url": share.repo}]}}) + + # Attempt to checkout an uncached artifact with remote artifact server + # configured but pull disabled. + result = cli.run( + project=project, args=["--no-strict", "artifact", "checkout", element_name, "--directory", checkout] + ) + result.assert_main_error(ErrorDomain.STREAM, "uncached-checkout-attempt") + + @pytest.mark.datafiles(DATA_DIR) @pytest.mark.parametrize("strict,hardlinks", [("non-strict", "hardlinks"),]) def test_build_invalid_suffix(datafiles, cli, strict, hardlinks):