Bug #1558

factor 1.5.1 virtual fact not correct for a xen dom0

Added by Lawrence Ludwig almost 2 years ago. Updated 4 months ago.

Status:Closed Start:09/04/2008
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:library
Target version:1.5.2
Keywords: Branch:
Votes: 0

Description

on a centos 5.2 x86_64 dom0 it retruns xenu

# facter virtual
xenu

Here is a patch to fix the issue.

--- facter-1.5.1/lib/facter/virtual.rb  2008-08-18 20:41:29.000000000 -0400
+++ facter-1.5.1.new/lib/facter/virtual.rb      2008-09-04 10:56:08.000000000 -0400
@@ -11,12 +11,14 @@
       result = "openvz"
     end
 
-    if FileTest.exists?("/proc/sys/xen/independent_wallclock")
-      result = "xenu"
-    elsif FileTest.exists?("/proc/xen/capabilities")
-      txt = File.read("/proc/xen/capabilities")
-      if txt =~ /control_d/i
-        result = "xen0"
+    # test if a xen domU
+    # half assed logic but it works
+    if FileTest.exists?("/proc/xen/capabilities")
+      xentest = %x{cat /proc/xen/capabilities}
+      if xentest =~ /control_d/i
+        result = "xen0"
+      else
+        result = "xenu"
       end
     end

After patch, both domu and a dom0 return correct results

dom0 test:

# facter virtual
xen0

domu test:

# facter virtual
xenu

Related issues

related to Facter - Bug #4508: Facter does not recognise Xen HVM DomU Accepted 08/10/2010

Associated revisions

Revision 0fac7040920a9d820f656ce3f121ae2f342df8e4
Added by James Turnbull almost 2 years ago

Fixed #1558 – Updated virtual fact for xenu and xen0

Revision 6e0a1f34d32023d37001fe6e5a32303aa2aec67f
Added by James Turnbull almost 2 years ago

Fixes #1558 – Adjusted virtual fact to allow non-root users to execute it

History

Updated by James Turnbull almost 2 years ago

  • Project changed from Puppet to Facter

Updated by James Turnbull almost 2 years ago

  • Category set to library
  • Status changed from Unreviewed to Ready for Testing
  • Target version set to 1.5.2

I made some mods to your patch.

diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index d84397d..46d76b8 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -11,12 +11,12 @@ Facter.add("virtual") do
       result = "openvz"
     end
 
-    if FileTest.exists?("/proc/sys/xen/independent_wallclock")
-      result = "xenu"
-    elsif FileTest.exists?("/proc/xen/capabilities")
+    if FileTest.exists?("/proc/xen/capabilities")
       txt = File.read("/proc/xen/capabilities")
       if txt =~ /control_d/i
         result = "xen0"
+      else
+        result = "xenu" 
       end
     end

Updated by James Turnbull almost 2 years ago

Pushed in commit:“0fac7040920a9d820f656ce3f121ae2f342df8e4” in branch master.

Updated by Bart Cortooms almost 2 years ago

Unfortunately this change breaks running facter with a non-root account:

$ ls -l /proc/xen/capabilities 
-r-------- 1 root root 0 Sep  7 21:04 /proc/xen/capabilities
$ facter
/usr/lib/ruby/1.8/facter/virtual.rb:15:in `read': Permission denied - /proc/xen/capabilities (Errno::EACCES)
[ ... ]

Something like this allows normal users to use facter again:

if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")

This still doesn’t allow non-root users to get the virtual fact for Xen, but other facts (such as the ones which use dmidecode) have the same problem.

Updated by James Turnbull almost 2 years ago

  • Status changed from Ready for Testing to Ready for Checkin

Updated fact pushed in commit:“6e0a1f34d32023d37001fe6e5a32303aa2aec67f” in branch master.

Updated by James Turnbull almost 2 years ago

  • Status changed from Ready for Checkin to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:“0fac7040920a9d820f656ce3f121ae2f342df8e4”.

Also available in: Atom PDF