summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@chef.io>2015-12-22 17:47:48 -0800
committerBryan McLellan <btm@chef.io>2015-12-22 17:48:21 -0800
commit230372117754675f52338bc2727e6beceb9a31f1 (patch)
tree04323788af3eb10e536dc34b5905caf20b6b77ea
parent2497fd9571b6ffb3f16182838fb2fc6e3c8b0c08 (diff)
downloadohai-230372117754675f52338bc2727e6beceb9a31f1.tar.gz
Fix tests for ipv6-only macaddress use case, add more debug logs
-rw-r--r--lib/ohai/plugins/linux/network.rb17
-rw-r--r--spec/unit/plugins/linux/network_spec.rb11
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 7aba7943..484f8621 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -308,6 +308,11 @@ Ohai.plugin(:Network) do
end
end
+ # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
+ def get_mac_for_interface(interfaces, interface)
+ interfaces[interface][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless interfaces[interface][:flags].include? "NOARP"
+ end
+
collect_data(:linux) do
require 'ipaddr'
@@ -407,16 +412,22 @@ Ohai.plugin(:Network) do
]
end.first
-
if route && !route.empty?
- macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP"
if family[:name] == "inet"
ipaddress route[:src]
+ m = get_mac_for_interface(iface, route[:dev])
+ Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{route[:dev]}") if macaddress
+ macaddress m
else
ip6address route[:src]
+ if macaddress
+ Ohai::Log.debug("Not setting macaddress from ipv6 interface #{route[:dev]} because macaddress is already set")
+ else
+ macaddress get_mac_for_interface(iface, route[:dev])
+ end
end
else
- macaddress iface[default_route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[default_route[:dev]][:flags].include? "NOARP"
+ Ohai::Log.debug("Unable to determine ideal default route, not setting ipaddress/ip6address/macaddress. Should have considered #{default_route[:dev]}?")
end
end
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index c1c6e065..99e9d7cd 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -834,12 +834,13 @@ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
expect(plugin['macaddress']).to eq("12:31:3D:02:BE:A2")
end
- describe "when then interface has the NOARP flag" do
+ context "when then ipv4 interface has the NOARP flag and no ipv6 routes exist" do
let(:linux_ip_route) {
'10.118.19.1 dev tun0 proto kernel src 10.118.19.39
default via 172.16.19.1 dev tun0
'
}
+ let(:linux_ip_route_inet6) { '' }
it "completes the run" do
expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
@@ -858,6 +859,14 @@ default via 172.16.19.1 dev tun0
plugin.run
expect(plugin['ip6address']).to eq("1111:2222:3333:4444::3")
end
+
+ context "with only ipv6 routes" do
+ let(:linux_ip_route) { '' }
+
+ it "sets macaddress to the mac address of the ip6 default interface" do
+ expect(plugin['macaddress']).to eq("00:AA:BB:CC:DD:EE")
+ end
+ end
end
describe "with a link level default route" do