[facter] Apply upstream patch to filter virt-what warnings from virtual fact

Todd Zullinger tmz at fedoraproject.org
Wed Apr 3 01:54:33 UTC 2013


commit be66d28fa4c401bccb26f7c7881c2b2177dea111
Author: Todd Zullinger <tmz at pobox.com>
Date:   Tue Apr 2 17:24:50 2013 -0400

    Apply upstream patch to filter virt-what warnings from virtual fact
    
    With the additional requirement of virt-what that was added in
    facter-1.6.18-1, the virtual fact was incorrect when facter was not run
    by root:
    
    $ facter | egrep '^(facterversion|virtual)'
    facterversion => 1.6.18
    virtual => virt-what: this script must be run as root
    
    This is upstream ticket #19989¹.  It was applied to the 1.7.x branch².
    
    ¹ https://projects.puppetlabs.com/issues/19989
    ² https://github.com/puppetlabs/facter/commit/b7784a3

 ...lter-virt-what-warnings-from-virtual-fact.patch |   68 ++++++++++++++++++++
 facter.spec                                        |    9 ++-
 2 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/0001-19989-Filter-virt-what-warnings-from-virtual-fact.patch b/0001-19989-Filter-virt-what-warnings-from-virtual-fact.patch
new file mode 100644
index 0000000..d4d32d7
--- /dev/null
+++ b/0001-19989-Filter-virt-what-warnings-from-virtual-fact.patch
@@ -0,0 +1,68 @@
+From c823dd47277bc88b95062dda726800860c75f1c3 Mon Sep 17 00:00:00 2001
+From: Todd Zullinger <tmz at pobox.com>
+Date: Fri, 29 Mar 2013 19:31:59 -0400
+Subject: [PATCH] (#19989) Filter virt-what warnings from virtual fact
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Presently, the virt-what command puts errors on stdout, prefixed with
+virt-what:.  This ends up in the virtual fact, which is undesirable.
+
+When a fixed virt-what is released and available for supported systems,
+the 'output.gsub /^virt-what: .*$/' can be removed from
+Facter::Util::Virtual::virt_what().
+
+A virt-what fix was committed upstream¹.
+
+Thanks to Adrien Thebo for help on making this testable.
+
+¹ http://git.annexia.org/?p=virt-what.git;a=commitdiff;h=2f47e06
+
+Conflicts:
+	spec/unit/util/virtual_spec.rb
+---
+ lib/facter/util/virtual.rb     | 10 +++++++++-
+ spec/unit/util/virtual_spec.rb |  6 ++++++
+ 2 files changed, 15 insertions(+), 1 deletion(-)
+
+diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
+index 41472b8..b5fa09d 100644
+--- a/lib/facter/util/virtual.rb
++++ b/lib/facter/util/virtual.rb
+@@ -3,8 +3,16 @@ module Facter::Util::Virtual
+   # virt_what is a delegating helper method intended to make it easier to stub
+   # the system call without affecting other calls to
+   # Facter::Util::Resolution.exec
++  #
++  # Per https://bugzilla.redhat.com/show_bug.cgi?id=719611 when run as a
++  # non-root user the virt-what command may emit an error message on stdout,
++  # and later versions of virt-what may emit this message on stderr. This
++  # method ensures stderr is redirected and that error messages are stripped
++  # from stdout.
+   def self.virt_what(command = "virt-what")
+-    Facter::Util::Resolution.exec command
++    redirected_cmd = "#{command} 2>/dev/null"
++    output = Facter::Util::Resolution.exec redirected_cmd
++    output.gsub(/^virt-what: .*$/, '')
+   end
+ 
+   ##
+diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
+index da74d70..c50084b 100755
+--- a/spec/unit/util/virtual_spec.rb
++++ b/spec/unit/util/virtual_spec.rb
+@@ -181,4 +181,10 @@ describe Facter::Util::Virtual do
+     Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660')
+     Facter::Util::Virtual.should_not be_hpvm
+   end
++
++  it "should strip out warnings on stdout from virt-what" do
++    virt_what_warning = "virt-what: this script must be run as root"
++    Facter::Util::Resolution.expects(:exec).with('virt-what 2>/dev/null').returns virt_what_warning
++    Facter::Util::Virtual.virt_what.should_not match /^virt-what: /
++  end
+ end
+-- 
+1.7.11.7
+
diff --git a/facter.spec b/facter.spec
index 2f090e1..0aff157 100644
--- a/facter.spec
+++ b/facter.spec
@@ -16,7 +16,7 @@
 
 Name:           facter
 Version:        1.6.18
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Command and ruby library for gathering system information
 
 Group:          System Environment/Base
@@ -24,6 +24,9 @@ License:        ASL 2.0
 URL:            http://www.puppetlabs.com/puppet/related-projects/%{name}/
 Source0:        http://downloads.puppetlabs.com/%{name}/%{name}-%{version}.tar.gz
 Source1:        http://downloads.puppetlabs.com/%{name}/%{name}-%{version}.tar.gz.asc
+# https://bugzilla.redhat.com/719611
+# https://projects.puppetlabs.com/issues/19989
+Patch0:         0001-19989-Filter-virt-what-warnings-from-virtual-fact.patch
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildRequires:  ruby >= 1.8.1
@@ -65,6 +68,7 @@ key off the values returned by facts.
 
 %prep
 %setup -q
+%patch0 -p1
 
 
 %build
@@ -108,6 +112,9 @@ rspec spec
 
 
 %changelog
+* Tue Apr 02 2013 Todd Zullinger <tmz at pobox.com> - 1.6.18-2
+- Apply upstream patch to filter virt-what warnings from virtual fact
+
 * Mon Mar 18 2013 Todd Zullinger <tmz at pobox.com> - 1.6.18-1
 - Update to 1.6.18
 - Restart puppet in %%postun (#806370)


More information about the scm-commits mailing list