diff options
author | Tim Smith <tsmith@chef.io> | 2020-12-23 12:45:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-23 12:45:12 -0800 |
commit | e90cf868c51c1104aecdadfe3b9c92309c3df222 (patch) | |
tree | d5aabc2e1d10c8eb8e1e9a23481e602872b7d4ea | |
parent | e1b27c497fb3409d7dab49fbf115c8b0a70c1403 (diff) | |
parent | 1994d044f44e8df9c55a489c4261245989c2e7b1 (diff) | |
download | ohai-e90cf868c51c1104aecdadfe3b9c92309c3df222.tar.gz |
Merge pull request #1564 from kuba-moo/network-pause-cfg
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 25 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 18 |
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") |