diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index c67bd2bc2f..1c4be9b64a 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -511,6 +511,10 @@ sub subvars { $inc =~ s/#GETNODEDOMAIN:([^#]+)#/get_node_domain($1)/eg; $inc =~ s/#GETPRINICMAC:([^#]+)#/xCAT::Utils::parseMacTabEntry(tabdb("mac",$1,"mac"),$1)/eg; $inc =~ s/#COLONHTTPPORT#/$httpportsuffix/eg; + # The master as a URI host: bracketed when it is an IPv6 literal, so a URL built in a + # template can carry it. #XCATVAR:XCATMASTER# is the bare value and stays that way, + # because bash reads /dev/tcp// with no brackets. + $inc =~ s/#MASTERURIHOST#/$master_uri_host/eg; if (($::XCATSITEVALS{xcatdebugmode} eq "1") or ($::XCATSITEVALS{xcatdebugmode} eq "2")) { $inc =~ s/#UNCOMMENTOENABLEDEBUGPORT#//g; diff --git a/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl b/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl index 4320ee9fd9..128ff8612d 100644 --- a/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl @@ -53,12 +53,12 @@ autoinstall: ip addr show ip route show echo "=== disk detection ===" - wget -T 30 -O /tmp/getinstdisk http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/getinstdisk + wget -T 30 -O /tmp/getinstdisk http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/getinstdisk test -s /tmp/getinstdisk chmod u+x /tmp/getinstdisk /tmp/getinstdisk echo "=== pre-install script ===" - wget -T 30 -O /tmp/pre.sh http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.pre + wget -T 30 -O /tmp/pre.sh http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.pre test -s /tmp/pre.sh chmod u+x /tmp/pre.sh /tmp/pre.sh @@ -107,7 +107,7 @@ autoinstall: printf ''%s\n'' ''GRUB_CMDLINE_LINUX="#TABLEBLANKOKAY:bootparams:$NODE:kcmdline#"'' >>/target/etc/default/grub; curtin in-target --target /target update-grub2; echo "Running late_command Installation script..."; - wget -T 30 http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.post; + wget -T 30 http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.post; chmod u+x #HOSTNAME#.post; cp ./#HOSTNAME#.post /target/root/post.script; curtin in-target --target /target /root/post.script; diff --git a/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl b/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl index 4320ee9fd9..128ff8612d 100644 --- a/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl @@ -53,12 +53,12 @@ autoinstall: ip addr show ip route show echo "=== disk detection ===" - wget -T 30 -O /tmp/getinstdisk http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/getinstdisk + wget -T 30 -O /tmp/getinstdisk http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/getinstdisk test -s /tmp/getinstdisk chmod u+x /tmp/getinstdisk /tmp/getinstdisk echo "=== pre-install script ===" - wget -T 30 -O /tmp/pre.sh http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.pre + wget -T 30 -O /tmp/pre.sh http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.pre test -s /tmp/pre.sh chmod u+x /tmp/pre.sh /tmp/pre.sh @@ -107,7 +107,7 @@ autoinstall: printf ''%s\n'' ''GRUB_CMDLINE_LINUX="#TABLEBLANKOKAY:bootparams:$NODE:kcmdline#"'' >>/target/etc/default/grub; curtin in-target --target /target update-grub2; echo "Running late_command Installation script..."; - wget -T 30 http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.post; + wget -T 30 http://#MASTERURIHOST##COLONHTTPPORT#/install/autoinst/#HOSTNAME#.post; chmod u+x #HOSTNAME#.post; cp ./#HOSTNAME#.post /target/root/post.script; curtin in-target --target /target /root/post.script; diff --git a/xCAT-test/unit/subiquity_uri_host.t b/xCAT-test/unit/subiquity_uri_host.t new file mode 100644 index 0000000000..7753ff98da --- /dev/null +++ b/xCAT-test/unit/subiquity_uri_host.t @@ -0,0 +1,57 @@ +#!/usr/bin/env perl +# The URLs the Subiquity templates fetch from carry the master as a URI host. +# +# They were built as "http://#XCATVAR:XCATMASTER##COLONHTTPPORT#/install/autoinst/...", and +# that tag renders the bare value. For an IPv6-only node that is a literal address, so wget +# read the last group as a port: +# +# wget -T 30 -O /tmp/getinstdisk http://2001:db8:147::1/install/autoinst/getinstdisk +# http://2001:db8:147::1/install/autoinst/getinstdisk: Bad port number. +# +# The early-commands script runs under "set -eux", so that one line failed the whole script, +# subiquity reported CalledProcessError from Early/run, and the install stopped before curtin. +# +# The templates are the artifact here, so they are read. #MASTERURIHOST# renders through +# format_uri_host, which networkutils_ipv6_helpers.t covers. +use strict; +use warnings; + +use File::Slurper qw(read_text); +use File::Spec; +use FindBin; +use Test::More; + +my $root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); + +foreach my $kind (qw(compute service)) { + my $tmpl = File::Spec->catfile( $root, 'xCAT-server', 'share', 'xcat', 'install', + 'ubuntu', "$kind.subiquity.tmpl" ); + SKIP: { + skip "$kind.subiquity.tmpl not found", 4 unless -f $tmpl; + my $text = read_text($tmpl); + + # Every http:// URL in the template takes the URI host, never the bare tag. + my @urls = $text =~ m{(http://#[A-Z:]+#[^ '"]*)}g; + ok( scalar(@urls), "$kind template builds at least one URL" ); + my @bare = grep { m{^http://#XCATVAR:XCATMASTER#} } @urls; + is_deeply( \@bare, [], + "$kind template builds no URL from the bare master value" ); + my @uri = grep { m{^http://#MASTERURIHOST#} } @urls; + is( scalar(@uri), scalar(@urls), + "$kind template builds every URL from the URI host" ); + + # /dev/tcp takes a bare host, so that one keeps the bare tag. + like( $text, qr{xm=#XCATVAR:XCATMASTER#}, + "$kind template still gives /dev/tcp the unbracketed host" ); + } +} + +# The tag has to be substituted, or it reaches the node as text. +my $pm = File::Spec->catfile( $root, 'xCAT-server', 'lib', 'perl', 'xCAT', 'Template.pm' ); +SKIP: { + skip 'Template.pm not found', 1 unless -f $pm; + ok( index( read_text($pm), 's/#MASTERURIHOST#/$master_uri_host/' ) >= 0, + 'Template.pm substitutes the tag' ); +} + +done_testing();