2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-08-27 00:56:43 +00:00

test(packimage): guard against the deprecated paths coming back

Scan destiny.pm and packimage.pm for statements sitting after an unconditional
return, which is how the deprecated provisioning paths stayed in the tree after
they stopped running.

Also assert the behavior that has to survive the removal: the deprecated
nodeset states are still rejected, packimage still rejects -o, -p and -a, and a
missing image name is now reported as such rather than as a missing option that
would be rejected anyway.
This commit is contained in:
Vinícius Ferrão
2026-08-08 01:08:52 -03:00
parent 2a3af4c34a
commit 354213e53d
@@ -0,0 +1,84 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Spec;
use Test::More;
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
sub slurp {
my ($rel) = @_;
my $path = File::Spec->catfile( $repo_root, $rel );
return unless -r $path;
open( my $fh, '<', $path ) or die "Unable to read $path: $!";
my $c = do { local $/; <$fh> };
close($fh);
return $c;
}
# Report statements that sit after an unconditional return inside the same
# block. Those are unreachable, which is how the deprecated provisioning paths
# survived in the tree for years after they stopped running.
sub unreachable_after_return {
my ($source) = @_;
my @lines = split( /\n/, $source, -1 );
my @found;
for my $i ( 0 .. $#lines ) {
my ($indent) = $lines[$i] =~ /^(\s*)(?:return\s*;|return\s+\d+\s*;)\s*$/;
next unless defined $indent;
my $depth = length($indent);
for my $j ( $i + 1 .. $#lines ) {
my $next = $lines[$j];
next if $next =~ /^\s*$/ || $next =~ /^\s*#/;
my ($ni) = $next =~ /^(\s*)/;
last if length($ni) < $depth;
last if $next =~ /^\s*[}\]\)]/;
push @found, ( $j + 1 ) . ": $next";
last;
}
}
return @found;
}
my $destiny = slurp('xCAT-server/lib/xcat/plugins/destiny.pm');
my $packimage = slurp('xCAT-server/lib/xcat/plugins/packimage.pm');
plan skip_all => 'destiny.pm or packimage.pm not found'
unless defined($destiny) && defined($packimage);
my @destiny_dead = unreachable_after_return($destiny);
is_deeply( \@destiny_dead, [], 'destiny.pm has no statements after an unconditional return' );
my @packimage_dead = unreachable_after_return($packimage);
is_deeply( \@packimage_dead, [], 'packimage.pm has no statements after an unconditional return' );
# The deprecated states must still be rejected. Removing the dead path below the
# rejection must not remove the rejection itself.
like(
$destiny,
qr/have been deprecated, use \\"osimage=/,
'the deprecated nodeset states are still rejected'
);
# packimage rejects -o, -p and -a up front, so nothing after that point can ask
# for them again. The old no-imagename branch demanded -o, which could never be
# supplied, and reported that as the error.
unlike(
$packimage,
qr/Please specify a os version with the -o flag/,
'packimage no longer asks for an option it rejects earlier'
);
like(
$packimage,
qr/-o, -p and -a options are obsoleted/,
'packimage still rejects the deprecated options'
);
like(
$packimage,
qr/An image name is required/,
'packimage reports the missing image name instead'
);
done_testing();