diff --git a/xCAT-test/unit/README.md b/xCAT-test/unit/README.md index abd70e1771..3be3c17828 100644 --- a/xCAT-test/unit/README.md +++ b/xCAT-test/unit/README.md @@ -43,6 +43,17 @@ real copy parser checks that executable before the test intercepts copy execution. Install rsync with the test dependencies; this test does not run it or connect to another node. The CI management-node install already includes it. +`debian_control_declarations.t` requires `libdpkg-perl` on Debian and Ubuntu. +It fails if the Dpkg modules are missing on those systems, and skips on other +systems without them. The test checks package declarations for amd64, ppc64el +and riscv64; it does not require those packages to be installed. + +The module requirements cover perl-xcat imports, Capture::Tiny for the client's +z/VM helpers, and CGI for the server's REST API. nmap and ipmitool-xcat are hard +requirements in the RPM packages too. The ipmitool-xcat floor in xcat's Debian +package matches xCAT.spec at 1.8.18-4. The test also preserves xcatsn's declared +floor of 1.8.18-4. + Use `XCAT::Test::Process` when a test needs a command's exit code and combined standard output and standard error: diff --git a/xCAT-test/unit/debian_control_declarations.t b/xCAT-test/unit/debian_control_declarations.t index e97feccbbb..e7117098a1 100644 --- a/xCAT-test/unit/debian_control_declarations.t +++ b/xCAT-test/unit/debian_control_declarations.t @@ -2,72 +2,73 @@ use strict; use warnings; -use File::Spec; use FindBin; +use lib "$FindBin::Bin/../lib"; use Test::More; -# dh_perl adds no module dependencies, unlike the rpm generator, so a deb declares only what its -# control file names. perl-xcat declared libhtml-form-perl alone while its files load nine other -# modules at top level, xcat-server shipped the REST API without CGI, xcat-client ships z/VM -# helpers that load Capture::Tiny, and nmap and ipmitool-xcat were recommendations where the rpm -# packages require them. +use XCAT::Test::File qw(repo_path); -my $repo_root = File::Spec->rel2abs( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); +unless ( eval { require Dpkg::Control::Info; require Dpkg::Deps; 1 } ) { + die "Install libdpkg-perl to check Debian package requirements: $@" + if -f '/etc/debian_version'; + plan skip_all => 'Dpkg::Control::Info and Dpkg::Deps are not available'; +} -# The relation fields of one binary package stanza as sets of package names, plus the version -# bound of each relation that has one. sub relations_of { - my ( $source, $package ) = @_; - my $file = File::Spec->catfile( $repo_root, $source, 'debian', 'control' ); - open( my $fh, '<', $file ) or die "Unable to read $file: $!"; - my $control = do { local $/; <$fh> }; - close($fh); - my ($stanza) = $control =~ /^Package:\s*\Q$package\E\s*\n(.*?)(?:\n\n|\z)/ms; - die "no stanza for $package in $file" unless defined $stanza; + my ( $source, $package, $arch ) = @_; + my $file = repo_path("$source/debian/control"); + my $fields = Dpkg::Control::Info->new($file)->get_pkg_by_name($package) + or die "No stanza for $package in $file\n"; my %rel; foreach my $field (qw(Depends Recommends)) { - my ($line) = $stanza =~ /^$field:\s*(.*)$/m; - foreach my $entry ( split( /[,|]/, $line // '' ) ) { - my ( $name, $bound ) = $entry =~ /^\s*(\S+?)\s*(?:\(([^)]*)\))?\s*(?:\[[^\]]*\])?\s*$/; - next unless defined $name; - $rel{$field}{$name} = 1; - $rel{version}{$name} = $bound if defined $bound; - } + my $value = $fields->{$field} // ''; + # Model dh_perl's generated dependency as Perl; module requirements must be declared explicitly. + $value =~ s/\$\{perl:Depends\}/perl/g; + $rel{$field} = Dpkg::Deps::deps_parse( $value, reduce_arch => 1, host_arch => $arch ); + die "Unable to parse $field of $package for $arch\n" unless defined $rel{$field}; } return \%rel; } sub depends_on { - my ( $rel, $name, $label ) = @_; - ok( $rel->{Depends}{$name}, "$label depends on $name" ); - ok( !$rel->{Recommends}{$name}, "... and no longer only recommends it" ) if $rel->{Recommends}{$name}; + my ( $rel, $requirement, $label ) = @_; + my $term = Dpkg::Deps::Simple->new($requirement); + # A one-term OR lets implies() check every branch of an alternative dependency. + my $required = Dpkg::Deps::OR->new($term); + ok( $rel->{Depends}->implies($required), "$label depends on $requirement" ) + or diag( 'Depends: ' . $rel->{Depends}->output() ); + + my @recommended; + Dpkg::Deps::deps_iterate( $rel->{Recommends}, sub { + my ($dep) = @_; + push @recommended, $dep->output() if $dep->{package} eq $term->{package}; + return 1; + } ); + is_deeply( \@recommended, [], "$label does not also recommend $term->{package}" ); } -my $perl_xcat = relations_of( 'perl-xCAT', 'perl-xcat' ); -depends_on( $perl_xcat, $_, 'perl-xcat' ) for qw( - libhtml-form-perl libxml-simple-perl libxml-parser-perl libio-socket-ssl-perl libdbi-perl libjson-perl - libwww-perl libxml-libxml-perl libexpect-perl libsnmp-perl libsocket6-perl libio-socket-inet6-perl -); +foreach my $arch (qw(amd64 ppc64el riscv64)) { + subtest $arch => sub { + my $perl_xcat = relations_of( 'perl-xCAT', 'perl-xcat', $arch ); + depends_on( $perl_xcat, $_, 'perl-xcat' ) for qw( + libhtml-form-perl libxml-simple-perl libxml-parser-perl libio-socket-ssl-perl libdbi-perl libjson-perl + libwww-perl libxml-libxml-perl libexpect-perl libsnmp-perl libsocket6-perl libio-socket-inet6-perl + ); -my $client = relations_of( 'xCAT-client', 'xcat-client' ); -depends_on( $client, 'libcapture-tiny-perl', 'xcat-client' ); + my $client = relations_of( 'xCAT-client', 'xcat-client', $arch ); + depends_on( $client, 'libcapture-tiny-perl', 'xcat-client' ); + depends_on( $client, 'nmap', 'xcat-client' ); -my $server = relations_of( 'xCAT-server', 'xcat-server' ); -depends_on( $server, 'libcgi-pm-perl', 'xcat-server' ); + my $server = relations_of( 'xCAT-server', 'xcat-server', $arch ); + depends_on( $server, 'libcgi-pm-perl', 'xcat-server' ); -# nmap and ipmitool-xcat are hard requirements on EL and were only recommended here. -my $xcat = relations_of( 'xCAT', 'xcat' ); -my $xcatsn = relations_of( 'xCATsn', 'xcatsn' ); -foreach my $case ( [ $xcat, 'xcat' ], [ $xcatsn, 'xcatsn' ], [ $client, 'xcat-client' ] ) { - my ( $rel, $label ) = @$case; - ok( $rel->{Depends}{nmap}, "$label depends on nmap" ); - ok( !$rel->{Recommends}{nmap}, "... and does not recommend it as well" ); -} -foreach my $case ( [ $xcat, 'xcat' ], [ $xcatsn, 'xcatsn' ] ) { - my ( $rel, $label ) = @$case; - ok( $rel->{Depends}{'ipmitool-xcat'}, "$label depends on ipmitool-xcat" ); - ok( !$rel->{Recommends}{'ipmitool-xcat'}, "... and does not recommend it as well" ); - is( $rel->{version}{'ipmitool-xcat'}, '>= 1.8.18-4', "... at the floor xCAT.spec requires" ); + foreach my $case ( [ 'xCAT', 'xcat' ], [ 'xCATsn', 'xcatsn' ] ) { + my ( $source, $package ) = @$case; + my $rel = relations_of( $source, $package, $arch ); + depends_on( $rel, 'nmap', $package ); + depends_on( $rel, 'ipmitool-xcat (>= 1.8.18-4)', $package ); + } + }; } done_testing();