On 25 July 2010 23:50, Jiri Kubicek <jiri.kubi...@kraxnet.cz> wrote: > There was no support for detecting FreeBSD jails as a virtual in facter. This > patch detects jail by getting "security.jail.jailed" kernel state via sysctl.
Thanks, on a scan looks good, but I'll try test later today. Paul > > Signed-off-by: Jiri Kubicek <jiri.kubi...@kraxnet.cz> > --- > lib/facter/util/virtual.rb | 3 +++ > lib/facter/virtual.rb | 6 +++++- > spec/unit/util/virtual.rb | 10 ++++++++++ > spec/unit/virtual.rb | 6 ++++++ > 4 files changed, 24 insertions(+), 1 deletions(-) > > diff --git a/lib/facter/util/virtual.rb b/lib/facter/util/virtual.rb > index 80f4e2c..900375f 100644 > --- a/lib/facter/util/virtual.rb > +++ b/lib/facter/util/virtual.rb > @@ -57,5 +57,8 @@ module Facter::Util::Virtual > "kvm" > end > > + def self.jail? > + Facter::Util::Resolution.exec("/sbin/sysctl -n > security.jail.jailed") == "1" > + end > > end > diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb > index c6d0f22..c14a715 100644 > --- a/lib/facter/virtual.rb > +++ b/lib/facter/virtual.rb > @@ -38,6 +38,10 @@ Facter.add("virtual") do > result = Facter::Util::Virtual.kvm_type() > end > > + if Facter.value(:kernel)=="FreeBSD" > + result = "jail" if Facter::Util::Virtual.jail? > + end > + > if result == "physical" > output = Facter::Util::Resolution.exec('lspci') > if not output.nil? > @@ -76,7 +80,7 @@ Facter.add("is_virtual") do > > setcode do > case Facter.value(:virtual) > - when "xenu", "openvzve", "vmware", "kvm", "vserver" > + when "xenu", "openvzve", "vmware", "kvm", "vserver", "jail" > true > else > false > diff --git a/spec/unit/util/virtual.rb b/spec/unit/util/virtual.rb > index de339b8..f1ccf1e 100644 > --- a/spec/unit/util/virtual.rb > +++ b/spec/unit/util/virtual.rb > @@ -100,4 +100,14 @@ describe Facter::Util::Virtual do > 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 > + end > + > + it "should not identify FreeBSD jail when not in jail" do > + Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n > security.jail.jailed").returns("0") > + Facter::Util::Virtual.should_not be_jail > + end > + > end > diff --git a/spec/unit/virtual.rb b/spec/unit/virtual.rb > index 7dbd146..311001d 100644 > --- a/spec/unit/virtual.rb > +++ b/spec/unit/virtual.rb > @@ -55,4 +55,10 @@ describe "is_virtual fact" do > Facter.fact(:is_virtual).value.should == true > end > > + it "should be true when running in jail" do > + Facter.fact(:kernel).stubs(:value).returns("FreeBSD") > + Facter.fact(:virtual).stubs(:value).returns("jail") > + Facter.fact(:is_virtual).value.should == true > + end > + > end > -- > 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.