summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2020-12-11 16:01:35 -0800
committerJakub Kicinski <kuba@kernel.org>2020-12-14 11:16:32 -0800
commit1994d044f44e8df9c55a489c4261245989c2e7b1 (patch)
tree2c21c0319f45838cc7074bd13a25a2b16e470d76
parentd02dbf3e45c147c714f498c662bab7b751dde833 (diff)
downloadohai-1994d044f44e8df9c55a489c4261245989c2e7b1.tar.gz
network: populate pause frame config
Query via ethtool and populate information whether the node has pause frames enabled or not. Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--lib/ohai/plugins/linux/network.rb25
-rw-r--r--spec/unit/plugins/linux/network_spec.rb18
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index e32c602c..5dfccd0c 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -273,6 +273,30 @@ Ohai.plugin(:Network) do
iface
end
+ # determine pause parameters for the interface using ethtool
+ def ethernet_pause_parameters(iface)
+ return iface unless ethtool_binary_path
+
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
+ so = shell_out("#{ethtool_binary_path} -a #{tmp_int}")
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
+ iface[tmp_int]["pause_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Pause parameters for")
+ next if line.strip.nil?
+
+ key, val = line.split(/:\s+/)
+ if val
+ pause_key = "#{key.downcase.tr(" ", "_")}"
+ iface[tmp_int]["pause_params"][pause_key] = val.strip.eql? "on"
+ end
+ end
+ end
+ iface
+ end
+
# determine driver info for the interface using ethtool
def ethernet_driver_info(iface)
return iface unless ethtool_binary_path
@@ -770,6 +794,7 @@ Ohai.plugin(:Network) do
iface = ethernet_channel_parameters(iface)
iface = ethernet_coalesce_parameters(iface)
iface = ethernet_driver_info(iface)
+ iface = ethernet_pause_parameters(iface)
counters[:network][:interfaces] = net_counters
network["interfaces"] = iface
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 744fafa8..c68f66f8 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -435,6 +435,16 @@ describe Ohai::System, "Linux Network Plugin" do
EOM
end
+ let(:linux_ethtool_a) do
+ <<~EOM
+ Pause parameters for eth0:
+ Autonegotiate: on
+ RX: off
+ TX: on
+
+ EOM
+ end
+
before do
allow(plugin).to receive(:collect_os).and_return(:linux)
@@ -452,6 +462,7 @@ describe Ohai::System, "Linux Network Plugin" do
allow(plugin).to receive(:shell_out).with(/ethtool -l/).and_return(mock_shell_out(0, linux_ethtool_l, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -c/).and_return(mock_shell_out(0, linux_ethtool_c, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -i/).and_return(mock_shell_out(0, linux_ethtool_i, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -a/).and_return(mock_shell_out(0, linux_ethtool_a, ""))
allow(plugin).to receive(:shell_out).with(/ethtool [^\-]/).and_return(mock_shell_out(0, linux_ethtool, ""))
end
@@ -698,6 +709,13 @@ describe Ohai::System, "Linux Network Plugin" do
end
+ it "detects the pause frame configuration of an ethernet interface" do
+ expect(plugin["network"]["interfaces"]["eth0"]["pause_params"]["autonegotiate"]).to eq(true)
+ expect(plugin["network"]["interfaces"]["eth0"]["pause_params"]["rx"]).to eq(false)
+ expect(plugin["network"]["interfaces"]["eth0"]["pause_params"]["tx"]).to eq(true)
+
+ end
+
it "detects the ipv4 addresses of the ethernet interface" do
expect(plugin["network"]["interfaces"]["eth0"]["addresses"].keys).to include("10.116.201.76")
expect(plugin["network"]["interfaces"]["eth0"]["addresses"]["10.116.201.76"]["netmask"]).to eq("255.255.255.0")