Bug 40901: (QA follow-up) Make the systemd unit validation test run in KTD
The test failed in KTD instead of skipping, and the systemd-analyze option it relied on doesn't exist in any systemd QA will meet, so the unit files were never actually checked anywhere. Load Test::NoWarnings after the plan, use the SYSTEMD_UNIT_PATH environment variable instead, and ignore noise from helper scripts the packages haven't installed yet. Test Plan: 1) Apply this patch 2) prove t/00-valid-systemd-units.t 3) Note all units are now verified instead of the file failing! Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
7169ea9e2d
commit
29e31a2257
|
|
@ -18,9 +18,9 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::More;
|
||||
use Test::NoWarnings;
|
||||
use Cwd qw( abs_path );
|
||||
use FindBin qw( $Bin );
|
||||
use Cwd qw( abs_path );
|
||||
use File::Basename qw( basename );
|
||||
use FindBin qw( $Bin );
|
||||
|
||||
my $analyzer = qx(which systemd-analyze 2>/dev/null);
|
||||
chomp $analyzer;
|
||||
|
|
@ -31,10 +31,6 @@ my $units_dir = abs_path("$Bin/../debian/systemd");
|
|||
plan( skip_all => 'debian/systemd not found' )
|
||||
unless $units_dir && -d $units_dir;
|
||||
|
||||
my $probe = qx(systemd-analyze verify --unit-path=/tmp /bin/true 2>&1);
|
||||
plan( skip_all => 'systemd-analyze --unit-path not supported; upgrade systemd' )
|
||||
if $probe =~ /unrecognized option/;
|
||||
|
||||
opendir( my $dh, $units_dir ) or die "Cannot open $units_dir: $!";
|
||||
my @units =
|
||||
sort
|
||||
|
|
@ -45,8 +41,42 @@ plan( skip_all => 'No unit files found in debian/systemd' ) unless @units;
|
|||
|
||||
plan tests => scalar(@units) + 1;
|
||||
|
||||
# Loaded after the plan because Test::NoWarnings adds a test at END time,
|
||||
# which turns every skip_all above into a 'Bad plan' failure under prove
|
||||
require Test::NoWarnings;
|
||||
Test::NoWarnings->import;
|
||||
|
||||
# The trailing colon appends the default unit path so dependencies like
|
||||
# sysinit.target still resolve
|
||||
$ENV{SYSTEMD_UNIT_PATH} = "$units_dir:";
|
||||
|
||||
for my $unit (@units) {
|
||||
my $output = qx(systemd-analyze verify --no-pager "--unit-path=$units_dir" $unit 2>&1);
|
||||
my $output = qx(systemd-analyze verify --man=no --no-pager $unit 2>&1);
|
||||
my $rc = $? >> 8;
|
||||
if ( $rc != 0 ) {
|
||||
my @errors = grep { !ignorable($_) } split /\n/, $output;
|
||||
$rc = 0 unless @errors;
|
||||
}
|
||||
ok( $rc == 0, "Valid unit file: $unit" ) or diag $output;
|
||||
}
|
||||
|
||||
sub ignorable {
|
||||
my ($line) = @_;
|
||||
|
||||
return 1 unless $line =~ /\S/;
|
||||
|
||||
# systemd rewrites legacy /var/run paths itself and only warns
|
||||
return 1 if $line =~ /references a path below legacy directory/;
|
||||
|
||||
# Helper scripts the units call are only installed to /usr/sbin by the
|
||||
# koha-systemd and koha-core packages, so on a dev checkout ignore
|
||||
# 'not executable' errors for commands this repo ships
|
||||
if ( $line =~ /Command (\S+) is not executable/ ) {
|
||||
my $script = basename($1);
|
||||
return 1
|
||||
if -e "$Bin/../debian/scripts/$script"
|
||||
|| -e "$Bin/../debian/systemd/$script";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue