[Pkg-puppet-devel] [facter] 24/61: ip address fact that return full ifconfig output

Stig Sandbeck Mathisen ssm at debian.org
Mon Nov 4 15:01:51 UTC 2013


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

ssm pushed a commit to branch master
in repository facter.

commit 32fd13a5f645c2fe5cfe8e6146a8fbcb95230043
Author: Clément Demonchy <cdemonchy at figarocms.fr>
Date:   Thu Jul 11 18:25:21 2013 +0200

    ip address fact that return full ifconfig output
    
    On system with non english locale, the ip address fact return full ifconfig
    output.
---
 lib/facter/ipaddress.rb                              |    6 ++++--
 .../unit/ipaddress/ifconfig_non_english_locale.txt   |   18 ++++++++++++++++++
 spec/unit/ipaddress_spec.rb                          |    2 ++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index b4ce2e8..b9475fd 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -33,11 +33,13 @@ Facter.add(:ipaddress) do
       regexp = /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
       output.split("\n").each do |line|
         match = regexp.match(line)
-        if match
-          break match[1] unless /^127/.match(match[1])
+        if match and not /^127\./.match(match[1])
+          ip = match[1]
+          break
         end
       end
     end
+    ip
   end
 end
 
diff --git a/spec/fixtures/unit/ipaddress/ifconfig_non_english_locale.txt b/spec/fixtures/unit/ipaddress/ifconfig_non_english_locale.txt
new file mode 100644
index 0000000..b61bc95
--- /dev/null
+++ b/spec/fixtures/unit/ipaddress/ifconfig_non_english_locale.txt
@@ -0,0 +1,18 @@
+lo        Link encap:Boucle locale  
+          inet adr:127.0.0.1  Masque:255.0.0.0
+          adr inet6: ::1/128 Scope:Hote
+          UP LOOPBACK RUNNING  MTU:65536  Metric:1
+          RX packets:1001 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:1001 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 lg file transmission:0 
+          RX bytes:52562 (51.3 KiB)  TX bytes:52562 (51.3 KiB)
+
+wlan0     Link encap:Ethernet  HWaddr ac:81:12:2d:86:25  
+          inet adr:192.168.1.83  Bcast:192.168.1.255  Masque:255.255.255.0
+          adr inet6: fe80::ae81:12ff:fe2d:8625/64 Scope:Lien
+          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
+          RX packets:493220 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:390375 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 lg file transmission:1000 
+          RX bytes:569234568 (542.8 MiB)  TX bytes:69778980 (66.5 MiB)
+
diff --git a/spec/unit/ipaddress_spec.rb b/spec/unit/ipaddress_spec.rb
index 4332556..969437e 100755
--- a/spec/unit/ipaddress_spec.rb
+++ b/spec/unit/ipaddress_spec.rb
@@ -32,5 +32,7 @@ describe "The ipaddress fact" do
       "Linux with multiple loopback addresses",
       "10.0.222.20",
       "ifconfig_multiple_127_addresses.txt"
+    example_behavior_for "ifconfig output",
+      "Linux with non english locale", nil, "ifconfig_non_english_locale.txt"
   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