Verified Commit 52f6eeb2 authored by Iñaki Malerba's avatar Iñaki Malerba
Browse files

Add --control-build parameter.

Allow reusing a previous build as control_build to avoid building the
control package if a previous build is available.

Intended to be applied on the Salsa CI Pipeline.
salsa-ci-team/pipeline#118
parent fa0e2865
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -264,10 +264,10 @@ class TestbedArgs(collections.namedtuple('_TestbedArgs',


class TestArgs(collections.namedtuple('_Test',
    'build_command source_root artifact_pattern result_dir source_pattern no_clean_on_error diffoscope_args')):
    'build_command source_root artifact_pattern result_dir source_pattern no_clean_on_error diffoscope_args control_build')):
    @classmethod
    def of(cls, build_command, source_root, artifact_pattern, result_dir=None,
                source_pattern=None, no_clean_on_error=False, diffoscope_args=['diffoscope']):
                source_pattern=None, no_clean_on_error=False, diffoscope_args=['diffoscope'], control_build=None):
        artifact_pattern = shell_syn.sanitize_globs(artifact_pattern)
        logger.debug("artifact_pattern sanitized to: %s", artifact_pattern)

@@ -275,7 +275,7 @@ class TestArgs(collections.namedtuple('_Test',
            source_pattern = shell_syn.sanitize_globs(source_pattern)
            logger.debug("source_pattern sanitized to: %s", source_pattern)
        return cls(build_command, source_root, artifact_pattern, result_dir,
                   source_pattern, no_clean_on_error, diffoscope_args)
                   source_pattern, no_clean_on_error, diffoscope_args, control_build)

    @coroutine
    def corun_builds(self, testbed_args):
@@ -286,7 +286,7 @@ class TestArgs(collections.namedtuple('_Test',
        .>>>     local_dist = proc.send((name, var))
        .>>>     ...
        """
        build_command, source_root, artifact_pattern, result_dir, source_pattern, no_clean_on_error, diffoscope_args = self
        build_command, source_root, artifact_pattern, result_dir, source_pattern, no_clean_on_error, diffoscope_args, control_build = self
        virtual_server_args, testbed_pre, testbed_init, testbed_build_pre, host_distro = testbed_args

        if not source_root:
@@ -354,13 +354,19 @@ class TestArgs(collections.namedtuple('_Test',

def check(test_args, testbed_args, build_variations=Variations.of(VariationSpec.default())):
    # default argument [] is safe here because we never mutate it.
    _, _, artifact_pattern, store_dir, _, _, diffoscope_args = test_args
    _, _, artifact_pattern, store_dir, _, _, diffoscope_args, control_build = test_args
    with empty_or_temp_dir(store_dir, "store_dir") as result_dir:
        assert store_dir == result_dir or store_dir is None
        proc = test_args._replace(result_dir=result_dir).corun_builds(testbed_args)

        bnames = ["control"] + ["experiment-%s" % i for i in range(1, len(build_variations))]
        local_dists = [proc.send(nv) for nv in zip(bnames, build_variations)]

        if control_build:
            local_dists = [control_build]
        else:
            local_dists = [proc.send(("control", build_variations[0]))]

        local_dists += [proc.send(nv) for nv in zip(bnames[1:], build_variations[1:])]

        retcodes = collections.OrderedDict(
            (bname, run_diff(local_dists[0], dist, diffoscope_args, store_dir))
@@ -385,7 +391,7 @@ def check(test_args, testbed_args, build_variations=Variations.of(VariationSpec.

def check_auto(test_args, testbed_args, build_variations=Variations.of(VariationSpec.default())):
    # default argument [] is safe here because we never mutate it.
    _, _, _, store_dir, _, _, diffoscope_args = test_args
    _, _, _, store_dir, _, _, diffoscope_args, _ = test_args
    with empty_or_temp_dir(store_dir, "store_dir") as result_dir:
        assert store_dir == result_dir or store_dir is None
        proc = test_args._replace(result_dir=result_dir).corun_builds(testbed_args)
@@ -425,7 +431,7 @@ def check_auto(test_args, testbed_args, build_variations=Variations.of(Variation

def check_env(test_args, testbed_args, build_variations=Variations.of(VariationSpec.default())):
    # default argument [] is safe here because we never mutate it.
    _, _, artifact_pattern, store_dir, _, _, diffoscope_args = test_args
    _, _, artifact_pattern, store_dir, _, _, diffoscope_args, _ = test_args
    with empty_or_temp_dir(store_dir, "store_dir") as result_dir:
        assert store_dir == result_dir or store_dir is None
        proc = test_args._replace(result_dir=result_dir).corun_builds(testbed_args)
@@ -635,6 +641,9 @@ def cli_parser():
    group3.add_argument('--print-sudoers', action='store_true', default=False,
        help='Print a sudoers file for passwordless operation using the given '
        '--variations, useful for user_group.available, domain_host.use_sudo.')
    group3.add_argument('--control-build',  default=None,
        help='Override control build with artifacts located on this path. '
        'Allows reusing previous build as baseline.')

    return parser

@@ -816,6 +825,7 @@ def run(argv, dry_run=None):
        diffoscope_args = None
    else:
        diffoscope_args = [diffoscope] + diffoscope_args
    control_build = parsed_args.control_build

    if not artifact_pattern:
        print("No <artifact> to test for differences provided. See --help for options.")
@@ -823,7 +833,7 @@ def run(argv, dry_run=None):

    testbed_args = TestbedArgs.of(virtual_server_args, testbed_pre, testbed_init, testbed_build_pre, host_distro)
    test_args = TestArgs.of(build_command, source_root, artifact_pattern, store_dir,
                            source_pattern, no_clean_on_error, diffoscope_args)
                            source_pattern, no_clean_on_error, diffoscope_args, control_build)

    check_args = (test_args, testbed_args, build_variations)
    if dry_run: