2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-22 10:22:18 +00:00
Files
xcat-core/xCAT-genesis-base/lib/XCAT/GenesisPayload.pm
T
Daniel Hilst c14d79790a fix(xcat-core): the Ubuntu Genesis image runs its awk programs under mawk
An Ubuntu compute node booted into legacy Genesis never reports a destiny. The console
shows doxcat reach "Getting initial certificate", then:

  awk: 8: unexpected character '&'
  awk: /usr/bin/allowcred.awk: line 14: syntax error at or near }

and the node stays in powering-on until the case times out. The payload built on
2026-10-23 carries /usr/bin/awk as a symlink to mawk, with no gawk.

allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess
and the /inet/ special file. mawk rejects both at parse time. install() in
dracut_105/ubuntu/module-setup.sh staged /usr/bin/awk from the build root, and on Ubuntu
that alternative is mawk, so the image got an awk that cannot parse its own programs. The
EL payload is unaffected: there /usr/bin/awk is gawk.

install() now installs gawk by name and points usr/bin/awk at it, the build root carries
gawk, and XCAT::GenesisPayload reads usr/bin/awk back and refuses a payload whose awk is
not gawk. dracut_install reports a missing command and returns, and awk is a symlink the
module makes itself, so nothing in the build said why.

genesis_ubuntu_awk.bats, genesis_ubuntu_build_root.t and genesis_payload_verification.t
fail on the parent commit and pass on this one.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-24 10:04:15 -03:00

226 lines
8.0 KiB
Perl

