This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch bschubert/standardize-source-tests in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 118b4b88f5275fe0aed2223128dccd3c4712c808 Author: Benjamin Schubert <[email protected]> AuthorDate: Tue Oct 6 19:48:27 2020 +0000 source_determinism.py: Adapt to use the standard source tests --- src/buildstream/testing/_sourcetests/__init__.py | 3 +- .../testing/_sourcetests/source_determinism.py | 136 +++++++++++---------- 2 files changed, 71 insertions(+), 68 deletions(-) diff --git a/src/buildstream/testing/_sourcetests/__init__.py b/src/buildstream/testing/_sourcetests/__init__.py index f046b02..c21d185 100644 --- a/src/buildstream/testing/_sourcetests/__init__.py +++ b/src/buildstream/testing/_sourcetests/__init__.py @@ -22,9 +22,10 @@ from .build_checkout import BuildCheckoutSourceTests from .fetch import FetchSourceTests from .mirror import MirrorSourceTests +from .source_determinism import SourceDeterminismTests __all__ = ["SourceTests"] -class SourceTests(BuildCheckoutSourceTests, FetchSourceTests, MirrorSourceTests): +class SourceTests(BuildCheckoutSourceTests, FetchSourceTests, MirrorSourceTests, SourceDeterminismTests): """Definition of standardized tests that each source should pass.""" diff --git a/src/buildstream/testing/_sourcetests/source_determinism.py b/src/buildstream/testing/_sourcetests/source_determinism.py index b834f32..af5ea63 100644 --- a/src/buildstream/testing/_sourcetests/source_determinism.py +++ b/src/buildstream/testing/_sourcetests/source_determinism.py @@ -23,10 +23,9 @@ import os import pytest from buildstream import _yaml +from .base import BaseSourceTests from .._utils.site import HAVE_SANDBOX, CASD_SEPARATE_USER -from .. import create_repo from .. import cli # pylint: disable=unused-import -from .utils import kind # pylint: disable=unused-import # Project directory TOP_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -47,68 +46,71 @@ def create_test_directory(*path, mode=0o644): os.chmod(path, mode) [email protected] [email protected](DATA_DIR) [email protected](not HAVE_SANDBOX, reason="Only available with a functioning sandbox") -def test_deterministic_source_umask(cli, tmpdir, datafiles, kind): - if CASD_SEPARATE_USER and kind == "ostree": - pytest.xfail("The ostree plugin ignores the umask") - - project = str(datafiles) - element_name = "list.bst" - element_path = os.path.join(project, "elements", element_name) - repodir = os.path.join(str(tmpdir), "repo") - sourcedir = os.path.join(project, "source") - - create_test_file(sourcedir, "a.txt", mode=0o700) - create_test_file(sourcedir, "b.txt", mode=0o755) - create_test_file(sourcedir, "c.txt", mode=0o600) - create_test_file(sourcedir, "d.txt", mode=0o400) - create_test_file(sourcedir, "e.txt", mode=0o644) - create_test_file(sourcedir, "f.txt", mode=0o4755) - create_test_file(sourcedir, "g.txt", mode=0o2755) - create_test_file(sourcedir, "h.txt", mode=0o1755) - create_test_directory(sourcedir, "dir-a", mode=0o0700) - create_test_directory(sourcedir, "dir-c", mode=0o0755) - create_test_directory(sourcedir, "dir-d", mode=0o4755) - create_test_directory(sourcedir, "dir-e", mode=0o2755) - create_test_directory(sourcedir, "dir-f", mode=0o1755) - - repo = create_repo(kind, repodir) - ref = repo.create(sourcedir) - source = repo.source_config(ref=ref) - element = { - "kind": "manual", - "depends": [{"filename": "base.bst", "type": "build"}], - "sources": [source], - "config": {"install-commands": ['ls -l >"%{install-root}/ls-l"']}, - } - _yaml.roundtrip_dump(element, element_path) - - def get_value_for_umask(umask): - checkoutdir = os.path.join(str(tmpdir), "checkout-{}".format(umask)) - - old_umask = os.umask(umask) - - try: - test_values = [] - result = cli.run(project=project, args=["build", element_name]) - result.assert_success() - - result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkoutdir]) - result.assert_success() - - with open(os.path.join(checkoutdir, "ls-l"), "r") as f: - for line in f.readlines(): - test_values.append(line.split()[0] + " " + line.split()[-1]) - return test_values - finally: - os.umask(old_umask) - cli.remove_artifact_from_cache(project, element_name) - - if CASD_SEPARATE_USER: - # buildbox-casd running as separate user of the same group can't - # function in a test environment with a too restrictive umask. - assert get_value_for_umask(0o002) == get_value_for_umask(0o007) - else: - assert get_value_for_umask(0o022) == get_value_for_umask(0o077) +class SourceDeterminismTests(BaseSourceTests): + @pytest.mark.integration + @pytest.mark.datafiles(DATA_DIR) + @pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox") + def test_deterministic_source_umask(self, cli, tmpdir, datafiles): + if CASD_SEPARATE_USER and self.KIND == "ostree": + pytest.xfail("The ostree plugin ignores the umask") + + project = str(datafiles) + element_name = "list.bst" + element_path = os.path.join(project, "elements", element_name) + repodir = os.path.join(str(tmpdir), "repo") + sourcedir = os.path.join(project, "source") + + create_test_file(sourcedir, "a.txt", mode=0o700) + create_test_file(sourcedir, "b.txt", mode=0o755) + create_test_file(sourcedir, "c.txt", mode=0o600) + create_test_file(sourcedir, "d.txt", mode=0o400) + create_test_file(sourcedir, "e.txt", mode=0o644) + create_test_file(sourcedir, "f.txt", mode=0o4755) + create_test_file(sourcedir, "g.txt", mode=0o2755) + create_test_file(sourcedir, "h.txt", mode=0o1755) + create_test_directory(sourcedir, "dir-a", mode=0o0700) + create_test_directory(sourcedir, "dir-c", mode=0o0755) + create_test_directory(sourcedir, "dir-d", mode=0o4755) + create_test_directory(sourcedir, "dir-e", mode=0o2755) + create_test_directory(sourcedir, "dir-f", mode=0o1755) + + repo = self.REPO(repodir) + ref = repo.create(sourcedir) + source = repo.source_config(ref=ref) + element = { + "kind": "manual", + "depends": [{"filename": "base.bst", "type": "build"}], + "sources": [source], + "config": {"install-commands": ['ls -l >"%{install-root}/ls-l"']}, + } + _yaml.roundtrip_dump(element, element_path) + + def get_value_for_umask(umask): + checkoutdir = os.path.join(str(tmpdir), "checkout-{}".format(umask)) + + old_umask = os.umask(umask) + + try: + test_values = [] + result = cli.run(project=project, args=["build", element_name]) + result.assert_success() + + result = cli.run( + project=project, args=["artifact", "checkout", element_name, "--directory", checkoutdir] + ) + result.assert_success() + + with open(os.path.join(checkoutdir, "ls-l"), "r") as f: + for line in f.readlines(): + test_values.append(line.split()[0] + " " + line.split()[-1]) + return test_values + finally: + os.umask(old_umask) + cli.remove_artifact_from_cache(project, element_name) + + if CASD_SEPARATE_USER: + # buildbox-casd running as separate user of the same group can't + # function in a test environment with a too restrictive umask. + assert get_value_for_umask(0o002) == get_value_for_umask(0o007) + else: + assert get_value_for_umask(0o022) == get_value_for_umask(0o077)
