[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, experimental_upstream, updated. 1.5.9-54-g5a4eeed

Nick Lewis nick at puppetlabs.com
Wed Jun 22 08:51:54 UTC 2011

The following commit has been merged in the experimental_upstream branch:
commit 2255abee7bdb9b6478ca228546e3d275dbac0ec3
Author: Nick Lewis <nick at puppetlabs.com>
Date:   Tue May 31 13:14:18 2011 -0700

    (#7670) Never fail to find a fact that is present
    With the previous behavior, any fact which depended on another fact in a file
    not matching its name would fail to properly load the required fact, resulting
    in missing, incorrect, or inconsistent values.
    For instance, the operatingsystem fact depends on the lsbdistid fact found in
    lsb.rb. The first time the operatingsystem fact is requested, it requires
    lsb.rb, and so the required fact is loaded first. But if Facter is subsequently
    cleared and the operatingsystem fact requested again, the require will not
    occur, and the fact will not be automatically loaded because it doesn't match
    its filename.
    Now if a fact is requested and can't be found, we will attempt to load all the
    facts to find it. Such an approach appears heavy-handed, but in the case where
    we want a particular fact, this is the only way to make sure we've found it. In
    the case where we eventually want other facts, we are conveniently eagerly
    loading them.
    Paired-With: Jacob Helwig <jacob at puppetlabs.com>

diff --git a/lib/facter/util/collection.rb b/lib/facter/util/collection.rb
index 3f8e0f8..b3d3a45 100644
--- a/lib/facter/util/collection.rb
+++ b/lib/facter/util/collection.rb
@@ -66,9 +66,13 @@ class Facter::Util::Collection
     def fact(name)
         name = canonize(name)
+        # Try to load the fact if necessary
         loader.load(name) unless @facts[name]
-        return @facts[name]
+        # Try HARDER
+        loader.load_all unless @facts[name]
+        @facts[name]
     # Flush all cached values.
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 28e7b72..483d4dc 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -18,6 +18,7 @@ RSpec.configure do |config|
   # Ensure that we don't accidentally cache between test cases.
   config.before :each do
+    Facter::Util::Loader.any_instance.stubs(:load_all)
diff --git a/spec/unit/interfaces_spec.rb b/spec/unit/interfaces_spec.rb
index 8b295d6..cfe4226 100755
--- a/spec/unit/interfaces_spec.rb
+++ b/spec/unit/interfaces_spec.rb
@@ -3,17 +3,14 @@
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 require 'facter'
+require 'facter/util/ip'
 describe "Per Interface IP facts" do
-    before do
-        Facter.loadfacts
-    end
     it "should replace the ':' in an interface list with '_'" do
         # So we look supported
-        Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2}
+        Facter::Util::IP.stubs(:get_interfaces).returns %w{eth0:1 eth1:2}
         Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2}
diff --git a/spec/unit/memory_spec.rb b/spec/unit/memory_spec.rb
index 5cae8cb..fe4ec36 100644
--- a/spec/unit/memory_spec.rb
+++ b/spec/unit/memory_spec.rb
@@ -6,7 +6,9 @@ require 'facter'
 describe "Memory facts" do
     before do
-        Facter.loadfacts
+        # We need these facts loaded, but they belong to a file with a
+        # different name, so load the file explicitly.
+        Facter.collection.loader.load(:memory)
     after do
diff --git a/spec/unit/operatingsystem_spec.rb b/spec/unit/operatingsystem_spec.rb
index 91cd311..9a7971d 100755
--- a/spec/unit/operatingsystem_spec.rb
+++ b/spec/unit/operatingsystem_spec.rb
@@ -34,6 +34,7 @@ describe "Operating System fact" do
     it "should identify Oracle VM as OVS" do
+        Facter.stubs(:value).with(:lsbdistid).returns(nil)
         FileTest.stubs(:exists?).returns false
         FileTest.expects(:exists?).with("/etc/ovs-release").returns true
@@ -44,6 +45,7 @@ describe "Operating System fact" do
     it "should identify VMWare ESX" do
+        Facter.stubs(:value).with(:lsbdistid).returns(nil)
         FileTest.stubs(:exists?).returns false
         FileTest.expects(:exists?).with("/etc/vmware-release").returns true
diff --git a/spec/unit/util/loader_spec.rb b/spec/unit/util/loader_spec.rb
index 90530e8..1bc909f 100755
--- a/spec/unit/util/loader_spec.rb
+++ b/spec/unit/util/loader_spec.rb
@@ -19,6 +19,10 @@ end
 describe Facter::Util::Loader do
+    before :each do
+        Facter::Util::Loader.any_instance.unstub(:load_all)
+    end
     def with_env(values)
         old = {}
         values.each do |var, value|

Packaging of Facter for debian

More information about the Pkg-puppet-devel mailing list