[Pkg-puppet-devel] [facter] 29/46: (#20229) Fix netmask fact with Linux net-tools 1.60

Stig Sandbeck Mathisen ssm at debian.org
Sun Sep 1 10:47:31 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 928b7e8b3638a05ab17bf66eafdf740cc65f6fc1
Author: Jeff McCune <jeff at puppetlabs.com>
Date:   Thu Apr 18 16:11:08 2013 -0400

    (#20229) Fix netmask fact with Linux net-tools 1.60
    
    Without this patch the netmask fact does not return a value on Archlinux
    because of the new format of the net-tools package.
    
    This patch addresses the problem by updating the regular expressions for
    the netmask fact.  Both the old format and the new format are covered by
    the regular expression now.
---
 lib/facter/util/netmask.rb                         |    2 +-
 .../unit/netmask/ifconfig_net_tools_1.60.txt       |   19 ++++++++++++
 .../fixtures/unit/netmask/ifconfig_ubuntu_1204.txt |   16 ++++++++++
 spec/unit/interfaces_spec.rb                       |    6 ++--
 spec/unit/netmask_spec.rb                          |   32 ++++++++++++++++++++
 5 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb
index 4a6d03c..7f1d279 100644
--- a/lib/facter/util/netmask.rb
+++ b/lib/facter/util/netmask.rb
@@ -8,7 +8,7 @@ module Facter::NetMask
     when 'Linux'
       ops = {
         :ifconfig_opts => ['2>/dev/null'],
-        :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
+        :regex => %r{#{Facter.ipaddress}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
         :munge => nil,
       }
     when 'SunOS'
diff --git a/spec/fixtures/unit/netmask/ifconfig_net_tools_1.60.txt b/spec/fixtures/unit/netmask/ifconfig_net_tools_1.60.txt
new file mode 100644
index 0000000..dcfdaf1
--- /dev/null
+++ b/spec/fixtures/unit/netmask/ifconfig_net_tools_1.60.txt
@@ -0,0 +1,19 @@
+em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
+        inet 131.252.209.153  netmask 255.255.255.0  broadcast 192.168.76.255
+        inet6 2610:10:20:209:212:3fff:febe:2201  prefixlen 128  scopeid 0x0<global>
+        inet6 fe80::221:ccff:fe4b:297d  prefixlen 64  scopeid 0x20<link>
+        ether 00:21:cc:4b:29:7d  txqueuelen 1000  (Ethernet)
+        RX packets 27222144  bytes 31247414760 (29.1 GiB)
+        RX errors 0  dropped 0  overruns 0  frame 0
+        TX packets 10259038  bytes 7784519352 (7.2 GiB)
+        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
+        device interrupt 20  memory 0xd2600000-d2620000  
+
+lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 16436
+        inet 127.0.0.1  netmask 255.0.0.0
+        inet6 ::1  prefixlen 128  scopeid 0x10<host>
+        loop  txqueuelen 0  (Local Loopback)
+        RX packets 257371  bytes 37104110 (35.3 MiB)
+        RX errors 0  dropped 0  overruns 0  frame 0
+        TX packets 257371  bytes 37104110 (35.3 MiB)
+        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
diff --git a/spec/fixtures/unit/netmask/ifconfig_ubuntu_1204.txt b/spec/fixtures/unit/netmask/ifconfig_ubuntu_1204.txt
new file mode 100644
index 0000000..f2800cc
--- /dev/null
+++ b/spec/fixtures/unit/netmask/ifconfig_ubuntu_1204.txt
@@ -0,0 +1,16 @@
+eth0      Link encap:Ethernet  HWaddr 42:01:0a:57:50:6e  
+          inet addr:10.87.80.110  Bcast:10.87.80.110  Mask:255.255.255.255
+          UP BROADCAST RUNNING MULTICAST  MTU:1460  Metric:1
+          RX packets:1609444 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:1479569 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:1000 
+          RX bytes:673812693 (673.8 MB)  TX bytes:221186872 (221.1 MB)
+
+lo        Link encap:Local Loopback  
+          inet addr:127.0.0.1  Mask:255.0.0.0
+          UP LOOPBACK RUNNING  MTU:16436  Metric:1
+          RX packets:5435415 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:5435415 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:0 
+          RX bytes:734540224 (734.5 MB)  TX bytes:734540224 (734.5 MB)
+
diff --git a/spec/unit/interfaces_spec.rb b/spec/unit/interfaces_spec.rb
index 159d040..6def1c6 100755
--- a/spec/unit/interfaces_spec.rb
+++ b/spec/unit/interfaces_spec.rb
@@ -3,7 +3,7 @@
 require 'spec_helper'
 require 'facter/util/ip'
 
-shared_examples_for "netmask from ifconfig output" do |platform, interface, address, fixture|
+shared_examples_for "netmask_* from ifconfig output" do |platform, interface, address, fixture|
   it "correctly on #{platform} interface #{interface}" do
     Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
     Facter::Util::IP.stubs(:get_output_for_interface_and_label).
@@ -41,10 +41,10 @@ describe "Netmask handling on Linux" do
     Facter.fact(:kernel).stubs(:value).returns("Linux")
   end
 
-  example_behavior_for "netmask from ifconfig output",
+  example_behavior_for "netmask_* from ifconfig output",
     "Archlinux (net-tools 1.60)", "em1",
     "255.255.255.0", "ifconfig_net_tools_1.60.txt"
-  example_behavior_for "netmask from ifconfig output",
+  example_behavior_for "netmask_* from ifconfig output",
     "Archlinux (net-tools 1.60)", "lo",
     "255.0.0.0", "ifconfig_net_tools_1.60.txt"
 end
diff --git a/spec/unit/netmask_spec.rb b/spec/unit/netmask_spec.rb
new file mode 100644
index 0000000..dcbcfdd
--- /dev/null
+++ b/spec/unit/netmask_spec.rb
@@ -0,0 +1,32 @@
+#! /usr/bin/env ruby
+
+require 'spec_helper'
+require 'facter/util/ip'
+
+shared_examples_for "netmask from ifconfig output" do |platform, address, fixture|
+  it "correctly on #{platform}" do
+    Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
+    Facter.collection.internal_loader.load(:netmask)
+
+    Facter.fact(:netmask).value.should eq(address)
+  end
+end
+
+RSpec.configure do |config|
+  config.alias_it_should_behave_like_to :example_behavior_for, "parses"
+end
+
+describe "netmask fact" do
+  before :each do
+    Facter.fact(:kernel).stubs(:value).returns("Linux")
+  end
+
+  context "on Linux" do
+    example_behavior_for "netmask from ifconfig output",
+      "Archlinux (net-tools 1.60)", "255.255.255.0",
+      "ifconfig_net_tools_1.60.txt"
+    example_behavior_for "netmask from ifconfig output",
+      "Ubuntu 12.04", "255.255.255.255",
+      "ifconfig_ubuntu_1204.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