Browse Source

Robustify test suite

Fix test suite for systemctl preset.

There are multiple problems:

1/ first the behaviour of "dsh enable" is no longer the same when
   the service was already installed or not... and as such the test suite
   must be fixed in multiple places to ensure that the metadata
   in /var/lib/systemd/ is properly purged before calling "enable" again
   and expecting it to do its job.

2/ "systemctl preset" does collaborate with the running systemd to do its
   job but the test suite uses its own filesystem namespace which is not
   shared with the running systemd... and hence we get errors about
   service files not existing in the systemd namespace even though they
   exist in the testsuite namespace.

   To work around this I modified the DEP-8 test to not use a separate
   namespace... and marked the test as breaking the system so that it
   does not get run on a real system. This has some consequences on some
   other tests that assume that the /{lib,etc}/systemd/ directories are
   empty. Those tests have been fixed along the way.
keep-around/0e43de3196a68e59d8a543d1cf7f5b4bfbb27451
Raphaël Hertzog 7 years ago
committed by Martin Pitt
parent
commit
042f0965fc
  1. 6
      debian/changelog
  2. 2
      debian/tests/control
  3. 2
      debian/tests/t
  4. 24
      t/001-deb-systemd-helper.t
  5. 8
      t/002-deb-systemd-helper-update.t
  6. 18
      t/003-deb-systemd-helper-complex.t

6
debian/changelog

@ -11,6 +11,12 @@ init-system-helpers (1.30) UNRELEASED; urgency=medium
* dh_systemd_*: Add DH promise to avoid being called for no reason.
* Update Vcs-* fields to use https.
[ Raphaël Hertzog ]
* tests: Support $TEST_ON_REAL_SYSTEM which skips the tmpfs bind mounts, and
use that in the autopkgtest. This provides a more realistic test and
unbreaks operations which communicate with pid1. Also purge metadata in
between tests.
-- Felipe Sateler <fsateler@debian.org> Fri, 11 Mar 2016 18:48:39 -0300
init-system-helpers (1.29) unstable; urgency=medium

2
debian/tests/control

@ -2,4 +2,4 @@ Tests: t
Depends: @,
cpanminus,
build-essential
Restrictions: needs-root, allow-stderr, isolation-container
Restrictions: needs-root, breaks-testbed, allow-stderr, isolation-container

2
debian/tests/t

@ -4,6 +4,8 @@ set -eu
mount --make-rprivate /
cpanm Linux::Clone
export TEST_ON_REAL_SYSTEM=1
for test in t/*.t; do
echo "======== $(basename $test) ======="
perl $test

24
t/001-deb-systemd-helper.t

@ -44,9 +44,11 @@ sub bind_mount_tmp {
return $tmp;
}
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
}
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Verify “is-enabled” is not true for a random, non-existing unit file. ┃
@ -88,8 +90,11 @@ isnt_debian_installed($random_unit);
# ┃ Verify “enable” creates the requested symlinks. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
ok(! -d '/etc/systemd/system/multi-user.target.wants',
'multi-user.target.wants does not exist yet');
unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
# This might exist if we don't start from a fresh directory
ok(! -d '/etc/systemd/system/multi-user.target.wants',
'multi-user.target.wants does not exist yet');
}
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
is($retval, 0, "enable command succeeded");
@ -176,6 +181,7 @@ $retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
is($retval, 0, "purge command succeeded");
isnt_enabled($random_unit);
isnt_debian_installed($random_unit);
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Verify “enable” after purging does re-create the symlinks. ┃
@ -284,6 +290,9 @@ unlink($mask_path);
# ┃ Verify Alias= handling. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
is($retval, 0, "purge command succeeded");
open($fh, '>', $servicefile_path);
print $fh <<'EOT';
[Unit]
@ -326,6 +335,8 @@ ok(! -l $alias_path, 'alias link does not exist any more');
# ┃ Verify Alias/mask with removed package (as in postrm) ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh purge $random_unit");
is($retval, 0, "purge command succeeded");
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
is($retval, 0, "enable command succeeded");
is(readlink($alias_path), $servicefile_path, 'correct alias link');
@ -370,7 +381,8 @@ isnt_enabled('footest.service');
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit");
is($retval, 0, "enable command succeeded");
is_enabled($random_unit);
ok(! -l $mask_path, 'mask link does not exist yet');
# systemctl enable does create the alias link even if it's not needed
#ok(! -l $mask_path, 'mask link does not exist yet');
unlink($servicefile_path);

8
t/002-deb-systemd-helper-update.t

@ -54,9 +54,11 @@ sub bind_mount_tmp {
return $tmp;
}
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
}
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Verify “is-enabled” is not true for a random, non-existing unit file. ┃

18
t/003-deb-systemd-helper-complex.t

@ -44,9 +44,11 @@ sub bind_mount_tmp {
return $tmp;
}
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
my $etc_systemd = bind_mount_tmp('/etc/systemd');
my $lib_systemd = bind_mount_tmp('/lib/systemd');
my $var_lib_systemd = bind_mount_tmp('/var/lib/systemd');
}
# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
# ┃ Create two unit files with random names; one refers to the other (Also=). ┃
@ -106,12 +108,16 @@ isnt_debian_installed($random_unit2);
# ┃ Verify “enable” creates all symlinks. ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
ok(! -d '/etc/systemd/system/multi-user.target.wants',
'multi-user.target.wants does not exist yet');
unless ($ENV{'TEST_ON_REAL_SYSTEM'}) {
# This might already exist if we don't start from a fresh directory
ok(! -d '/etc/systemd/system/multi-user.target.wants',
'multi-user.target.wants does not exist yet');
}
$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh enable $random_unit1");
my %links = map { (basename($_), readlink($_)) }
</etc/systemd/system/multi-user.target.wants/*.service>;
("/etc/systemd/system/multi-user.target.wants/$random_unit1",
"/etc/systemd/system/multi-user.target.wants/$random_unit2");
is_deeply(
\%links,
{

Loading…
Cancel
Save