package XCAT::GenesisPayload;
# verify-genesis-payload runs this module in the rpm %install of xCAT-genesis-base and inside
# the Ubuntu build root, where only perl-base is installed. Use core modules only.
use strict;
use warnings;
use Exporter 'import';
our @EXPORT_OK = qw(module_commands missing_paths check_payload main);
my $ME = 'verify-genesis-payload';
#-------------------------------------------------------------------------------
=head3 module_commands
Descriptions: read back the names a dracut module installs.
Only the top level of install() counts. A name under a condition is
release-dependent, so the caller names it as a required path instead.
An option to dracut_install (a word that starts with "-") is not a name.
Arguments:
$module_setup: the path of the module-setup.sh
Returns:
the names, sorted, each one once. A name that starts with "/" is an
absolute path; any other name is a command.
Dies with "verify-genesis-payload: cannot read <file>" when the file
cannot be read, and with "verify-genesis-payload: no command name read
from <file>" when install() names nothing.
=cut
#-------------------------------------------------------------------------------
sub module_commands {
my ($module_setup) = @_;
open(my $fh, '<', $module_setup)
or die "$ME: cannot read $module_setup\n";
my ($in_install, %names);
while (my $line = <$fh>) {
if ($line =~ /^install\(\)/) { $in_install = 1; next }
$in_install = 0 if $in_install && $line =~ /^}/;
next unless $in_install && $line =~ s/^ dracut_install //;
$line =~ s/#.*//s;
$names{$_} = 1 for grep { length && !/^-/ } split /\s+/, $line;
}
close($fh);
die "$ME: no command name read from $module_setup\n" unless %names;
return sort keys %names;
}
#-------------------------------------------------------------------------------
=head3 missing_paths
Descriptions: list what a Genesis payload lacks.
dracut_install reports a missing binary and returns, so the image can
ship without it. This check runs on the extracted payload before it is
packaged.
Arguments:
$have: code ref. It takes a path relative to the payload root and
returns true when the payload carries it.
%opt:
required: paths relative to the payload root that the caller needs
commands: names from module_commands. A bare command is looked
for in bin, sbin, usr/bin and usr/sbin; an absolute
path is looked for under the payload root.
source: the module the commands came from, for the message
sshd: the content of usr/sbin/sshd, or undef without one
awk: the content of usr/bin/awk, or undef without one
Returns:
one "<path> (<reason>)" string per missing item, in the order checked.
An empty list means the payload is complete.
=cut
#-------------------------------------------------------------------------------
sub missing_paths {
my ($have, %opt) = @_;
my @missing;
for my $path (@{ $opt{required} || [] }) {
push @missing, "$path (required by the build)" unless $have->($path);
}
for my $want (@{ $opt{commands} || [] }) {
my $found =
$want =~ m{^/(.*)}
? $have->($1)
: scalar(grep { $have->("$_/$want") } qw(bin sbin usr/bin usr/sbin));
push @missing, "$want (installed by $opt{source})" unless $found;
}
push @missing, "usr/sbin/sshd (Genesis is reached over ssh)"
unless $have->('usr/sbin/sshd');
push @missing, "usr/bin/mktemp (getdestiny makes its request file with it)"
unless $have->('usr/bin/mktemp');
# OpenSSH 9.8 split the per-connection work into sshd-session, which sshd execs by
# absolute path. EL9 carries OpenSSH 9.9, so an image with sshd alone refuses every
# connection.
if (index($opt{sshd} // '', 'sshd-session') >= 0
&& !$have->('usr/libexec/openssh/sshd-session')
&& !$have->('usr/lib/openssh/sshd-session'))
{
push @missing,
"usr/libexec/openssh/sshd-session (this sshd execs it for every connection)";
}
# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |&
# coprocess and the /inet/ special file. mawk rejects both at parse time and the node
# then asks for no credential, so read the binary back. gawk carries its own name. An
# empty file carries no name and is not a program, so there is nothing to read.
if (length($opt{awk} // '') && index($opt{awk}, 'GNU Awk') < 0) {
push @missing,
'usr/bin/awk is not gawk (allowcred.awk opens its TCP stream with the gawk /inet/ coprocess)';
}
# tmux exits under the C locale. The hook then runs doxcat directly, but a Genesis
# shell without tmux loses the console attach.
if ($have->('usr/bin/tmux') && !$have->('usr/lib/locale/C.utf8/LC_CTYPE')) {
push @missing,
"usr/lib/locale/C.utf8/LC_CTYPE (tmux refuses to start without a UTF-8 locale)";
}
return @missing;
}
#-------------------------------------------------------------------------------
=head3 check_payload
Descriptions: the command line of verify-genesis-payload, without the output:
[--commands-from <module-setup.sh>] <payload-root> [required-path ...]
Arguments:
@args: the command line
Returns:
($status, $message). $status is the exit status: 0 when the payload is
complete, 1 when it lacks something, 2 on a usage error. $message is
the text to print, one line or a list of missing items.
=cut
#-------------------------------------------------------------------------------
sub check_payload {
my @args = @_;
my $commands_from = '';
while (@args) {
if ($args[0] eq '--commands-from') {
shift @args;
$commands_from = shift(@args) // '';
} elsif ($args[0] =~ /^--commands-from=(.*)/s) {
$commands_from = $1;
shift @args;
} else {
last;
}
}
my $payload = shift(@args) // '';
if ($payload eq '' || !-d $payload) {
return (2, "$ME: not a payload directory: " . ($payload eq '' ? '<empty>' : $payload) . "\n");
}
my @commands;
if ($commands_from ne '') {
@commands = eval { module_commands($commands_from) };
return (2, $@) if $@;
}
my ($sshd, $awk) = (slurp("$payload/usr/sbin/sshd"), slurp("$payload/usr/bin/awk"));
my @missing = missing_paths(sub { -e "$payload/$_[0]" },
required => \@args,
commands => \@commands,
source => $commands_from,
sshd => $sshd,
awk => $awk);
return (1, "$ME: $payload is incomplete:" . join('', map { "\n $_" } @missing) . "\n")
if @missing;
return (0, "$ME: $payload is complete\n");
}
#-------------------------------------------------------------------------------
=head3 slurp
Descriptions: read a file whole, in raw mode. usr/bin/awk and usr/sbin/sshd are
binaries, and both are read to tell one program from another.
Arguments:
$path: the path to read
Returns:
the content, or undef when the file cannot be read
=cut
#-------------------------------------------------------------------------------
sub slurp {
my ($path) = @_;
open(my $fh, '<:raw', $path) or return undef;
local $/;
my $content = <$fh> // '';
close($fh);
return $content;
}
#-------------------------------------------------------------------------------
=head3 main
Descriptions: run check_payload and print its message: on STDOUT when the
payload is complete, on STDERR otherwise.
Arguments:
@args: the command line
Returns:
the exit status from check_payload
=cut
#-------------------------------------------------------------------------------
sub main {
my ($status, $message) = check_payload(@_);
print { $status ? *STDERR : *STDOUT } $message;
return $status;
}
1;