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
26 changes: 7 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,21 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.1.5
script: bundle exec rake test
env:
- PUPPET_VERSION="~> 3.2.0"
- PUPPET_VERSION="~> 3.3.0"
- PUPPET_VERSION="~> 3.4.0"
- PUPPET_VERSION="~> 3.5.0"
- PUPPET_VERSION="~> 3.6.0"
- 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="~> 3.8.7" STRICT_VARIABLES=no FUTURE_PARSER=no
- PUPPET_VERSION="~> 3.8.7" STRICT_VARIABLES=yes FUTURE_PARSER=yes
- PUPPET_VERSION="~> 4.10.0"

matrix:
exclude:
# Ruby 1.9.3
- rvm: 1.9.3
env: PUPPET_VERSION="~> 2.7.0"

env: PUPPET_VERSION="~> 4.10.0"
# Ruby 2.0.0
- rvm: 2.0.0
env: PUPPET_VERSION="~> 2.7.0"

env: PUPPET_VERSION="~> 4.10.0"
# Ruby 2.1.0
- rvm: 2.1.0
env: PUPPET_VERSION="~> 2.7.0"
- rvm: 2.1.0
env: PUPPET_VERSION="~> 3.2.0"
- rvm: 2.1.0
env: PUPPET_VERSION="~> 3.3.0"
- rvm: 2.1.0
env: PUPPET_VERSION="~> 3.4.0"
env: PUPPET_VERSION="~> 4.10.0"
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ group :test do
gem "rake"
gem "json", RUBY_VERSION == '1.9.3' && '< 2.0.0' || nil
gem "json_pure", RUBY_VERSION == '1.9.3' && '< 2.0.0' || nil
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0'
gem "puppet", ENV['PUPPET_VERSION']
gem "puppet-lint"
gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git'
gem "puppet-syntax"
gem "metadata-json-lint"
gem "puppetlabs_spec_helper"
gem "semantic_puppet"
end

group :development do
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ task :test => [
:syntax,
:lint,
:spec,
:metadata,
:metadata_lint,
]
51 changes: 27 additions & 24 deletions lib/facter/ethtool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def self.exists?
end

