mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-08-28 09:36:40 +00:00
158c16a138
Assert that a node-targeted makedhcp maps its nodes to their service nodes and skips the ones serving none of them, that regenerating the networks with -n stays exempt because a dynamic range is not tied to a node, and that an unmapped noderange still reaches every service node instead of none. Also pin the two conditions the loop already had, so restricting the fan-out does not quietly drop the self dispatch guards.
59 lines
1.8 KiB
Perl
59 lines
1.8 KiB
Perl
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
use File::Spec;
|
|
use Test::More;
|
|
|
|
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
|
|
my $plugin = File::Spec->catfile( $repo_root, 'xCAT-server/lib/xcat/plugins/dhcp.pm' );
|
|
|
|
plan skip_all => "$plugin not found" unless -r $plugin;
|
|
|
|
open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!";
|
|
my $source = do { local $/; <$fh> };
|
|
close($fh);
|
|
|
|
# The dispatch loop that fans a node-targeted makedhcp out to service nodes.
|
|
my ($loop) = $source =~ m{
|
|
( my \s+ %servingsn .*? foreach \s+ my \s+ \$s \s+ \(\@snlist\) .*? \n \s* \} \n )
|
|
}sx;
|
|
|
|
ok( $loop, 'the service node dispatch loop was located' )
|
|
or BAIL_OUT('dhcp.pm no longer matches the expected dispatch shape');
|
|
|
|
like(
|
|
$loop,
|
|
qr/getSNformattedhash\(\\\@nodes/,
|
|
'the named nodes are mapped to their service nodes'
|
|
);
|
|
like(
|
|
$loop,
|
|
qr/next \s+ if \s+ \(keys\(%servingsn\) \s* && \s* !exists\(\$servingsn\{\$s\}\)\)/x,
|
|
'a service node serving none of the named nodes is skipped'
|
|
);
|
|
|
|
# Regenerating the networks must still reach every dhcp server, because a
|
|
# dynamic range does not belong to any node.
|
|
like(
|
|
$loop,
|
|
qr/unless \s* \(\$opt\{n\}\)/x,
|
|
'network regeneration is exempt from the node based restriction'
|
|
);
|
|
|
|
# Empty mapping must fall back to the previous fan-out rather than silently
|
|
# dispatching to nothing.
|
|
my ($guard) = $loop =~ /(next\s+if\s+\(keys\(%servingsn\)[^\n]*)/;
|
|
like(
|
|
$guard,
|
|
qr/keys\(%servingsn\)\s*&&/,
|
|
'an unmapped noderange still reaches every service node'
|
|
);
|
|
|
|
# The pre-existing conditions in the loop must survive.
|
|
like( $loop, qr/scalar \@nodes == 1 and \$nodes\[0\] eq \$s/, 'the self dispatch guard is retained' );
|
|
like( $loop, qr/\$issn && exists\(\$iphash\{\$s\}\)/, 'the service node self skip is retained' );
|
|
|
|
done_testing();
|