(#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.
Jeff McCune
10 years ago
7 | 7 | :ipaddress => /inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, |
8 | 8 | :ipaddress6 => /inet6 (?:addr: )?((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, |
9 | 9 | :macaddress => /(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})/, |
10 | :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, | |
10 | :netmask => /(?:Mask:|netmask )([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, | |
11 | 11 | :mtu => /MTU:(\d+)/ |
12 | 12 | }, |
13 | 13 | :bsd => { |
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 | 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 |
0 | lo: flags=73<UP,LOOPBACK,RUNNING> mtu 16436 | |
1 | inet 127.0.0.1 netmask 255.0.0.0 | |
2 | inet6 ::1 prefixlen 128 scopeid 0x10<host> | |
3 | loop txqueuelen 0 (Local Loopback) | |
4 | RX packets 257371 bytes 37104110 (35.3 MiB) | |
5 | RX errors 0 dropped 0 overruns 0 frame 0 | |
6 | TX packets 257371 bytes 37104110 (35.3 MiB) | |
7 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 | 1 | |
2 | 2 | require 'spec_helper' |
3 | 3 | require 'facter/util/ip' |
4 | ||
5 | shared_examples_for "netmask from ifconfig output" do |platform, interface, address, fixture| | |
6 | it "correctly on #{platform} interface #{interface}" do | |
7 | Facter::Util::IP.stubs(:exec_ifconfig).returns(my_fixture_read(fixture)) | |
8 | Facter::Util::IP.stubs(:get_output_for_interface_and_label). | |
9 | returns(my_fixture_read("#{fixture}.#{interface}")) | |
10 | Facter.collection.internal_loader.load(:interfaces) | |
11 | ||
12 | fact = Facter.fact("netmask_#{interface}".intern) | |
13 | fact.value.should eq(address) | |
14 | end | |
15 | end | |
16 | ||
17 | RSpec.configure do |config| | |
18 | config.alias_it_should_behave_like_to :example_behavior_for, "parses" | |
19 | end | |
4 | 20 | |
5 | 21 | describe "Per Interface IP facts" do |
6 | 22 | it "should replace the ':' in an interface list with '_'" do |
18 | 34 | Facter.fact(:interfaces).value.should == %{Local_Area_Connection,Loopback__Pseudo_Interface____1_} |
19 | 35 | end |
20 | 36 | end |
37 | ||
38 | describe "Netmask handling on Linux" do | |
39 | before :each do | |
40 | Facter.fact(:kernel).stubs(:value).returns("Linux") | |
41 | end | |
42 | ||
43 | example_behavior_for "netmask from ifconfig output", | |
44 | "Archlinux (net-tools 1.60)", "em1", | |
45 | "255.255.255.0", "ifconfig_net_tools_1.60.txt" | |
46 | example_behavior_for "netmask from ifconfig output", | |
47 | "Archlinux (net-tools 1.60)", "lo", | |
48 | "255.0.0.0", "ifconfig_net_tools_1.60.txt" | |
49 | end |