diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 77ac981ea..55619e3c3 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -3230,8 +3230,11 @@ sub isc_dhcp_installed_version # systemd host runs it, so that bridge cannot be relied on. sub debian_sysconfig_interface_keys { + # The caller establishes the version, so what is passed here is the whole + # input: an undefined version means "could not be established", never "go + # and look at whatever this machine happens to have installed". The result + # is then the same on any machine, which is what makes it testable. my $version = shift; - $version = isc_dhcp_installed_version() unless (defined($version)); # With no version to go on, write both spellings. An unset variable expands # to nothing and leaves dhcpd binding every interface on the machine, which diff --git a/xCAT-test/unit/dhcp_debian_interfaces.t b/xCAT-test/unit/dhcp_debian_interfaces.t index 97ce4ba86..f981984e5 100644 --- a/xCAT-test/unit/dhcp_debian_interfaces.t +++ b/xCAT-test/unit/dhcp_debian_interfaces.t @@ -156,6 +156,23 @@ foreach my $unknown (undef, '', 'none') { } } +# ...and it means that on every machine, not just one with no isc-dhcp-server +# on it. A writer that goes and asks the local dpkg when it is handed no +# version answers differently on the build host than on the machine being +# configured, which is exactly the kind of thing a test only catches once it +# runs somewhere else. +{ + no warnings qw(redefine once); + local *xCAT_plugin::dhcp::isc_dhcp_installed_version = sub { + return '4.4.3-P1-4ubuntu2'; + }; + my @keys = xCAT_plugin::dhcp::debian_sysconfig_interface_keys(undef); + my $written = xCAT_plugin::dhcp::_sysconfig_interfaces_content( + $stock, [@keys], ['eth1']); + is( launched_with($written, 'INTERFACES'), 'eth1', + 'an unknown version is not silently replaced by the local package version' ); +} + # Ordering of the package versions themselves. 20.04 and 22.04 both ship # upstream 4.4.1 and are told apart only by the Debian revision, so a # comparison that stops at the upstream version puts them on the wrong side.