diff --git a/xCAT-test/unit/blade_findme_chassis_filter.t b/xCAT-test/unit/blade_findme_chassis_filter.t index 2fb8d7e90..444017572 100644 --- a/xCAT-test/unit/blade_findme_chassis_filter.t +++ b/xCAT-test/unit/blade_findme_chassis_filter.t @@ -5,35 +5,13 @@ use warnings; use FindBin; use File::Spec; use Test::More; - -my $root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); -my $plugin = File::Spec->catfile( $root, - 'xCAT-server', 'lib', 'xcat', 'plugins', 'blade.pm' ); -plan skip_all => 'blade.pm not found' unless -r $plugin; - -my $lib = File::Spec->catdir( $root, 'xCAT-server', 'lib', 'perl' ); -my $module = File::Spec->catfile( $lib, 'xCAT', 'BladeUtils.pm' ); -my $direct_module = -r $module; -my $source; - -if ($direct_module) { - unshift @INC, $lib; - require xCAT::BladeUtils; -} else { - open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!"; - $source = do { local $/; <$fh> }; - close($fh); - - my ($routine) = $source =~ /(sub blade_nodes_from_mp \{.*?\n\}\n)/s; - BAIL_OUT('could not extract blade_nodes_from_mp from blade.pm') unless $routine; - eval "package BladeFilter; $routine 1;" - or BAIL_OUT("could not evaluate the routine: $@"); -} +use lib File::Spec->catdir( $FindBin::Bin, '..', '..', + 'xCAT-server', 'lib', 'perl' ); +use xCAT::BladeUtils; sub blades { - my @nodes = $direct_module - ? xCAT::BladeUtils::blade_nodes_from_mp(@_) - : BladeFilter::blade_nodes_from_mp(@_); + my @entries = @_; + my @nodes = xCAT::BladeUtils::blade_nodes_from_mp(@entries); return [ sort @nodes ]; } @@ -105,14 +83,4 @@ is_deeply( blades(), [], 'an empty table asks nothing' ); is_deeply( blades( {}, { node => 'x220b', nodetype => 'blade' } ), ['x220b'], 'a row without a node name is skipped' ); -# The caller has to read the two attributes the routine needs, and has to stop -# before the work that reads the arp table when nothing is left to ask. -unless ($direct_module) { - like( $source, qr/getAllNodeAttribs\(\[qw\(node nodetype mpa\)\]\)/, - 'the findme request reads the hardware type and the chassis' ); - like( $source, - qr/my \@blades\s*=\s*blade_nodes_from_mp\(\@bladents\);.*?unless \(\@blades\) \{ return; \}/s, - 'the handler returns when the table holds no blades' ); -} - done_testing(); diff --git a/xCAT-test/unit/blade_findme_dispatch.t b/xCAT-test/unit/blade_findme_dispatch.t index 86e096198..39133a86b 100644 --- a/xCAT-test/unit/blade_findme_dispatch.t +++ b/xCAT-test/unit/blade_findme_dispatch.t @@ -5,77 +5,40 @@ use warnings; use FindBin; use File::Spec; use Test::More; - -my $root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); -my $plugin = File::Spec->catfile( $root, 'xCAT-server', 'lib', 'xcat', - 'plugins', 'blade.pm' ); -plan skip_all => 'blade.pm not found' unless -r $plugin; - -my $lib = File::Spec->catdir( $root, 'xCAT-server', 'lib', 'perl' ); -my $module = File::Spec->catfile( $lib, 'xCAT', 'BladeUtils.pm' ); -my $direct_module = -r $module; -my $source; - -if ($direct_module) { - unshift @INC, $lib; - require xCAT::BladeUtils; -} else { - open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!"; - $source = do { local $/; <$fh> }; - close($fh); - - my ($entry) = $source =~ - /(sub preprocess_request \{.*?\n if \(\$command eq 'findme'\) \{ return \[\$request\]; \})/s; - BAIL_OUT('blade.pm does not hand a findme request on before the noderange check') - unless $entry; - $entry .= "\n return 'REACHED-NODERANGE-CHECK';\n}\n"; - eval "package BladeEntry; $entry 1;" - or BAIL_OUT("could not evaluate the entry: $@"); -} +use lib File::Spec->catdir( $FindBin::Bin, '..', '..', + 'xCAT-server', 'lib', 'perl' ); +use xCAT::BladeUtils; sub entry_for { my ($req) = @_; - my @said; - my $r = $direct_module - ? xCAT::BladeUtils::findme_request_for_handler($req) - : BladeEntry::preprocess_request( $req, sub { push @said, $_[0] } ); - return ( $r, \@said ); + return xCAT::BladeUtils::findme_request_for_handler($req); } # This is the request a booting node sends: a command and its own details, and # no node, because the node is what the request asks xCAT to find. -my ( $got, $said ) = entry_for( - { - command => ['findme'], - arch => ['x86_64'], - uuid => ['00000000-0000-0000-0000-000000000000'], - } -); +my $request = { + command => ['findme'], + arch => ['x86_64'], + uuid => ['00000000-0000-0000-0000-000000000000'], +}; +my $got = entry_for($request); is( ref $got, 'ARRAY', 'a findme request is handed on to the handler' ); -is( scalar @$said, 0, 'a findme request draws no error from the preprocessor' ); # The request that comes back has to be the one that arrived, or the handler # loses the client address that it matches the node by. -is( $got->[0]->{command}->[0], 'findme', 'the request that is handed on is the findme request' ); +is( $got->[0], $request, 'the request that arrived is handed on unchanged' ); # A request that was already preprocessed elsewhere is still handed on. -( $got, $said ) = entry_for( - { command => ['findme'], _xcatpreprocessed => [1] } ); +$got = entry_for( { command => ['findme'], _xcatpreprocessed => [1] } ); is( ref $got, 'ARRAY', 'an already preprocessed findme request is handed on' ); # Every other command keeps the noderange requirement. foreach my $command (qw(rpower rinv rvitals rbeacon)) { - my ( $other, undef ) = entry_for( { command => [$command] } ); - isnt( ref $other, 'ARRAY', - "a $command request without a noderange is not handed on" ); + is( entry_for( { command => [$command] } ), undef, + "a $command request is left for normal preprocessing" ); } -# The preprocessor used to drop a node from a findme request by its hardware -# type. A findme request now returns above that point, so the test could never -# run again and must not come back. -unless ($direct_module) { - unlike( $source, qr/eq 'findme' and \$ent->\{nodetype\}/, - 'the preprocessor holds no findme test that cannot run' ); -} +is( entry_for({}), undef, 'a request without a command is left alone' ); +is( entry_for(undef), undef, 'an undefined request is left alone' ); done_testing();