From 38f395f64d59de81f07fa2c1e7dc043f4d50f36d Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 25 Sep 2026 12:33:11 -0300 Subject: [PATCH] test(xcat-core): read the interfaces config without starting sh launched_with wrote the generated isc-dhcp-server file to disk and ran sh to source it, so every check also depended on sh and hid its errors. The writer emits only KEY="value" lines. launched_with now returns the value of the last assignment to the variable, as sh would see it. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/dhcp_debian_interfaces.t | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/xCAT-test/unit/dhcp_debian_interfaces.t b/xCAT-test/unit/dhcp_debian_interfaces.t index 04877810d..bd7fb19d3 100644 --- a/xCAT-test/unit/dhcp_debian_interfaces.t +++ b/xCAT-test/unit/dhcp_debian_interfaces.t @@ -8,7 +8,6 @@ use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; use lib "$FindBin::Bin/../../perl-xCAT"; use Test::More; -use File::Temp qw(tempdir); $ENV{XCATCFG} ||= 'SQLite:/tmp'; @@ -50,19 +49,13 @@ INTERFACESv4="" INTERFACESv6="" EOF -# Expand a variable exactly as the systemd unit does: source the file in sh and -# print what would land on dhcpd's command line. +# The value of the last assignment to $variable, as sh would see it after +# sourcing the file. The writer emits only KEY="value" lines. sub launched_with { my ($content, $variable) = @_; - - my $dir = tempdir(CLEANUP => 1); - my $path = "$dir/isc-dhcp-server"; - open(my $fh, '>', $path) or die "cannot write $path: $!"; - print $fh $content; - close($fh); - - my $out = `sh -c '. "$path"; printf %s "\$$variable"' 2>/dev/null`; - return defined($out) ? $out : ''; + my ($value) = (reverse($content =~ /^\s*\Q$variable\E=(.*)$/mg), ''); + $value =~ s/^"(.*)"$/$1/; + return $value; } # Every release in support, the package it ships, and the variable its unit