diff --git a/xCAT-test/unit/ipv6_socket_modules_declared.t b/xCAT-test/unit/ipv6_socket_modules_declared.t index eb013e6b05..4573755297 100644 --- a/xCAT-test/unit/ipv6_socket_modules_declared.t +++ b/xCAT-test/unit/ipv6_socket_modules_declared.t @@ -1,15 +1,20 @@ #!/usr/bin/env perl -# xCAT must declare the two Perl modules that carry every IPv6 socket path. +# Every IPv6 socket path in xCAT goes through Socket6 and IO::Socket::INET6. # # xCAT::SLP, xCAT::IPMI, xCAT::Client, xCAT::NetworkUtils and the dhcp, nodestat and -# credentials plugins reach IPv6 only through Socket6 and IO::Socket::INET6, and each one -# loads them with eval { require ... }. A missing module is therefore not an error: the -# guard variable stays false and the IPv6 branch is never taken. SLP discovery and IPMI -# over IPv6 are silently off. +# credentials plugins load both with eval { require ... }, so a missing module is not an +# error: the guard variable stays false and the IPv6 branch is never taken. SLP discovery +# and IPMI over IPv6 then do nothing and report nothing. # -# Nothing derives the dependency anywhere. perl-generators reads use statements, not a -# require inside an eval, so the EL build generates no perl(Socket6) either. On a Leap 15.6 -# management node both modules are absent and $ip6support evaluates to 0. +# A recommendation is the right strength where the package manager installs one, which is +# what dnf does. It is not enough on openSUSE: the Minimal-VM image sets +# solver.onlyRequires = true in /etc/zypp/zypp.conf, so zypper installs no recommended +# package at all. Measured on a Leap 15.6 management node carrying every other xCAT +# dependency, both modules were absent and the SLP guard evaluated to 0. xCAT already names +# a DHCP server directly for this same reason. +# +# So openSUSE requires both, and the families whose package manager honours a weak +# dependency recommend them. use strict; use warnings; @@ -20,67 +25,81 @@ use Test::More; use File::Slurper qw(read_text); use XCAT::Test::File qw(repo_path); -my @MODULES = ('Socket6', 'IO::Socket::INET6'); - -# Every RPM family needs the declaration, so this is not an openSUSE-only table. EL carries -# both in appstream and openSUSE in the main repository. my @SPECS = ('perl-xCAT/perl-xCAT.spec', 'xCAT-server/xCAT-server.spec'); -my @DISTROS = ( - [ 'openSUSE', 'suse_version 1500' ], - [ 'EL', 'rhel 10' ], - [ 'openEuler', 'openEuler 1' ], +# The two specs spell the dependency differently: one names the capability and the other +# the openSUSE and EL package name. Either one resolves. +my %SPELLINGS = ( + 'Socket6' => [ 'perl(Socket6)', 'perl-Socket6' ], + 'IO::Socket::INET6' => [ 'perl(IO::Socket::INET6)', 'perl-IO-Socket-INET6' ], ); +# The families whose package manager installs a recommendation by default. +my @WEAK = ( [ 'EL', 'rhel 10' ], [ 'openEuler', 'openEuler 1' ] ); + my $rpmspec = qx(command -v rpmspec 2>/dev/null); chomp($rpmspec); plan skip_all => 'rpmspec is required' unless $rpmspec && -x $rpmspec; -# requires -- the Requires of one spec for one distro -sub requires +# dependencies -- one dependency kind of one spec for one distro +sub dependencies { - my ($spec, $define) = @_; - open(my $fh, '-|', $rpmspec, '-q', '--requires', '--target', 'x86_64', + my ($spec, $kind, $define) = @_; + open(my $fh, '-|', $rpmspec, '-q', "--$kind", '--target', 'x86_64', '--define', 'version 2.20.0', '--define', 'release 1', '--define', 'gitinfo none', '--undefine', 'rhel', '--undefine', 'suse_version', '--undefine', 'openEuler', '--define', $define, repo_path($spec)) or die "run rpmspec: $!"; - my @requires = <$fh>; + my @found = <$fh>; close($fh) or die "rpmspec failed for $spec with $define"; - chomp @requires; - return @requires; + chomp @found; + return @found; } -# field -- one deb control field, with its continuation lines -sub field +# declares -- whether the list names the module in either spelling +sub declares { - my ($text, $name) = @_; - return '' unless $text =~ /^\Q$name\E:[ \t]*(.*(?:\n[ \t]+.*)*)/m; - my $value = $1; - $value =~ s/\s+/ /g; - return $value; + my ($list, $module) = @_; + foreach my $spelling (@{ $SPELLINGS{$module} }) { + return 1 if grep { $_ eq $spelling } @$list; + } + return 0; } foreach my $spec (@SPECS) { - foreach my $distro (@DISTROS) { - my ($name, $define) = @$distro; - my @requires = requires($spec, $define); - foreach my $module (@MODULES) { - is(scalar(grep { $_ eq "perl($module)" } @requires), 1, - "$spec requires perl($module) on $name"); + my @suse_requires = dependencies($spec, 'requires', 'suse_version 1500'); + my @suse_recommends = dependencies($spec, 'recommends', 'suse_version 1500'); + + foreach my $module (sort keys %SPELLINGS) { + ok(declares(\@suse_requires, $module), + "$spec requires $module on openSUSE, where a recommendation is not installed"); + ok(!declares(\@suse_recommends, $module), + "$spec does not leave $module a recommendation on openSUSE"); + } + + foreach my $family (@WEAK) { + my ($name, $define) = @$family; + my @requires = dependencies($spec, 'requires', $define); + my @recommends = dependencies($spec, 'recommends', $define); + + foreach my $module (sort keys %SPELLINGS) { + ok(declares(\@recommends, $module), "$spec recommends $module on $name"); + ok(!declares(\@requires, $module), + "$spec does not require $module on $name, where the code works without it"); } } } -# The deb packages name the modules directly. A Recommends is not enough: apt 3.0 solver3 -# drops a Recommends it cannot place, which is how Ubuntu 26.04 lost bind9. -foreach my $package ('perl-xCAT', 'xCAT-server') { - my $text = read_text(repo_path("$package/debian/control")); - my $depends = field($text, 'Depends'); - my $suggests = field($text, 'Recommends'); +# apt installs a recommendation by default, so the deb packages need no hard dependency. +# perl-xCAT has carried one since before this rule and keeps it; nothing is gained by +# weakening a dependency that already resolves everywhere apt runs. +my %DEB_FIELD = ('perl-xCAT' => 'Depends', 'xCAT-server' => 'Recommends'); + +foreach my $package (sort keys %DEB_FIELD) { + my $field = $DEB_FIELD{$package}; + my $text = read_text(repo_path("$package/debian/control")); foreach my $deb ('libsocket6-perl', 'libio-socket-inet6-perl') { - like($depends, qr/\b\Q$deb\E\b/, "$package/debian/control depends on $deb"); - unlike($suggests, qr/\b\Q$deb\E\b/, - "$package/debian/control does not leave $deb a Recommends"); + like($text, qr/^\Q$field\E:.*\b\Q$deb\E\b/m, + "$package/debian/control names $deb in $field"); } } diff --git a/xCAT-test/unit/xcat_server_inet6_optional_dependency.t b/xCAT-test/unit/xcat_server_inet6_optional_dependency.t index 54e81f5308..7593e8bd88 100644 --- a/xCAT-test/unit/xcat_server_inet6_optional_dependency.t +++ b/xCAT-test/unit/xcat_server_inet6_optional_dependency.t @@ -3,6 +3,12 @@ # the caller keeps working on IPv4 when the load fails. A hard dependency in # either packaging manifest would state a dependency the code does not have, # and would stop xCAT installing where the modules are missing. +# +# openSUSE is the exception, and it is asserted in +# xCAT-test/unit/ipv6_socket_modules_declared.t: the Minimal-VM image sets +# solver.onlyRequires = true, so zypper installs no recommended package and the +# modules have to be required there. This file reads the EL and Debian spelling +# of the dependency, which carries no openSUSE branch. use strict; use warnings; use FindBin;