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     |   24 ++++++++++++++++++++++++
 spec/unit/osfamily_spec.rb |   26 ++++++++++++++++++++++++++
 2 files changed, 50 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..fb23af4
--- /dev/null
+++ b/lib/facter/osfamily.rb
@@ -0,0 +1,24 @@
+# Fact: osfamily
+#
+# Purpose: Returns the operating system
+#
+# Resolution:
+#   On Redhat and derivatives, returns redhat
+#   On Debian and derivatives, returns debian
+#   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"
+    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..dd8e73e
--- /dev/null
+++ b/spec/unit/osfamily_spec.rb
@@ -0,0 +1,26 @@
+#!/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 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.

Reply via email to