[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, squeeze-1.5.7, updated. debian/1.5.7-1-29-g115f872

Micah Anderson micah at riseup.net
Thu Dec 23 16:45:07 UTC 2010


The following commit has been merged in the squeeze-1.5.7 branch:
commit 37d03701d708cab6c9da68e5e1b53580c9e6ccca
Author: John Ferlito <johnf at inodes.org>
Date:   Sun Feb 14 18:07:43 2010 +1100

    Add kvm support to virtual fact
    
    Based on initial patch by James Turnbull

diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 80439f3..f7c64c7 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -40,4 +40,21 @@ module Facter::Util::Virtual
             FileTest.exists?(f)
         end
     end
+
+    def self.kvm?
+       if FileTest.exists?("/proc/cpuinfo")
+           txt = File.read("/proc/cpuinfo")
+           return true if txt =~ /QEMU Virtual CPU/
+       end
+       return false
+    end
+
+    def self.kvm_type
+      # TODO Tell the difference between kvm and qemu
+      # Can't work out a way to do this at the moment that doesn't
+      # require a special binary
+      "kvm"
+    end
+
+
 end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index 78413a9..3f02003 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -34,6 +34,10 @@ Facter.add("virtual") do
             end
         end
 
+        if Facter::Util::Virtual.kvm?
+            result = Facter::Util::Virtual.kvm_type()
+        end
+
         if result == "physical"
             output = Facter::Util::Resolution.exec('lspci')
             if not output.nil?
@@ -72,7 +76,7 @@ Facter.add("is_virtual") do
 
     setcode do
         case Facter.value(:virtual)
-        when "xenu", "openvzve", "vmware"
+        when "xenu", "openvzve", "vmware", "kvm"
             true
         else 
             false
diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb
index 1f1c0f8..de339b8 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual.rb
@@ -93,4 +93,11 @@ describe Facter::Util::Virtual do
         FileTest.expects(:exists?).with("/proc/xen").returns(false)
         Facter::Util::Virtual.should_not be_xen
     end
+
+    it "should detect kvm" do
+        FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(true)
+        File.stubs(:read).with("/proc/cpuinfo").returns("model name : QEMU Virtual CPU version 0.9.1\n")
+        Facter::Util::Virtual.should be_kvm
+    end
+
 end
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb
index cc72ffc..fe9988e 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -48,4 +48,10 @@ describe "is_virtual fact" do
         Facter.fact(:virtual).stubs(:value).returns("openvzve")
         Facter.fact(:is_virtual).value.should == true
     end
+
+    it "should be true when running on kvm" do
+        Facter.fact(:virtual).stubs(:value).returns("kvm")
+        Facter.fact(:is_virtual).value.should == true
+    end
+
 end

-- 
Packaging of Facter for debian



More information about the Pkg-puppet-devel mailing list