summaryrefslogtreecommitdiff
path: root/tests/frontend/pull.py
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2018-11-14 17:33:24 +0000
committerTom Pollard <tom.pollard@codethink.co.uk>2019-01-29 15:11:15 +0000
commit51bb1341e7db35538aca0aa0a1ca273ee373be0c (patch)
treefc86c2c6e570e55e2541593fb2348f95e2d2bcea /tests/frontend/pull.py
parent99f0d726f993f2c3d5e2a4683fa35d7a28efc2ad (diff)
downloadbuildstream-tpollard/752.tar.gz
Add ability to build without interacting with available artifacttpollard/752
servers. By adding a new user context and bst main option, we can provide more granular control of what remotes are utilised during relevant bst pull and push actions. _artifactcache/artifactcache.py: Expand setup_remotes() to consider the user context value of 'use_remotes'. Allowing the user to omit interacting with all, or all non user defined remotes. tests/frontend: pull.py & push.py addition of tests for checking expected behaviour. Ensures interaction with user, project or no remotes.
Diffstat (limited to 'tests/frontend/pull.py')
-rw-r--r--tests/frontend/pull.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py
index 20b740948..57e1bfdb4 100644
--- a/tests/frontend/pull.py
+++ b/tests/frontend/pull.py
@@ -408,3 +408,75 @@ def test_pull_missing_notifies_user(caplog, cli, tmpdir, datafiles):
assert "INFO Remote ({}) does not have".format(share.repo) in result.stderr
assert "SKIPPED Pull" in result.stderr
+
+
+# Tests that:
+#
+# * The bst main option --use-remotes limits remote action
+# as expected for pull jobs
+#
+@pytest.mark.datafiles(DATA_DIR)
+def test_useremotes_cli_options(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare1')) as shareuser,\
+ create_artifact_share(os.path.join(str(tmpdir), 'artifactshare2')) as shareproject:
+
+ # Add shareproject repo url to project.conf
+ with open(os.path.join(project, "project.conf"), "a") as projconf:
+ projconf.write("artifacts:\n url: {}\n push: True".format(shareproject.repo))
+
+ # First build the target element and push to the remotes.
+ # We need the artifact available in the remotes to test against.
+ cli.configure({
+ 'artifacts': {'url': shareuser.repo, 'push': True}
+ })
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ assert cli.get_element_state(project, 'target.bst') == 'cached'
+
+ # Assert that everything is now cached in the remotes.
+ all_elements = ['target.bst', 'import-bin.bst', 'compose-all.bst']
+ for element_name in all_elements:
+ assert_shared(cli, shareuser, project, element_name)
+ assert_shared(cli, shareproject, project, element_name)
+
+ # Now we've pushed, delete the user's local artifact cache
+ artifacts = os.path.join(cli.directory, 'artifacts')
+ shutil.rmtree(artifacts)
+
+ # Assert that nothing is cached locally anymore
+ for element_name in all_elements:
+ assert cli.get_element_state(project, element_name) != 'cached'
+
+ # Attempt bst build with --use-remotes set as none, this should lead to
+ # a complete rebuild without pulling from either artifact remote cache
+ result = cli.run(project=project, args=['--use-remotes', 'none', 'build', 'target.bst'])
+ result.assert_success()
+ for element_name in all_elements:
+ assert element_name not in result.get_pulled_elements()
+
+ # Delete local cache again
+ artifacts = os.path.join(cli.directory, 'artifacts')
+ shutil.rmtree(artifacts)
+
+ # Attempt bst build with --use-remotes set as user, as the shareuser is
+ # passed in as user config and not via a project, assert project remote
+ # was not attempted by it not being in the output
+ result = cli.run(project=project, args=['--use-remotes', 'user', 'build', 'target.bst'])
+ result.assert_success()
+ for element_name in all_elements:
+ assert element_name in result.get_pulled_elements()
+ assert shareproject.repo not in result.stderr
+
+ # Delete local cache again
+ artifacts = os.path.join(cli.directory, 'artifacts')
+ shutil.rmtree(artifacts)
+
+ # Attempt bst build with --use-remotes set as all, this time
+ # assert that project remote is attempted and in the output
+ result = cli.run(project=project, args=['--use-remotes', 'all', 'build', 'target.bst'])
+ result.assert_success()
+ for element_name in all_elements:
+ assert element_name in result.get_pulled_elements()
+ assert shareproject.repo in result.stderr