[Pkg-puppet-devel] [facter] 111/352: (fact-79) Enforce standard format for all macaddresses

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:36 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 7fd3d1fe802c7114aeceeee2851cb399f644a9bb
Author: Kylo Ginsberg <kylo at puppetlabs.com>
Date:   Mon Dec 23 15:25:18 2013 -0800

    (fact-79) Enforce standard format for all macaddresses
    
    Prior to this patch, the 'macaddress' fact was standardized,
    but the 'macaddress_<interface>' facts were not. This patch
    adds a spec test to catch this and the fix to use the same
    method for both.
---
 lib/facter/interfaces.rb     |  7 ++++++-
 spec/unit/interfaces_spec.rb | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb
index 4ace619..75706c7 100644
--- a/lib/facter/interfaces.rb
+++ b/lib/facter/interfaces.rb
@@ -15,6 +15,7 @@
 #
 
 require 'facter/util/ip'
+require 'facter/util/macaddress'
 
 # Note that most of this only works on a fixed list of platforms; notably, Darwin
 # is missing.
@@ -34,7 +35,11 @@ Facter::Util::IP.get_interfaces.each do |interface|
   %w{ipaddress ipaddress6 macaddress netmask mtu}.each do |label|
     Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do
       setcode do
-        Facter::Util::IP.get_interface_value(interface, label)
+        value = Facter::Util::IP.get_interface_value(interface, label)
+        if label == "macaddress"
+          value = Facter::Util::Macaddress.standardize(value)
+        end
+        value
       end
     end
   end
diff --git a/spec/unit/interfaces_spec.rb b/spec/unit/interfaces_spec.rb
index 41a7d66..1b244c5 100755
--- a/spec/unit/interfaces_spec.rb
+++ b/spec/unit/interfaces_spec.rb
@@ -31,6 +31,16 @@ describe "Per Interface IP facts" do
     Facter::Util::IP.stubs(:get_interfaces).returns ["Local Area Connection", "Loopback \"Pseudo-Interface\" (#1)"]
     Facter.fact(:interfaces).value.should == %{Local_Area_Connection,Loopback__Pseudo_Interface____1_}
   end
+
+  it "should properly format a mac address" do
+    Facter::Util::IP.stubs(:get_interfaces).returns ["net0"]
+    Facter::Util::IP.stubs(:get_interface_value).returns "0:12:34:56:78:90"
+
+    Facter.collection.internal_loader.load(:interfaces)
+
+    fact = Facter.fact("macaddress_net0".intern)
+    fact.value.should eq("00:12:34:56:78:90")
+  end
 end
 
 describe "Netmask handling on Linux" do

-- 
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