(#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.
Jeff McCune
10 years ago
7 | 7 |
when 'Linux'
|
8 | 8 |
ops = {
|
9 | 9 |
:ifconfig_opts => ['2>/dev/null'],
|
10 | |
:regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x,
|
|
10 |
:regex => %r{#{Facter.ipaddress}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
|
11 | 11 |
:munge => nil,
|
12 | 12 |
}
|
13 | 13 |
when 'SunOS'
|
|
0 |
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
|
|
1 |
inet 131.252.209.153 netmask 255.255.255.0 broadcast 192.168.76.255
|
|
2 |
inet6 2610:10:20:209:212:3fff:febe:2201 prefixlen 128 scopeid 0x0<global>
|
|
3 |
inet6 fe80::221:ccff:fe4b:297d prefixlen 64 scopeid 0x20<link>
|
|
4 |
ether 00:21:cc:4b:29:7d txqueuelen 1000 (Ethernet)
|
|
5 |
RX packets 27222144 bytes 31247414760 (29.1 GiB)
|
|
6 |
RX errors 0 dropped 0 overruns 0 frame 0
|
|
7 |
TX packets 10259038 bytes 7784519352 (7.2 GiB)
|
|
8 |
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
|
9 |
device interrupt 20 memory 0xd2600000-d2620000
|
|
10 |
|
|
11 |
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436
|
|
12 |
inet 127.0.0.1 netmask 255.0.0.0
|
|
13 |
inet6 ::1 prefixlen 128 scopeid 0x10<host>
|
|
14 |
loop txqueuelen 0 (Local Loopback)
|
|
15 |
RX packets 257371 bytes 37104110 (35.3 MiB)
|
|
16 |
RX errors 0 dropped 0 overruns 0 frame 0
|
|
17 |
TX packets 257371 bytes 37104110 (35.3 MiB)
|
|
18 |
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
|
0 |
eth0 Link encap:Ethernet HWaddr 42:01:0a:57:50:6e
|
|
1 |
inet addr:10.87.80.110 Bcast:10.87.80.110 Mask:255.255.255.255
|
|
2 |
UP BROADCAST RUNNING MULTICAST MTU:1460 Metric:1
|
|
3 |
RX packets:1609444 errors:0 dropped:0 overruns:0 frame:0
|
|
4 |
TX packets:1479569 errors:0 dropped:0 overruns:0 carrier:0
|
|
5 |
collisions:0 txqueuelen:1000
|
|
6 |
RX bytes:673812693 (673.8 MB) TX bytes:221186872 (221.1 MB)
|
|
7 |
|
|
8 |
lo Link encap:Local Loopback
|
|
9 |
inet addr:127.0.0.1 Mask:255.0.0.0
|
|
10 |
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
|
11 |
RX packets:5435415 errors:0 dropped:0 overruns:0 frame:0
|
|
12 |
TX packets:5435415 errors:0 dropped:0 overruns:0 carrier:0
|
|
13 |
collisions:0 txqueuelen:0
|
|
14 |
RX bytes:734540224 (734.5 MB) TX bytes:734540224 (734.5 MB)
|
|
15 |
|
2 | 2 |
require 'spec_helper'
|
3 | 3 |
require 'facter/util/ip'
|
4 | 4 |
|
5 | |
shared_examples_for "netmask from ifconfig output" do |platform, interface, address, fixture|
|
|
5 |
shared_examples_for "netmask_* from ifconfig output" do |platform, interface, address, fixture|
|
6 | 6 |
it "correctly on #{platform} interface #{interface}" do
|
7 | 7 |
Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
|
8 | 8 |
Facter::Util::IP.stubs(:get_output_for_interface_and_label).
|
|
40 | 40 |
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
41 | 41 |
end
|
42 | 42 |
|
43 | |
example_behavior_for "netmask from ifconfig output",
|
|
43 |
example_behavior_for "netmask_* from ifconfig output",
|
44 | 44 |
"Archlinux (net-tools 1.60)", "em1",
|
45 | 45 |
"255.255.255.0", "ifconfig_net_tools_1.60.txt"
|
46 | |
example_behavior_for "netmask from ifconfig output",
|
|
46 |
example_behavior_for "netmask_* from ifconfig output",
|
47 | 47 |
"Archlinux (net-tools 1.60)", "lo",
|
48 | 48 |
"255.0.0.0", "ifconfig_net_tools_1.60.txt"
|
49 | 49 |
end
|
|
0 |
#! /usr/bin/env ruby
|
|
1 |
|
|
2 |
require 'spec_helper'
|
|
3 |
require 'facter/util/ip'
|
|
4 |
|
|
5 |
shared_examples_for "netmask from ifconfig output" do |platform, address, fixture|
|
|
6 |
it "correctly on #{platform}" do
|
|
7 |
Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture))
|
|
8 |
Facter.collection.internal_loader.load(:netmask)
|
|
9 |
|
|
10 |
Facter.fact(:netmask).value.should eq(address)
|
|
11 |
end
|
|
12 |
end
|
|
13 |
|
|
14 |
RSpec.configure do |config|
|
|
15 |
config.alias_it_should_behave_like_to :example_behavior_for, "parses"
|
|
16 |
end
|
|
17 |
|
|
18 |
describe "netmask fact" do
|
|
19 |
before :each do
|
|
20 |
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
|
21 |
end
|
|
22 |
|
|
23 |
context "on Linux" do
|
|
24 |
example_behavior_for "netmask from ifconfig output",
|
|
25 |
"Archlinux (net-tools 1.60)", "255.255.255.0",
|
|
26 |
"ifconfig_net_tools_1.60.txt"
|
|
27 |
example_behavior_for "netmask from ifconfig output",
|
|
28 |
"Ubuntu 12.04", "255.255.255.255",
|
|
29 |
"ifconfig_ubuntu_1204.txt"
|
|
30 |
end
|
|
31 |
end
|