2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-22 10:22:18 +00:00

fix(template): the Subiquity autoinstall gives an IPv6-only node DHCPv4 only

Both Subiquity templates wrote "dhcp4: true" for every node, in the network
section the installer uses and in the netplan the late command writes into the
installed system. An IPv6-only node has no DHCPv4 server to answer, so netplan
brought the provisioning NIC up with no address.

Measured on an IPv6-only node: the installer fetched its autoinstall seed over
IPv6, then could not configure the interface and fell back to asking at the
console. On a serial console that waits for a keypress, so the install stopped
at the mode prompt with no sign of why. The installed system would have had no
address either, which is the defect xcatroot had for a diskless node and
cd6719946 fixed there.

#SUBIQUITYDHCP:<indent># and #SUBIQUITYTARGETDHCP# render from the address
family of the node, beside the #SUBIQUITYINSTALLNIC# and #SUBIQUITYINSTALLMAC#
tags that were already there. An IPv6-only node gets dhcp6 with dhcp4 turned
off explicitly, because netplan defaults dhcp4 to false only when nothing
names it, and the overrides follow the family in use. An IPv4 node gets what
it had, byte for byte.

$node_ipv6_only becomes 'our' so a test can set it. subvars already computes
it before these substitutions run, so nothing recomputes the lookup.

