You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:57:29 UTC

[buildstream] 01/03: cli.py: Allow push to handle artifact refs

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch jennis/deps_for_push
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 1cd7a9c046167a4627106f952deeb0d16e2fe118
Author: James Ennis <ja...@codethink.co.uk>
AuthorDate: Thu Aug 29 10:54:18 2019 +0100

    cli.py: Allow push to handle artifact refs
    
    This patch extends support for bst artifact push so that is now
    able to handle artifact refs.
    
    If --deps all is selected and a ref is given, BuildStream will
    error.
---
 src/buildstream/_frontend/cli.py |  10 ++--
 src/buildstream/_stream.py       |   3 +-
 tests/frontend/push.py           | 102 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 661e395..e78f7b4 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -1177,10 +1177,10 @@ def artifact_pull(app, elements, deps, remote):
               help='The dependencies to push (default: none)')
 @click.option('--remote', '-r', default=None,
               help="The URL of the remote cache (defaults to the first configured cache)")
-@click.argument('elements', nargs=-1,
+@click.argument('artifacts', nargs=-1,
                 type=click.Path(readable=False))
 @click.pass_obj
-def artifact_push(app, elements, deps, remote):
+def artifact_push(app, artifacts, deps, remote):
     """Push a built artifact to a remote artifact cache.
 
     Specifying no elements will result in pushing the default targets
@@ -1206,12 +1206,12 @@ def artifact_push(app, elements, deps, remote):
     with app.initialized(session_name="Push"):
         ignore_junction_targets = False
 
-        if not elements:
-            elements = app.project.get_default_targets()
+        if not artifacts:
+            artifacts = app.project.get_default_targets()
             # Junction elements cannot be pushed, exclude them from default targets
             ignore_junction_targets = True
 
-        app.stream.push(elements, selection=deps, remote=remote,
+        app.stream.push(artifacts, selection=deps, remote=remote,
                         ignore_junction_targets=ignore_junction_targets)
 
 
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index 554deba..bea43f8 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -457,7 +457,8 @@ class Stream():
                                  selection=selection,
                                  ignore_junction_targets=ignore_junction_targets,
                                  use_artifact_config=use_config,
-                                 artifact_remote_url=remote)
+                                 artifact_remote_url=remote,
+                                 load_refs=True)
 
         if not self._artifacts.has_push_remotes():
             raise StreamError("No artifact caches available for pushing artifacts")
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index 9c3947c..4f0fa3c 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -98,6 +98,60 @@ def test_push(cli, tmpdir, datafiles):
             assert_shared(cli, share1, project, 'target.bst')
             assert_shared(cli, share2, project, 'target.bst')
 
+
+# Tests `bst artifact push $artifact_ref`
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_artifact(cli, tmpdir, datafiles):
+    project = str(datafiles)
+    element = 'target.bst'
+
+    # Configure a local cache
+    local_cache = os.path.join(str(tmpdir), 'cache')
+    cli.configure({'cachedir': local_cache})
+
+    with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+
+        # First build it without the artifact cache configured
+        result = cli.run(project=project, args=['build', element])
+        result.assert_success()
+
+        # Assert that the *artifact* is cached locally
+        cache_key = cli.get_element_key(project, element)
+        artifact_ref = os.path.join('test', os.path.splitext(element)[0], cache_key)
+        assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact_ref))
+
+        # Configure artifact share
+        cli.configure({
+            #
+            # FIXME: This test hangs "sometimes" if we allow
+            #        concurrent push.
+            #
+            #        It's not too bad to ignore since we're
+            #        using the local artifact cache functionality
+            #        only, but it should probably be fixed.
+            #
+            'scheduler': {
+                'pushers': 1
+            },
+            'artifacts': {
+                'url': share.repo,
+                'push': True,
+            }
+        })
+
+        # Now try bst artifact push all the deps
+        result = cli.run(project=project, args=[
+            'artifact', 'push', artifact_ref
+        ])
+        result.assert_success()
+
+        # And finally assert that all the artifacts are in the share
+        #
+        # Note that assert shared tests that an element is shared by obtaining
+        # the artifact ref and asserting that the path exists in the share
+        assert_shared(cli, share, project, element)
+
+
 # Tests that:
 #
 #  * `bst artifact push` fails if the element is not cached locally
@@ -231,6 +285,54 @@ def test_push_all(cli, tmpdir, datafiles):
         assert_shared(cli, share, project, 'import-dev.bst')
         assert_shared(cli, share, project, 'compose-all.bst')
 
+# Tests that `bst artifact push --deps run $artifact_ref` fails
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_artifacts_all_deps_fails(cli, tmpdir, datafiles):
+    project = str(datafiles)
+    element = 'checkout-deps.bst'
+
+    # Configure a local cache
+    local_cache = os.path.join(str(tmpdir), 'cache')
+    cli.configure({'cachedir': local_cache})
+
+    with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+
+        # First build it without the artifact cache configured
+        result = cli.run(project=project, args=['build', element])
+        result.assert_success()
+
+        # Assert that the *artifact* is cached locally
+        cache_key = cli.get_element_key(project, element)
+        artifact_ref = os.path.join('test', os.path.splitext(element)[0], cache_key)
+        assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact_ref))
+
+        # Configure artifact share
+        cli.configure({
+            #
+            # FIXME: This test hangs "sometimes" if we allow
+            #        concurrent push.
+            #
+            #        It's not too bad to ignore since we're
+            #        using the local artifact cache functionality
+            #        only, but it should probably be fixed.
+            #
+            'scheduler': {
+                'pushers': 1
+            },
+            'artifacts': {
+                'url': share.repo,
+                'push': True,
+            }
+        })
+
+        # Now try bst artifact push all the deps
+        result = cli.run(project=project, args=[
+            'artifact', 'push', '--deps', 'all', artifact_ref
+        ])
+        result.assert_main_error(ErrorDomain.STREAM, None)
+
+        assert "Error: '--deps all' is not supported for artifact refs" in result.stderr
+
 
 # Tests that `bst build` won't push artifacts to the cache it just pulled from.
 #