]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
(GH-139) Throw away STDERR from dpkg-query in Fact
authorDan Carley <dan.carley@gmail.com>
Mon, 4 Mar 2013 08:08:51 +0000 (08:08 +0000)
committerDan Carley <dan.carley@gmail.com>
Mon, 4 Mar 2013 08:08:51 +0000 (08:08 +0000)
Newer versions of dpkg-query, as of Ubuntu 12.10, will make noise on STDERR
if the queried package isn't currently installed. Facter's `exec()` outputs
this without giving us a chance to catch it.

Pipe STDERR to `/dev/null` so that it's not seen by the end-user. STDOUT
will still be `nil` if the package isn't installed. It doesn't seem
reasonable to spec test for this without reaching deep into Facter, so I'm
not going to.

lib/facter/iptables_persistent_version.rb

index 2bae97a36c7c04483659c822bd9535f0b99a0598..80bf9dea1a45341aa6f65f4ddcd1dd3b6b3af5a0 100644 (file)
@@ -1,7 +1,9 @@
 Facter.add(:iptables_persistent_version) do
   confine :operatingsystem => %w{Debian Ubuntu}
   setcode do
-    cmd = "dpkg-query -Wf '${Version}' iptables-persistent"
+    # Throw away STDERR because dpkg >= 1.16.7 will make some noise if the
+    # package isn't currently installed.
+    cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null"
     version = Facter::Util::Resolution.exec(cmd)
 
     if version.nil? or !version.match(/\d+\.\d+/)