diff options
Diffstat (limited to 'tests/sourcecache/push.py')
-rw-r--r-- | tests/sourcecache/push.py | 175 |
1 files changed, 67 insertions, 108 deletions
diff --git a/tests/sourcecache/push.py b/tests/sourcecache/push.py index 406aeba9f..719860425 100644 --- a/tests/sourcecache/push.py +++ b/tests/sourcecache/push.py @@ -47,6 +47,7 @@ def message_handler(message, is_silenced): @contextmanager def _configure_caches(tmpdir, *directories): with ExitStack() as stack: + def create_share(directory): return create_artifact_share(os.path.join(str(tmpdir), directory)) @@ -55,37 +56,27 @@ def _configure_caches(tmpdir, *directories): @pytest.mark.datafiles(DATA_DIR) def test_source_push_split(cli, tmpdir, datafiles): - cache_dir = os.path.join(str(tmpdir), 'cache') + cache_dir = os.path.join(str(tmpdir), "cache") project_dir = str(datafiles) - with _configure_caches(tmpdir, 'indexshare', 'storageshare') as (index, storage): - user_config_file = str(tmpdir.join('buildstream.conf')) + with _configure_caches(tmpdir, "indexshare", "storageshare") as (index, storage): + user_config_file = str(tmpdir.join("buildstream.conf")) user_config = { - 'scheduler': { - 'pushers': 1 - }, - 'source-caches': [{ - 'url': index.repo, - 'push': True, - 'type': 'index' - }, { - 'url': storage.repo, - 'push': True, - 'type': 'storage' - }], - 'cachedir': cache_dir + "scheduler": {"pushers": 1}, + "source-caches": [ + {"url": index.repo, "push": True, "type": "index"}, + {"url": storage.repo, "push": True, "type": "storage"}, + ], + "cachedir": cache_dir, } _yaml.roundtrip_dump(user_config, file=user_config_file) cli.configure(user_config) - repo = create_repo('git', str(tmpdir)) - ref = repo.create(os.path.join(project_dir, 'files')) - element_path = os.path.join(project_dir, 'elements') - element_name = 'push.bst' - element = { - 'kind': 'import', - 'sources': [repo.source_config(ref=ref)] - } + repo = create_repo("git", str(tmpdir)) + ref = repo.create(os.path.join(project_dir, "files")) + element_path = os.path.join(project_dir, "elements") + element_name = "push.bst" + element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) # get the source object @@ -93,7 +84,7 @@ def test_source_push_split(cli, tmpdir, datafiles): project = Project(project_dir, context) project.ensure_fully_loaded() - element = project.load_elements(['push.bst'])[0] + element = project.load_elements(["push.bst"])[0] assert not element._source_cached() source = list(element.sources())[0] @@ -103,7 +94,7 @@ def test_source_push_split(cli, tmpdir, datafiles): # build the element, this should fetch and then push the source to the # remote - res = cli.run(project=project_dir, args=['build', 'push.bst']) + res = cli.run(project=project_dir, args=["build", "push.bst"]) res.assert_success() assert "Pushed source" in res.stderr @@ -118,32 +109,24 @@ def test_source_push_split(cli, tmpdir, datafiles): @pytest.mark.datafiles(DATA_DIR) def test_source_push(cli, tmpdir, datafiles): - cache_dir = os.path.join(str(tmpdir), 'cache') + cache_dir = os.path.join(str(tmpdir), "cache") project_dir = str(datafiles) - with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share: - user_config_file = str(tmpdir.join('buildstream.conf')) + with create_artifact_share(os.path.join(str(tmpdir), "sourceshare")) as share: + user_config_file = str(tmpdir.join("buildstream.conf")) user_config = { - 'scheduler': { - 'pushers': 1 - }, - 'source-caches': { - 'url': share.repo, - 'push': True, - }, - 'cachedir': cache_dir, + "scheduler": {"pushers": 1}, + "source-caches": {"url": share.repo, "push": True,}, + "cachedir": cache_dir, } _yaml.roundtrip_dump(user_config, file=user_config_file) cli.configure(user_config) - repo = create_repo('git', str(tmpdir)) - ref = repo.create(os.path.join(project_dir, 'files')) - element_path = os.path.join(project_dir, 'elements') - element_name = 'push.bst' - element = { - 'kind': 'import', - 'sources': [repo.source_config(ref=ref)] - } + repo = create_repo("git", str(tmpdir)) + ref = repo.create(os.path.join(project_dir, "files")) + element_path = os.path.join(project_dir, "elements") + element_name = "push.bst" + element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) # get the source object @@ -151,7 +134,7 @@ def test_source_push(cli, tmpdir, datafiles): project = Project(project_dir, context) project.ensure_fully_loaded() - element = project.load_elements(['push.bst'])[0] + element = project.load_elements(["push.bst"])[0] assert not element._source_cached() source = list(element.sources())[0] @@ -161,7 +144,7 @@ def test_source_push(cli, tmpdir, datafiles): # build the element, this should fetch and then push the source to the # remote - res = cli.run(project=project_dir, args=['build', 'push.bst']) + res = cli.run(project=project_dir, args=["build", "push.bst"]) res.assert_success() assert "Pushed source" in res.stderr @@ -177,35 +160,27 @@ def test_source_push(cli, tmpdir, datafiles): @pytest.mark.datafiles(DATA_DIR) def test_push_pull(cli, datafiles, tmpdir): project_dir = str(datafiles) - cache_dir = os.path.join(str(tmpdir), 'cache') + cache_dir = os.path.join(str(tmpdir), "cache") - with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share: - user_config_file = str(tmpdir.join('buildstream.conf')) + with create_artifact_share(os.path.join(str(tmpdir), "sourceshare")) as share: + user_config_file = str(tmpdir.join("buildstream.conf")) user_config = { - 'scheduler': { - 'pushers': 1 - }, - 'source-caches': { - 'url': share.repo, - 'push': True, - }, - 'cachedir': cache_dir, + "scheduler": {"pushers": 1}, + "source-caches": {"url": share.repo, "push": True,}, + "cachedir": cache_dir, } _yaml.roundtrip_dump(user_config, file=user_config_file) cli.configure(user_config) # create repo to pull from - repo = create_repo('git', str(tmpdir)) - ref = repo.create(os.path.join(project_dir, 'files')) - element_path = os.path.join(project_dir, 'elements') - element_name = 'push.bst' - element = { - 'kind': 'import', - 'sources': [repo.source_config(ref=ref)] - } + repo = create_repo("git", str(tmpdir)) + ref = repo.create(os.path.join(project_dir, "files")) + element_path = os.path.join(project_dir, "elements") + element_name = "push.bst" + element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) - res = cli.run(project=project_dir, args=['build', 'push.bst']) + res = cli.run(project=project_dir, args=["build", "push.bst"]) res.assert_success() # remove local cache dir, and repo files and check it all works @@ -214,45 +189,37 @@ def test_push_pull(cli, datafiles, tmpdir): shutil.rmtree(repo.repo) # check it's pulls from the share - res = cli.run(project=project_dir, args=['build', 'push.bst']) + res = cli.run(project=project_dir, args=["build", "push.bst"]) res.assert_success() @pytest.mark.datafiles(DATA_DIR) def test_push_fail(cli, tmpdir, datafiles): project_dir = str(datafiles) - cache_dir = os.path.join(str(tmpdir), 'cache') + cache_dir = os.path.join(str(tmpdir), "cache") # set up config with remote that we'll take down - with create_artifact_share(os.path.join(str(tmpdir), 'sourceshare')) as share: + with create_artifact_share(os.path.join(str(tmpdir), "sourceshare")) as share: remote = share.repo - user_config_file = str(tmpdir.join('buildstream.conf')) + user_config_file = str(tmpdir.join("buildstream.conf")) user_config = { - 'scheduler': { - 'pushers': 1 - }, - 'source-caches': { - 'url': share.repo, - 'push': True, - }, - 'cachedir': cache_dir, + "scheduler": {"pushers": 1}, + "source-caches": {"url": share.repo, "push": True,}, + "cachedir": cache_dir, } _yaml.roundtrip_dump(user_config, file=user_config_file) cli.configure(user_config) # create repo to pull from - repo = create_repo('git', str(tmpdir)) - ref = repo.create(os.path.join(project_dir, 'files')) - element_path = os.path.join(project_dir, 'elements') - element_name = 'push.bst' - element = { - 'kind': 'import', - 'sources': [repo.source_config(ref=ref)] - } + repo = create_repo("git", str(tmpdir)) + ref = repo.create(os.path.join(project_dir, "files")) + element_path = os.path.join(project_dir, "elements") + element_name = "push.bst" + element = {"kind": "import", "sources": [repo.source_config(ref=ref)]} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) # build and check that it fails to set up the remote - res = cli.run(project=project_dir, args=['build', 'push.bst']) + res = cli.run(project=project_dir, args=["build", "push.bst"]) res.assert_success() assert "Failed to initialize remote {}".format(remote) in res.stderr @@ -260,37 +227,29 @@ def test_push_fail(cli, tmpdir, datafiles): assert "Pushed" not in res.stderr -@pytest.mark.xfail(HAVE_SANDBOX == 'buildbox', reason='Not working with BuildBox') +@pytest.mark.xfail(HAVE_SANDBOX == "buildbox", reason="Not working with BuildBox") @pytest.mark.datafiles(DATA_DIR) def test_source_push_build_fail(cli, tmpdir, datafiles): project_dir = str(datafiles) - cache_dir = os.path.join(str(tmpdir), 'cache') + cache_dir = os.path.join(str(tmpdir), "cache") - with create_artifact_share(os.path.join(str(tmpdir), 'share')) as share: + with create_artifact_share(os.path.join(str(tmpdir), "share")) as share: user_config = { - 'scheduler': { - 'pushers': 1 - }, - 'source-caches': { - 'url': share.repo, - 'push': True, - }, - 'cachedir': cache_dir, + "scheduler": {"pushers": 1}, + "source-caches": {"url": share.repo, "push": True,}, + "cachedir": cache_dir, } cli.configure(user_config) - repo = create_repo('git', str(tmpdir)) - ref = repo.create(os.path.join(project_dir, 'files')) - element_path = os.path.join(project_dir, 'elements') + repo = create_repo("git", str(tmpdir)) + ref = repo.create(os.path.join(project_dir, "files")) + element_path = os.path.join(project_dir, "elements") - element_name = 'always-fail.bst' - element = { - 'kind': 'always_fail', - 'sources': [repo.source_config(ref=ref)] - } + element_name = "always-fail.bst" + element = {"kind": "always_fail", "sources": [repo.source_config(ref=ref)]} _yaml.roundtrip_dump(element, os.path.join(element_path, element_name)) - res = cli.run(project=project_dir, args=['build', 'always-fail.bst']) + res = cli.run(project=project_dir, args=["build", "always-fail.bst"]) res.assert_main_error(ErrorDomain.STREAM, None) res.assert_task_error(ErrorDomain.ELEMENT, None) |