Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pkg
spec/fixtures/manifests
spec/fixtures/modules
.rspec_system
.ruby-version
.ruby-gemset
Gemfile.lock
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.4.5
- 2.5.3
script: bundle exec rake test
env:
- PUPPET_VERSION="~> 3.2.0"
Expand All @@ -17,6 +19,8 @@ env:
- PUPPET_VERSION="~> 3.7.0"
- PUPPET_VERSION="~> 3.8.0" STRICT_VARIABLES=no FUTURE_PARSER=no
- PUPPET_VERSION="~> 3.8.0" STRICT_VARIABLES=yes FUTURE_PARSER=yes
- PUPPET_VERSION="~> 5.0" STRICT_VARIABLES=yes
- PUPPET_VERSION="~> 6.0" STRICT_VARIABLES=yes

matrix:
exclude:
Expand All @@ -37,3 +41,10 @@ matrix:
env: PUPPET_VERSION="~> 3.3.0"
- rvm: 2.1.0
env: PUPPET_VERSION="~> 3.4.0"

# Ruby 2.4.5
- rvm: 2.4.5
env: PUPPET_VERSION="~> 5.0"
# Ruby 2.5.3
- rvm: 2.5.3
env: PUPPET_VERSION="~> 6.0"
38 changes: 38 additions & 0 deletions lib/facter/ethtool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def self.ethtool(interface)
%x{/usr/sbin/ethtool #{Shellwords.escape(interface)} 2>/dev/null}
end

# Run ethtool driver command
def self.ethtool_driver(interface)
%x{/usr/sbin/ethtool -i #{Shellwords.escape(interface)} 2>/dev/null}
end

# Get all interfaces on the system
def self.interfaces
Dir.foreach('/sys/class/net').reject{|x| x.start_with?('.', 'veth')}
Expand Down Expand Up @@ -40,9 +45,20 @@ def self.gather
max_speed = linkmodes && linkmodes.scan(/\d+/).map(&:to_i).max
metrics['max_speed'] = max_speed.to_i if max_speed

# Collect driver information
driver_data = {}
driver_output = ethtool_driver(interface).split("\n").each do |line|
k, v = line.split(': ')
if v
driver_data[k]=v
end
end
metrics['driver_data'] = driver_data

# Gather the interface statistics
next interfaces if metrics.empty?
interfaces[alphafy(interface)] = metrics

interfaces
end
end
Expand Down Expand Up @@ -84,6 +100,28 @@ def self.facts
end
end
end

# Expose driver data
ifstats.each do |interface, data|
next unless data['driver_data']['driver']
Facter.add('driver_' + interface) do
confine :kernel => 'Linux'
setcode do
# Backwards compatibility
data['driver_data']['driver'].to_s
end
end
end
ifstats.each do |interface, data|
next unless data['driver_data']['version']
Facter.add('driver_version' + interface) do
confine :kernel => 'Linux'
setcode do
# Backwards compatibility
data['driver_data']['version'].to_s
end
end
end
end

end
Expand Down
30 changes: 0 additions & 30 deletions lib/facter/interface_driver.rb

This file was deleted.

7 changes: 6 additions & 1 deletion spec/unit/facts/ethtool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@
Auto-negotiation: off
MDI-X: Unknown
Link detected: no')
expect(Ethtool::Facts.gather).to eq({'enp0s25'=>{'max_speed'=>1000},'vboxnet0'=>{'speed'=>10}})
expect(Ethtool::Facts.gather).to eq(
{
'enp0s25'=>{'max_speed'=>1000,'driver_data'=>{}},
'vboxnet0'=>{'speed'=>10,'driver_data'=>{}}
}
)
end
end

Expand Down