Added osfamily fact to determine if a given operating system is a derivative of a common operating system.
Signed-off-by: Adrien Thebo <adr...@puppetlabs.com> --- Local-branch: ticket/master/6792 lib/facter/osfamily.rb | 27 +++++++++++++++++++++++++++ spec/unit/osfamily_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 lib/facter/osfamily.rb create mode 100755 spec/unit/osfamily_spec.rb diff --git a/lib/facter/osfamily.rb b/lib/facter/osfamily.rb new file mode 100644 index 0000000..b43cce5 --- /dev/null +++ b/lib/facter/osfamily.rb @@ -0,0 +1,27 @@ +# Fact: osfamily +# +# Purpose: Returns the operating system +# +# Resolution: +# On Redhat and derivatives, returns redhat +# On Debian and derivatives, returns debian +# On SuSE and derivatives, returns suse +# Else, falls back to the kernel +# +# Caveats: +# + +Facter.add(:osfamily) do + + setcode do + if FileTest.exists?("/etc/redhat-release") + "redhat" + elsif FileTest.exists?("/etc/debian_version") + "debian" + elsif FileTest.exists?("/etc/SuSE-version") + "suse" + else + Facter.value("kernel") + end + end +end diff --git a/spec/unit/osfamily_spec.rb b/spec/unit/osfamily_spec.rb new file mode 100755 index 0000000..b8c10d6 --- /dev/null +++ b/spec/unit/osfamily_spec.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +require 'facter' + +describe "Operating system family facts" do + it "should return redhat on redhat based systems" do + FileTest.stubs(:exists?).returns(false) + FileTest.stubs(:exists?).once.with("/etc/redhat-release").returns(true) + Facter.fact("osfamily").value.should == "redhat" + end + + it "should return redhat on redhat based systems" do + FileTest.stubs(:exists?).returns(false) + FileTest.stubs(:exists?).once.with("/etc/debian_version").returns(true) + Facter.fact("osfamily").value.should == "debian" + end + + it "should return suse on SuSE based systems" do + FileTest.stubs(:exists?).returns(false) + FileTest.stubs(:exists?).once.with("/etc/SuSE-version").returns(true) + Facter.fact("osfamily").value.should == "suse" + end + + it "should fall back to the kernel if no family was specified" do + FileTest.stubs(:exists?).returns(false) + Facter.stubs("value").with("kernel").returns("dummy") + + Facter.fact("osfamily").value.should == "dummy" + end +end -- 1.7.4.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@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.