summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2015-12-21 16:09:17 -0800
committerTim Smith <tsmith84@gmail.com>2015-12-21 18:00:13 -0800
commit2497fd9571b6ffb3f16182838fb2fc6e3c8b0c08 (patch)
tree055ece5278ed6da46f2532ba9d537af5dc60ca91
parentaaea7427db86079d16e6f9ddcd43bfaaf93543aa (diff)
downloadohai-2497fd9571b6ffb3f16182838fb2fc6e3c8b0c08.tar.gz
Update comments and revert test
-rw-r--r--lib/ohai/plugins/network.rb31
-rw-r--r--spec/unit/plugins/linux/network_spec.rb4
-rw-r--r--spec/unit/plugins/network_spec.rb4
3 files changed, 19 insertions, 20 deletions
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 756fa139..42858d24 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -26,10 +26,10 @@ Ohai.plugin(:NetworkAddresses) do
depends "network/interfaces"
- # from interf data create array of hashes with ipaddress, scope, and iface
- # sorted by scope, prefixlen and then ip address where longest prefixes first
+ # from interface data create array of hashes with ipaddress, scope, and iface
+ # sorted by scope, prefixlen and then ipaddress where longest prefixes first
def sorted_ips(family = "inet")
- raise "bad family #{family}" unless [ "inet", "inet6" ].include? family
+ fail "bad family #{family}" unless %w(inet inet6).include? family
# priority of ipv6 link scopes to sort by later
scope_prio = [ "global", "site", "link", "host", "node", nil ]
@@ -59,7 +59,7 @@ Ohai.plugin(:NetworkAddresses) do
end
# finds ip address / interface for interface with default route based on
- # passed in family. returns [ipaddress, interface] uses 1st ip if no default
+ # passed in family. returns [ipaddress, interface] uses 1st ip if no default
# route is found
def find_ip(family = "inet")
ips = sorted_ips(family)
@@ -120,10 +120,10 @@ Ohai.plugin(:NetworkAddresses) do
r.nil? || r.first.nil? ? nil : r.first.first
end
+ # address_to_match: String
+ # ipaddress: IPAddress
+ # iface: String
def network_contains_address(address_to_match, ipaddress, iface)
- # address_to_match: String
- # ipaddress: IPAddress
- # iface: String
if peer = network["interfaces"][iface]["addresses"][ipaddress.to_s][:peer]
IPAddress(peer) == IPAddress(address_to_match)
else
@@ -135,7 +135,6 @@ Ohai.plugin(:NetworkAddresses) do
# #{os}::network plugin. atm it is expected macaddress is set at the same
# time as ipaddress. if ipaddress is set and macaddress is nil, that means
# the interface ipaddress is bound to has the NOARP flag
-
collect_data do
results = {}
@@ -144,14 +143,14 @@ Ohai.plugin(:NetworkAddresses) do
counters Mash.new unless counters
counters[:network] = Mash.new unless counters[:network]
- # inet family is processed before inet6
+ # inet family is processed before inet6 to give ipv4 precedence
Ohai::Mixin::NetworkConstants::FAMILIES.keys.sort.each do |family|
r = {}
# find the ip/interface with the default route for this family
- ( r["ip"], r["iface"] ) = find_ip(family)
+ (r["ip"], r["iface"]) = find_ip(family)
r["mac"] = find_mac_from_iface(r["iface"]) unless r["iface"].nil?
# don't overwrite attributes if they've already been set by the "#{os}::network" plugin
- if family == "inet" and ipaddress.nil?
+ if (family == "inet") && ipaddress.nil?
if r["ip"].nil?
Ohai::Log.warn("unable to detect ipaddress")
# i don't issue this warning if r["ip"] exists and r["mac"].nil?
@@ -161,14 +160,14 @@ Ohai.plugin(:NetworkAddresses) do
ipaddress r["ip"]
macaddress r["mac"]
end
- elsif family == "inet6" and ip6address.nil?
+ elsif (family == "inet6") && ip6address.nil?
if r["ip"].nil?
Ohai::Log.debug("unable to detect ip6address")
else
ip6address r["ip"]
# don't overwrite macaddress set by "#{os}::network" plugin
- # and also
- if r["mac"] and macaddress.nil? and ( ipaddress.nil? || ipaddress == "127.0.0.1" )
+ # and also overwrite mac address from ipv4 loopback interface
+ if r["mac"] && macaddress.nil? && (ipaddress.nil? || ipaddress == "127.0.0.1")
Ohai::Log.debug("macaddress set to #{r["mac"]} from the ipv6 setup")
macaddress r["mac"]
end
@@ -177,8 +176,8 @@ Ohai.plugin(:NetworkAddresses) do
results[family] = r
end
- if results["inet"]["iface"] and results["inet6"]["iface"] and
- results["inet"]["iface"] != results["inet6"]["iface"]
+ if results["inet"]["iface"] && results["inet6"]["iface"] &&
+ (results["inet"]["iface"] != results["inet6"]["iface"])
Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]}), macaddress has been set using the ipaddress interface")
end
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 67cc1758..c1c6e065 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Caleb Tennis <caleb.tennis@gmail.com>
# Author:: Chris Read <chris.read@gmail.com>
-# Copyright:: Copyright (c) 2011 Opscode, Inc.
+# Copyright:: Copyright (c) 2011-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -798,7 +798,7 @@ default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:333
end
end
- describe "when there's a source field in a local route entry " do
+ describe "when there's a source field in a local route entry" do
let(:linux_ip_route) {
'10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb
index 8a71af47..4ea036cb 100644
--- a/spec/unit/plugins/network_spec.rb
+++ b/spec/unit/plugins/network_spec.rb
@@ -388,10 +388,10 @@ describe Ohai::System, "Network Plugin" do
expect(@plugin["ip6address"]).to eq("3ffe:1111:3333::1")
end
- it "sets mac address to mac of eth1, skipping eth0 due to NOARP" do
+ it "doesn't set macaddress, ipv4 setup is valid and has precedence over ipv6" do
expect(Ohai::Log).not_to receive(:warn).with(/^unable to detect macaddress/)
@plugin.run
- expect(@plugin["macaddress"]).to eq("00:16:3E:2F:36:80")
+ expect(@plugin["macaddress"]).to be_nil
end
it "informs about this setup" do