[Pkg-puppet-devel] [facter] 28/46: (#20229) Fix per-interface netmask_* facts with 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 d249246bf7ce1d9f0c8488e80713f37f7c66e25e
Author: Jeff McCune <jeff at puppetlabs.com>
Date: Wed Apr 17 23:53:47 2013 -0400
(#20229) Fix per-interface netmask_* facts with net-tools 1.60
Without this patch the interface specific facts for the netmask are not
correctly parsed on systems with net-tools 1.60 or later, such as
Archlinux.
This patch addresses the problem by adjusting the regular expression to
take into account the new format of the ifconfig command.
This patch is specific to the netmask_* facts and does not affect the
behavior of the general `netmask` fact.
---
lib/facter/util/ip.rb | 2 +-
.../unit/interfaces/ifconfig_net_tools_1.60.txt | 19 +++++++++++++
.../interfaces/ifconfig_net_tools_1.60.txt.em1 | 10 +++++++
.../unit/interfaces/ifconfig_net_tools_1.60.txt.lo | 8 ++++++
spec/unit/interfaces_spec.rb | 29 ++++++++++++++++++++
5 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 63e74bb..cb035e3 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -8,7 +8,7 @@ module Facter::Util::IP
:ipaddress => /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
:ipaddress6 => /inet6 (?:addr: )?((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
:macaddress => /(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})/,
- :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
+ :netmask => /(?:Mask:|netmask )([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
:mtu => /MTU:(\d+)/
},
:bsd => {
diff --git a/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt b/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt
new file mode 100644
index 0000000..dcfdaf1
--- /dev/null
+++ b/spec/fixtures/unit/interfaces/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/interfaces/ifconfig_net_tools_1.60.txt.em1 b/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.em1
new file mode 100644
index 0000000..e06be7f
--- /dev/null
+++ b/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.em1
@@ -0,0 +1,10 @@
+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
diff --git a/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.lo b/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.lo
new file mode 100644
index 0000000..6101930
--- /dev/null
+++ b/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.lo
@@ -0,0 +1,8 @@
+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/unit/interfaces_spec.rb b/spec/unit/interfaces_spec.rb
index 3798721..159d040 100755
--- a/spec/unit/interfaces_spec.rb
+++ b/spec/unit/interfaces_spec.rb
@@ -3,6 +3,22 @@
require 'spec_helper'
require 'facter/util/ip'
+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).
+ returns(my_fixture_read("#{fixture}.#{interface}"))
+ Facter.collection.internal_loader.load(:interfaces)
+
+ fact = Facter.fact("netmask_#{interface}".intern)
+ fact.value.should eq(address)
+ end
+end
+
+RSpec.configure do |config|
+ config.alias_it_should_behave_like_to :example_behavior_for, "parses"
+end
+
describe "Per Interface IP facts" do
it "should replace the ':' in an interface list with '_'" do
# So we look supported
@@ -19,3 +35,16 @@ describe "Per Interface IP facts" do
Facter.fact(:interfaces).value.should == %{Local_Area_Connection,Loopback__Pseudo_Interface____1_}
end
end
+
+describe "Netmask handling on Linux" do
+ before :each do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ end
+
+ 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",
+ "Archlinux (net-tools 1.60)", "lo",
+ "255.0.0.0", "ifconfig_net_tools_1.60.txt"
+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