From dfe1fa4b0a25076c1b8b65b6d6eaa9c01949c2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:01:22 -0300 Subject: [PATCH] refactor(dhcp): return the DHCPv6 host commands from addnode6 addnode6 printed its omshell commands to a file-scope handle, so no test could read the DHCPv6 host that ISC DHCP is told to create. It now returns the commands, and makedhcp prints them to the same omshell session. The commands and their order do not change. (cherry picked from commit 178de13a677ffe9326ed9cc697a063de39337e42) (cherry picked from commit d7c8c41a0762fd8799dad695737618774d953bc7) --- xCAT-server/lib/xcat/plugins/dhcp.pm | 53 +++++++++++++++------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 778d3d1414..16675905af 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -781,7 +781,7 @@ sub delnode sub addnode6 { - #omshell to add host dynamically + # The omshell commands that add the host, or nothing when the node is skipped. my $node = shift; unless ($vpdhash) { $callback->({ node => [ { name => [$node], warning => ["Skipping DHCPv6 setup due to missing vpd.uuid information."] } ] }); @@ -817,44 +817,46 @@ sub addnode6 { if ( $ip and $ip =~ /:/ and _reject_dynamic_node_ip( $node, $ip, 'IPv6', $callback ) ) { return; } + my $commands = ''; if ($ip and $ip =~ /:/) { $ip = getipaddr($ip, GetNumber => 1); $ip = $ip->as_hex; $ip =~ s/^0x//; $ip =~ s/(..)/$1:/g; $ip =~ s/:\z//; - print $omshell6 "set ip-address = $ip\n"; + $commands .= "set ip-address = $ip\n"; } else { $ip = 0; } - print $omshell6 "new host\n"; - print $omshell6 "set name = \"$node\"\n"; #Find and destroy conflict name - print $omshell6 "open\n"; - print $omshell6 "remove\n"; - print $omshell6 "close\n"; + $commands .= "new host\n"; + $commands .= "set name = \"$node\"\n"; #Find and destroy conflict name + $commands .= "open\n"; + $commands .= "remove\n"; + $commands .= "close\n"; if ($ip) { - print $omshell6 "new host\n"; - print $omshell6 "set ip-address = $ip\n"; #find and destroy ip conflict - print $omshell6 "open\n"; - print $omshell6 "remove\n"; - print $omshell6 "close\n"; + $commands .= "new host\n"; + $commands .= "set ip-address = $ip\n"; #find and destroy ip conflict + $commands .= "open\n"; + $commands .= "remove\n"; + $commands .= "close\n"; } - print $omshell6 "new host\n"; - print $omshell6 "set dhcp-client-identifier = " . $uuid . "\n"; #find and destroy DUID-UUID conflict - print $omshell6 "open\n"; - print $omshell6 "remove\n"; - print $omshell6 "close\n"; - print $omshell6 "new host\n"; - print $omshell6 "set name = \"$node\"\n"; - print $omshell6 "set dhcp-client-identifier = $uuid\n"; - print $omshell6 'set statements = "ddns-hostname \"' . $node . '\";";' . "\n"; + $commands .= "new host\n"; + $commands .= "set dhcp-client-identifier = " . $uuid . "\n"; #find and destroy DUID-UUID conflict + $commands .= "open\n"; + $commands .= "remove\n"; + $commands .= "close\n"; + $commands .= "new host\n"; + $commands .= "set name = \"$node\"\n"; + $commands .= "set dhcp-client-identifier = $uuid\n"; + $commands .= 'set statements = "ddns-hostname \"' . $node . '\";";' . "\n"; if ($ip) { - print $omshell6 "set ip-address = $ip\n"; + $commands .= "set ip-address = $ip\n"; } - print $omshell6 "create\n"; - print $omshell6 "close\n"; + $commands .= "create\n"; + $commands .= "close\n"; + return $commands; } sub _infiniband_twin_mac @@ -2684,7 +2686,8 @@ sub process_request next if $unchanged->{$_}; addnode $_; if ($usingipv6) { - addnode6 $_; + my $commands = addnode6($_); + print $omshell6 $commands if $commands; } } }