2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-05 04:27:55 +00:00
Files
xcat-core/xCAT-test/unit/xcatd_debian_conffile_lifecycle.t
T
Vinícius Ferrão 036bb24c87 fix(packaging): preserve xcatd init state on Debian (#7615)
* refactor(packaging): share precise systemd state detection

* test(packaging): cover precise systemd state detection

* test(packaging): allow explicit Debian init mode

* fix(packaging): honor explicit Debian init targets

* test(packaging): cover Debian init target detection

* fix(packaging): add Debian xcatd init state helper

* test(packaging): cover Debian xcatd init state helper

* test(packaging): allow delegated SysV registration

* fix(packaging): preserve Debian xcatd conffile lifecycle

* test(packaging): mirror explicit Debian init mode

* test(packaging): cover Debian xcatd conffile lifecycle

* fix(packaging): contain init state file umask

* test(packaging): cover init state permissions

* fix(packaging): contain preinstall context umask

* test(packaging): cover preinstall umask containment

* fix(packaging): detect all systemd enablement links

* test(packaging): cover all systemd enablement links

* test(packaging): allow shared purge state path

* refactor(packaging): reuse Debian init state path

* fix(packaging): detect runtime systemd masks

* test(packaging): cover runtime systemd masks

* test(packaging): model Debian SysV registration

* refactor(packaging): reuse shared init state detection

* test(packaging): enforce shared Debian state probes

* test(packaging): allow explicit unregistered masks

* fix(packaging): preserve Debian SysV registration state

* test(packaging): cover Debian SysV registration states

* fix(packaging): clean failed Debian state writes

* test(packaging): cover failed Debian state writes

* fix(packaging): retain unregistered systemd provenance

* test(packaging): cover unregistered systemd upgrades

* fix(packaging): fail closed on shared state errors

* test(packaging): cover shared state detector failures

* test(packaging): mirror native xcatd runlevels

* fix(packaging): recover rejected SysV layouts

* test(packaging): cover rejected SysV layouts

* test(packaging): cover SysV rebuild retries

* refactor(packaging): reuse systemctl readiness guard

* test(packaging): enforce shared systemctl guard
2026-07-28 19:31:36 +00:00

103 lines
3.6 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use File::Spec;
use FindBin;
use Test::More;
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
sub read_file {
my ($path) = @_;
open( my $fh, '<', $path ) or die "Unable to read $path: $!";
binmode($fh);
my $contents = do { local $/; <$fh> };
close($fh);
return $contents;
}
my $deb_install = read_file(
File::Spec->catfile( $repo_root, 'xCAT-server', 'debian', 'install' )
);
my $dpkg_managed =
$deb_install =~ qr{^etc/init\.d/xcatd etc/init\.d$}m;
my $ucf_managed =
$deb_install =~ qr{^etc/init\.d/xcatd opt/xcat/share/xcat/scripts$}m;
ok( $dpkg_managed || $ucf_managed,
'Debian selects a configuration-aware legacy init backend' );
if ($dpkg_managed) {
pass('dpkg owns the directly packaged legacy init conffile');
done_testing();
exit;
}
my $deb_control = read_file(
File::Spec->catfile( $repo_root, 'xCAT-server', 'debian', 'control' )
);
like( $deb_control, qr{^Depends:.*(?:,\s+|^)ucf(?:,|$)}m,
'the generated-conffile backend depends on ucf' );
like( $deb_install,
qr{^debian/xcatd\.md5sum opt/xcat/share/xcat/scripts$}m,
'historical template checksums are installed beside the template' );
my $sum_path = File::Spec->catfile(
$repo_root, 'xCAT-server', 'debian', 'xcatd.md5sum'
);
ok( -f $sum_path, 'the Debian package carries historical template checksums' );
my $sums = -f $sum_path ? read_file($sum_path) : '';
like( $sums, qr{^0b1eea60994ff79faa9a8d0bcd53c558\s+2\.17\.0$}m,
'the last pre-transition release is recognized as unmodified' );
my $template = read_file(
File::Spec->catfile(
$repo_root, 'xCAT-server', 'etc', 'init.d', 'xcatd'
)
);
like( $sums, qr{^\Q@{[ md5_hex($template) ]}\E\s+2\.18\.0$}m,
'the current released template is recognized as unmodified' );
my $postinst = read_file(
File::Spec->catfile( $repo_root, 'xCAT-server', 'debian', 'postinst' )
);
like( $postinst,
qr{"\$xcatd_init_state" configure-legacy "\$xcatd_transition_context"},
'postinst delegates legacy conffile transitions to the state helper' );
my $state_helper = read_file(
File::Spec->catfile( $repo_root, 'xCAT-server', 'debian', 'xcatd-init-state' )
);
like( $state_helper, qr{ucf "\$legacy_template" "\$legacy_init"},
'legacy configuration delegates updates to ucf' );
like( $state_helper, qr{ucfr xcat-server "\$legacy_init"},
'legacy configuration registers ucf ownership' );
like( $state_helper, qr{state_content=stashed.*?stash_candidate}s,
'a present legacy script is represented by an exact stash' );
like( $state_helper, qr{state_content=deleted},
'administrator deletion has a distinct persistent state' );
like( $state_helper,
qr{package-default\).*?UCF_FORCE_CONFFMISS=1 ucf}s,
'only known package omission forces recreation of a missing script' );
like( $state_helper,
qr{state_content=unknown.*?preserving its absence}s,
'ambiguous markerless upgrades preserve absence instead of guessing' );
my $postrm = read_file(
File::Spec->catfile( $repo_root, 'xCAT-server', 'debian', 'postrm' )
);
like( $postrm,
qr{xcatd\.ucf-old.*?xcatd\.ucf-new.*?xcatd\.ucf-dist}s,
'purge removes ucf backup artifacts' );
like( $postrm, qr{ucf --purge /etc/init\.d/xcatd},
'purge removes ucf checksum state' );
like( $postrm, qr{ucfr --purge xcat-server /etc/init\.d/xcatd},
'purge removes the ucf ownership registration' );
like( $postrm,
qr{xcatd_state_dir=/var/lib/xcat/xcatd-init-state.*?(?:/var/lib/xcat/xcatd-init-state/state|"\$xcatd_state_dir/state")}s,
'purge removes the persistent init transition state' );
done_testing();