[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 51bcebe38cab6088c901f1006339bbe40a36d161
Jiri Kubicek
jiri.kubicek at kraxnet.cz
Wed Aug 18 05:55:55 UTC 2010
The following commit has been merged in the upstream branch:
commit faaa169d73e5132b7f2ea491461690324c1133ab
Author: Jiri Kubicek <jiri.kubicek at kraxnet.cz>
Date: Mon Jul 26 00:08:16 2010 +0200
Fix #4352 - Support for detecting KVM virtuals on FreeBSD
There was no support for detecting FreeBSD running in KVM as a virtual in facter. This patch detects KVM by getting "hw.model" kernel state via sysctl. Jails running in KVM are also correctly detected as "jail" not "kvm".
Signed-off-by: Jiri Kubicek <jiri.kubicek at kraxnet.cz>
diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb
index 900375f..2d18c33 100644
--- a/lib/facter/util/virtual.rb
+++ b/lib/facter/util/virtual.rb
@@ -43,11 +43,12 @@ module Facter::Util::Virtual
end
def self.kvm?
- if FileTest.exists?("/proc/cpuinfo")
- txt = File.read("/proc/cpuinfo")
- return true if txt =~ /QEMU Virtual CPU/
+ txt = if FileTest.exists?("/proc/cpuinfo")
+ File.read("/proc/cpuinfo")
+ elsif Facter.value(:kernel)=="FreeBSD"
+ Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
end
- return false
+ (txt =~ /QEMU Virtual CPU/) ? true : false
end
def self.kvm_type
diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb
index f1ccf1e..5b59cf9 100644
--- a/spec/unit/util/virtual.rb
+++ b/spec/unit/util/virtual.rb
@@ -100,6 +100,12 @@ describe Facter::Util::Virtual do
Facter::Util::Virtual.should be_kvm
end
+ it "should detect kvm on FreeBSD" do
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
+ Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4")
+ Facter::Util::Virtual.should be_kvm
+ end
+
it "should identify FreeBSD jail when in jail" do
Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1")
Facter::Util::Virtual.should be_jail
diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb
index 311001d..8ee843b 100644
--- a/spec/unit/virtual.rb
+++ b/spec/unit/virtual.rb
@@ -17,6 +17,13 @@ describe "Virtual fact" do
Facter.fact(:virtual).value.should == "zone"
end
+ it "should be jail on FreeBSD when a jail in kvm" do
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
+ Facter::Util::Virtual.stubs(:jail?).returns(true)
+ Facter::Util::Virtual.stubs(:kvm?).returns(true)
+ Facter.fact(:virtual).value.should == "jail"
+ end
+
end
describe "is_virtual fact" do
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list