summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2017-11-29 15:13:07 +0000
committerJürg Billeter <j@bitron.ch>2018-02-08 16:38:48 +0100
commit4062a70de39b9b9361459421bd271fee06298242 (patch)
tree50c04688b1ddd1bab002f82dbf5cdbc3798ec257
parent4b3d83107d80c193b812ddb63b7e6628ba678c87 (diff)
downloadbuildstream-4062a70de39b9b9361459421bd271fee06298242.tar.gz
Add test for project-specific artifact shares with junctions
-rw-r--r--tests/artifactcache/junctions.py97
-rw-r--r--tests/artifactcache/junctions/foo/.bst/workspaces.yml0
-rw-r--r--tests/artifactcache/junctions/foo/app.bst7
-rw-r--r--tests/artifactcache/junctions/foo/base.bst4
-rw-r--r--tests/artifactcache/junctions/foo/base/base.txt1
-rw-r--r--tests/artifactcache/junctions/foo/base/project.conf1
-rw-r--r--tests/artifactcache/junctions/foo/base/target.bst4
-rw-r--r--tests/artifactcache/junctions/foo/foo.txt1
-rw-r--r--tests/artifactcache/junctions/foo/project.conf1
-rw-r--r--tests/artifactcache/junctions/foo/target.bst5
10 files changed, 121 insertions, 0 deletions
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
new file mode 100644
index 000000000..9b0786c61
--- /dev/null
+++ b/tests/artifactcache/junctions.py
@@ -0,0 +1,97 @@
+import os
+import shutil
+import pytest
+from tests.testutils import cli, create_artifact_share
+from tests.testutils.site import IS_LINUX
+
+from buildstream import _yaml
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "junctions",
+)
+
+
+# Assert that a given artifact is in the share
+#
+def assert_shared(cli, share, project_name, project, element_name):
+ # NOTE: 'test' here is the name of the project
+ # specified in the project.conf we are testing with.
+ #
+ cache_key = cli.get_element_key(project, element_name)
+ if not share.has_artifact(project_name, element_name, cache_key):
+ raise AssertionError("Artifact share at {} does not contain the expected element {}"
+ .format(share.repo, element_name))
+
+
+def project_set_artifacts(project, url):
+ project_conf_file = os.path.join(project, 'project.conf')
+ project_config = _yaml.load(project_conf_file)
+ project_config.update({
+ 'artifacts': {
+ 'url': url,
+ 'push': True
+ }
+ })
+ _yaml.dump(_yaml.node_sanitize(project_config), filename=project_conf_file)
+
+
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on linux')
+@pytest.mark.datafiles(DATA_DIR)
+def test_push_pull(cli, tmpdir, datafiles):
+ project = os.path.join(str(datafiles), 'foo')
+ base_project = os.path.join(str(project), 'base')
+
+ share = create_artifact_share(os.path.join(str(tmpdir), 'artifactshare-foo'))
+ base_share = create_artifact_share(os.path.join(str(tmpdir), 'artifactshare-base'))
+
+ # First build it without the artifact cache configured
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ assert result.exit_code == 0
+
+ # Assert that we are now cached locally
+ state = cli.get_element_state(project, 'target.bst')
+ assert state == 'cached'
+ state = cli.get_element_state(base_project, 'target.bst')
+ assert state == 'cached'
+
+ project_set_artifacts(project, share.repo)
+ project_set_artifacts(base_project, base_share.repo)
+
+ # Now try bst push
+ result = cli.run(project=project, args=['push', '--deps', 'all', 'target.bst'])
+ assert result.exit_code == 0
+
+ # And finally assert that the artifacts are in the right shares
+ assert_shared(cli, share, 'foo', project, 'target.bst')
+ assert_shared(cli, base_share, 'base', base_project, 'target.bst')
+
+ # Make sure we update the summary in our artifact shares,
+ # we dont have a real server around to do it
+ #
+ share.update_summary()
+ base_share.update_summary()
+
+ # Now we've pushed, delete the user's local artifact cache
+ # directory and try to redownload it from the share
+ #
+ artifacts = os.path.join(cli.directory, 'artifacts')
+ shutil.rmtree(artifacts)
+
+ # Assert that we are now in a downloadable state, nothing
+ # is cached locally anymore
+ state = cli.get_element_state(project, 'target.bst')
+ assert state == 'downloadable'
+ state = cli.get_element_state(base_project, 'target.bst')
+ assert state == 'downloadable'
+
+ # Now try bst pull
+ result = cli.run(project=project, args=['pull', '--deps', 'all', 'target.bst'])
+ assert result.exit_code == 0
+
+ # And assert that they are again in the local cache, without having built
+ state = cli.get_element_state(project, 'target.bst')
+ assert state == 'cached'
+ state = cli.get_element_state(base_project, 'target.bst')
+ assert state == 'cached'
diff --git a/tests/artifactcache/junctions/foo/.bst/workspaces.yml b/tests/artifactcache/junctions/foo/.bst/workspaces.yml
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/.bst/workspaces.yml
diff --git a/tests/artifactcache/junctions/foo/app.bst b/tests/artifactcache/junctions/foo/app.bst
new file mode 100644
index 000000000..e658628b0
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/app.bst
@@ -0,0 +1,7 @@
+kind: import
+sources:
+- kind: local
+ path: foo.txt
+depends:
+- junction: base.bst
+ filename: target.bst
diff --git a/tests/artifactcache/junctions/foo/base.bst b/tests/artifactcache/junctions/foo/base.bst
new file mode 100644
index 000000000..10ce559a9
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/base.bst
@@ -0,0 +1,4 @@
+kind: junction
+sources:
+- kind: local
+ path: base
diff --git a/tests/artifactcache/junctions/foo/base/base.txt b/tests/artifactcache/junctions/foo/base/base.txt
new file mode 100644
index 000000000..a496efee8
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/base/base.txt
@@ -0,0 +1 @@
+This is a text file
diff --git a/tests/artifactcache/junctions/foo/base/project.conf b/tests/artifactcache/junctions/foo/base/project.conf
new file mode 100644
index 000000000..951ea1a34
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/base/project.conf
@@ -0,0 +1 @@
+name: base
diff --git a/tests/artifactcache/junctions/foo/base/target.bst b/tests/artifactcache/junctions/foo/base/target.bst
new file mode 100644
index 000000000..2b61c518b
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/base/target.bst
@@ -0,0 +1,4 @@
+kind: import
+sources:
+- kind: local
+ path: base.txt
diff --git a/tests/artifactcache/junctions/foo/foo.txt b/tests/artifactcache/junctions/foo/foo.txt
new file mode 100644
index 000000000..257cc5642
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/foo.txt
@@ -0,0 +1 @@
+foo
diff --git a/tests/artifactcache/junctions/foo/project.conf b/tests/artifactcache/junctions/foo/project.conf
new file mode 100644
index 000000000..5a240e3ed
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/project.conf
@@ -0,0 +1 @@
+name: foo
diff --git a/tests/artifactcache/junctions/foo/target.bst b/tests/artifactcache/junctions/foo/target.bst
new file mode 100644
index 000000000..70b78a3fc
--- /dev/null
+++ b/tests/artifactcache/junctions/foo/target.bst
@@ -0,0 +1,5 @@
+kind: stack
+depends:
+- junction: base.bst
+ filename: target.bst
+- app.bst