diff options
author | Phil Dibowitz <phil@ipom.com> | 2014-08-16 02:01:07 -0700 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2014-08-16 02:01:07 -0700 |
commit | 0bf2ed32744445a253082910ee4e07b2b38023a7 (patch) | |
tree | dc766fc3aa80d12251a1baf5bd0e1325ff1c8f16 | |
parent | 28dcc46ceae73b5ff22e72735db182ffa1e3a574 (diff) | |
parent | 5db8383fdcb88ad4b1f7f847e3577bb01cb9450c (diff) | |
download | ohai-0bf2ed32744445a253082910ee4e07b2b38023a7.tar.gz |
Merge pull request #390 from jaymzh/7-ecmp-routes
[Ohai 7] Add support for ECMP routes to linux::network
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | RELEASE_NOTES.md | 1 | ||||
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 17 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 7 |
4 files changed, 21 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e728e9a9..18da2c07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ Add Parallels Cloud Server (PCS) platform support. * [**Christian Vozar**](https://github.com/christianvozar): Add Go language plugin. +* [**Phil Dibowitz**](https://github.com/jaymzh): + linux::network should handle ECMP routes ## Last Release: 7.2.0 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 2ba50fae..115a759e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -29,5 +29,6 @@ populate the old system (role & system) with LXC if there are no other virtualiz * Ohai now collects mdadm RAID information. * Ohai know uses lsblk, if available, instead of blkid * linux::filesystem now reads all of /proc/mounts instead of just 4K +* linux::network now handles ECMP routes # Ohai Breaking Changes: diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 11d88673..3d80a057 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -200,12 +200,21 @@ Ohai.plugin(:Network) do # the routing table source field. # 3) and since we're at it, let's populate some :routes attributes # (going to do that for both inet and inet6 addresses) - so = shell_out("ip -f #{family[:name]} route show") + so = shell_out("ip -o -f #{family[:name]} route show") so.stdout.lines do |line| - if line =~ /^([^\s]+)\s(.*)$/ + line.strip! + Ohai::Log.debug("Parsing #{line}") + if line =~ /\\/ + parts = line.split('\\') + route_dest = parts.shift.strip + route_endings = parts + elsif line =~ /^([^\s]+)\s(.*)$/ route_dest = $1 - route_ending = $2 - # + route_endings = [$2] + else + next + end + route_endings.each do |route_ending| if route_ending =~ /\bdev\s+([^\s]+)\b/ route_int = $1 else diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index b92d5626..ae1dd348 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -31,8 +31,8 @@ def do_stubs @plugin.stub(:shell_out).with("ip -d -s link").and_return(mock_shell_out(0, @linux_ip_link_s_d, "")) @plugin.stub(:shell_out).with("ip -f inet neigh show").and_return(mock_shell_out(0, @linux_ip_neighbor_show, "")) @plugin.stub(:shell_out).with("ip -f inet6 neigh show").and_return(mock_shell_out(0, @linux_ip_inet6_neighbor_show, "")) - @plugin.stub(:shell_out).with("ip -f inet route show").and_return(mock_shell_out(0, @linux_ip_route, "")) - @plugin.stub(:shell_out).with("ip -f inet6 route show").and_return(mock_shell_out(0, @linux_ip_route_inet6, "")) + @plugin.stub(:shell_out).with("ip -o -f inet route show").and_return(mock_shell_out(0, @linux_ip_route, "")) + @plugin.stub(:shell_out).with("ip -o -f inet6 route show").and_return(mock_shell_out(0, @linux_ip_route_inet6, "")) @plugin.stub(:shell_out).with("route -n").and_return(mock_shell_out(0, @linux_route_n, "")) @plugin.stub(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @linux_ifconfig, "")) @plugin.stub(:shell_out).with("arp -an").and_return(mock_shell_out(0, @linux_arp_an, "")) @@ -245,6 +245,7 @@ NEIGHBOR_SHOW 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 +10.5.4.0/24 \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1 default via 10.116.201.1 dev eth0 IP_ROUTE_SCOPE @@ -555,6 +556,8 @@ ROUTE_N it "adds routes" do @plugin.run @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" ) + @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.1") + @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.2") @plugin['network']['interfaces']['foo:veth0@eth0']['routes'].should include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" ) @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" ) @plugin['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" ) |