mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-05-05 16:49:08 +00:00
Address DHCP backend review findings
This commit is contained in:
@@ -48,10 +48,14 @@ sub default_backend {
|
||||
my ( $class, %args ) = @_;
|
||||
|
||||
my $platform = exists $args{platform} ? $args{platform} : $class->_osver('platform');
|
||||
return 'kea' if defined($platform) && $platform =~ /^el10\b/i;
|
||||
if ( defined($platform) && $platform =~ /^el(\d+)\b/i ) {
|
||||
return 'kea' if $1 >= 10;
|
||||
}
|
||||
|
||||
my $os = exists $args{os} ? $args{os} : $class->_osver();
|
||||
return 'kea' if defined($os) && $os =~ /^(?:rhel|rhels|rocky|alma|centos|ol)10(?:\D|$)/i;
|
||||
if ( defined($os) && $os =~ /^(?:rhel|rhels|rocky|alma|centos|ol)(\d+)(?:\D|$)/i ) {
|
||||
return 'kea' if $1 >= 10;
|
||||
}
|
||||
|
||||
my $os_name = exists $args{os_name} ? $args{os_name} : $class->_osver('os');
|
||||
my $version = exists $args{version} ? $args{version} : $class->_osver('version');
|
||||
|
||||
@@ -37,7 +37,7 @@ sub kea_client_classes {
|
||||
},
|
||||
{
|
||||
name => 'xcat-ppc64',
|
||||
test => 'option[93].hex == 0x000c',
|
||||
test => '(option[93].hex == 0x000c or option[93].hex == 0x000e)',
|
||||
'boot-file-name' => '/boot/grub2/grub2.ppc',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -854,12 +854,10 @@ sub dhcp_dynamic_range_check {
|
||||
if ($kea_config) {
|
||||
$dhcpconfig = undef;
|
||||
my $config_json = eval {
|
||||
require JSON;
|
||||
open(my $fh, '<', $kea_config) or die $!;
|
||||
local $/;
|
||||
my $content = <$fh>;
|
||||
close($fh);
|
||||
JSON::decode_json($content);
|
||||
require xCAT::DHCP::Backend::Kea;
|
||||
my $loaded = xCAT::DHCP::Backend::Kea->new()->load_dhcp4_config($kea_config);
|
||||
die $loaded->{error} if $loaded->{error};
|
||||
$loaded;
|
||||
};
|
||||
if ($@) {
|
||||
probe_utils->send_msg("stdout", "f", $msg);
|
||||
|
||||
@@ -25,12 +25,24 @@ is(
|
||||
'EL10 defaults to Kea by platform'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->default_backend( platform => 'el11', os => 'rhel11', os_name => 'rhel', version => 11 ),
|
||||
'kea',
|
||||
'EL releases newer than EL10 default to Kea by platform'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->default_backend( platform => '', os => 'rocky10', os_name => 'rocky', version => 10 ),
|
||||
'kea',
|
||||
'EL10 derivatives default to Kea by osver'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->default_backend( platform => '', os => 'alma11', os_name => 'alma', version => 11 ),
|
||||
'kea',
|
||||
'EL derivatives newer than EL10 default to Kea by osver'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->default_backend( platform => '', os => 'ubuntu22.04', os_name => 'ubuntu', version => '22.04' ),
|
||||
'isc',
|
||||
@@ -49,6 +61,12 @@ is(
|
||||
'Ubuntu releases newer than 24.04 default to Kea'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->default_backend( platform => '', os => 'ubuntu26.04', os_name => 'ubuntu', version => '26.04' ),
|
||||
'kea',
|
||||
'Ubuntu LTS releases newer than 24.04 default to Kea'
|
||||
);
|
||||
|
||||
is(
|
||||
xCAT::DHCP::Backend->choose( requested => 'isc', os => 'rhel10', platform => 'el10' )->{name},
|
||||
'isc',
|
||||
|
||||
@@ -13,6 +13,7 @@ is( scalar @$fallback_classes, 4, 'Kea boot policy omits xNBA classes when xNBA
|
||||
my %fallback_by_name = map { $_->{name} => $_ } @$fallback_classes;
|
||||
is( $fallback_by_name{'xcat-bios'}{'boot-file-name'}, 'pxelinux.0', 'BIOS clients fall back to pxelinux.0 without xNBA loaders' );
|
||||
ok( !exists $fallback_by_name{'xcat-xnba-bios'}, 'xNBA user-class is not advertised without xNBA kpxe' );
|
||||
like( $fallback_by_name{'xcat-ppc64'}{test}, qr/0x000e/, 'POWER class covers OPAL-v3 client architecture' );
|
||||
|
||||
my $classes = xCAT::DHCP::BootPolicy->kea_client_classes(xnba_kpxe => 1, xnba_efi => 1);
|
||||
is( scalar @$classes, 5, 'Kea boot policy renders expected xNBA client classes' );
|
||||
@@ -25,6 +26,8 @@ like( $by_name{'xcat-uefi-x64'}{test}, qr/0x0009/, 'UEFI x64 class matches archi
|
||||
like( $by_name{'xcat-uefi-x64'}{test}, qr/not \(\(option\[77\]\.exists/, 'generic UEFI class excludes xNBA second-stage clients' );
|
||||
is( $by_name{'xcat-aarch64'}{'boot-file-name'}, 'boot/grub2/grub2.aarch64', 'AArch64 clients receive grub2 boot file' );
|
||||
is( $by_name{'xcat-ppc64'}{'boot-file-name'}, '/boot/grub2/grub2.ppc', 'POWER clients receive grub2 Open Firmware boot file' );
|
||||
like( $by_name{'xcat-ppc64'}{test}, qr/0x000c/, 'POWER class matches existing POWER architecture id' );
|
||||
like( $by_name{'xcat-ppc64'}{test}, qr/0x000e/, 'POWER class matches OPAL-v3 architecture id' );
|
||||
|
||||
my $xnba_classes = xCAT::DHCP::BootPolicy->kea_xnba_node_classes(
|
||||
xnba_efi => 1,
|
||||
|
||||
@@ -120,8 +120,7 @@ is( $empty_boot_subnet->{'boot-file-name'}, '', 'empty boot-file-name is preserv
|
||||
|
||||
my $comment_dir = tempdir(CLEANUP => 1);
|
||||
my $commented_config = "$comment_dir/kea-dhcp4.conf";
|
||||
open( my $comment_fh, '>', $commented_config ) or die "Unable to write $commented_config: $!";
|
||||
print {$comment_fh} <<'COMMENTED_JSON';
|
||||
my $commented_content = <<'COMMENTED_JSON';
|
||||
// Packaged Kea configs may contain comments before xCAT rewrites them.
|
||||
{
|
||||
"Dhcp4": {
|
||||
@@ -136,6 +135,8 @@ print {$comment_fh} <<'COMMENTED_JSON';
|
||||
}
|
||||
}
|
||||
COMMENTED_JSON
|
||||
open( my $comment_fh, '>', $commented_config ) or die "Unable to write $commented_config: $!";
|
||||
print {$comment_fh} $commented_content;
|
||||
close($comment_fh);
|
||||
my $loaded_commented = $backend->load_dhcp4_config($commented_config);
|
||||
ok( !$loaded_commented->{error}, 'Kea DHCPv4 loader accepts packaged JSON comments' );
|
||||
|
||||
Reference in New Issue
Block a user