diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index 84f5ce76ee..55b28e4dcf 100644 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -4186,10 +4186,11 @@ sub send_tcp_msg { Returns: the command line, with the placeholder replaced. - A placeholder that a port follows is bracketed when the address is IPv6, - because "http://2001:db8::1:80/" cannot be split into a host and a port. - Every other placeholder takes the bare address: xcatd=!myipfn! names a host - with no port, and the postscripts read that value as it stands. + A placeholder that a port or an NFS path follows is bracketed when the + address is IPv6, because neither "http://2001:db8::1:80/" nor + "root=nfs:2001:db8::1:/install" can be split at the right colon. Every other + placeholder takes the bare address: xcatd=!myipfn! names a host with no port, + and the postscripts read that value as it stands. =cut @@ -4199,7 +4200,12 @@ sub substitute_facing_address { return $cmdline unless defined($cmdline) && defined($address) && length($address); if (index($address, ':') >= 0) { + # A port follows the placeholder, as in "http://!myipfn!:80/". Without the brackets + # the port cannot be told from the last group of the address. $cmdline =~ s/!myipfn!(?=:\d)/[$address]/g; + # An NFS path follows it, as in "root=nfs:!myipfn!:/install". dracut reads the + # server up to the last colon, so an unbracketed address loses its last group. + $cmdline =~ s{!myipfn!(?=:/)}{[$address]}g; } $cmdline =~ s/!myipfn!/$address/g; return $cmdline; diff --git a/xCAT-test/unit/networkutils_ipv6_helpers.t b/xCAT-test/unit/networkutils_ipv6_helpers.t index 9ab3893081..d873063a0b 100644 --- a/xCAT-test/unit/networkutils_ipv6_helpers.t +++ b/xCAT-test/unit/networkutils_ipv6_helpers.t @@ -718,4 +718,23 @@ SKIP: { 'a value that is neither a host nor the placeholder is still refused' ); } +# An NFS root carries the server between two colons: "root=nfs::/install". dracut +# reads the server up to the last colon, so an unbracketed IPv6 address lost its last group +# and a statelite node could not mount its root. +is( xCAT::NetworkUtils::substitute_facing_address('root=nfs:!myipfn!:/install/netboot', '2001:db8::1'), + 'root=nfs:[2001:db8::1]:/install/netboot', + 'an NFS server is bracketed before its path' ); +is( xCAT::NetworkUtils::substitute_facing_address('root=nfs:!myipfn!:/install/netboot', '192.0.2.1'), + 'root=nfs:192.0.2.1:/install/netboot', + 'an IPv4 NFS server is left alone' ); +is( xCAT::NetworkUtils::substitute_facing_address('imgurl=http://!myipfn!:80/x root=nfs:!myipfn!:/y', '2001:db8::1'), + 'imgurl=http://[2001:db8::1]:80/x root=nfs:[2001:db8::1]:/y', + 'a port and an NFS path are both bracketed in one command line' ); +is( xCAT::NetworkUtils::substitute_facing_address('xcatd=!myipfn!', '2001:db8::1'), + 'xcatd=2001:db8::1', + 'a placeholder with nothing after it still takes the bare address' ); +is( xCAT::NetworkUtils::substitute_facing_address('path=!myipfn!/install', '2001:db8::1'), + 'path=2001:db8::1/install', + 'a slash that no colon precedes does not bracket' ); + done_testing();