2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00
Files
xcat-core/xCAT-test/native/debian_live_root_delivery.t
T
2026-12-01 21:20:17 -03:00

94 lines
4.5 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use File::Slurper qw(write_binary);
use Test::More;
use XCAT::Test::File qw(repo_path);
use XCAT::Test::Lifecycle;
use XCAT::Test::Process qw(run_command);
plan skip_all => 'Run as an ordinary user on Debian or Ubuntu'
unless $^O eq 'linux' && $< != 0 && -f '/etc/debian_version';
my $work = tempdir(CLEANUP => 1);
make_path(map { "$work/$_" } qw(source home bin capture));
for my $entry (qw(builddebs.pl build-utils Version Release perl-xCAT xCAT-server xCATsn)) {
XCAT::Test::Lifecycle::checked('cp', '-a', repo_path($entry), "$work/source/");
}
write_binary("$work/bin/dpkg-buildpackage", <<'SH');
#!/bin/sh
set -eu
/usr/bin/dpkg-buildpackage "$@"
destination="$XCAT_SOURCE_CAPTURE/${PWD##*/}"
mkdir -p "$destination"
cp ../*.dsc ../*.tar.gz "$destination/"
SH
chmod oct('0755'), "$work/bin/dpkg-buildpackage" or die "chmod wrapper: $!";
{
local %ENV = (%ENV, HOME => "$work/home", SOURCE_DATE_EPOCH => 1750000000,
PATH => "$work/bin:/usr/bin:/bin", LC_ALL => 'C', XCAT_SOURCE_CAPTURE => "$work/capture");
my ($status, $output) = run_command($^X, "$work/source/builddebs.pl",
'--package', 'perl-xCAT', '--package', 'xCAT-server', '--package', 'xCATsn',
'--dist', 'noble', '--release', 'test1', '--dest', "$work/output");
is($status, 0, 'builds all three packages through the production Debian builder') or diag $output;
die 'package build failed' if $status;
}
for my $package (qw(xCAT-server xCATsn)) {
subtest "$package standalone source export" => sub {
my @sources = glob "$work/capture/$package/*.dsc";
is(scalar @sources, 1, 'captures one source package') or return;
my $extracted = "$work/capture/$package/extracted";
XCAT::Test::Lifecycle::checked('dpkg-source', '--no-check', '-x', $sources[0], $extracted);
my $rebuilt = XCAT::Test::Lifecycle::build_deb('extracted', "$work/capture/$package");
for my $live (0, 1) {
my $root = XCAT::Test::Lifecycle->new;
$root->{live} = $live;
$root->write('/calls', '');
my ($script, @args);
if ($package eq 'xCAT-server') {
$script = 'prerm';
@args = ('remove');
local $root->{deb} = $rebuilt;
my @unpack = $root->run('/bin/sh', '-ec',
'dpkg-deb -x /package.deb /unpacked; mkdir -p /opt/xcat/share/xcat; ' .
'cp -a /unpacked/opt/xcat/share/xcat/scripts /opt/xcat/share/xcat/');
is($unpack[0], 0, 'stage the rebuilt runtime helpers') or diag "$unpack[1]$unpack[2]";
$root->record_command('/test-bin/systemctl');
$root->write('/etc/os-release', "ID=ubuntu\nVERSION_ID=24.04\n");
$root->write('/run/systemd/system/.fixture', '') if $live;
} else {
$script = 'postinst';
@args = ('configure');
$root->record_command('/test-bin/update-rc.d');
$root->record_command('/etc/init.d/apache2');
$root->record_command('/etc/init.d/xcatd');
$root->record_command('/test-bin/a2enmod');
$root->write('/etc/apache2/conf-enabled/.fixture', '');
}
my ($status, $out, $err) = $root->deb_script($rebuilt, $script, @args);
is($status, 0, 'rebuilt control script executes without a sibling source helper') or diag "$out$err";
unlike("$out$err", qr/not found/, 'the rebuilt script has no missing command');
if (!$live) {
unlike($root->read('/calls'), qr/(?:<start>|<stop>|<reload>|<--now>)/,
'the rebuilt script performs no live service action in an offline root');
} elsif ($package eq 'xCAT-server') {
like($root->read('/calls'), qr/^systemctl <stop> <xcatd\.service>$/m,
'rebuilt removal stops xcatd in a live root');
like($root->read('/calls'), qr/^systemctl <disable> <--now> <xcat-uftp-listener\.service>$/m,
'rebuilt removal stops the live UFTP listener');
} else {
like($root->read('/calls'), qr/^xcatd <start>$/m,
'rebuilt service-node configuration starts xcatd in a live root');
like($root->read('/calls'), qr/^apache2 <reload>$/m,
'rebuilt service-node configuration reloads Apache in a live root');
}
}
};
}
done_testing;