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/b7784a3epel9
parent
d9094e4269
commit
be66d28fa4
@ -0,0 +1,68 @@
|
||||
From c823dd47277bc88b95062dda726800860c75f1c3 Mon Sep 17 00:00:00 2001
|
||||
From: Todd Zullinger <tmz@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
|
||||
|
Loading…
Reference in new issue