[reprotest] 01/01: More refactoring to support > 2 builds
Ximin Luo
infinity0 at debian.org
Fri Sep 15 12:42:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository reprotest.
commit 57021e9d146ddb2381914955674f6802959899c9
Author: Ximin Luo <infinity0 at debian.org>
Date: Fri Sep 15 14:41:49 2017 +0200
More refactoring to support > 2 builds
---
README.rst | 8 ++++----
reprotest/__init__.py | 31 +++++++++++++++----------------
reprotest/build.py | 8 +++++---
tests/test_reprotest.py | 4 +++-
4 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/README.rst b/README.rst
index 21308c0..3e5eb30 100644
--- a/README.rst
+++ b/README.rst
@@ -270,11 +270,11 @@ your use-case::
$ cat <<EOF | sudo tee -a /etc/sudoers.d/local-reprotest
$USER ALL = ($OTHERUSER) NOPASSWD: ALL
$USER ALL = NOPASSWD: /bin/chown -h -R --from=$OTHERUSER $USER /tmp/autopkgtest.$a$a$a$a$a$a/const_build_path/
- $USER ALL = NOPASSWD: /bin/chown -h -R --from=$OTHERUSER $USER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment/
- $USER ALL = NOPASSWD: /bin/chown -h -R --from=$OTHERUSER $USER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-before-disorderfs/
+ $USER ALL = NOPASSWD: /bin/chown -h -R --from=$OTHERUSER $USER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-[1-9]/
+ $USER ALL = NOPASSWD: /bin/chown -h -R --from=$OTHERUSER $USER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-[1-9]-before-disorderfs/
$USER ALL = NOPASSWD: /bin/chown -h -R --from=$USER $OTHERUSER /tmp/autopkgtest.$a$a$a$a$a$a/const_build_path/
- $USER ALL = NOPASSWD: /bin/chown -h -R --from=$USER $OTHERUSER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment/
- $USER ALL = NOPASSWD: /bin/chown -h -R --from=$USER $OTHERUSER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-before-disorderfs/
+ $USER ALL = NOPASSWD: /bin/chown -h -R --from=$USER $OTHERUSER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-[1-9]/
+ $USER ALL = NOPASSWD: /bin/chown -h -R --from=$USER $OTHERUSER /tmp/autopkgtest.$a$a$a$a$a$a/build-experiment-[1-9]-before-disorderfs/
EOF
Repeat this for each user you'd like to use. Obviously, don't pick a privileged
diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index 76ab788..31a285a 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -79,7 +79,7 @@ def start_testbed(args, temp_dir, no_clean_on_error=False, host_distro='debian')
# put build artifacts in ${dist}/source-root, to support tools that put artifacts in ..
VSRC_DIR = "source-root"
-class BuildContext(collections.namedtuple('_BuildContext', 'testbed_root local_dist_root local_src build_name')):
+class BuildContext(collections.namedtuple('_BuildContext', 'testbed_root local_dist_root local_src build_name variations')):
"""
The idiom os.path.join(x, '') is used here to ensure a trailing directory
@@ -105,15 +105,13 @@ class BuildContext(collections.namedtuple('_BuildContext', 'testbed_root local_d
tree = self.testbed_src
)
- def plan_variations(self, build, is_control, variations):
- if is_control:
- variations = variations._replace(spec=VariationSpec.empty())
- actions = variations.spec.actions()
+ def plan_variations(self, build):
+ actions = self.variations.spec.actions()
logging.info('build "%s": %s',
self.build_name,
", ".join("%s %s" % ("FIX" if not vary else "vary", v) for v, vary, action in actions))
for v, vary, action in actions:
- build = action(variations, build, vary)
+ build = action(self.variations, build, vary)
return build
def copydown(self, testbed):
@@ -175,9 +173,10 @@ def run_diff(dist_0, dist_1, diffoscope_args, store_dir):
os.symlink(os.path.basename(dist_0), dist_1)
return retcode
+
def check(build_command, artifact_pattern, virtual_server_args, source_root,
no_clean_on_error=False, store_dir=None, diffoscope_args=[],
- variations=Variations.default(),
+ build_variations=Variations.of(VariationSpec.default()),
testbed_pre=None, testbed_init=None, host_distro='debian'):
# default argument [] is safe here because we never mutate it.
if not source_root:
@@ -203,7 +202,8 @@ def check(build_command, artifact_pattern, virtual_server_args, source_root,
source_root = new_source_root
logging.debug("source_root: %s", source_root)
- variations = variations._replace(spec=variations.spec.apply_dynamic_defaults(source_root))
+ build_variations = [(n, v._replace(spec=v.spec.apply_dynamic_defaults(source_root)))
+ for n, v in build_variations]
# TODO: an alternative strategy is to run the testbed many times, one for each build
# not sure if it's worth implementing at this stage, but perhaps in the future.
@@ -216,15 +216,14 @@ def check(build_command, artifact_pattern, virtual_server_args, source_root,
result_dir = os.path.join(temp_dir, 'artifacts')
os.makedirs(result_dir)
- build_contexts = [BuildContext(testbed.scratch, result_dir, source_root, name)
- for name in ('control', 'experiment')]
+ build_contexts = [BuildContext(testbed.scratch, result_dir, source_root, name, variations)
+ for name, variations in build_variations]
builds = [bctx.make_build_commands(
'cd "$REPROTEST_BUILD_PATH"; unset REPROTEST_BUILD_PATH; ' + build_command, os.environ)
for bctx in build_contexts]
logging.log(5, "builds: %r", builds)
- builds = [c.plan_variations(b, c.build_name == "control", variations)
- for c, b in zip(build_contexts, builds)]
+ builds = [c.plan_variations(b) for c, b in zip(build_contexts, builds)]
logging.log(5, "builds: %r", builds)
try:
@@ -511,7 +510,7 @@ def run(argv, check):
logging.warn("--dont-vary is deprecated; use --vary=-$variation instead")
variations += ["-%s" % a for x in parsed_args.dont_vary for a in x.split(",")]
spec = VariationSpec().extend(variations)
- variations = Variations(verbosity, spec)
+ build_variations = Variations.of(spec, verbosity=verbosity)
# Remaining args
host_distro = parsed_args.host_distro
@@ -526,8 +525,7 @@ def run(argv, check):
check_args_keys = (
"build_command", "artifact_pattern", "virtual_server_args", "source_root",
- "no_clean_on_error", "store_dir", "diffoscope_args",
- "variations",
+ "no_clean_on_error", "store_dir", "diffoscope_args", "build_variations",
"testbed_pre", "testbed_init", "host_distro")
l = locals()
check_args = collections.OrderedDict([(k, l[k]) for k in check_args_keys])
@@ -539,6 +537,7 @@ def run(argv, check):
def main():
r = run(sys.argv[1:], check)
if isinstance(r, collections.OrderedDict):
- print("check(%s)" % ", ".join("%s=%r" % (k, v) for k, v in r.items()))
+ import pprint
+ pprint.pprint(r)
else:
return r
diff --git a/reprotest/build.py b/reprotest/build.py
index 85c460e..e4e9704 100644
--- a/reprotest/build.py
+++ b/reprotest/build.py
@@ -417,10 +417,12 @@ class VariationSpec(mdiffconf.ImmutableNamespace):
})
-class Variations(collections.namedtuple('_Variations', 'verbosity spec')):
+class Variations(collections.namedtuple('_Variations', 'spec verbosity')):
@classmethod
- def default(cls, *args, **kwargs):
- return cls(0, VariationSpec.default(*args, **kwargs))
+ def of(cls, *specs, verbosity=0):
+ return [("control", cls(VariationSpec.empty(), verbosity))] + [
+ ("experiment-%s" % i, cls(spec, verbosity))
+ for i, spec in enumerate(specs, 1)]
if __name__ == "__main__":
diff --git a/tests/test_reprotest.py b/tests/test_reprotest.py
index 81f1baf..48775ce 100644
--- a/tests/test_reprotest.py
+++ b/tests/test_reprotest.py
@@ -20,8 +20,10 @@ TEST_VARIATIONS = frozenset(reprotest.build.VARIATIONS.keys()) - frozenset(REPRO
def check_return_code(command, virtual_server, code):
try:
+ build_variations = reprotest.build.Variations.of(
+ reprotest.build.VariationSpec.default(TEST_VARIATIONS))
retcode = reprotest.check(command, 'artifact', virtual_server, 'tests',
- variations=reprotest.build.Variations.default(TEST_VARIATIONS))
+ build_variations=build_variations)
except SystemExit as system_exit:
retcode = system_exit.args[0]
finally:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/reprotest.git
More information about the Reproducible-commits
mailing list