summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-03-14 17:38:48 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-25 11:46:44 +0000
commit85b86204a7114e0b388b65871258f562853240c0 (patch)
tree79e8a3fd4cc6c3d59b5bd11712cc1728a9fdc4f1
parent5b96fa6bfc8fd6fc897a3aafe889221db268bbcf (diff)
downloadbuildstream-85b86204a7114e0b388b65871258f562853240c0.tar.gz
tests: source and artifact cache test
Ensures that remote source cache and artifact caches work fine together. Part of #440
-rw-r--r--tests/frontend/remote-caches.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/frontend/remote-caches.py b/tests/frontend/remote-caches.py
new file mode 100644
index 000000000..3e3e226fc
--- /dev/null
+++ b/tests/frontend/remote-caches.py
@@ -0,0 +1,91 @@
+#
+# Copyright (C) 2019 Bloomberg Finance LP
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>
+#
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+import os
+import shutil
+import pytest
+
+from buildstream.plugintestutils import cli # pylint: disable=unused-import
+from buildstream import _yaml
+
+from tests.testutils import create_artifact_share, create_element_size
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'project')
+
+
+def message_handler(message, context):
+ pass
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_source_artifact_caches(cli, tmpdir, datafiles):
+ cachedir = os.path.join(str(tmpdir), 'cache')
+ project_dir = str(datafiles)
+ element_path = os.path.join(project_dir, 'elements')
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'share')) as share:
+ user_config_file = str(tmpdir.join('buildstream.conf'))
+ user_config = {
+ 'scheduler': {
+ 'pushers': 1
+ },
+ 'source-caches': {
+ 'url': share.repo,
+ 'push': True,
+ },
+ 'artifacts': {
+ 'url': share.repo,
+ 'push': True,
+ },
+ 'cachedir': cachedir
+ }
+ _yaml.dump(_yaml.node_sanitize(user_config), filename=user_config_file)
+ cli.configure(user_config)
+
+ create_element_size('repo.bst', project_dir, element_path, [], 10000)
+
+ res = cli.run(project=project_dir, args=['build', 'repo.bst'])
+ res.assert_success()
+ assert "Pushed source " in res.stderr
+ assert "Pushed artifact " in res.stderr
+
+ # delete local sources and artifacts and check it pulls them
+ shutil.rmtree(os.path.join(cachedir, 'cas'))
+ shutil.rmtree(os.path.join(cachedir, 'sources'))
+
+ # this should just fetch the artifacts
+ res = cli.run(project=project_dir, args=['build', 'repo.bst'])
+ res.assert_success()
+ assert "Pulled artifact " in res.stderr
+ assert "Pulled source " not in res.stderr
+
+ # remove the artifact from the repo and check it pulls sources, builds
+ # and then pushes the artifacts
+ shutil.rmtree(os.path.join(cachedir, 'cas'))
+ print(os.listdir(os.path.join(share.repodir, 'cas', 'refs', 'heads')))
+ shutil.rmtree(os.path.join(share.repodir, 'cas', 'refs', 'heads', 'test'))
+
+ res = cli.run(project=project_dir, args=['build', 'repo.bst'])
+ res.assert_success()
+ assert "Remote ({}) does not have artifact ".format(share.repo) in res.stderr
+ assert "Pulled source" in res.stderr
+ assert "Caching artifact" in res.stderr
+ assert "Pushed artifact" in res.stderr