diff --git a/xCAT-test/bats/go_xcat_package_lists.bats b/xCAT-test/bats/go_xcat_package_lists.bats new file mode 100644 index 000000000..0cd54b565 --- /dev/null +++ b/xCAT-test/bats/go_xcat_package_lists.bats @@ -0,0 +1,101 @@ +#!/usr/bin/env bats +# +# go-xcat installs one package list and removes another, with the deb names when "type dpkg" +# succeeds. On riscv64 it drops the legacy Genesis, which has no riscv64 build, and asks for the +# OpenEmbedded Genesis instead. The x86 boot loaders stay: a riscv64 management node serves them +# to the x86 nodes of a mixed cluster. +# +# Each test sources go-xcat in a subshell and reads the lists the installer would use. + +load 'helpers/go_xcat' + +LEGACY_GENESIS='-genesis-(scripts|base)-' + +setup() +{ + go_xcat_require_source +} + +# Print one list of go-xcat, one package per line. +# +# $1 The package format: rpm or deb. +# $2 install, uninstall, or riscv64 for the install list of a riscv64 management node. +go_xcat_list() +{ + local format="$1" list="$2" + ( + if [ "$format" = "deb" ]; then + dpkg() { :; } + fi + # A real dpkg on the build host would select the deb names on every run. go-xcat sets PATH + # again, and riscv64_install_list looks for dpkg too. + PATH="" + source "$GO_XCAT_SOURCE" || exit 70 + PATH="" + case "$list" in + install) printf '%s\n' "${GO_XCAT_INSTALL_LIST[@]}" ;; + uninstall) printf '%s\n' "${GO_XCAT_UNINSTALL_LIST[@]}" ;; + riscv64) riscv64_install_list "${GO_XCAT_INSTALL_LIST[@]}" ;; + *) exit 64 ;; + esac + ) +} + +openembedded_genesis() +{ + case "$1" in + rpm) echo 'xCAT-genesis-openembedded-riscv64' ;; + deb) echo 'xcat-genesis-openembedded-riscv64' ;; + esac +} + +# Print the lines of the first list that the second list does not have. +missing_from() +{ + local list="$1" other="$2" package + while IFS= read -r package; do + grep -Fqx -- "$package" <<<"$other" || printf '%s\n' "$package" + done <<<"$list" +} + +@test "go-xcat loads its package lists without running the installer" { + for format in rpm deb; do + for list in install uninstall riscv64; do + run go_xcat_list "$format" "$list" + [ "$status" -eq 0 ] + [ -n "$output" ] + done + done +} + +@test "the riscv64 install list has no legacy Genesis and asks for the OpenEmbedded Genesis" { + for format in rpm deb; do + riscv64="$(go_xcat_list "$format" riscv64)" + [ -z "$(grep -E -- "$LEGACY_GENESIS" <<<"$riscv64")" ] + grep -Fqx -- "$(openembedded_genesis "$format")" <<<"$riscv64" + done +} + +@test "the riscv64 install list keeps every other package, the x86 boot loaders included" { + for format in rpm deb; do + install="$(go_xcat_list "$format" install)" + riscv64="$(go_xcat_list "$format" riscv64)" + [ -n "$(grep -E -- "$LEGACY_GENESIS" <<<"$install")" ] + + run missing_from "$(grep -v -E -- "$LEGACY_GENESIS" <<<"$install")" "$riscv64" + [ -z "$output" ] || { echo "$format: the riscv64 list drops: $output"; false; } + + run missing_from "$riscv64" "$install" + [ "$output" = "$(openembedded_genesis "$format")" ] + done +} + +@test "the uninstall list removes every package go-xcat installs on any architecture" { + for format in rpm deb; do + uninstall="$(go_xcat_list "$format" uninstall)" + for list in install riscv64; do + run missing_from "$(go_xcat_list "$format" "$list")" "$uninstall" + [ -z "$output" ] || { echo "$format: uninstall misses $list packages: $output"; false; } + done + done +} diff --git a/xCAT-test/unit/go_xcat_riscv64_packages.t b/xCAT-test/unit/go_xcat_riscv64_packages.t deleted file mode 100644 index 0067209b3..000000000 --- a/xCAT-test/unit/go_xcat_riscv64_packages.t +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use File::Temp qw(tempdir); -use FindBin; -use Test::More; - -# go-xcat installs a fixed package list. On riscv64 that list asked for the amd64 and ppc64 -# Genesis scripts and bases, so the supported install path put the x86 Genesis on a riscv64 -# management node even though the xcat metapackage excludes it there. -# -# The x86 boot loaders are a different matter: they are payload the management node serves to x86 -# nodes, so they belong on a riscv64 management node of a mixed cluster and must survive the filter. -# -# The function that builds the riscv64 list is taken from the shipped script and run, so the -# assertions read the package names go-xcat would hand to the package manager. - -my $go_xcat = "$FindBin::Bin/../../xCAT-server/share/xcat/tools/go-xcat"; -plan skip_all => 'go-xcat not found' unless -r $go_xcat; - -my $tmpdir = tempdir( CLEANUP => 1 ); -my $driver = "$tmpdir/driver.sh"; -open( my $fh, '>', $driver ) or die "open $driver: $!"; -print {$fh} <<'DRIVER'; -#!/bin/bash -set -euo pipefail -eval "$(awk ' - $0 == "function riscv64_install_list()" { copy = 1 } - copy { print } - copy && /^}$/ { exit } -' "$GO_XCAT_SOURCE")" - -# The real list, as go-xcat defines it for each package manager. -if [[ ${WITH_DPKG:-0} == 1 ]]; then - dpkg() { :; } - list=(perl-xcat xcat-client xcat xcat-buildkit - xcat-genesis-scripts-amd64 xcat-genesis-scripts-ppc64 xcat-server - elilo-xcat grub2-xcat ipmitool-xcat syslinux-xcat - xcat-genesis-base-amd64 xcat-genesis-base-ppc64 xnba-undi) -else - type() { return 1; } - list=(perl-xCAT xCAT-client xCAT xCAT-buildkit - xCAT-genesis-scripts-ppc64 xCAT-genesis-scripts-x86_64 xCAT-server - elilo-xcat grub2-xcat ipmitool-xcat syslinux-xcat - xCAT-genesis-base-ppc64 xCAT-genesis-base-x86_64 xnba-undi) -fi -riscv64_install_list "${list[@]}" -DRIVER -close($fh); -chmod 0755, $driver; - -sub riscv64_list { - my ($with_dpkg) = @_; - my $out = `GO_XCAT_SOURCE='$go_xcat' WITH_DPKG=$with_dpkg bash '$driver' 2>&1`; - is( $?, 0, "the riscv64 list builds (dpkg=$with_dpkg)" ) or diag($out); - return [ grep { length } split( /\n/, $out ) ]; -} - -foreach my $case ( [ 1, 'deb', 'xcat-genesis-openembedded-riscv64', 'xcat-server' ], - [ 0, 'rpm', 'xCAT-genesis-openembedded-riscv64', 'xCAT-server' ] ) -{ - my ( $with_dpkg, $name, $genesis, $server ) = @{$case}; - my $list = riscv64_list($with_dpkg); - - is_deeply( [ grep { /genesis-scripts-/i } @{$list} ], [], - "$name: no legacy Genesis scripts on riscv64" ); - is_deeply( [ grep { /genesis-base-/i } @{$list} ], [], - "$name: no legacy Genesis base on riscv64" ); - is_deeply( [ sort grep { /^(elilo-xcat|syslinux-xcat|xnba-undi)$/ } @{$list} ], - [ sort qw(elilo-xcat syslinux-xcat xnba-undi) ], - "$name: the x86 boot payload a mixed cluster needs is still installed" ); - - ok( scalar( grep { $_ eq $genesis } @{$list} ), - "$name: the riscv64 OpenEmbedded Genesis package is asked for" ); - - # The filter must take nothing else with it. - foreach my $keep ( $server, 'grub2-xcat', 'ipmitool-xcat' ) { - ok( scalar( grep { $_ eq $keep } @{$list} ), "$name: $keep is still installed" ); - } -} - -done_testing();