diff options
authorintrigeri <>2019-01-27 12:13:47 +0000
committerintrigeri <>2019-01-27 12:13:47 +0000
commitfef1d042712bdcff814e654768f646357b96655a (patch)
parentc8cdbf01d6a8711895bf790c9b991e271f9df27e (diff)
Test suite: don't rely on the state of the APT lists to check if a package is installed (refs: #14596)
I've seen cases where "apt-cache policy" would fail, when run by 'the package "cowsay" is not installed', as part of "I am notified when Additional Software fails to install a package", with: E: Malformed Description-md5 line; doesn't have the required length (32 != 29) '0143a1c3acbdb045e4fcaab0d8657" This seems wrong and I don't know why this happens, but let's not get side-tracked: the goal here is to check whether a given package is installed, not to validate the state of the APT lists. So let's use dpkg instead. For details about why "dpkg -s" was initially replaced with "apt-cache policy", see c77c2dd90480f8eb53e0c7861e531574345659ec. The analysis of the problem in that commit message was correct: "deinstall" means "The package is selected for deinstallation" and is indeed a transient state. The solution did work until we face a situation when the higher level tool fails while checking things we're not interested in.
1 files changed, 4 insertions, 3 deletions
diff --git a/features/step_definitions/apt.rb b/features/step_definitions/apt.rb
index 7d8d3ff..81c1f61 100644
--- a/features/step_definitions/apt.rb
+++ b/features/step_definitions/apt.rb
@@ -75,14 +75,15 @@ end
def check_for_removal(package)
try_for(3*60) do
- state = $vm.execute("apt-cache policy #{package}").stdout.split("\n")[1]
- /^\s{2}Installed:\s\(none\)$/.match(state) != nil
+ # Once purged, a package is removed from the installed package status database
+ # and "dpkg -s" returns a non-zero exit code
+ ! $vm.execute("dpkg -s #{package}").success?
Then /^I uninstall "(.+)" using apt$/ do |package|
$vm.execute("echo #{@sudo_password} | " +
- "sudo -S apt -y remove #{package}",
+ "sudo -S apt -y purge #{package}",
:user => LIVE_USER,
:spawn => true)