You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.8 KiB
74 lines
2.8 KiB
From 39382efcf16e3f3b30ce8284ae3aefcf09b1b2d6 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.
|
|
|
|
This also rolls in a follow-up fix to suppress warnings when virt-what
|
|
produces no output:
|
|
|
|
4a59d36 ((Maint) Don't parse nil Facter::Util::Resolution output)
|
|
|
|
¹ 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..534f31a 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: .*$/, '') if output
|
|
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
|
|
|