From 2f5d317177976043dc3480ff715da5e1e56b8957 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 15 Dec 2011 15:52:21 +0100 Subject: [PATCH 1/2] (#11413) Update dpkg query used by apt::force This patch fixes the query used by apt::force to determine rather or not the package is installed. Previously, the expression was not specific enough and could not lead to false positives in cases where a package name is contained within another package name (puppet could be incorrectly determined as being installed if puppet-common is installed) This commit resolves that by improving the query expression. --- manifests/force.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/force.pp b/manifests/force.pp index 0a3007d..ece532a 100644 --- a/manifests/force.pp +++ b/manifests/force.pp @@ -8,8 +8,8 @@ define apt::force( exec { "/usr/bin/aptitude -y -t ${release} install ${name}": unless => $version ? { - false => "/usr/bin/dpkg -l | grep ${name}", - default => "/usr/bin/dpkg -l | grep ${name} | grep ${version}" + false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'", + default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'" } } From f71db53130c28e9fc6fd7468df6800b15ad7676e Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Fri, 13 Jan 2012 11:02:42 -0800 Subject: [PATCH 2/2] (#11413) Add spec test for apt::force to verify changes to unless In the Previous commits, the query being done by the apt::force install command was not strict enough and could lead to false positives. These queries represented by the unless parameter have been resolved in another commit. This commit accompanies that commit and adds basic unit tests to correspond to the changes. --- spec/defines/force_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/defines/force_spec.rb diff --git a/spec/defines/force_spec.rb b/spec/defines/force_spec.rb new file mode 100644 index 0000000..d040dc9 --- /dev/null +++ b/spec/defines/force_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' +describe 'apt::force', :type => :define do + + let :title do + 'my_package' + end + + [false, '1'].each do |version| + describe "with version: #{version}" do + let :params do + {:version => version, :release => 'testing'} + end + let :unless_query do + base_command = "/usr/bin/dpkg -s #{title} | grep -q " + base_command + (version ? "'Version: #{params[:version]}'" : "'Status: install'") + end + let :exec_title do + "/usr/bin/aptitude -y -t #{params[:release]} install #{title}" + end + it { should contain_exec(exec_title).with_unless(unless_query) } + end + end +end