# Run ethtool on an interface
def self.ethtool(interface)
%x{/usr/sbin/ethtool #{Shellwords.escape(interface)} 2>/dev/null}
def self.ethtool(interface, option='')
%x{/usr/sbin/ethtool #{option} #{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')}
Dir.foreach('/sys/class/net').reject {|x| x.start_with?('.', 'veth')}
end

# Convert raw interface names into a canonical version
Expand All @@ -27,11 +27,12 @@ def self.alphafy str
def self.gather
interfaces.inject({}) do |interfaces, interface|
output = ethtool(interface)
output_i = ethtool(interface, '-i')

metrics = {}

# Extract the interface speed
speedline = output.split("\n").detect{|x| x.include?('Speed:')}
speedline = output.split("\n").detect {|x| x.include?('Speed:')}
speed = speedline && speedline.scan(/\d+/).first
metrics['speed'] = speed.to_i if speed

Expand All @@ -40,6 +41,14 @@ def self.gather
max_speed = linkmodes && linkmodes.scan(/\d+/).map(&:to_i).max
metrics['max_speed'] = max_speed.to_i if max_speed

# Extract the interface driver info
driver_line = output_i.match(/^driver:\s+(?<driver>.*)/)
metrics['driver'] = driver_line[:driver].to_s if driver_line

# Extract the interface driver info
driver_version_line = output_i.match(/^version:\s+(?<version>.*)/)
metrics['driver_version'] = driver_version_line[:version].to_s if driver_version_line

# Gather the interface statistics
next interfaces if metrics.empty?
interfaces[alphafy(interface)] = metrics
Expand All @@ -50,7 +59,7 @@ def self.gather
# Gather all facts
def self.facts
# Ethtool isn't installed, don't collect facts
return if ! exists?
return if !exists?

ifstats = gather

Expand All @@ -63,29 +72,23 @@ def self.facts
end

# Legacy facts
ifstats.each do |interface, data|
next unless data['speed']
Facter.add('speed_' + interface) do
confine :kernel => 'Linux'
setcode do
# Backwards compatibility
data['speed'].to_s
end
end
end

ifstats.each do |interface, data|
next unless data['max_speed']
Facter.add('maxspeed_' + interface) do
confine :kernel => 'Linux'
setcode do
# Backwards compatibility
data['max_speed'].to_s
['speed', 'maxspeed', 'driver', 'driver_version'].each do |fact_name|
ifstats.each do |interface, data|
next unless data[fact_name]
Facter.add("#{fact_name}_" + interface) do
confine :kernel => 'Linux'
setcode do
# Backwards compatibility
if fact_name == 'maxspeed'
data['max_speed'].to_s
else
data[fact_name].to_s
end
end
end
end
end
end

end
end

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

This file was deleted.

4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "bobtfish/ethtool",
"name": "bobtfish-ethtool",
"version": "0.0.7",
"author": "Tomas Doran",
"summary": "Manage ethernet interfaces with ethtool",
Expand All @@ -11,7 +11,7 @@
"dependencies": [
{
"name": "puppetlabs-stdlib",
"version_requirement": ">= 1.0.0"
"version_requirement": ">= 1.0.0 < 5.0.0"
}
],
"operatingsystem_support": [
Expand Down
22 changes: 22 additions & 0 deletions spec/fixtures/ethtool_outputs/enp0s25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Settings for enp0s25:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: Unknown!
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 2
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown (auto)
Current message level: 0x00000007 (7)
drv probe link
Link detected: no
10 changes: 10 additions & 0 deletions spec/fixtures/ethtool_outputs/i/ubuntuxenial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
driver: ath10k_pci
version: 4.4.0-77-generic
firmware-version: WLAN.RM.2.0-00180-QCARMSWPZ-1
expansion-rom-version:
bus-info: 0000:3a:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
16 changes: 16 additions & 0 deletions spec/fixtures/ethtool_outputs/vboxnet0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Settings for vboxnet0:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
MDI-X: Unknown
Link detected: no
56 changes: 17 additions & 39 deletions spec/unit/facts/ethtool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,23 @@
describe '#gather' do
it 'returns a hash of interfaces and their speeds' do
Ethtool::Facts.stubs(:interfaces).returns(['enp0s25', 'vboxnet0'])
Ethtool::Facts.stubs(:ethtool).with('enp0s25').returns('Settings for enp0s25:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: Unknown!
Duplex: Unknown! (255)
Port: Twisted Pair
PHYAD: 2
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown (auto)
Current message level: 0x00000007 (7)
drv probe link
Link detected: no')
Ethtool::Facts.stubs(:ethtool).with('vboxnet0').returns('Settings for vboxnet0:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
MDI-X: Unknown
Link detected: no')
expect(Ethtool::Facts.gather).to eq({'enp0s25'=>{'max_speed'=>1000},'vboxnet0'=>{'speed'=>10}})
Ethtool::Facts.stubs(:ethtool).with('enp0s25').
returns(IO.read("#{File.dirname(__FILE__)}/../../fixtures/ethtool_outputs/enp0s25.txt"))
Ethtool::Facts.stubs(:ethtool).with('enp0s25', '-i').
returns(IO.read("#{File.dirname(__FILE__)}/../../fixtures/ethtool_outputs/i/ubuntuxenial.txt"))
Ethtool::Facts.stubs(:ethtool).with('vboxnet0').
returns(IO.read("#{File.dirname(__FILE__)}/../../fixtures/ethtool_outputs/vboxnet0.txt"))
Ethtool::Facts.stubs(:ethtool).with('vboxnet0', '-i').
returns(IO.read("#{File.dirname(__FILE__)}/../../fixtures/ethtool_outputs/i/ubuntuxenial.txt"))

expect(Ethtool::Facts.gather).to eq({
'enp0s25' => {'max_speed' => 1000,
'driver' => 'ath10k_pci',
'driver_version' => '4.4.0-77-generic', },
'vboxnet0' => {'speed' => 10,
'driver' => 'ath10k_pci',
'driver_version' => '4.4.0-77-generic', }
})
end
end

Expand Down