Skip to content
Permalink
Browse files Browse the repository at this point in the history
ENH: reprotest:lib: add distro abstraction
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.
  • Loading branch information
SantiagoTorres committed Jul 12, 2017
1 parent 06456d3 commit dbda486
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
12 changes: 7 additions & 5 deletions reprotest/lib/adt_testbed.py
Expand Up @@ -40,6 +40,7 @@

# from debian import debian_support

from reprotest.lib.system_interface.debian import debian_interface
from reprotest.lib import adtlog
from reprotest.lib import VirtSubproc
from reprotest.lib.util import TempPath, Path, killtree
Expand All @@ -52,13 +53,14 @@
class Testbed:
def __init__(self, vserver_argv, output_dir, user,
setup_commands=[], add_apt_pockets=[], copy_files=[]):
self.system_interface = debian_interface()
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
Expand Down Expand Up @@ -212,8 +214,8 @@ def _opened(self, pl):
self.user = c.split('=', 1)[1]

# 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_exec(), 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)
Expand All @@ -222,9 +224,9 @@ def _opened(self, pl):
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_testbed_packages(pkglist))
pkglist.copyup()

self.post_boot_setup()
Expand Down
26 changes: 26 additions & 0 deletions reprotest/lib/system_interface/__init__.py
@@ -0,0 +1,26 @@
# adt_testbed.py is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
#
# 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 system_interface:

def __init__ (self):
print("lel")
56 changes: 56 additions & 0 deletions reprotest/lib/system_interface/debian.py
@@ -0,0 +1,56 @@
# adt_testbed.py is part of autopkgtest
# autopkgtest is a tool for testing Debian binary packages
#
# autopkgtest is Copyright (C) 2006-2015 Canonical Ltd.
#
# 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 os
import sys
import errno
import time
import pipes
import traceback
import re
import signal
import subprocess
import tempfile
import shutil
import urllib.parse

from . import system_interface

# TODO: removing this import disables install_tmp, may want to restore
# it at some point if I'm improving support for building Debian packages in
# particular.

class debian_interface(system_interface):

def get_arch_exec(self):
return ['dpkg', '--print-architecture']

def get_testbed_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:
return 0

0 comments on commit dbda486

Please sign in to comment.