Control: tags -1 + patch
On Tue, Dec 10, 2024 at 10:11:19PM +0100, Michael Biebl wrote: > On Mon, 7 Oct 2024 12:18:51 -0400 =?UTF-8?Q?Louis-Philippe_V=C3=A9ronneau?= > <po...@debian.org> wrote: > > Source: nut > > Severity: important > > User: debian-pyt...@lists.debian.org > > Usertags: pep-594-deprecation-313 > > > > crypt: debian/tests/testlib.py:22 > > > This "only" affects the autopkgtests, Trivial patch attached that keeps the autopktests working. Chris
>From a61f37195f333759f1f42bf4a4ffbde6e75adadf Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler <z...@debian.org> Date: Wed, 11 Dec 2024 14:32:00 +0100 Subject: [PATCH] d/tests/testlib: remove unused code relying on crypt --- debian/tests/testlib.py | 212 +--------------------------------------- 1 file changed, 1 insertion(+), 211 deletions(-) diff --git a/debian/tests/testlib.py b/debian/tests/testlib.py index bc72b07..0c10f49 100644 --- a/debian/tests/testlib.py +++ b/debian/tests/testlib.py @@ -19,7 +19,7 @@ '''Common classes and functions for package tests.''' -import string, random, crypt, subprocess, pwd, grp, signal, time, unittest, tempfile, shutil, os, os.path, re, glob +import string, random, subprocess, pwd, grp, signal, time, unittest, tempfile, shutil, os, os.path, re, glob import sys, socket, gzip from stat import * @@ -448,121 +448,6 @@ def dpkg_compare_installed_version(pkg, check, version): return True return False -def prepare_source(source, builder, cached_src, build_src, patch_system): - '''Download and unpack source package, installing necessary build depends, - adjusting the permissions for the 'builder' user, and returning the - directory of the unpacked source. Patch system can be one of: - - cdbs - - dpatch - - quilt - - quiltv3 - - None (not the string) - - This is normally used like this: - - def setUp(self): - ... - self.topdir = os.getcwd() - self.cached_src = os.path.join(os.getcwd(), "source") - self.tmpdir = tempfile.mkdtemp(prefix='testlib', dir='/tmp') - self.builder = testlib.TestUser() - testlib.cmd(['chgrp', self.builder.login, self.tmpdir]) - os.chmod(self.tmpdir, 0775) - - def tearDown(self): - ... - self.builder = None - self.topdir = os.getcwd() - if os.path.exists(self.tmpdir): - testlib.recursive_rm(self.tmpdir) - - def test_suite_build(self): - ... - build_dir = testlib.prepare_source('foo', \ - self.builder, \ - self.cached_src, \ - os.path.join(self.tmpdir, \ - os.path.basename(self.cached_src)), - "quilt") - os.chdir(build_dir) - - # Example for typical build, adjust as necessary - print "" - print " make clean" - rc, report = testlib.cmd(['sudo', '-u', self.builder.login, 'make', 'clean']) - - print " configure" - rc, report = testlib.cmd(['sudo', '-u', self.builder.login, './configure', '--prefix=%s' % self.tmpdir, '--enable-debug']) - - print " make (will take a while)" - rc, report = testlib.cmd(['sudo', '-u', self.builder.login, 'make']) - - print " make check (will take a while)", - rc, report = testlib.cmd(['sudo', '-u', self.builder.login, 'make', 'check']) - expected = 0 - result = 'Got exit code %d, expected %d\n' % (rc, expected) - self.assertEquals(expected, rc, result + report) - - def test_suite_cleanup(self): - ... - if os.path.exists(self.cached_src): - testlib.recursive_rm(self.cached_src) - - It is up to the caller to clean up cached_src and build_src (as in the - above example, often the build_src is in a tmpdir that is cleaned in - tearDown() and the cached_src is cleaned in a one time clean-up - operation (eg 'test_suite_cleanup()) which must be run after the build - suite test (obviously). - ''' - - # Make sure we have a clean slate - assert (os.path.exists(os.path.dirname(build_src))) - assert (not os.path.exists(build_src)) - - cdir = os.getcwd() - if os.path.exists(cached_src): - shutil.copytree(cached_src, build_src) - os.chdir(build_src) - else: - # Only install the build dependencies on the initial setup - rc, report = cmd(['apt-get','-y','--force-yes','build-dep',source]) - assert (rc == 0) - - os.makedirs(build_src) - os.chdir(build_src) - - # These are always needed - pkgs = ['build-essential', 'dpkg-dev', 'fakeroot'] - rc, report = cmd(['apt-get','-y','--force-yes','install'] + pkgs) - assert (rc == 0) - - rc, report = cmd(['apt-get','source',source]) - assert (rc == 0) - shutil.copytree(build_src, cached_src) - - unpacked_dir = os.path.join(build_src, glob.glob('%s-*' % source)[0]) - - # Now apply the patches. Do it here so that we don't mess up our cached - # sources. - os.chdir(unpacked_dir) - assert (patch_system in ['cdbs', 'dpatch', 'quilt', 'quiltv3', None]) - if patch_system != None and patch_system != "quiltv3": - if patch_system == "quilt": - os.environ.setdefault('QUILT_PATCHES','debian/patches') - rc, report = cmd(['quilt', 'push', '-a']) - assert (rc == 0) - elif patch_system == "cdbs": - rc, report = cmd(['./debian/rules', 'apply-patches']) - assert (rc == 0) - elif patch_system == "dpatch": - rc, report = cmd(['dpatch', 'apply-all']) - assert (rc == 0) - - cmd(['chown', '-R', '%s:%s' % (builder.uid, builder.gid), build_src]) - os.chdir(cdir) - - return unpacked_dir - def _aa_status(): '''Get aa-status output''' exe = "/usr/sbin/aa-status" @@ -1022,101 +907,6 @@ class TestlibCase(unittest.TestCase): return True return False -class TestGroup: - '''Create a temporary test group and remove it again in the dtor.''' - - def __init__(self, group=None, lower=False): - '''Create a new group''' - - self.group = None - if group: - if group_exists(group): - raise ValueError('group name already exists') - else: - while(True): - group = random_string(7,lower=lower) - if not group_exists(group): - break - - assert subprocess.call(['groupadd',group]) == 0 - self.group = group - g = grp.getgrnam(self.group) - self.gid = g[2] - - def __del__(self): - '''Remove the created group.''' - - if self.group: - rc, report = cmd(['groupdel', self.group]) - assert rc == 0 - -class TestUser: - '''Create a temporary test user and remove it again in the dtor.''' - - def __init__(self, login=None, home=True, group=None, uidmin=None, lower=False, shell=None): - '''Create a new user account with a random password. - - By default, the login name is random, too, but can be explicitly - specified with 'login'. By default, a home directory is created, this - can be suppressed with 'home=False'.''' - - self.login = None - - if os.geteuid() != 0: - raise ValueError("You must be root to run this test") - - if login: - if login_exists(login): - raise ValueError('login name already exists') - else: - while(True): - login = 't' + random_string(7,lower=lower) - if not login_exists(login): - break - - self.salt = random_string(2) - self.password = random_string(8,lower=lower) - self.crypted = crypt.crypt(self.password, self.salt) - - creation = ['useradd', '-p', self.crypted] - if home: - creation += ['-m'] - if group: - creation += ['-G',group] - if uidmin: - creation += ['-K','UID_MIN=%d'%uidmin] - if shell: - creation += ['-s',shell] - creation += [login] - assert subprocess.call(creation) == 0 - # Set GECOS - assert subprocess.call(['usermod','-c','Buddy %s' % (login),login]) == 0 - - self.login = login - p = pwd.getpwnam(self.login) - self.uid = p[2] - self.gid = p[3] - self.gecos = p[4] - self.home = p[5] - self.shell = p[6] - - def __del__(self): - '''Remove the created user account.''' - - if self.login: - # sanity check the login name so we don't accidentally wipe too much - if len(self.login)>3 and not '/' in self.login: - subprocess.call(['rm','-rf', '/home/'+self.login, '/var/mail/'+self.login]) - rc, report = cmd(['userdel', '-f', self.login]) - assert rc == 0 - - def add_to_group(self, group): - '''Add user to the specified group name''' - rc, report = cmd(['usermod', '-G', group, self.login]) - if rc != 0: - print(report) - assert rc == 0 - # Timeout handler using alarm() from John P. Speno's Pythonic Avocado class TimeoutFunctionException(Exception): """Exception to raise on a timeout""" -- 2.45.2