[reprotest] 03/07: main: extend Testbed with a check_exec2 that doesn't bomb on stderr

Ximin Luo infinity0 at debian.org
Tue Sep 26 14:36:08 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 f492b68dde51ee60af1449151dd7c35b1761b2bf
Author: Ximin Luo <infinity0 at debian.org>
Date:   Tue Sep 26 15:48:12 2017 +0200

    main: extend Testbed with a check_exec2 that doesn't bomb on stderr
---
 README.rst            |  8 ++++----
 reprotest/__init__.py | 27 ++++++++++++++++++---------
 reprotest/presets.py  |  2 +-
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/README.rst b/README.rst
index bc6603e..97621cc 100644
--- a/README.rst
+++ b/README.rst
@@ -78,7 +78,7 @@ directory" preset would look like, if we ran it using the full CLI::
     # In the non-preset full CLI, this is roughly similar to:
     $ reprotest \
         --testbed-init 'apt-get -y --no-install-recommends install \
-                        util-linux disorderfs 2>/dev/null; \
+                        disorderfs faketime locales-all sudo util-linux; \
                         test -c /dev/fuse || mknod -m 666 /dev/fuse c 10 229' \
         --build-command 'PATH=/sbin:/usr/sbin:$PATH apt-get -y --no-install-recommends build-dep ./; \
                          dpkg-buildpackage -uc -us -b' \
@@ -112,10 +112,10 @@ so that it uses our `experimental toolchain
 <https://wiki.debian.org/ReproducibleBuilds/ExperimentalToolchain>`__::
 
     $ reprotest --store-dir=artifacts \
-        --auto-preset-expr '_.prepend.testbed_init("apt-get install -y wget 2>/dev/null; \
+        --auto-preset-expr '_.prepend.testbed_init("apt-get install -y wget; \
             echo deb http://reproducible.alioth.debian.org/debian/ ./ >> /etc/apt/sources.list; \
-            wget -q -O- https://reproducible.alioth.debian.org/reproducible.asc | apt-key add - 2>/dev/null; \
-            apt-get update; apt-get upgrade -y 2>/dev/null; ")' \
+            wget -q -O- https://reproducible.alioth.debian.org/reproducible.asc | apt-key add -; \
+            apt-get update; apt-get upgrade -y; ")' \
         ./bash_4.4-4.0~reproducible1.dsc \
         -- \
         schroot unstable-amd64-sbuild
diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index b393438..b75e6e0 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -51,6 +51,17 @@ def get_all_servers():
 # variety of other options including Docker etc that use different
 # approaches.
 
+class Testbed(adt_testbed.Testbed):
+    def check_exec2(self, argv, stdout=False, kind='short', xenv=[]):
+        """Like check_exec but does not bomb on stderr, and can pass xenv."""
+        (code, out, err) = self.execute(argv,
+                                        stdout=(stdout and subprocess.PIPE or None),
+                                        xenv=xenv, kind=kind)
+        if code != 0:
+            self.bomb('"%s" failed with status %i' % (' '.join(argv), code),
+                      adtlog.AutopkgtestError)
+        return out
+
 @contextlib.contextmanager
 def start_testbed(args, temp_dir, no_clean_on_error=False, host_distro='debian'):
     '''This is a simple wrapper around adt_testbed that automates the
@@ -59,7 +70,7 @@ def start_testbed(args, temp_dir, no_clean_on_error=False, host_distro='debian')
     # path for the correct virt-server script.
     server_path = get_server_path(args[0])
     logging.info('STARTING VIRTUAL SERVER %r', [server_path] + args[1:])
-    testbed = adt_testbed.Testbed([server_path] + args[1:], temp_dir, None,
+    testbed = Testbed([server_path] + args[1:], temp_dir, None,
             host_distro=host_distro)
     testbed.start()
     testbed.open()
@@ -153,7 +164,7 @@ class BuildContext(collections.namedtuple('_BuildContext',
             self.testbed_src, artifact_pattern)
         # remove any existing artifact, in case the build script doesn't overwrite
         # it e.g. like how make(1) sometimes works.
-        testbed.check_exec(
+        testbed.check_exec2(
             ['sh', '-ec', 'cd "%s" && rm -rf %s' %
             (self.testbed_src, artifact_pattern)])
         # this dance is necessary because the cwd can't be cd'd into during the setup phase under some variations like user_group
@@ -162,13 +173,11 @@ class BuildContext(collections.namedtuple('_BuildContext',
         _ = _.append_setup_exec_raw('export', 'REPROTEST_UMASK=$(umask)')
         new_script = _.to_script()
         logging.info("executing: %s", new_script)
-        argv = ['sh', '-ec', new_script]
-        xenv = ['%s=%s' % (k, v) for k, v in build.env.items()]
-        (code, _, _) = testbed.execute(argv, xenv=xenv, kind='build')
-        if code != 0:
-            testbed.bomb('"%s" failed with status %i' % (' '.join(argv), code), adtlog.AutopkgtestError)
+        testbed.check_exec2(['sh', '-ec', new_script],
+            xenv=['%s=%s' % (k, v) for k, v in build.env.items()],
+            kind='build')
         dist_base = os.path.join(self.testbed_dist, VSRC_DIR)
-        testbed.check_exec(
+        testbed.check_exec2(
             ['sh', '-ec', """mkdir -p "{0}"
 cd "{1}" && cp --parents -a -t "{0}" {2}
 cd "{0}" && touch -d at 0 . .. {2}
@@ -272,7 +281,7 @@ def corun_builds(test_args, testbed_args):
                 logging.log(5, "build %s: %r", name, build)
 
                 if testbed_init:
-                    testbed.check_exec(["sh", "-ec", testbed_init])
+                    testbed.check_exec2(["sh", "-ec", testbed_init])
 
                 bctx.copydown(testbed)
                 bctx.run_build(testbed, build, artifact_pattern)
diff --git a/reprotest/presets.py b/reprotest/presets.py
index 76c3e25..289724d 100644
--- a/reprotest/presets.py
+++ b/reprotest/presets.py
@@ -68,7 +68,7 @@ def preset_deb_schroot(preset):
     return preset.str_replace.build_command("dpkg-buildpackage",
         'PATH=/sbin:/usr/sbin:$PATH apt-get -y --no-install-recommends build-dep ./; dpkg-buildpackage'
     ).set.testbed_init(
-        'apt-get -y --no-install-recommends install disorderfs faketime locales-all sudo util-linux 2>/dev/null; \
+        'apt-get -y --no-install-recommends install disorderfs faketime locales-all sudo util-linux; \
         test -c /dev/fuse || mknod -m 666 /dev/fuse c 10 229'
     )
 

-- 
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