From c2a90293ea588d97341d2d58eb0918906ce426ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 23 Apr 2026 18:41:42 -0300 Subject: [PATCH] Address DHCP backend review findings --- perl-xCAT/xCAT/DHCP/Backend.pm | 8 ++++++-- perl-xCAT/xCAT/DHCP/BootPolicy.pm | 2 +- xCAT-probe/subcmds/discovery | 10 ++++------ xCAT-test/unit/dhcp_backend_selection.t | 18 ++++++++++++++++++ xCAT-test/unit/dhcp_boot_policy.t | 3 +++ xCAT-test/unit/dhcp_kea_renderer.t | 5 +++-- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/perl-xCAT/xCAT/DHCP/Backend.pm b/perl-xCAT/xCAT/DHCP/Backend.pm index 568fb6f19..ecd4c1dc4 100644 --- a/perl-xCAT/xCAT/DHCP/Backend.pm +++ b/perl-xCAT/xCAT/DHCP/Backend.pm @@ -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'); diff --git a/perl-xCAT/xCAT/DHCP/BootPolicy.pm b/perl-xCAT/xCAT/DHCP/BootPolicy.pm index 1d918e5b3..102f006d1 100644 --- a/perl-xCAT/xCAT/DHCP/BootPolicy.pm +++ b/perl-xCAT/xCAT/DHCP/BootPolicy.pm @@ -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', }, { diff --git a/xCAT-probe/subcmds/discovery b/xCAT-probe/subcmds/discovery index 6c015198e..ebb3d8e5e 100755 --- a/xCAT-probe/subcmds/discovery +++ b/xCAT-probe/subcmds/discovery @@ -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); diff --git a/xCAT-test/unit/dhcp_backend_selection.t b/xCAT-test/unit/dhcp_backend_selection.t index 85e07991c..9675c62d1 100644 --- a/xCAT-test/unit/dhcp_backend_selection.t +++ b/xCAT-test/unit/dhcp_backend_selection.t @@ -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', diff --git a/xCAT-test/unit/dhcp_boot_policy.t b/xCAT-test/unit/dhcp_boot_policy.t index d7bcf3b93..a21aa6cb3 100644 --- a/xCAT-test/unit/dhcp_boot_policy.t +++ b/xCAT-test/unit/dhcp_boot_policy.t @@ -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, diff --git a/xCAT-test/unit/dhcp_kea_renderer.t b/xCAT-test/unit/dhcp_kea_renderer.t index 2a5a4d37a..60755f4e1 100644 --- a/xCAT-test/unit/dhcp_kea_renderer.t +++ b/xCAT-test/unit/dhcp_kea_renderer.t @@ -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' );