[Pkg-puppet-devel] [facter] 97/180: (FACT-451) Only use /etc/os-release on Cumulus Linux

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 62ae435ebc6c7dd500cf28b49c83f15cb913af41
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Tue May 13 13:55:08 2014 -0700

    (FACT-451) Only use /etc/os-release on Cumulus Linux
    
    Without this commit the Cumulus Linux operatingsystem check always uses
    the contents of /etc/os-release to set the operatingsystem fact. This is
    backwards incompatible as this field may not resolve to the same value
    as the older detection. This commit adds a Cumulus Linux specific
    resolver that checks /etc/os-release early so it resolves before Debian,
    but only returns a value if the operatingsystem is Linux.
---
 lib/facter/operatingsystem.rb     | 21 +++++++++++++++++----
 spec/unit/operatingsystem_spec.rb | 19 +++++++++++--------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb
index 6f304ec..609ace9 100644
--- a/lib/facter/operatingsystem.rb
+++ b/lib/facter/operatingsystem.rb
@@ -11,6 +11,8 @@
 # Caveats:
 #
 
+require 'facter/util/operatingsystem'
+
 Facter.add(:operatingsystem) do
   confine :kernel => :sunos
   setcode do
@@ -32,12 +34,23 @@ Facter.add(:operatingsystem) do
 end
 
 Facter.add(:operatingsystem) do
+  # Cumulus Linux is a variant of Debian so this resolution needs to come
+  # before the Debian resolution.
+  has_weight(10)
+  confine :kernel => :linux
+
+  setcode do
+    release_info = Facter::Util::Operatingsystem.os_release
+    if release_info['NAME'] == "Cumulus Linux"
+      'CumulusLinux'
+    end
+  end
+end
+
+Facter.add(:operatingsystem) do
   confine :kernel => :linux
   setcode do
-    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"
+    if Facter.value(:lsbdistid) == "Ubuntu"
        "Ubuntu"
     elsif FileTest.exists?("/etc/debian_version")
       "Debian"
diff --git a/spec/unit/operatingsystem_spec.rb b/spec/unit/operatingsystem_spec.rb
index 0b64935..111b56c 100755
--- a/spec/unit/operatingsystem_spec.rb
+++ b/spec/unit/operatingsystem_spec.rb
@@ -137,13 +137,16 @@ describe "Operating System fact" do
       File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux CERN SLC 5.7 (Boron)")
       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
+
+    it "should identify Cumulus Linux" do
+      Facter::Util::Operatingsystem.expects(:os_release).returns({'NAME' => 'Cumulus Linux'})
+      Facter.fact(:operatingsystem).value.should == "CumulusLinux"
     end
+
+    it "should not use '/etc/os-release' on platforms other than Cumulus Linux" do
+      Facter::Util::Operatingsystem.expects(:os_release).returns({'NAME' => 'Debian GNU/Linux'})
+      FileTest.expects(:exists?).with('/etc/debian_version').returns true
+      Facter.fact(:operatingsystem).value.should == "Debian"
+    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