From a66e3a4d04beaab11cc29c4d6f3f699a0acfea7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:27:36 -0300 Subject: [PATCH 1/3] test(dhcp): use shared version helpers in intent harness --- xCAT-test/unit/dhcp_kea_plugin_intent.t | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xCAT-test/unit/dhcp_kea_plugin_intent.t b/xCAT-test/unit/dhcp_kea_plugin_intent.t index 84b68b397..b5f09fd93 100644 --- a/xCAT-test/unit/dhcp_kea_plugin_intent.t +++ b/xCAT-test/unit/dhcp_kea_plugin_intent.t @@ -5,6 +5,7 @@ no warnings 'once'; use FindBin; use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; use File::Temp qw(tempdir); use Socket (); @@ -24,11 +25,6 @@ BEGIN { sub get_site_attribute { return; } $INC{'xCAT/TableUtils.pm'} = __FILE__; - package xCAT::Utils; - sub osver { return 'rhels9'; } - sub runcmd { return; } - $INC{'xCAT/Utils.pm'} = __FILE__; - package xCAT::NetworkUtils; sub import { my $caller = caller; @@ -78,6 +74,13 @@ BEGIN { $INC{'xCAT/NodeRange.pm'} = __FILE__; } +require xCAT::Utils; +{ + no warnings 'redefine'; + *xCAT::Utils::osver = sub { return 'rhels9'; }; + *xCAT::Utils::runcmd = sub { return; }; +} + my $source_dhcp_plugin = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/dhcp.pm"; if ( -f $source_dhcp_plugin ) { require $source_dhcp_plugin; From 94531ecf798a62f3415838304b865a7c6ee86107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:28:56 -0300 Subject: [PATCH 2/3] refactor(dhcp): reuse shared OS version parsing --- xCAT-server/lib/xcat/plugins/dhcp.pm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index da94251ac..c0874ce9f 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -31,6 +31,7 @@ my $candoipv6 = eval { use Sys::Syslog; use IPC::Open2; use xCAT::Utils; +use xCAT::SvrUtils; use xCAT::DHCP::BootPolicy; use xCAT::DHCP::Backend; use xCAT::DHCP::OmapiPolicy; @@ -2835,11 +2836,24 @@ sub kea_apply_ddns_behavior sub dhcpd_sysconfig_uses_interface_key { my $os = shift || ""; - my $os_ver = $os; - $os_ver =~ s/[^0-9.^0-9]//g; + my ( $os_family, $os_major, $os_minor ) = xCAT::SvrUtils::parseosver($os); + if (!$os_family || !defined $os_major || !length $os_major) { + return 0; + } - return 1 if $os =~ /(sles|opensuse[-_]?leap|leap)/i && $os_ver >= 11; - return 1 if $os =~ /rhels?/i && $os_ver >= 7; + my $os_version = $os_major; + if (defined $os_minor && length $os_minor) { + $os_version .= ".$os_minor"; + } + + if ( $os_family =~ /(sles|opensuse[-_]?leap|leap)/i + && xCAT::Utils->version_cmp( $os_version, '11' ) >= 0) { + return 1; + } + if ( $os_family =~ /rhels?/i + && xCAT::Utils->version_cmp( $os_version, '7' ) >= 0) { + return 1; + } return 0; } From 804edace81b568350bfad928cf6febbec2033e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:32:17 -0300 Subject: [PATCH 3/3] test(dhcp): cover sysconfig OS version policy --- xCAT-test/unit/dhcp_kea_plugin_intent.t | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/xCAT-test/unit/dhcp_kea_plugin_intent.t b/xCAT-test/unit/dhcp_kea_plugin_intent.t index b5f09fd93..844df362e 100644 --- a/xCAT-test/unit/dhcp_kea_plugin_intent.t +++ b/xCAT-test/unit/dhcp_kea_plugin_intent.t @@ -122,9 +122,32 @@ my %network_entry = ( tftpserver => '', ); -ok(xCAT_plugin::dhcp::dhcpd_sysconfig_uses_interface_key('opensuse-leap15.6'), 'openSUSE Leap head node uses SUSE dhcpd interface key'); -ok(xCAT_plugin::dhcp::dhcpd_sysconfig_uses_interface_key('leap15.6'), 'Leap head node osver uses SUSE dhcpd interface key'); -ok(!xCAT_plugin::dhcp::dhcpd_sysconfig_uses_interface_key('opensuse-tumbleweed'), 'generic openSUSE names do not enable Leap-specific dhcpd handling'); +my @sysconfig_policy_cases = ( + [ 'sles10', 0, 'SLES 10' ], + [ 'sles11', 1, 'SLES 11' ], + [ 'sles15.10', 1, 'SLES 15.10' ], + [ 'sles-sap15.6', 1, 'SLES for SAP 15.6' ], + [ 'opensuse-leap15.6', 1, 'openSUSE Leap 15.6' ], + [ 'opensuse_leap15.6', 1, 'underscored openSUSE Leap 15.6' ], + [ 'leap15.6', 1, 'short Leap 15.6' ], + [ 'rhel6', 0, 'RHEL 6' ], + [ 'rhel6.10', 0, 'RHEL 6.10' ], + [ 'rhel7', 1, 'RHEL 7' ], + [ 'rhels7.0', 1, 'RHEL Server 7.0' ], + [ 'rhel10', 1, 'RHEL 10' ], + [ 'RHEL7', 1, 'uppercase RHEL 7' ], + [ 'ubuntu24.04', 0, 'Ubuntu release' ], + [ 'debian12', 0, 'Debian release' ], + [ 'opensuse-tumbleweed', 0, 'openSUSE Tumbleweed release' ], + [ 'unknown', 0, 'unknown release' ], + [ undef, 0, 'undefined release' ], +); + +foreach my $case (@sysconfig_policy_cases) { + my ( $os, $expected, $description ) = @{$case}; + my $actual = xCAT_plugin::dhcp::dhcpd_sysconfig_uses_interface_key($os); + is( $actual, $expected, "$description keeps the dhcpd sysconfig policy" ); +} { my $tmpdir = tempdir(CLEANUP => 1);