[Pkg-puppet-devel] [facter] 95/180: (#21260) Add Cumulus Linux OS detection support

Stig Sandbeck Mathisen ssm at debian.org
Mon Jun 30 15:06:35 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 c0c7b504bcf069623464b1961849f1249ac5e869
Author: Matt Peterson <matt at cumulusnetworks.com>
Date:   Fri Jun 14 16:25:54 2013 -0700

    (#21260) Add Cumulus Linux OS detection support
---
 lib/facter/operatingsystem.rb               |  5 ++++-
 lib/facter/operatingsystemmajrelease.rb     |  3 ++-
 lib/facter/operatingsystemrelease.rb        | 11 +++++++++++
 lib/facter/osfamily.rb                      |  2 +-
 spec/unit/operatingsystem_spec.rb           |  8 ++++++++
 spec/unit/operatingsystemmajrelease_spec.rb |  2 +-
 spec/unit/operatingsystemrelease_spec.rb    |  7 +++++++
 7 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb
index 20f6feb..6f304ec 100644
--- a/lib/facter/operatingsystem.rb
+++ b/lib/facter/operatingsystem.rb
@@ -34,7 +34,10 @@ end
 Facter.add(:operatingsystem) do
   confine :kernel => :linux
   setcode do
-    if Facter.value(:lsbdistid) == "Ubuntu"
+    if FileTest.exists?("/etc/os-release")
+      match = File.read('/etc/os-release').match /^NAME=["']?(.+?)["']?$/
+      match[1].gsub(/[^a-zA-Z]/, '')
+    elsif Facter.value(:lsbdistid) == "Ubuntu"
        "Ubuntu"
     elsif FileTest.exists?("/etc/debian_version")
       "Debian"
diff --git a/lib/facter/operatingsystemmajrelease.rb b/lib/facter/operatingsystemmajrelease.rb
index f058a9f..03d588b 100644
--- a/lib/facter/operatingsystemmajrelease.rb
+++ b/lib/facter/operatingsystemmajrelease.rb
@@ -29,7 +29,8 @@ Facter.add(:operatingsystemmajrelease) do
     :OVS,
     :RedHat,
     :Scientific,
-    :SLC
+    :SLC,
+    :CumulusLinux
   ]
   setcode do
     Facter.value('operatingsystemrelease').split('.').first
diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb
index 8d94ffc..3b9c21f 100644
--- a/lib/facter/operatingsystemrelease.rb
+++ b/lib/facter/operatingsystemrelease.rb
@@ -72,6 +72,17 @@ Facter.add(:operatingsystemrelease) do
 end
 
 Facter.add(:operatingsystemrelease) do
+confine :operatingsystem => 'CumulusLinux'
+  setcode do
+    if release = Facter::Util::FileRead.read('/etc/os-release')
+      if match = release.match(/VERSION_ID=["']?(.+?)["']?$/)
+        match[1]
+      end
+    end
+  end
+end
+
+Facter.add(:operatingsystemrelease) do
   confine :operatingsystem => %w{SLES SLED OpenSuSE}
   setcode do
     if release = Facter::Util::FileRead.read('/etc/SuSE-release')
diff --git a/lib/facter/osfamily.rb b/lib/facter/osfamily.rb
index 6162ef8..f7008c1 100644
--- a/lib/facter/osfamily.rb
+++ b/lib/facter/osfamily.rb
@@ -18,7 +18,7 @@ Facter.add(:osfamily) do
     case Facter.value(:operatingsystem)
     when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon", "XenServer"
       "RedHat"
-    when "Ubuntu", "Debian"
+    when "Ubuntu", "Debian", "CumulusLinux"
       "Debian"
     when "SLES", "SLED", "OpenSuSE", "SuSE"
       "Suse"
diff --git a/spec/unit/operatingsystem_spec.rb b/spec/unit/operatingsystem_spec.rb
index 97236c9..0b64935 100755
--- a/spec/unit/operatingsystem_spec.rb
+++ b/spec/unit/operatingsystem_spec.rb
@@ -138,4 +138,12 @@ describe "Operating System fact" do
       Facter.fact(:operatingsystem).value.should == "SLC"
     end
   end
+    describe "on Cumulus Linux" do
+      it "should identify as 'Cumulus Linux'" do
+        Facter.fact(:kernel).stubs(:value).returns("Linux")
+        FileTest.expects(:exists?).with("/etc/os-release").returns true
+        File.expects(:read).with("/etc/os-release").returns 'NAME="Cumulus Linux"'
+        Facter.fact(:operatingsystem).value.should == "CumulusLinux"
+      end
+    end
 end
diff --git a/spec/unit/operatingsystemmajrelease_spec.rb b/spec/unit/operatingsystemmajrelease_spec.rb
index 9973b23..04e89b1 100644
--- a/spec/unit/operatingsystemmajrelease_spec.rb
+++ b/spec/unit/operatingsystemmajrelease_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
 require 'facter'
 
 describe "OS Major Release fact" do
-  ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC'].each do |operatingsystem|
+  ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC','CumulusLinux'].each do |operatingsystem|
     context "on #{operatingsystem} operatingsystems" do
       it "should be derived from operatingsystemrelease" do
         Facter.fact(:kernel).stubs(:value).returns("Linux")
diff --git a/spec/unit/operatingsystemrelease_spec.rb b/spec/unit/operatingsystemrelease_spec.rb
index 93c4c87..8acfdcf 100755
--- a/spec/unit/operatingsystemrelease_spec.rb
+++ b/spec/unit/operatingsystemrelease_spec.rb
@@ -225,4 +225,11 @@ describe "Operating System Release fact" do
       Facter.fact(:operatingsystemrelease).value.should == "10.04"
     end
   end
+
+  it "for Cumulus Linux" do
+    Facter.fact(:kernel).stubs(:value).returns("Linux")
+    Facter.fact(:operatingsystem).stubs(:value).returns("CumulusLinux")
+    File.expects(:read).with("/etc/os-release").returns("VERSION_ID=1.5.0")
+    Facter.fact(:operatingsystemrelease).value.should == "1.5.0"
+  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