Skip to content

Commit

Permalink
(FACT-2072) Update the regex to get Infiniband MAC and IP address on …
Browse files Browse the repository at this point in the history
…CentOS 7.x platform (#1838)

* Update ip.rb

* Update RegEx for finding MAC and IP addresses from ifconfig on CentOS 7.x

* (FACT-2072) Added test to test new RegEx.

* Reverting an unnecessary change
  • Loading branch information
raj76 authored and GabrielNagy committed Oct 22, 2019
1 parent 8ff0fac commit bd4015d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facter/util/ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def self.get_single_interface_output(interface)
ifconfig_output = Facter::Util::IP.ifconfig_interface(interface)
if interface =~ /^ib/ then
real_mac_address = get_infiniband_macaddress(interface)
output = ifconfig_output.sub(%r{(?:ether|HWaddr)\s+((\w{1,2}:){5,}\w{1,2})}, "HWaddr #{real_mac_address}")
output = ifconfig_output.sub(%r{(?:ether|HWaddr|infiniband)\s+((\w{1,2}:){5,}\w{1,2})}, "HWaddr #{real_mac_address}")
else
output = ifconfig_output
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ib0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 2044
inet 10.55.200.50 netmask 255.255.0.0 broadcast 10.55.255.255
Infiniband hardware address can be incorrect! Please read BUGS section in ifconfig(8).
HWaddr 80:00:00:03:fe:80:00:00:00:00:00:00:00:11:75:00:00:6f:02:fe txqueuelen 256 (InfiniBand)
RX packets 26603237 bytes 15921365732 (14.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22735277 bytes 4196650455 (3.9 GiB)
TX errors 0 dropped 2 overruns 0 carrier 0 collisions 0
8 changes: 8 additions & 0 deletions spec/fixtures/unit/util/ip/linux_ifconfig_ib0_centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ib0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 2044
inet 10.55.200.50 netmask 255.255.0.0 broadcast 10.55.255.255
Infiniband hardware address can be incorrect! Please read BUGS section in ifconfig(8).
infiniband 80:00:00:03:FE:80:00:00:00:00:00:00:00:00:00:00:00:00:00:00 txqueuelen 256 (InfiniBand)
RX packets 26603237 bytes 15921365732 (14.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22735277 bytes 4196650455 (3.9 GiB)
TX errors 0 dropped 2 overruns 0 carrier 0 collisions 0
20 changes: 20 additions & 0 deletions spec/unit/util/ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@
Facter::Util::IP.get_single_interface_output("ib0").should == correct_ifconfig_interface
end

it "should return correct macaddress information for infiniband on Linux CentOS 7" do
correct_ifconfig_interface = my_fixture_read("linux_get_single_interface_ib0_centos7")

Facter::Util::IP.expects(:get_single_interface_output).with("ib0").returns(correct_ifconfig_interface)
Facter.stubs(:value).with(:kernel).returns("Linux")

Facter::Util::IP.get_interface_value("ib0", "macaddress").should == "80:00:00:03:fe:80:00:00:00:00:00:00:00:11:75:00:00:6f:02:fe"
end

it "should replace the incorrect macaddress with the correct macaddress in ifconfig for infiniband on Linux CentOS 7" do
ifconfig_interface = my_fixture_read("linux_ifconfig_ib0_centos7")
correct_ifconfig_interface = my_fixture_read("linux_get_single_interface_ib0_centos7")

Facter::Util::IP.expects(:get_infiniband_macaddress).with("ib0").returns("80:00:00:03:fe:80:00:00:00:00:00:00:00:11:75:00:00:6f:02:fe")
Facter::Util::IP.expects(:ifconfig_interface).with("ib0").returns(ifconfig_interface)
Facter.stubs(:value).with(:kernel).returns("Linux")

Facter::Util::IP.get_single_interface_output("ib0").should == correct_ifconfig_interface
end

it "should return fake macaddress information for infiniband on Linux when neither sysfs or /sbin/ip are available" do
ifconfig_interface = my_fixture_read("linux_ifconfig_ib0")

Expand Down

0 comments on commit bd4015d

Please sign in to comment.