diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 9756289720..1b195d5e24 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -503,6 +503,7 @@ sub subvars { $inc =~ s/^((?:[ \t]*- [^\n]*\n)*)([ \t]*)- #INCLUDE_DEFAULT_PKGLIST_AUTOINSTALL#[ \t]*\n/$1 . ubuntu_autoinstall_items($2, $1, \@autoinstall)/meg; $inc =~ s/#SUBIQUITYINSTALLNIC#/subiquity_install_nic()/eg; $inc =~ s/#SUBIQUITYINSTALLMAC#/subiquity_install_mac()/eg; + $inc =~ s/#SUBIQUITYINSTALLMATCH:(\d+)#/subiquity_install_match($1)/eg; $inc =~ s/#SUBIQUITYDHCP:(\d+)#/subiquity_dhcp_keys($1)/eg; $inc =~ s/#SUBIQUITYTARGETDHCP#/subiquity_target_dhcp_keys()/eg; $inc =~ s/#MACHINEPASSWORD#/machinepassword()/eg; @@ -2030,11 +2031,73 @@ sub subiquity_install_netcfg { #-------------------------------------------------------------------------------- sub subiquity_install_netcfg_for_node { + my ($nodename) = @_; + + $nodename = $node unless defined($nodename); return subiquity_install_netcfg( tabdb('noderes', '$NODE', 'installnic', 1), tabdb('noderes', '$NODE', 'primarynic', 1), tabdb('mac', '$NODE', 'mac'), - $node); + $nodename); +} + +#----------------------------------------------------------------------------- + +=head3 _subiquity_netplan6 + + The netplan keys of an IPv6-only node, static, as one block of lines. + + Arguments: + $nodename the node being templated + $indent how many spaces each top-level key is indented by + Returns: + the keys, one per line, or undef when the node has no usable address + +=cut + +#----------------------------------------------------------------------------- +sub _subiquity_netplan6 { + my ($nodename, $indent) = @_; + + my $pad = ' ' x (defined($indent) ? $indent : 8); + + my ($address, undef, $gateway, $prefix) = + xCAT::NetworkUtils->getNodeNetworkCfg6($nodename); + unless ($address && defined($prefix) && $prefix =~ /^\d+$/ && $prefix <= 128) { + $tmplerr = "Cannot resolve the static IPv6 network configuration of $nodename"; + return; + } + + if (defined($gateway) && length($gateway)) { + $gateway = xCAT::NetworkUtils->ipv6_server_for_node($nodename, $gateway); + } + + # site.nameservers holds one list for the cluster, so the node can be given the IPv4 + # resolver of another network. An IPv6-only node cannot reach it, and an unreachable + # server in resolv.conf makes every lookup wait for its timeout. + # + # '' is the management node, which runs named. It is not the gateway: a + # cluster whose gateway is a separate router would be given a resolver that answers + # nothing. + my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$nodename]) }; + my $master6 = xCAT::NetworkUtils->ipv6_server_for_node($nodename, ''); + my @resolvers = grep { index($_, ':') >= 0 } + grep { defined && length } + map { $_ eq '' ? $master6 : $_ } split(/,/, $nameservers{$nodename} // ''); + @resolvers = ($master6) + if !@resolvers && defined($master6) && index($master6, ':') >= 0; + + my @lines = ("${pad}dhcp4: false", "${pad}addresses: [$address/$prefix]"); + if (defined($gateway) && length($gateway)) { + # 'to: default' rather than the deprecated gateway6, which netplan warns about and + # drops. This is the shape xcatroot already writes for a diskless IPv6 node, so the + # cluster runs one netplan dialect. + push @lines, "${pad}routes:", "${pad} - to: default", "${pad} via: $gateway"; + } + push @lines, "${pad}nameservers:", "${pad} addresses: [" . join(', ', @resolvers) . "]" + if @resolvers; + + return join("\n", @lines); } #----------------------------------------------------------------------------- @@ -2049,8 +2112,18 @@ sub subiquity_install_netcfg_for_node { installer then cannot reach its package source and falls back to asking at the console, which on a serial console waits forever. + DHCPv6 is not the answer either. A DHCPv6 client is identified by its DUID, + not by the MAC, so the installer sends a DUID that matches no Kea + reservation and takes an address out of the dynamic range. That address has + no PTR record, makedns writes PTRs from the hosts table, and xcatd + identifies a client over IPv6 only by the name its address resolves to. The + install then reaches post.xcat, which fetches mypostscript and is answered + by a getpostscript that cannot say which node asked. So the node is given + the address makedhcp reserved for it. + Arguments: - $indent how many spaces each key is indented by + $indent how many spaces each key is indented by + $nodename optional, for tests; defaults to the node being templated Returns: the keys, one per line, indented as asked. @@ -2058,11 +2131,14 @@ sub subiquity_install_netcfg_for_node { #----------------------------------------------------------------------------- sub subiquity_dhcp_keys { - my ($indent) = @_; + my ($indent, $nodename) = @_; my $pad = ' ' x (defined($indent) ? $indent : 8); return "${pad}dhcp4: true" unless $node_ipv6_only; - return "${pad}dhcp6: true\n${pad}dhcp4: false"; + + $nodename = $node unless defined($nodename); + my $section = _subiquity_netplan6($nodename, defined($indent) ? $indent : 8); + return defined($section) ? $section : ''; } #----------------------------------------------------------------------------- @@ -2072,6 +2148,13 @@ sub subiquity_dhcp_keys { The same keys for the netplan that the late command writes into the installed system, as printf arguments. + An IPv6-only node keeps the static address here too. systemd-networkd + generates its own DUID, so a reinstalled node that asked for DHCPv6 would + come up on a third address, again with no PTR, and the first xcatdsklspost + and every later updatenode would fail the same way as the install. + + Arguments: + $nodename optional, for tests; defaults to the node being templated Returns: the arguments, each already quoted and indented for netplan. @@ -2079,11 +2162,52 @@ sub subiquity_dhcp_keys { #----------------------------------------------------------------------------- sub subiquity_target_dhcp_keys { + my ($nodename) = @_; unless ($node_ipv6_only) { return '" dhcp4: true" " dhcp4-overrides:" " use-domains: true"'; } - return '" dhcp6: true" " dhcp4: false" " dhcp6-overrides:" " use-domains: true"'; + $nodename = $node unless defined($nodename); + my $section = _subiquity_netplan6($nodename, 6); + return '' unless defined($section); + return join(' ', map { qq("$_") } split(/\n/, $section)); +} + +#----------------------------------------------------------------------------- + +=head3 subiquity_install_match + + The netplan match key that picks the provisioning NIC of the node being + installed. + + An IPv4 node keeps the glob the templates carried: DHCPv4 answers on one + interface only, so every candidate may be offered the lease. An IPv6-only + node is given a static address, and a static address on each of three + interfaces of one bridge is a broken network, so that node is matched by + its own MAC. + + Arguments: + $indent how many spaces the key is indented by + $nodename optional, for tests; defaults to the node being templated + Returns: + the key, indented as asked. + +=cut + +#----------------------------------------------------------------------------- +sub subiquity_install_match { + my ($indent, $nodename) = @_; + + my $pad = ' ' x (defined($indent) ? $indent : 10); + return "${pad}name: \"e*\"" unless $node_ipv6_only; + + $nodename = $node unless defined($nodename); + my (undef, $macaddress) = subiquity_install_netcfg_for_node($nodename); + unless (defined($macaddress) && length($macaddress)) { + $tmplerr = "Cannot resolve the MAC address of $nodename"; + return ''; + } + return "${pad}macaddress: \"$macaddress\""; } #----------------------------------------------------------------------------- diff --git a/xCAT-server/lib/xcat/plugins/debian.pm b/xCAT-server/lib/xcat/plugins/debian.pm index fbece26055..9f657a1980 100644 --- a/xCAT-server/lib/xcat/plugins/debian.pm +++ b/xCAT-server/lib/xcat/plugins/debian.pm @@ -882,6 +882,14 @@ sub subiquity_iso_url { configure_networking reads ip= into IP and treats off as already done. ip6=dhcp: casper reads ip6= and configures the interface with dhcpcd -6. + There is no static form. initramfs-tools reads ip6= in + scripts/functions:configure_networking, where every value but + ""/none/done/off runs dhcpcd -6, and a value that is not on/dhcp/any is + taken as the name of a device. A static address written here would become a + device name, so the lease dhcpcd takes comes from the dynamic range and + carries a DUID that matches no reservation. The node is given its reserved + address by the static netplan in the autoinstall instead, which replaces + that lease before the installer runs. netboot=url: do_urlmount downloads the ISO with casper's own wget, which speaks IPv6, and loop-mounts it. nfsroot= is left out, because klibc @@ -1031,7 +1039,9 @@ sub subiquity_boot_params { # nfsmount, which has no IPv6: it answers "need a path" for "[2001:db8::1]:/export" and # for "2001:db8::1:/export", while an IPv4 server gets past parsing to the mount. The # network itself is not the limit, because casper reads ip6= and configures the interface - # with dhcpcd -6. + # with dhcpcd -6. That lease is from the dynamic range, because dhcpcd generates its own + # DUID in the initramfs: the reserved address reaches the node through the static netplan + # of the autoinstall, not through ip6=. # # do_urlmount downloads the ISO with casper's own wget, which speaks IPv6. That needs the # ISO in the install tree, which copycds links there, so a tree copied before this change diff --git a/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl b/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl index 128ff8612d..0e0e4a19fd 100644 --- a/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl @@ -8,7 +8,7 @@ autoinstall: ethernets: xcat-install: match: - name: "e*" +#SUBIQUITYINSTALLMATCH:10# #SUBIQUITYDHCP:8# ssh: allow-pw: true diff --git a/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl b/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl index 128ff8612d..0e0e4a19fd 100644 --- a/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/service.subiquity.tmpl @@ -8,7 +8,7 @@ autoinstall: ethernets: xcat-install: match: - name: "e*" +#SUBIQUITYINSTALLMATCH:10# #SUBIQUITYDHCP:8# ssh: allow-pw: true diff --git a/xCAT-test/bats/ubuntu_subiquity_target_netplan.bats b/xCAT-test/bats/ubuntu_subiquity_target_netplan.bats new file mode 100644 index 0000000000..febebd23c0 --- /dev/null +++ b/xCAT-test/bats/ubuntu_subiquity_target_netplan.bats @@ -0,0 +1,111 @@ +#!/usr/bin/env bats +# +# The netplan the Subiquity late-command writes into the installed system. +# +# The template renders #SUBIQUITYTARGETDHCP# into a printf argument list, so the shell decides +# which lines reach /etc/netplan/00-xcat-install.yaml and in which order. An IPv6-only node now +# gets static keys there: systemd-networkd generates its own DUID, so a node that asked for +# DHCPv6 after reboot took an address out of the dynamic range, which has no PTR record, and +# xcatd could not tell which node ran xcatdsklspost. +# +# Perl renders the arguments, the shell writes the file, so this half is a bats test. + +load 'helpers/shell_source' + +MAC='aa:bb:cc:dd:ee:07' +DHCP4_KEYS='" dhcp4: true" " dhcp4-overrides:" " use-domains: true"' +STATIC6_KEYS='" dhcp4: false" " addresses: [2001:db8:147::20/64]" " routes:" " - to: default" " via: 2001:db8:147::1" " nameservers:" " addresses: [2001:db8:147::1]"' + +setup() +{ + TMPL="$(require_repo_file \ + 'xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl')" + SNIPPET="$(extract_line_range "$TMPL" \ + 'installnic="#SUBIQUITYINSTALLNIC#"' 'chmod 600 /target/etc/netplan')" \ + || skip 'the netplan late-command is not in the template' + # The autoinstall carries the late-command as a single-quoted YAML scalar, so each quote in + # the shell is doubled. Undo that, and keep the writes inside the test tree. + SNIPPET="${SNIPPET//\'\'/\'}" + SNIPPET="${SNIPPET//\/target\//${BATS_TEST_TMPDIR}/target/}" + NETPLAN="${BATS_TEST_TMPDIR}/target/etc/netplan/00-xcat-install.yaml" +} + +render() +{ + local script="$SNIPPET" + script="${script//'#SUBIQUITYINSTALLNIC#'/$1}" + script="${script//'#SUBIQUITYINSTALLMAC#'/$2}" + script="${script//'#SUBIQUITYTARGETDHCP#'/$3}" + sh -c "set -e +$script" +} + +@test "an IPv4 node is written the DHCPv4 netplan it always had" { + render 'eno1' "$MAC" "$DHCP4_KEYS" + [ "$(cat "$NETPLAN")" = 'network: + version: 2 + ethernets: + xcat-install: + match: + macaddress: "aa:bb:cc:dd:ee:07" + set-name: eno1 + dhcp4: true + dhcp4-overrides: + use-domains: true' ] +} + +@test "an IPv6-only node is written its reserved address" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + [ "$(cat "$NETPLAN")" = 'network: + version: 2 + ethernets: + xcat-install: + match: + macaddress: "aa:bb:cc:dd:ee:07" + set-name: eno1 + dhcp4: false + addresses: [2001:db8:147::20/64] + routes: + - to: default + via: 2001:db8:147::1 + nameservers: + addresses: [2001:db8:147::1]' ] +} + +@test "the static address survives the printf argument list" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + grep -qx ' addresses: \[2001:db8:147::20/64\]' "$NETPLAN" +} + +@test "the default route is written as its own netplan list item" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + grep -qx ' - to: default' "$NETPLAN" + grep -qx ' via: 2001:db8:147::1' "$NETPLAN" +} + +@test "the static keys are never mixed with a DHCP request" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + # grep answers 2 for a file that is not there, and refute_grep reads that as "absent", so + # the two refutals below need a line that must be present to prove the file was written. + grep -qx ' dhcp4: false' "$NETPLAN" + refute_grep -q 'dhcp6' "$NETPLAN" + refute_grep -q 'dhcp4: true' "$NETPLAN" +} + +@test "a node with no interface name to set still gets the static address" { + render '' "$MAC" "$STATIC6_KEYS" + refute_grep -q 'set-name' "$NETPLAN" + grep -qx ' addresses: \[2001:db8:147::20/64\]' "$NETPLAN" +} + +@test "the netplan binds to the MAC of the node, whichever branch wrote it" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + grep -qx " macaddress: \"$MAC\"" "$NETPLAN" + render '' "$MAC" "$STATIC6_KEYS" + grep -qx " macaddress: \"$MAC\"" "$NETPLAN" +} + +@test "netplan refuses a file other users can read, so the late-command chmods it" { + render 'eno1' "$MAC" "$STATIC6_KEYS" + [ "$(stat -c '%a' "$NETPLAN")" = '600' ] +} diff --git a/xCAT-test/unit/debian_subiquity_boot_params.t b/xCAT-test/unit/debian_subiquity_boot_params.t index e4480aa497..f58b8eedc8 100644 --- a/xCAT-test/unit/debian_subiquity_boot_params.t +++ b/xCAT-test/unit/debian_subiquity_boot_params.t @@ -158,6 +158,10 @@ my $resolver = sub { $_[0] eq 'mn.cluster' ? '10.0.0.1' : undef }; qr{\Qurl=http://[2001:db8::1]:80/install/ubuntu24.04/x86_64/install.iso\E}, '... from the bracketed install server, so the port can still be read' ); + # initramfs-tools reads ip6= in configure_networking, where every value but + # ""/none/done/off runs dhcpcd -6 and a value that is not on/dhcp/any is taken as a device + # name. There is no static form, so this lease comes from the dynamic range. The reserved + # address reaches the node through the static netplan of the autoinstall instead. like( $kcmdline, qr{\bip6=dhcp\b}, '... with ip6=, which casper gives to dhcpcd -6' ); # casper calls configure_networking only when ip= is set, whatever the value. Without it # the whole networking stage is skipped and wget has no source address. diff --git a/xCAT-test/unit/subiquity_install_match.t b/xCAT-test/unit/subiquity_install_match.t new file mode 100644 index 0000000000..2c1bbd5007 --- /dev/null +++ b/xCAT-test/unit/subiquity_install_match.t @@ -0,0 +1,89 @@ +#!/usr/bin/env perl +# The netplan match key of the Subiquity installer. +# +# Both autoinstall templates carried the literal glob name: "e*". A DHCPv4 node can take it: the +# lease is offered on one interface only, so the other candidates stay unaddressed. An IPv6-only +# node is given a static address instead, and three interfaces of one bridge all match "e*", so +# netplan put the same static address on each of them. The node then answered on whichever +# interface won, and the installer could not reach its package source. An IPv6-only node is +# matched by its own MAC. +use strict; +use warnings; +no warnings 'once'; + +use File::Slurper qw(read_text); +use File::Spec; +use FindBin; +BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; } +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; +use xCAT::Template; + +my $NODE = 'cn7'; +my %TAB = ( + 'noderes:installnic' => '', + 'noderes:primarynic' => '', + 'mac:mac' => 'AA:BB:CC:DD:EE:07', +); + +no warnings 'redefine'; +local *xCAT::Template::tabdb = sub { + my ($table, undef, $field) = @_; + my $value = $TAB{"$table:$field"}; + return defined($value) ? $value : ''; +}; + +sub match_for { + my ($ipv6_only, $indent) = @_; + local $xCAT::Template::node_ipv6_only = $ipv6_only; + return xCAT::Template::subiquity_install_match($indent, $NODE); +} + +# An IPv4 node keeps the glob the templates carried, byte for byte. +is( match_for( 0, 10 ), ' name: "e*"', + 'an IPv4 node matches every ethernet candidate, as before' ); +is( match_for( 0, 8 ), ' name: "e*"', + '... at whichever indent the tag asks for' ); + +# An IPv6-only node matches one interface, and netplan wants the address lower-cased. +is( match_for( 1, 10 ), ' macaddress: "aa:bb:cc:dd:ee:07"', + 'an IPv6-only node matches its own MAC, lower-cased' ); +unlike( match_for( 1, 10 ), qr/name:/, + '... and no longer every interface on the bridge' ); +is( match_for( 1, 8 ), ' macaddress: "aa:bb:cc:dd:ee:07"', + '... indented as the tag asks' ); + +# noderes.installnic is resolved by the same path the set-name key uses, so a MAC named there +# wins over mac.mac. +{ + local $TAB{'noderes:installnic'} = 'aa:bb:cc:dd:ee:09'; + is( match_for( 1, 10 ), ' macaddress: "aa:bb:cc:dd:ee:09"', + 'the MAC noderes.installnic names is the one netplan matches' ); +} + +# A node with no MAC cannot be matched at all. Rendering macaddress: "" gives the installer a +# netplan it cannot apply, and the install stops at the console. +{ + local $TAB{'mac:mac'} = ''; + is( match_for( 1, 10 ), '', + 'an IPv6-only node with no MAC renders no match key' ); +} + +# The templates ask for the tag, or the sub is dead code and the glob is still shipped. +foreach my $kind (qw(compute service)) { + my $tmpl = File::Spec->catfile( $FindBin::Bin, '..', '..', 'xCAT-server', 'share', + 'xcat', 'install', 'ubuntu', "$kind.subiquity.tmpl" ); + SKIP: { + skip "$kind.subiquity.tmpl not found", 3 unless -f $tmpl; + my $text = read_text($tmpl); + like( $text, qr/^#SUBIQUITYINSTALLMATCH:10#$/m, + "$kind template asks for the match key" ); + unlike( $text, qr/name: "e\*"/, + "$kind template carries no hardcoded interface glob" ); + like( $text, qr/^\s+match:\n#SUBIQUITYINSTALLMATCH:10#$/m, + "$kind template puts the key under its own match block" ); + } +} + +done_testing(); diff --git a/xCAT-test/unit/subiquity_ipv6_netplan.t b/xCAT-test/unit/subiquity_ipv6_netplan.t index a28624038a..1385483a32 100644 --- a/xCAT-test/unit/subiquity_ipv6_netplan.t +++ b/xCAT-test/unit/subiquity_ipv6_netplan.t @@ -6,36 +6,67 @@ # source and fell back to asking at the console, which on a serial console waits forever. The # installed system had no address either, which is the same defect xcatroot had for a diskless # node. +# +# DHCPv6 replaced that and was still wrong. A DHCPv6 client is identified by its DUID, so the +# installer took an address out of the dynamic range instead of the one makedhcp reserved. That +# address has no PTR record, and xcatd identifies a client over IPv6 only by the name its address +# resolves to, so post.xcat fetched a mypostscript that getpostscript could not build and the +# install stopped. Both netplans are static for an IPv6-only node now. use strict; use warnings; +no warnings 'once'; +use File::Slurper qw(read_text); use File::Spec; use FindBin; +BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; } use lib "$FindBin::Bin/../../perl-xCAT"; use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; use Test::More; +use xCAT::Template; -my $template = File::Spec->catfile( - $FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl', 'xCAT', 'Template.pm' -); -plan skip_all => "Template.pm not found" unless -f $template; +my $NODE = 'cn7'; +my $ADDR = '2001:db8:147::20'; +my $PREFIX = 64; +my $MASTER = '2001:db8:147::1'; -# The subs read the file-scoped $node_ipv6_only that subvars sets, so they are driven by -# setting it rather than by stubbing a lookup. -require $template; +# The node's own network configuration, and the resolvers site.nameservers hands it. The IPv4 +# resolver is in the list on purpose: an IPv6-only node cannot reach it, and an unreachable +# server in resolv.conf makes every lookup wait for its timeout. +my $cfg6 = [ $ADDR, $NODE, '', $PREFIX ]; +my $nameservers = ',192.0.2.53'; +my $DEFAULT_CFG6 = [ @$cfg6 ]; +my $DEFAULT_NAMESERVERS = $nameservers; + +no warnings 'redefine'; +local *xCAT::NetworkUtils::getNodeNetworkCfg6 = sub { + my $candidate = shift; + $candidate = shift if defined($candidate) && $candidate eq 'xCAT::NetworkUtils'; + return @$cfg6; +}; +local *xCAT::NetworkUtils::ipv6_server_for_node = sub { + my $candidate = shift; + $candidate = shift if defined($candidate) && $candidate eq 'xCAT::NetworkUtils'; + my $server = shift; + return $MASTER if defined($server) && $server eq ''; + return $server; +}; +local *xCAT::NetworkUtils::getNodeNameservers = sub { + my $nodes = shift; + $nodes = shift if defined($nodes) && $nodes eq 'xCAT::NetworkUtils'; + return { $nodes->[0] => $nameservers }; +}; sub keys_for { my ($ipv6_only, $indent) = @_; - no warnings 'once'; local $xCAT::Template::node_ipv6_only = $ipv6_only; - return xCAT::Template::subiquity_dhcp_keys($indent); + return xCAT::Template::subiquity_dhcp_keys($indent, $NODE); } sub target_for { my ($ipv6_only) = @_; - no warnings 'once'; local $xCAT::Template::node_ipv6_only = $ipv6_only; - return xCAT::Template::subiquity_target_dhcp_keys(); + return xCAT::Template::subiquity_target_dhcp_keys($NODE); } # An IPv4 node keeps exactly what it had. @@ -45,23 +76,75 @@ is( target_for(0), '" dhcp4: true" " dhcp4-overrides:" " use-domains: true"', 'and the installed system too, byte for byte as before' ); -# An IPv6-only node asks for DHCPv6 and says so for IPv4, because netplan defaults -# dhcp4 to false only when nothing names it. -my $v6 = keys_for( 8, 8 ); -like( $v6, qr/^\s+dhcp6: true$/m, 'an IPv6-only node is addressed with DHCPv6' ); -like( $v6, qr/^\s+dhcp4: false$/m, '... and DHCPv4 is turned off explicitly' ); +# ---- the installer netplan of an IPv6-only node ------------------------------------------------ +my $v6 = keys_for( 1, 8 ); +is( $v6, <<'EOV6' =~ s/\n\z//r, 'an IPv6-only node is given its reserved address, statically' ); + dhcp4: false + addresses: [2001:db8:147::20/64] + routes: + - to: default + via: 2001:db8:147::1 + nameservers: + addresses: [2001:db8:147::1] +EOV6 +like( $v6, qr/^\s+addresses: \[\Q$ADDR\E\/$PREFIX\]$/m, + '... with the prefix length netplan needs' ); +like( $v6, qr/^\s+- to: default$/m, '... and a default route' ); +like( $v6, qr/^\s+via: \Q$MASTER\E$/m, '... through the resolved IPv6 gateway' ); +like( $v6, qr/^\s+addresses: \[\Q$MASTER\E\]$/m, '... resolving through the IPv6 resolver' ); +unlike( $v6, qr/192\.0\.2\.53/, + '... and not through the IPv4 resolver it cannot reach' ); +like( $v6, qr/^\s+dhcp4: false$/m, '... with DHCPv4 turned off explicitly' ); +unlike( $v6, qr/dhcp6/, '... asking for no DHCPv6, whose DUID matches no reservation' ); unlike( $v6, qr/dhcp4: true/, '... never asking for DHCPv4' ); +# A literal resolver address is kept as it stands; only the IPv4 one is dropped. +{ + $nameservers = '2001:db8:147::53,192.0.2.53'; + my $literal = keys_for( 1, 8 ); + $nameservers = $DEFAULT_NAMESERVERS; + like( $literal, qr/^\s+addresses: \[2001:db8:147::53\]$/m, + 'a resolver named by address is used as it stands' ); +} + +# A node with no address must fail the template rather than install and hang at post.xcat. +{ + $cfg6 = [ undef, $NODE, '', undef ]; + is( keys_for( 1, 8 ), '', + 'an IPv6-only node with no resolvable address renders nothing' ); + $cfg6 = [ @$DEFAULT_CFG6 ]; +} + +# A link with no gateway still reaches an install server on its own link. +{ + $cfg6 = [ $ADDR, $NODE, '', $PREFIX ]; + my $norouter = keys_for( 1, 8 ); + $cfg6 = [ @$DEFAULT_CFG6 ]; + like( $norouter, qr/^\s+addresses: \[\Q$ADDR\E\/$PREFIX\]$/m, + 'a node on a link with no gateway still gets its address' ); + unlike( $norouter, qr/routes:/, '... and no default route it cannot use' ); +} + +# ---- the netplan of the installed system ------------------------------------------------------- my $t6 = target_for(1); -like( $t6, qr/dhcp6: true/, 'the installed system is addressed with DHCPv6' ); -like( $t6, qr/dhcp4: false/, '... with DHCPv4 off' ); -like( $t6, qr/dhcp6-overrides/, '... and the overrides follow the family it uses' ); -unlike( $t6, qr/" dhcp4: true"/, '... never asking for DHCPv4' ); +is( $t6, + '" dhcp4: false" " addresses: [2001:db8:147::20/64]" " routes:"' + . ' " - to: default" " via: 2001:db8:147::1" " nameservers:"' + . ' " addresses: [2001:db8:147::1]"', + 'the installed system keeps the same static address' ); +like( $t6, qr/" addresses: \[\Q$ADDR\E\/$PREFIX\]"/, + '... as a quoted printf argument' ); +like( $t6, qr/" - to: default"/, '... with the default route as its own argument' ); +like( $t6, qr/" via: \Q$MASTER\E"/, '... through the resolved gateway' ); +unlike( $t6, qr/" dhcp6: true"/, + '... never asking for DHCPv6, which would take a third address' ); +unlike( $t6, qr/dhcp4: true/, '... and never for DHCPv4' ); # The indent is what keeps the YAML valid where the tag sits. -is( keys_for( 0, 6 ), ' dhcp4: true', 'the keys are indented as the tag asks' ); -like( keys_for( 1, 4 ), qr/^ dhcp6: true\n dhcp4: false$/, - 'and both lines of the IPv6 form share that indent' ); +is( keys_for( 0, 8 ), ' dhcp4: true', 'the keys are indented as the tag asks' ); +is( keys_for( 0, 6 ), ' dhcp4: true', '... at whichever indent it asks for' ); +like( keys_for( 1, 4 ), qr/^ dhcp4: false\n addresses: /, + 'and the IPv6 form shares that indent' ); # The templates carry the tags rather than a literal, or the subs are dead code. foreach my $kind (qw(compute service)) { @@ -69,7 +152,7 @@ foreach my $kind (qw(compute service)) { 'xcat', 'install', 'ubuntu', "$kind.subiquity.tmpl" ); SKIP: { skip "$kind.subiquity.tmpl not found", 3 unless -f $tmpl; - my $text = do { local ( @ARGV, $/ ) = ($tmpl); <> }; + my $text = read_text($tmpl); like( $text, qr/#SUBIQUITYDHCP:\d+#/, "$kind template asks for the installer keys" ); is( scalar( () = $text =~ /#SUBIQUITYTARGETDHCP#/g ), 2,