On 25 July 2010 23:50, Jiri Kubicek <jiri.kubi...@kraxnet.cz> wrote: > 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".
Looks good, as with other patch once I've had a chance to test will merge. Thanks Paul > > Signed-off-by: Jiri Kubicek <jiri.kubi...@kraxnet.cz> > --- > lib/facter/util/virtual.rb | 9 +++++---- > spec/unit/util/virtual.rb | 6 ++++++ > spec/unit/virtual.rb | 7 +++++++ > 3 files changed, 18 insertions(+), 4 deletions(-) > > 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 > -- > 1.6.4.3 > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to puppet-...@googlegroups.com. > To unsubscribe from this group, send email to > puppet-dev+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-...@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.