2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

test(grub2): the facing address is substituted without brackets into a URL

grub2.pm replaces !myipfn! with the facing address of the management node. The
placeholder stands in front of ":$httpport" in the install URLs, so an IPv6
address was substituted bare and the authority could not be read.

grub2_ipv6.t now exercises setstate with a kcmdline that carries the placeholder
inside an install URL. sles_install_url_ipv6.t asserts the substitution itself
against the real module, in both contexts: bracketed where a port follows, bare
where none does.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-28 10:46:39 -03:00
parent a701dfc206
commit 19dc1de843
2 changed files with 47 additions and 0 deletions
+33
View File
@@ -40,6 +40,18 @@ BEGIN {
$INC{'xCAT/ServiceNodeUtils.pm'} = __FILE__;
package xCAT::NetworkUtils;
# The real helper brackets a placeholder that a port follows, so the port after an
# IPv6 address can still be read, and leaves every other placeholder bare.
sub substitute_facing_address {
my ($cmdline, $address) = @_;
return $cmdline unless defined($cmdline) && defined($address) && length($address);
if (index($address, ':') >= 0) {
$cmdline =~ s/!myipfn!(?=:\d)/[$address]/g;
}
$cmdline =~ s/!myipfn!/$address/g;
return $cmdline;
}
our %addresses = (
nodev4 => { 4 => '192.0.2.50' },
nodev6 => { 6 => '2001:db8:1::50' },
@@ -291,6 +303,27 @@ ok(
-e "$v6_root/grub.cfg-01-02-00-00-00-00-61",
'IPv6-only node retains its MAC-specific GRUB config alias'
);
# The !myipfn! placeholder stands where a URI authority expects a host. sles.pm and
# anaconda.pm put it in front of ":$httpport", so an unbracketed IPv6 address gives
# "install=http://2001:db8::1:80/..." and the installer cannot reach the repository.
# facing_address_for_cmdline itself is asserted against the real module in
# sles_install_url_ipv6.t; here the subject is whether setstate routes the substitution
# through it.
my ($ph_dir, $ph_root, $ph_config, $ph_rc, $ph_message) =
exercise_setstate('nodev6', '02:00:00:00:00:62',
'autoyast=http://!myipfn!:80/install/autoinst/nodev6 install=http://!myipfn!:80/install/leap15.6/x86_64/1');
is($ph_rc, 0, "a kcmdline carrying !myipfn! generates a config: $ph_message");
like(
$ph_config,
qr{\Qautoyast=http://[2001:db8::1]:80/install/autoinst/nodev6\E},
'the substituted IPv6 facing address is bracketed in the install URL'
);
unlike(
$ph_config,
qr{http://2001:db8::1:80},
'no unbracketed IPv6 authority reaches the generated config'
);
my @v6_ip_aliases = grep { $_ !~ /grub\.cfg-01-02-00-00-00-00-61$/ } glob("$v6_root/grub.cfg-*");
is_deeply(
\@v6_ip_aliases,
+14
View File
@@ -57,4 +57,18 @@ is( xCAT_plugin::sles::rootimg_url('http', '192.168.156.1', 80, 'install/netboot
'http://192.168.156.1:80/install/netboot/x86_64/rootimg.gz',
'imgurl= leaves an IPv4 image server alone' );
# grub2.pm substitutes !myipfn! into these same URLs, after the port is already appended.
is( xCAT::NetworkUtils::substitute_facing_address(
'install=http://!myipfn!:80/install/leap15.6/x86_64/1', '2001:db8:156::1'),
'install=http://[2001:db8:156::1]:80/install/leap15.6/x86_64/1',
'a placeholder that a port follows is bracketed for IPv6' );
is( xCAT::NetworkUtils::substitute_facing_address('xcatd=!myipfn! quiet', '2001:db8:156::1'),
'xcatd=2001:db8:156::1 quiet',
'a placeholder with no port keeps the bare IPv6 address' );
is( xCAT::NetworkUtils::substitute_facing_address(
'install=http://!myipfn!:80/x', '192.168.156.1'),
'install=http://192.168.156.1:80/x', 'an IPv4 address is never bracketed' );
is( xCAT::NetworkUtils::substitute_facing_address('xcatd=!myipfn!', undef),
'xcatd=!myipfn!', 'no facing address leaves the command line alone' );
done_testing();