4b98da9
From 39382efcf16e3f3b30ce8284ae3aefcf09b1b2d6 Mon Sep 17 00:00:00 2001
be66d28
From: Todd Zullinger <tmz@pobox.com>
be66d28
Date: Fri, 29 Mar 2013 19:31:59 -0400
be66d28
Subject: [PATCH] (#19989) Filter virt-what warnings from virtual fact
be66d28
MIME-Version: 1.0
be66d28
Content-Type: text/plain; charset=UTF-8
be66d28
Content-Transfer-Encoding: 8bit
be66d28
be66d28
Presently, the virt-what command puts errors on stdout, prefixed with
be66d28
virt-what:.  This ends up in the virtual fact, which is undesirable.
be66d28
be66d28
When a fixed virt-what is released and available for supported systems,
be66d28
the 'output.gsub /^virt-what: .*$/' can be removed from
be66d28
Facter::Util::Virtual::virt_what().
be66d28
be66d28
A virt-what fix was committed upstream┬╣.
be66d28
be66d28
Thanks to Adrien Thebo for help on making this testable.
be66d28
4b98da9
This also rolls in a follow-up fix to suppress warnings when virt-what
4b98da9
produces no output:
4b98da9
4b98da9
4a59d36 ((Maint) Don't parse nil Facter::Util::Resolution output)
4b98da9
be66d28
┬╣ http://git.annexia.org/?p=virt-what.git;a=commitdiff;h=2f47e06
be66d28
be66d28
Conflicts:
be66d28
	spec/unit/util/virtual_spec.rb
be66d28
---
be66d28
 lib/facter/util/virtual.rb     | 10 +++++++++-
be66d28
 spec/unit/util/virtual_spec.rb |  6 ++++++
be66d28
 2 files changed, 15 insertions(+), 1 deletion(-)
be66d28
be66d28
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
4b98da9
index 41472b8..534f31a 100644
be66d28
--- a/lib/facter/util/virtual.rb
be66d28
+++ b/lib/facter/util/virtual.rb
be66d28
@@ -3,8 +3,16 @@ module Facter::Util::Virtual
be66d28
   # virt_what is a delegating helper method intended to make it easier to stub
be66d28
   # the system call without affecting other calls to
be66d28
   # Facter::Util::Resolution.exec
be66d28
+  #
be66d28
+  # Per https://bugzilla.redhat.com/show_bug.cgi?id=719611 when run as a
be66d28
+  # non-root user the virt-what command may emit an error message on stdout,
be66d28
+  # and later versions of virt-what may emit this message on stderr. This
be66d28
+  # method ensures stderr is redirected and that error messages are stripped
be66d28
+  # from stdout.
be66d28
   def self.virt_what(command = "virt-what")
be66d28
-    Facter::Util::Resolution.exec command
be66d28
+    redirected_cmd = "#{command} 2>/dev/null"
be66d28
+    output = Facter::Util::Resolution.exec redirected_cmd
4b98da9
+    output.gsub(/^virt-what: .*$/, '') if output
be66d28
   end
be66d28
 
be66d28
   ##
be66d28
diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
be66d28
index da74d70..c50084b 100755
be66d28
--- a/spec/unit/util/virtual_spec.rb
be66d28
+++ b/spec/unit/util/virtual_spec.rb
be66d28
@@ -181,4 +181,10 @@ describe Facter::Util::Virtual do
be66d28
     Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660')
be66d28
     Facter::Util::Virtual.should_not be_hpvm
be66d28
   end
be66d28
+
be66d28
+  it "should strip out warnings on stdout from virt-what" do
be66d28
+    virt_what_warning = "virt-what: this script must be run as root"
be66d28
+    Facter::Util::Resolution.expects(:exec).with('virt-what 2>/dev/null').returns virt_what_warning
be66d28
+    Facter::Util::Virtual.virt_what.should_not match /^virt-what: /
be66d28
+  end
be66d28
 end
be66d28
-- 
be66d28
1.7.11.7
be66d28