summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-06-11 17:16:04 +0100
committerRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-06-24 10:21:27 +0100
commitc69a6ee7a464bc651567e67217c8c093cc956f88 (patch)
treed460e75e322612a99a72f3570a3d847fce3d50f8
parent7372381f42d6982b584e9d1176f1269728aebf1b (diff)
downloadbuildstream-c69a6ee7a464bc651567e67217c8c093cc956f88.tar.gz
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
-rw-r--r--tests/frontend/buildcheckout.py64
1 files changed, 63 insertions, 1 deletions
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)