From 354213e53d3aa596995d0f020ff02843e4f7de05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sat, 8 Aug 2026 01:08:52 -0300 Subject: [PATCH] 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. --- .../deprecated_provisioning_reachability.t | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 xCAT-test/unit/deprecated_provisioning_reachability.t diff --git a/xCAT-test/unit/deprecated_provisioning_reachability.t b/xCAT-test/unit/deprecated_provisioning_reachability.t new file mode 100644 index 000000000..b1df7911e --- /dev/null +++ b/xCAT-test/unit/deprecated_provisioning_reachability.t @@ -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();