]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Handle release parameter more sensibly in force manifest.
authorAndreas Teuchert <ant+github@teuchert.org>
Sat, 23 Feb 2013 15:42:14 +0000 (16:42 +0100)
committerHunter Haugen <h.haugen@gmail.com>
Wed, 3 Jul 2013 17:36:15 +0000 (10:36 -0700)
Use release parameter to construct $release_string.

The release parameter may also be set to false to use the system's
default release (so just force a specific version). Use false as the
default setting instead of 'testing'.

Change $install_check to also check if package is installed from the
right release, instead of just checking the version.

manifests/force.pp

index 2d33e942dcda0a7ddfd564d5d69be95e85a4afb1..a1ec4a60882f0939882815a355d8e6caa4f394f9 100644 (file)
@@ -2,7 +2,7 @@
 # force a package from a specific release
 
 define apt::force(
-  $release = 'testing',
+  $release = false,
   $version = false,
   $timeout = 300
 ) {
@@ -12,11 +12,27 @@ define apt::force(
     default => "=${version}",
   }
 
-  $install_check = $version ? {
-    false   => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
-    default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
+  $release_string = $release ? {
+    false   => undef,
+    default => "-t ${release}",
+  }
+
+  if $version == false {
+    if $release == false {
+      $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'"
+    } else {
+      # If installed version and candidate version differ, this check returns 1 (false).
+      $install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1"
+    }
+  } else {
+    if $release == false {
+      $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'"
+    } else {
+      $install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'"
+    }
   }
-  exec { "/usr/bin/apt-get -y -t ${release} install ${name}${version_string}":
+
+  exec { "/usr/bin/apt-get -y ${release_string} install ${name}${version_string}":
     unless    => $install_check,
     logoutput => 'on_failure',
     timeout   => $timeout,