mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-20 09:22:17 +00:00
37de3e634e
xcatprobe asks 'tput cols' for the screen width whenever TERM is set. The GitHub Actions container sets TERM=unknown, terminfo carries no such terminal, and tput writes nothing. The width became 0 and the layout cut every checkpoint message to the empty string, so the probe printed a column of bare [ OK ], [WARN] and [FAIL] marks with no text beside them. xcatprobe_xcatmn_selinux failed on that output. It asserts that the SELinux checkpoint reports [ OK ], and no checkpoint text reached the log. The rest of the probe diagnostics were unreadable for the same reason, so the one [FAIL] in the run named no checkpoint. probe_format::screen_width keeps the 80 column default when 'tput cols' gives no usable number. probe_xcatmn_selinux_case.t renders the checkpoint at that width and three of its assertions fail without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
125 lines
3.5 KiB
Perl
125 lines
3.5 KiB
Perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
package probe_format;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
my $DESIRED_WIDTH = 120;
|
|
my $DEFAULT_WIDTH = 80;
|
|
my $FLAG_WIDTH = 6;
|
|
|
|
#-----------------------------------
|
|
|
|
=head3 screen_width
|
|
|
|
Descriptions:
|
|
Return the number of columns to format a message in.
|
|
Arguments:
|
|
raw: the output of 'tput cols', or undef when there is no terminal
|
|
Returns:
|
|
the column count, always more than the flag width
|
|
|
|
=cut
|
|
|
|
#-----------------------------------
|
|
sub screen_width {
|
|
my ($raw) = @_;
|
|
|
|
# 'tput cols' writes nothing when TERM names a terminal terminfo does not
|
|
# carry, and the GitHub Actions container sets TERM=unknown. A width of 0
|
|
# cuts every checkpoint message down to the empty string.
|
|
return $DEFAULT_WIDTH unless (defined($raw) && $raw =~ /(\d+)/);
|
|
my $cols = $1 + 0;
|
|
return $cols > $FLAG_WIDTH ? $cols : $DEFAULT_WIDTH;
|
|
}
|
|
|
|
#-----------------------------------
|
|
|
|
=head3 render
|
|
|
|
Descriptions:
|
|
Lay out one message line of a probe subcommand.
|
|
Arguments:
|
|
line: the line the subcommand printed, "[<flag>]:<message>"
|
|
fullmsg: true to wrap a long message, false to truncate it
|
|
screenwidth: the column count from screen_width()
|
|
Returns:
|
|
(lines, mark). lines is an array reference. Print every line but the
|
|
last with a newline. mark is what follows the last line: undef when
|
|
the line carries no flag, and otherwise the mark to print, which
|
|
already holds its newline.
|
|
|
|
=cut
|
|
|
|
#-----------------------------------
|
|
sub render {
|
|
my ($line, $fullmsg, $screenwidth) = @_;
|
|
|
|
my $msg = $line;
|
|
my $flag;
|
|
if ($line =~ /\[(\w+)\]\s*:(.+)/) {
|
|
$flag = $1;
|
|
$msg = $2;
|
|
}
|
|
|
|
$msg =~ s/\t/ /g;
|
|
my $maxlen = ($screenwidth > $DESIRED_WIDTH ? $DESIRED_WIDTH : $screenwidth);
|
|
|
|
my @finalmsg = ();
|
|
my $msglen = length($msg);
|
|
if ($msglen <= $maxlen) {
|
|
if (!$fullmsg && $flag) {
|
|
my $leftspace = $maxlen - length($msg);
|
|
if ($leftspace < $FLAG_WIDTH) {
|
|
$msg = substr($msg, 0, $maxlen - $FLAG_WIDTH);
|
|
$msg =~ s/(.*).../$1\.\.\./g;
|
|
}
|
|
}
|
|
push @finalmsg, $msg;
|
|
} else {
|
|
my $head = 0;
|
|
my $tail = $maxlen;
|
|
while ($head < $msglen) {
|
|
push @finalmsg, substr($msg, $head, ($tail - $head));
|
|
if (!$fullmsg) {
|
|
if ($flag) {
|
|
$finalmsg[0] =~ s/(.*).........$/$1\.\.\./g;
|
|
} else {
|
|
$finalmsg[0] =~ s/(.*)...$/$1\.\.\./g;
|
|
}
|
|
last;
|
|
}
|
|
$head = $tail;
|
|
$tail = $head + ($maxlen <= ($msglen - $tail) ? $maxlen : ($msglen - $tail));
|
|
}
|
|
}
|
|
|
|
return (\@finalmsg, undef) unless ($flag);
|
|
|
|
my $last = $finalmsg[-1];
|
|
my $leftspace = $maxlen - length($last);
|
|
my $debug = ($flag =~ /debug/i) ? 1 : 0;
|
|
my $mark = '';
|
|
if ($flag =~ /failed/i) {
|
|
$mark = "[FAIL]\n";
|
|
} elsif ($flag =~ /warning/i) {
|
|
$mark = "[WARN]\n";
|
|
} elsif ($flag =~ /ok/i) {
|
|
$mark = "[ OK ]\n";
|
|
} elsif ($debug) {
|
|
$mark = "\n";
|
|
} elsif ($flag =~ /info/i) {
|
|
$mark = "[INFO]\n";
|
|
}
|
|
|
|
my $spacenum = 0;
|
|
if (!$debug) {
|
|
$spacenum = (($leftspace >= $FLAG_WIDTH) ? ($leftspace - $FLAG_WIDTH) : ($screenwidth - length($last) + $maxlen - $FLAG_WIDTH));
|
|
}
|
|
$finalmsg[-1] = $last . (" " x $spacenum);
|
|
|
|
return (\@finalmsg, $mark);
|
|
}
|
|
|
|
1;
|