diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index bd254c094e..0f82d158c9 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -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'; + + + true + linux + + + + dhcp + eth0 + onboot + + + true + + false + + +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 '' ? $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 diff --git a/xCAT-server/share/xcat/install/sles/compute.leap15.tmpl b/xCAT-server/share/xcat/install/sles/compute.leap15.tmpl index e90ad19559..03c35017cd 100644 --- a/xCAT-server/share/xcat/install/sles/compute.leap15.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.leap15.tmpl @@ -65,23 +65,7 @@ - - - true - linux - - - - dhcp - eth0 - onboot - - - true - - false - - + #YAST2NET6# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sle# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles# diff --git a/xCAT-server/share/xcat/install/sles/compute.sle15.tmpl b/xCAT-server/share/xcat/install/sles/compute.sle15.tmpl index a34a689540..fb3d4c414e 100644 --- a/xCAT-server/share/xcat/install/sles/compute.sle15.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.sle15.tmpl @@ -63,23 +63,7 @@ - - - true - linux - - - - dhcp - eth0 - onboot - - - true - - false - - + #YAST2NET6# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sle# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles# diff --git a/xCAT-test/unit/autoyast_ipv6_network.t b/xCAT-test/unit/autoyast_ipv6_network.t new file mode 100644 index 0000000000..e07044a57d --- /dev/null +++ b/xCAT-test/unit/autoyast_ipv6_network.t @@ -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{static}, 'the interface is static, not dhcp'); +like($xml, qr{\Q2001:db8:1::50\E}, 'it carries the IPv6 address of the node'); +like($xml, qr{64}, 'and a prefix length, which is what AutoYaST takes for IPv6'); +unlike($xml, qr{(?!-)}, 'no IPv4 netmask is emitted for the interface'); +like($xml, qr{\Q2001:db8:1::fe\E}, 'the default route carries the IPv6 gateway'); +like($xml, qr{\Q2001:db8:1::fe\E}, '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{