From c69a6ee7a464bc651567e67217c8c093cc956f88 Mon Sep 17 00:00:00 2001 From: Raoul Hidalgo Charman Date: Tue, 11 Jun 2019 17:16:04 +0100 Subject: tests: Add tests to buildcheckout for pulling One test to check that artifacts are pulled and a checkout is successful when the --pull option is specified. Another to check that it attempts to pull but fails gracefully if the artifact isn't present. Part of #1044 --- tests/frontend/buildcheckout.py | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 556bf811c..97bce91a7 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -5,6 +5,7 @@ import os import tarfile import hashlib import subprocess +import re import pytest @@ -12,8 +13,9 @@ from buildstream.testing import cli # pylint: disable=unused-import from buildstream.testing._utils.site import IS_WINDOWS from buildstream import _yaml from buildstream._exceptions import ErrorDomain, LoadErrorReason +from buildstream import utils -from tests.testutils import generate_junction, yaml_file_get_provenance +from tests.testutils import generate_junction, yaml_file_get_provenance, create_artifact_share from . import configure_project @@ -823,3 +825,63 @@ def test_build_junction_transitive_short_notation_with_junction(cli, tmpdir, dat # cross-junction elements is not allowed. result = cli.run(project=project, args=['build', 'junction-dep.bst']) result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA) + + +# Should check that after a build we have partial artifacts locally, but should +# then attempt to fetch them when doing a artifact checkout +@pytest.mark.datafiles(DATA_DIR) +def test_partial_artifact_checkout_fetch(cli, datafiles, tmpdir): + project = str(datafiles) + build_elt = 'import-bin.bst' + checkout_dir = os.path.join(str(tmpdir), 'checkout') + + with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share: + + cli.configure({'artifacts': { + 'url': share.repo, + 'push': True + }}) + + result = cli.run(project=project, args=['build', build_elt]) + result.assert_success() + + # A push artifact cache means we have to pull to push to them, so + # delete some blobs from that CAS such that we have to fetch + digest = utils.sha256sum(os.path.join(project, 'files', 'bin-files', 'usr', 'bin', 'hello')) + objpath = os.path.join(cli.directory, 'cas', 'objects', digest[:2], digest[2:]) + os.unlink(objpath) + + # Verify that the build-only dependency is not (complete) in the local cache + result = cli.run(project=project, args=[ + 'artifact', 'checkout', build_elt, + '--directory', checkout_dir]) + result.assert_main_error(ErrorDomain.STREAM, 'uncached-checkout-attempt') + + # Verify that the pull method fetches relevant artifacts in order to stage + result = cli.run(project=project, args=[ + 'artifact', 'checkout', '--pull', build_elt, + '--directory', checkout_dir]) + result.assert_success() + + # should have pulled whatever was deleted previous + assert 'import-bin.bst' in result.get_pulled_elements() + + +@pytest.mark.datafiles(DATA_DIR) +def test_partial_checkout_fail(tmpdir, datafiles, cli): + project = str(datafiles) + build_elt = 'import-bin.bst' + checkout_dir = os.path.join(str(tmpdir), 'checkout') + + with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share: + + cli.configure({'artifacts': { + 'url': share.repo, + 'push': True + }}) + + res = cli.run(project=project, args=[ + 'artifact', 'checkout', '--pull', build_elt, '--directory', + checkout_dir]) + res.assert_main_error(ErrorDomain.STREAM, 'uncached-checkout-attempt') + assert re.findall(r'Remote \((\S+)\) does not have artifact (\S+) cached', res.stderr) -- cgit v1.2.1