subiquity_ipv6_netplan.t covers both families and both sites, and asserts the
templates carry the tags rather than a literal. ubuntu_subiquity_installnic.t
renders the new tag and gains an IPv6 case: it runs the late command for real,
and an unrendered tag is a shell comment that swallows the redirect, so that
test would have written no file at all.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-30 14:59:20 -03:00
parent 518ddee895
commit 319a20106e
5 changed files with 157 additions and 12 deletions
+56 -1
View File
@@ -42,7 +42,9 @@ my $idir;
my $node;
my $master;
my $master_uri_host;
my $node_ipv6_only;
# 'our', not 'my', so a test can set it: the subiquity netplan helpers below read it and
# nothing else in this file needs it to be lexical.
our $node_ipv6_only;
my $template_os;
my $httpportsuffix;
my %loggedrealms;
@@ -477,6 +479,8 @@ 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/#SUBIQUITYDHCP:(\d+)#/subiquity_dhcp_keys($1)/eg;
$inc =~ s/#SUBIQUITYTARGETDHCP#/subiquity_target_dhcp_keys()/eg;
$inc =~ s/#MACHINEPASSWORD#/machinepassword()/eg;
$inc =~ s/#CRYPT:([^:]+):([^:]+):([^#]+)#/crydb($1,$2,$3)/eg;
$inc =~ s/#CRYPTORLOCKED:([^:]+):([^:]+):([^#]+)#/crydb_or_locked($1,$2,$3)/eg;
@@ -2020,6 +2024,57 @@ sub subiquity_install_netcfg_for_node {
$node);
}
#-----------------------------------------------------------------------------
=head3 subiquity_dhcp_keys
The netplan keys that tell the Subiquity installer how to address the
provisioning NIC.
An IPv6-only node has no DHCPv4 server to answer, and netplan brings the
interface up with no address at all when it is told to use DHCPv4 only. The
installer then cannot reach its package source and falls back to asking at
the console, which on a serial console waits forever.
Arguments:
$indent how many spaces each key is indented by
Returns:
the keys, one per line, indented as asked.
=cut
#-----------------------------------------------------------------------------
sub subiquity_dhcp_keys {
my ($indent) = @_;
my $pad = ' ' x (defined($indent) ? $indent : 8);
return "${pad}dhcp4: true" unless $node_ipv6_only;
return "${pad}dhcp6: true\n${pad}dhcp4: false";
}
#-----------------------------------------------------------------------------
=head3 subiquity_target_dhcp_keys
The same keys for the netplan that the late command writes into the
installed system, as printf arguments.
Returns:
the arguments, each already quoted and indented for netplan.
=cut
#-----------------------------------------------------------------------------
sub subiquity_target_dhcp_keys {
unless ($node_ipv6_only) {
return '" dhcp4: true" " dhcp4-overrides:" " use-domains: true"';
}
return '" dhcp6: true" " dhcp4: false" " dhcp6-overrides:" " use-domains: true"';
}
#-----------------------------------------------------------------------------
sub subiquity_install_nic {
my ($setname) = subiquity_install_netcfg_for_node();
return $setname;
@@ -9,7 +9,7 @@ autoinstall:
xcat-install:
match:
name: "e*"
dhcp4: true
#SUBIQUITYDHCP:8#
ssh:
allow-pw: true
authorized-keys: []
@@ -90,9 +90,9 @@ autoinstall:
installmac="#SUBIQUITYINSTALLMAC#";
mkdir -p /target/etc/netplan;
if [ -z "${installnic}" ]; then
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " dhcp4: true" " dhcp4-overrides:" " use-domains: true" >/target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" #SUBIQUITYTARGETDHCP# >/target/etc/netplan/00-xcat-install.yaml;
else
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " set-name: ${installnic}" " dhcp4: true" " dhcp4-overrides:" " use-domains: true" >/target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " set-name: ${installnic}" #SUBIQUITYTARGETDHCP# >/target/etc/netplan/00-xcat-install.yaml;
fi;
chmod 600 /target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' ''#HOSTNAME#'' >/target/etc/hostname;
@@ -9,7 +9,7 @@ autoinstall:
xcat-install:
match:
name: "e*"
dhcp4: true
#SUBIQUITYDHCP:8#
ssh:
allow-pw: true
authorized-keys: []
@@ -90,9 +90,9 @@ autoinstall:
installmac="#SUBIQUITYINSTALLMAC#";
mkdir -p /target/etc/netplan;
if [ -z "${installnic}" ]; then
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " dhcp4: true" " dhcp4-overrides:" " use-domains: true" >/target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" #SUBIQUITYTARGETDHCP# >/target/etc/netplan/00-xcat-install.yaml;
else
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " set-name: ${installnic}" " dhcp4: true" " dhcp4-overrides:" " use-domains: true" >/target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \"${installmac}\"" " set-name: ${installnic}" #SUBIQUITYTARGETDHCP# >/target/etc/netplan/00-xcat-install.yaml;
fi;
chmod 600 /target/etc/netplan/00-xcat-install.yaml;
printf ''%s\n'' ''#HOSTNAME#'' >/target/etc/hostname;
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env perl
# The netplan the Subiquity installer uses, and the one it writes into the installed system.
#
# Both said "dhcp4: true" for every node. An IPv6-only node has no DHCPv4 server to answer, so
# netplan brought the interface up with no address: the installer could not reach its package
# 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.
use strict;
use warnings;
use File::Spec;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More;
my $template = File::Spec->catfile(
$FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl', 'xCAT', 'Template.pm'
);
plan skip_all => "Template.pm not found" unless -f $template;
# 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;
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);
}
sub target_for {
my ($ipv6_only) = @_;
no warnings 'once';
local $xCAT::Template::node_ipv6_only = $ipv6_only;
return xCAT::Template::subiquity_target_dhcp_keys();
}
# An IPv4 node keeps exactly what it had.
is( keys_for( 0, 8 ), ' dhcp4: true',
'an IPv4 node is addressed with DHCPv4' );
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' );
unlike( $v6, qr/dhcp4: true/, '... never asking for DHCPv4' );
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' );
# 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' );
# The templates carry the tags rather than a literal, or the subs are dead code.
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 = do { local ( @ARGV, $/ ) = ($tmpl); <> };
like( $text, qr/#SUBIQUITYDHCP:\d+#/,
"$kind template asks for the installer keys" );
is( scalar( () = $text =~ /#SUBIQUITYTARGETDHCP#/g ), 2,
"$kind template asks for the installed-system keys on both branches" );
unlike( $text, qr/dhcp4: true/,
"$kind template carries no hardcoded DHCPv4" );
}
}
done_testing();
+13 -5
View File
@@ -109,15 +109,25 @@ SKIP: {
skip 'netplan late-command not found in the template', 5 unless $snippet;
$snippet =~ s/''/'/g; # undo the YAML single-quote escaping
# #SUBIQUITYTARGETDHCP# is rendered by Template.pm from the address family of the node.
# Unrendered it is a shell comment, which would swallow the redirect and write no file.
my $dhcp4 = '" dhcp4: true" " dhcp4-overrides:" " use-domains: true"';
my $dhcp6 = '" dhcp6: true" " dhcp4: false" " dhcp6-overrides:" " use-domains: true"';
for my $case (
{ name => 'a resolved interface name', setname => 'eno1', mac => 'aa:bb:cc:dd:ee:01' },
{ name => 'no interface name', setname => '', mac => 'aa:bb:cc:dd:ee:03' },
{ name => 'a resolved interface name', setname => 'eno1', mac => 'aa:bb:cc:dd:ee:01',
dhcp => $dhcp4, keys => [ ' dhcp4: true', ' dhcp4-overrides:', ' use-domains: true' ] },
{ name => 'no interface name', setname => '', mac => 'aa:bb:cc:dd:ee:03',
dhcp => $dhcp4, keys => [ ' dhcp4: true', ' dhcp4-overrides:', ' use-domains: true' ] },
{ name => 'an IPv6-only node', setname => 'eno1', mac => 'aa:bb:cc:dd:ee:05',
dhcp => $dhcp6, keys => [ ' dhcp6: true', ' dhcp4: false', ' dhcp6-overrides:', ' use-domains: true' ] },
)
{
my $dir = tempdir(CLEANUP => 1);
my $script = $snippet;
$script =~ s/#SUBIQUITYINSTALLNIC#/$case->{setname}/g;
$script =~ s/#SUBIQUITYINSTALLMAC#/$case->{mac}/g;
$script =~ s/#SUBIQUITYTARGETDHCP#/$case->{dhcp}/g;
$script =~ s{/target/}{$dir/target/}g;
system('sh', '-c', "set -e\n$script") == 0
or die "netplan late-command failed for $case->{name}\n";
@@ -131,9 +141,7 @@ SKIP: {
'network:', ' version: 2', ' ethernets:', ' xcat-install:',
' match:', qq( macaddress: "$case->{mac}"),
($case->{setname} ne '' ? " set-name: $case->{setname}" : ()),
' dhcp4: true',
' dhcp4-overrides:',
' use-domains: true',
@{ $case->{keys} },
);
is($netplan, join("\n", @expected) . "\n",
"the netplan written for $case->{name} matches the resolved values");