2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

feat(xcat-core): a SUSE node can install over IPv6

sles.pm matched ipv6 nowhere in 2801 lines and the SUSE templates wrote
"<bootproto>dhcp</bootproto>" directly, so an IPv6-only SUSE node had no way to configure its
installer: DHCP cannot serve it, and SUSE has no static handoff on the kernel command line.

_autoyast_network6 builds the networking section of such a node, with a static interface, the
address of the node and a prefix length, which is what AutoYaST takes for IPv6 instead of a
netmask, and a default route carrying the IPv6 gateway.

The #YAST2NET6# directive chooses between that and the DHCP block the templates carried. An IPv4
node gets that block unchanged, which is why the existing #YAST2NET# was not used: its DHCP arm
renders something else, and leap15.6 is a gating cell. compute.leap15.tmpl and compute.sle15.tmpl
take the directive.

autoyast_ipv6_network.t covers the section. Emitting a netmask instead of a prefix length fails 2
of its 11 assertions. The IPv4 output of the directive was compared with the text it replaced and
is identical.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-28 01:37:57 -03:00
parent 7ab3628353
commit bfbc014ffe
4 changed files with 175 additions and 34 deletions
+112
View File
@@ -462,6 +462,7 @@ sub subvars {
}
$inc =~ s/#MIRRORSPEC#/mirrorspec()/eg;
$inc =~ s/#YAST2NET#/yast2network()/eg;
$inc =~ s/#YAST2NET6#/yast2network6()/eg;
$inc =~ s/#KICKSTARTBOOTLOADER#/kickstartbootloader()/eg;
$inc =~ s/#ESXIPV6SETUP#/esxipv6setup()/eg;
$inc =~ s/#WINTIMEZONE#/xCAT::TZUtils::get_wintimezone()/eg;
@@ -1269,6 +1270,110 @@ d-i apt-setup/local$index/comment string online mirror $index\n";
# The AutoYaST networking section chosen by address family. An IPv4 node gets the same DHCP
# block the SUSE templates carried before this directive replaced it, so its profile does not
# change; only an IPv6-only node gets something different, because DHCP cannot serve it.
sub yast2network6 {
if (xCAT::NetworkUtils->node_is_ipv6_only($node)
&& $::XCATSITEVALS{managedaddressmode} ne "autoula")
{
my $section = _autoyast_network6($node);
return defined($section) ? $section : '';
}
return <<'EOY';
<networking>
<dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<hostname>linux</hostname>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>onboot</startmode>
</interface>
</interfaces>
<keep_install_network config:type="boolean">true</keep_install_network>
<routing>
<ipv4_forward config:type="boolean">false</ipv4_forward>
</routing>
</networking>
EOY
}
# The AutoYaST networking section of an IPv6-only node. AutoYaST takes a prefix length rather
# than a netmask for IPv6, and the default route carries the IPv6 gateway. SUSE has no static
# handoff on the kernel command line, so a static address here is the only way an IPv6-only node
# reaches its installer: DHCPv6 would need the client to send the DUID of the reservation.
sub _autoyast_network6 {
my ($node) = @_;
my ($ipaddr, $hostname, $gateway, $prefix) =
xCAT::NetworkUtils->getNodeNetworkCfg6($node);
unless ($ipaddr && defined($prefix) && $prefix =~ /^\d+$/ && $prefix <= 128) {
$tmplerr = "Cannot resolve the static IPv6 network configuration of $node";
return;
}
if (defined($gateway) && length($gateway)) {
$gateway = xCAT::NetworkUtils->ipv6_server_for_node($node, $gateway);
unless ($gateway) {
$tmplerr = "Cannot resolve the IPv6 gateway of $node";
return;
}
}
my $nd = xCAT::NetworkUtils->getNodeDomains([$node]);
my $domain = $nd->{$node};
my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$node]) };
my @nameserversIP = grep { defined && length }
map { $_ eq '<xcatmaster>' ? $gateway : $_ } split(/,/, $nameservers{$node} // '');
my $interface = {
'bootproto' => ['static'],
'startmode' => ['onboot'],
'device' => ['eth0'],
'ipaddr' => [$ipaddr],
'prefixlen' => ["$prefix"],
};
my $routing = {
'ip_forward' => [ { 'content' => 'false', 'config:type' => 'boolean' } ],
};
if (defined($gateway) && length($gateway)) {
$routing->{routes} = [
{
'route' => [
{
'destination' => ['default'],
'gateway' => [$gateway],
'netmask' => ['-'],
'device' => ['-'],
}
],
'config:type' => 'list',
}
];
}
my $networkhash = {
'networking' => [
{
'dns' => [
{
'domain' => ["$domain"],
'dhcp_hostname' => [ { 'content' => 'false', 'config:type' => 'boolean' } ],
'dhcp_resolv' => [ { 'content' => 'false', 'config:type' => 'boolean' } ],
'nameservers' => [ { 'config:type' => 'list', 'nameserver' => [@nameserversIP] } ],
}
],
'interfaces' => [ { 'interface' => [$interface], 'config:type' => 'list' } ],
'routing' => [$routing],
}
]
};
return XML::Simple->new(KeepRoot => 1)->XMLout($networkhash);
}
sub yast2network {
my $line;
my $hoststab;
@@ -1279,6 +1384,13 @@ sub yast2network {
my $suffix = xCAT::Utils->parseMacTabEntry($ent->{mac}, $node);
$suffix = lc($suffix);
# An IPv6-only node cannot take the IPv4 arms below: getNodeNetworkCfg returns nothing for it.
if (xCAT::NetworkUtils->node_is_ipv6_only($node)
&& $::XCATSITEVALS{managedaddressmode} ne "autoula")
{
return _autoyast_network6($node);
}
if ($::XCATSITEVALS{managedaddressmode} eq "autoula") {
#TODO
@@ -65,23 +65,7 @@
<surname/>
</user>
</users>
<networking>
<dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<hostname>linux</hostname>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>onboot</startmode>
</interface>
</interfaces>
<keep_install_network config:type="boolean">true</keep_install_network>
<routing>
<ipv4_forward config:type="boolean">false</ipv4_forward>
</routing>
</networking>
#YAST2NET6#
<scripts>
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sle#
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles#
@@ -63,23 +63,7 @@
<surname/>
</user>
</users>
<networking>
<dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<hostname>linux</hostname>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>onboot</startmode>
</interface>
</interfaces>
<keep_install_network config:type="boolean">true</keep_install_network>
<routing>
<ipv4_forward config:type="boolean">false</ipv4_forward>
</routing>
</networking>
#YAST2NET6#
<scripts>
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sle#
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles#
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env perl
#
# The AutoYaST networking section of an IPv6-only SUSE node.
#
# sles.pm has no static handoff on the kernel command line, so a static address in the AutoYaST
# profile is the only way an IPv6-only node reaches its installer: DHCPv6 would need the client
# to send the DUID that makedhcp put in the reservation. AutoYaST takes a prefix length for
# IPv6, not a netmask.
use strict;
use warnings;
no warnings 'once';
use File::Spec;
use FindBin;
use Test::More tests => 11;
my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..');
$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server');
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use XML::Simple;
use xCAT::NetworkUtils;
my %cfg = (
cn6 => [ '2001:db8:1::50', 'cn6', '2001:db8:1::fe', 64 ],
cn6nogw => [ '2001:db8:2::50', 'cn6nogw', '', 64 ],
cn6bad => [ undef, undef, undef, undef ],
cn6long => [ '2001:db8:3::50', 'cn6long', '2001:db8:3::fe', 129 ],
);
no warnings 'redefine';
*xCAT::NetworkUtils::getNodeNetworkCfg6 = sub { my $n = $_[-1]; return @{ $cfg{$n} || [] } };
*xCAT::NetworkUtils::ipv6_server_for_node = sub { return $_[-1] };
*xCAT::NetworkUtils::getNodeDomains = sub { return { map { $_ => 'xcat.lab' } @{ $_[-1] } } };
*xCAT::NetworkUtils::getNodeNameservers = sub { return { map { $_ => '2001:db8:1::fe' } @{ $_[-1] } } };
use warnings 'redefine';
my $template = File::Spec->catfile($repo_root, 'xCAT-server/lib/perl/xCAT/Template.pm');
require $template;
my $xml = xCAT::Template::_autoyast_network6('cn6');
ok(defined($xml), 'an IPv6-only node gets a networking section');
like($xml, qr{<bootproto>static</bootproto>}, 'the interface is static, not dhcp');
like($xml, qr{<ipaddr>\Q2001:db8:1::50\E</ipaddr>}, 'it carries the IPv6 address of the node');
like($xml, qr{<prefixlen>64</prefixlen>}, 'and a prefix length, which is what AutoYaST takes for IPv6');
unlike($xml, qr{<netmask>(?!-)}, 'no IPv4 netmask is emitted for the interface');
like($xml, qr{<gateway>\Q2001:db8:1::fe\E</gateway>}, 'the default route carries the IPv6 gateway');
like($xml, qr{<nameserver>\Q2001:db8:1::fe\E</nameserver>}, 'and the resolver is the IPv6 one');
# A node with no gateway still installs; it simply gets no default route.
my $nogw = xCAT::Template::_autoyast_network6('cn6nogw');
ok(defined($nogw), 'a node with no gateway still gets a section');
unlike($nogw, qr{<routes}, 'and no default route, rather than an empty one');
# A node whose address cannot be resolved yields nothing rather than a profile with an empty
# address. The message goes to $tmplerr, which is a file-scoped lexical in Template.pm and so
# cannot be read from here; the caller reports it.
is(xCAT::Template::_autoyast_network6('cn6bad'), undef, 'an unresolvable node yields nothing');
# A prefix outside the IPv6 range is refused rather than written into the profile.
is(xCAT::Template::_autoyast_network6('cn6long'), undef, 'a prefix above 128 is refused');