[Pkg-puppet-devel] [facter] 66/180: (FACT-466) Make kernelmajversion useful in FreeBSD

Stig Sandbeck Mathisen ssm at debian.org
Mon Jun 30 15:06:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit be9b62b823706aa549cb3b4f6038d0f05a13a9d8
Author: Ryan Langseth <ryan.langseth at gmail.com>
Date:   Fri Feb 7 23:33:51 2014 -0600

    (FACT-466) Make kernelmajversion useful in FreeBSD
    
    FreeBSD has used a 2-element release number since before 3.0. The
    current kernalmajversion returns the first two elements of
    kernelversion, which is exactly the same as kernelversion on FreeBSD.
    This fact now returns just the first element when on FreeBSD.
---
 lib/facter/kernelmajversion.rb     |  8 ++++++++
 spec/unit/kernelmajversion_spec.rb | 23 ++++++++++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb
index f7302d4..641f1e7 100644
--- a/lib/facter/kernelmajversion.rb
+++ b/lib/facter/kernelmajversion.rb
@@ -4,6 +4,7 @@
 #
 # Resolution:
 #   Takes the first 2 elements of the kernel version as delimited by periods.
+#   Takes the first element of the kernel version on FreeBSD
 #
 # Caveats:
 #
@@ -13,3 +14,10 @@ Facter.add("kernelmajversion") do
     Facter.value(:kernelversion).split('.')[0..1].join('.')
   end
 end
+
+Facter.add("kernelmajversion") do
+  confine :kernel => :FreeBSD
+  setcode do
+    Facter.value(:kernelversion).split('.')[0]
+  end
+end
diff --git a/spec/unit/kernelmajversion_spec.rb b/spec/unit/kernelmajversion_spec.rb
old mode 100644
new mode 100755
index 426a87c..f63d712
--- a/spec/unit/kernelmajversion_spec.rb
+++ b/spec/unit/kernelmajversion_spec.rb
@@ -3,15 +3,20 @@
 require 'spec_helper'
 
 describe "Kernel major version fact" do
-  
-  before do 
-    Facter.fact(:kernelversion).stubs(:value).returns("12.34.56")
-  end 
-  
-  it "should return the kernel major release using the kernel release" do 
-    Facter.fact(:kernelmajversion).value.should == "12.34"
-  end 
-end 
+  context "when the kernelrelease fact contains three components" do
+    it "returns the first two components" do
+      Facter.fact(:kernelversion).stubs(:value).returns("12.34.56")
 
+      Facter.fact(:kernelmajversion).value.should == "12.34"
+    end
+  end
 
+  context "when the kernelrelease fact only contains two components" do
+    it "returns the first component" do
+      Facter.fact(:kernel).stubs(:value).returns('FreeBSD')
+      Facter.fact(:kernelversion).stubs(:value).returns("9.2")
 
+      Facter.fact(:kernelmajversion).value.should == "9"
+    end
+  end
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list