From 5760b73d573c49576f6b7df923b863ca9f63dfad Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:49:07 -0300 Subject: [PATCH] test(networkutils): the facing-address placeholder is dropped by format_host_port format_host_port validates its host with format_uri_host, which refuses '!myipfn!' because it is not a host name. The call returns undef, so a command line built from it loses both the server and the port. These assertions fail without the fix that follows: format_host_port and format_uri_host return nothing for the placeholder, and the imgurl built from it reads "imgurl=http:///install/..." for an IPv6 and an IPv4 facing address alike. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/networkutils_ipv6_helpers.t | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/xCAT-test/unit/networkutils_ipv6_helpers.t b/xCAT-test/unit/networkutils_ipv6_helpers.t index 0ff46b97b8..9ab3893081 100644 --- a/xCAT-test/unit/networkutils_ipv6_helpers.t +++ b/xCAT-test/unit/networkutils_ipv6_helpers.t @@ -693,4 +693,29 @@ SKIP: { 'a value that is not an address gives no zone' ); } +# '!myipfn!' is the facing-address placeholder. pxe.pm, grub2.pm and petitboot.pm replace it +# after the command line is built. format_host_port validated it as a host name and returned +# undef, so the imgurl of a diskless node lost both its server and its port and read +# "imgurl=http:////install/...". That reached every Ubuntu diskless node, not only an IPv6 one. +{ + is( xCAT::NetworkUtils->format_host_port('!myipfn!', 80), '!myipfn!:80', + 'the facing-address placeholder survives being formatted with a port' ); + is( xCAT::NetworkUtils->format_uri_host('!myipfn!'), '!myipfn!', + 'and survives being formatted as a URI host' ); + + my $cmdline = 'imgurl=http://' + . ( xCAT::NetworkUtils->format_host_port('!myipfn!', 80) // '' ) + . '/install/netboot/rootimg.cpio.gz'; + is( xCAT::NetworkUtils::substitute_facing_address($cmdline, '2001:db8:147::1'), + 'imgurl=http://[2001:db8:147::1]:80/install/netboot/rootimg.cpio.gz', + 'an IPv6 facing address reaches the imgurl bracketed' ); + is( xCAT::NetworkUtils::substitute_facing_address($cmdline, '192.0.2.1'), + 'imgurl=http://192.0.2.1:80/install/netboot/rootimg.cpio.gz', + 'and an IPv4 facing address reaches the imgurl bare' ); + + # The placeholder is an exception, not the removal of the check. + ok( !defined( xCAT::NetworkUtils->format_host_port('not a host', 80) ), + 'a value that is neither a host nor the placeholder is still refused' ); +} + done_testing();