From a69debb41b6f09bf30c24ec14cda180ad888df15 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Mon, 28 Sep 2026 14:55:50 -0300 Subject: [PATCH] test(xcat-core): go-xcat complete uninstall skips packages with config files left After `apt-get remove`, dpkg reports a package as "deinstall ok config-files". uninstall_xcat_completely() selects packages with installed_packages(), which accepts only "install ok installed". A complete uninstall after an ordinary uninstall therefore does not purge the xCAT packages, and their configuration files stay on the node. The new bats test runs both uninstall paths against a dpkg-query stub. The two purge tests fail on this tree. The ordinary uninstall keeps its installed-only filter. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../bats/go_xcat_uninstall_config_files.bats | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 xCAT-test/bats/go_xcat_uninstall_config_files.bats diff --git a/xCAT-test/bats/go_xcat_uninstall_config_files.bats b/xCAT-test/bats/go_xcat_uninstall_config_files.bats new file mode 100644 index 000000000..cf65fa9dc --- /dev/null +++ b/xCAT-test/bats/go_xcat_uninstall_config_files.bats @@ -0,0 +1,67 @@ +#!/usr/bin/env bats +# +# `apt-get remove` leaves a package in the "deinstall ok config-files" state (dpkg `rc`). +# `go-xcat uninstall` removes, so it skips those. `go-xcat uninstall --completely` purges, +# so it must include them, or a remove followed by a complete uninstall leaves the +# configuration files behind. +# +# go-xcat is sourced. dpkg-query and the package, kill and trash steps are shell functions +# here, and PATH is empty, so no test reads or changes the host package database or files. + +load 'helpers/go_xcat' + +setup() +{ + go_xcat_require_source + # shellcheck disable=SC1090 + source "$GO_XCAT_SOURCE" + remove_package() { printf 'remove %s\n' "$@"; } + purge_package() { printf 'purge %s\n' "$@"; } + kill_xcat() { :; } + trash_xcat() { :; } + # The state dpkg reports after `apt-get remove xcat-test-removed`. + dpkg-query() + { + case "$3" in + xcat-test-installed) printf 'install ok installed' ;; + xcat-test-removed) printf 'deinstall ok config-files' ;; + *) return 1 ;; + esac + } + GO_XCAT_UNINSTALL_LIST=(xcat-test-absent xcat-test-installed xcat-test-removed) +} + +without_path() +{ + local PATH="" + "$@" +} + +@test "deb: complete uninstall purges packages that only have configuration files left" { + run without_path uninstall_xcat_completely + [ "$status" -eq 0 ] + [ "$output" = "purge -y +purge xcat-test-installed +purge xcat-test-removed" ] +} + +@test "deb: complete uninstall after a remove purges the removed package" { + GO_XCAT_UNINSTALL_LIST=(xcat-test-absent xcat-test-removed) + run without_path uninstall_xcat_completely + [ "$status" -eq 0 ] + [ "$output" = "purge -y +purge xcat-test-removed" ] +} + +@test "deb: ordinary uninstall removes only the installed packages" { + run without_path uninstall_xcat -y + [ "$status" -eq 0 ] + [ "$output" = "remove -y +remove xcat-test-installed" ] +} + +@test "deb: a package with only configuration files left is not reported as installed" { + run without_path installed_packages xcat-test-removed xcat-test-installed + [ "$status" -eq 0 ] + [ "$output" = "xcat-test-installed" ] +}