From 29e31a22573f867966bd7c2d8f441e9007f88a0a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 24 Jul 2026 12:12:04 -0400 Subject: [PATCH] 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 Signed-off-by: Pedro Amorim --- t/00-valid-systemd-units.t | 46 +++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/t/00-valid-systemd-units.t b/t/00-valid-systemd-units.t index ec5c2a622d..1d84e0116c 100755 --- a/t/00-valid-systemd-units.t +++ b/t/00-valid-systemd-units.t @@ -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; +}