[reprotest] 01/04: ENH: lib: add a system_interface abstraction for Debian-specific calls

Ximin Luo infinity0 at debian.org
Thu Aug 17 18:05:57 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 134f9cc4134fec51e232ea43fa5fdce3e9782759
Author: Santiago Torres <torresariass at gmail.com>
Date:   Wed Jul 12 11:10:50 2017 -0400

    ENH: lib: add a system_interface abstraction for Debian-specific calls
    
    Many distros may want to use reprotest and the current implementation
    depends on the Debian toolchain. Abstract away the debian-specific
    toolchain to a separate module, and provide a way to extend this for
    cross-distro compatility.
---
 reprotest/lib/adt_testbed.py               | 12 ++++----
 reprotest/lib/system_interface/__init__.py | 32 ++++++++++++++++++++
 reprotest/lib/system_interface/debian.py   | 47 ++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/reprotest/lib/adt_testbed.py b/reprotest/lib/adt_testbed.py
index 0929d8a..2907ac9 100644
--- a/reprotest/lib/adt_testbed.py
+++ b/reprotest/lib/adt_testbed.py
@@ -36,6 +36,7 @@ import urllib.parse
 # Don't need this in reprotest, try to be distro-agnostic
 #from debian import debian_support
 
+from reprotest.lib.system_interface.debian import DebianInterface
 from reprotest.lib import adtlog
 from reprotest.lib import VirtSubproc
 
@@ -48,13 +49,14 @@ class Testbed:
     def __init__(self, vserver_argv, output_dir, user,
                  setup_commands=[], setup_commands_boot=[], add_apt_pockets=[],
                  copy_files=[]):
+        self.system_interface = DebianInterface()
         self.sp = None
         self.lastsend = None
         self.scratch = None
         self.modified = False
         self._need_reset_apt = False
         self.stop_sent = False
-        self.dpkg_arch = None
+        self.system_arch = None
         self.exec_cmd = None
         self.output_dir = output_dir
         self.shared_downtmp = None  # testbed's downtmp on the host, if supported
@@ -226,8 +228,8 @@ class Testbed:
         self.run_setup_commands()
 
         # determine testbed architecture
-        self.dpkg_arch = self.check_exec(['dpkg', '--print-architecture'], True).strip()
-        adtlog.info('testbed dpkg architecture: ' + self.dpkg_arch)
+        self.system_arch = self.check_exec(self.system_interface.get_arch(), True).strip()
+        adtlog.info('testbed package architecture: ' + self.system_arch)
 
         # do we have eatmydata?
         (code, out, err) = self.execute(['which', 'eatmydata'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -236,9 +238,9 @@ class Testbed:
             self.eatmydata_prefix = [out.strip()]
 
         # record package versions of pristine testbed
-        if self.output_dir and self.execute(['which', 'dpkg-query'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)[0] == 0:
+        if self.output_dir and self.system_interface.can_query_packages():
             pkglist = TempPath(self, 'testbed-packages', autoclean=False)
-            self.check_exec(['sh', '-ec', "dpkg-query --show -f '${Package}\\t${Version}\\n' > %s" % pkglist.tb])
+            self.check_exec(self.system_interface.get_installed_packages(pkglist))
             pkglist.copyup()
 
         self.post_boot_setup()
diff --git a/reprotest/lib/system_interface/__init__.py b/reprotest/lib/system_interface/__init__.py
new file mode 100644
index 0000000..76a1b68
--- /dev/null
+++ b/reprotest/lib/system_interface/__init__.py
@@ -0,0 +1,32 @@
+# adt_testbed.py is part of autopkgtest
+# autopkgtest is a tool for testing Debian binary packages. The
+# system_interface module is an addition for reprotest to make
+# this module distro-agnostic
+#
+# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
+# the system_interface module is Copyright (C) 2017 Santiago Torres-Arias
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# See the file CREDITS for a full list of credits information (often
+# installed as /usr/share/doc/autopkgtest/CREDITS).
+
+class SystemInterface:
+    """
+        A base class for a system interface class. It provides a common
+        ancestor for adt_testbed to figure out which commands/call on each
+        specific host.
+    """
+    pass
diff --git a/reprotest/lib/system_interface/debian.py b/reprotest/lib/system_interface/debian.py
new file mode 100644
index 0000000..dc0792c
--- /dev/null
+++ b/reprotest/lib/system_interface/debian.py
@@ -0,0 +1,47 @@
+# adt_testbed.py is part of autopkgtest
+# autopkgtest is a tool for testing Debian binary packages. The
+# system_interface module is an addition for reprotest to make
+# this module distro-agnostic
+#
+# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
+# the system_interface module is Copyright (C) 2017 Santiago Torres-Arias
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# See the file CREDITS for a full list of credits information (often
+# installed as /usr/share/doc/autopkgtest/CREDITS).
+import subprocess
+
+from . import SystemInterface
+
+
+class DebianInterface(SystemInterface):
+    """
+        SystemInterface implementation for Debian hosts. Contains commands that
+        are specific to the Debian toolchain.
+    """
+
+    def get_arch(self):
+        return ['dpkg', '--print-architecture']
+
+    def get_installed_packages(self, target_file):
+        return ['sh', '-ec',
+                "dpkg-query --show -f '${Package}\\t${Version}\\n' > %s" % target_file.tb]
+
+    def can_query_packages(self):
+        try:
+            return subprocess.check_call(['which', 'dpkg-query'], stdout=subprocess.DEVNULL) == 0
+        except subprocess.CalledProcessError:
+            return 0

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