Skip to content

Commit

Permalink
Merge pull request #133 from trovitsys/fix_jessie
Browse files Browse the repository at this point in the history
Ignore new Debian Jessie's features
  • Loading branch information
jyaworski committed Jan 28, 2016
2 parents 1d69665 + 2d58129 commit 1be5bcd
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Metrics/ClassLength:
Enabled: false

# dealbreaker:
Style/TrailingComma:
Style/TrailingCommaInLiteral:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/ClosingParenthesisIndentation:
Enabled: false
Expand Down
16 changes: 10 additions & 6 deletions lib/puppet/provider/network_config/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def to_hash

def squeeze_options
@options.each_with_object({}) do |(key, value), hash|
if value.size <= 1
hash[key] = value.pop
else
hash[key] = value
end
hash[key] = if value.size <= 1
value.pop
else
value
end
hash
end
end
Expand Down Expand Up @@ -123,7 +123,6 @@ def self.parse_file(_filename, contents)
# parsed.
status = :none
current_interface = nil

lines = contents.split("\n")
# TODO: Join lines that end with a backslash

Expand All @@ -137,6 +136,11 @@ def self.parse_file(_filename, contents)
# Ignore comments and blank lines
next

when /^source|^source-directory/
# ignore source|source-directory sections, it makes this provider basically useless
# with Debian Jessie. Please refer to man 5 interfaces
next

when /^auto|^allow-auto/
# Parse out any auto sections
interfaces = line.split(' ')
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/network_config/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
has_feature :provider_options

# @return [String] The path to network-script directory on redhat systems
SCRIPT_DIRECTORY = '/etc/sysconfig/network-scripts'
SCRIPT_DIRECTORY = '/etc/sysconfig/network-scripts'.freeze

# The valid vlan ID range is 0-4095; 4096 is out of range
VLAN_RANGE_REGEX = /\d{1,3}|40[0-9][0-5]/
Expand All @@ -35,7 +35,7 @@
:name => 'DEVICE',
:hotplug => 'HOTPLUG',
:mtu => 'MTU',
}
}.freeze

# Map provider instances to files based on their name
#
Expand Down Expand Up @@ -89,7 +89,7 @@ def self.parse_file(filename, contents)
# Strip out all comments
lines.map! { |line| line.sub(/#.*$/, '') }
# Remove all blank lines
lines.reject! { |line| line.match(/^\s*$/) }
lines.reject! { |line| line =~ /^\s*$/ }

pair_regex = /^\s*(.+?)\s*=\s*(.*)\s*$/

Expand Down Expand Up @@ -117,11 +117,11 @@ def self.parse_file(filename, contents)
# issue that caused this, and https://github.com/adrienthebo/puppet-network/issues/16
# for the resolution.
#
props.merge!(:family => :inet)
props[:family] = :inet

# If there is no DEVICE property in the interface configuration we retrieve
# the interface name from the file name itself
props.merge!(:name => filename.split('ifcfg-')[1]) unless props.key?(:name)
props[:name] = filename.split('ifcfg-')[1] unless props.key?(:name)

# The FileMapper mixin expects an array of providers, so we return the
# single interface wrapped in an array
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/network_route/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def self.format_file(_filename, providers)
[:network, :netmask, :gateway, :interface].each do |prop|
fail Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil?
end
if provider.network == 'default'
contents << "#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
else
contents << "#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
end
contents << if provider.network == 'default'
"#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
else
"#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
end
end
contents.join
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/network_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
# is 42 with a 802.1q header and 46 without.
min_mtu = 42
max_mtu = 65_536
unless (min_mtu..max_mtu).include?(value.to_i)
unless (min_mtu..max_mtu).cover?(value.to_i)
fail ArgumentError, "#{value} is not in the valid mtu range (#{min_mtu} .. #{max_mtu})"
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*
source-directory /etc/network/custom-ifaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
11 changes: 11 additions & 0 deletions spec/unit/provider/network_config/interfaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def fixture_data(file)
:options => {},)
end

it 'should ignore source and source-directory lines' do
fixture = fixture_data('jessie_source_stanza')
data = described_class.parse_file('', fixture)
expect(data.find { |h| h[:name] == 'eth0' }).to eq(:family => 'inet',
:method => 'dhcp',
:mode => :raw,
:name => 'eth0',
:hotplug => true,
:options => {},)
end

it 'should ignore variable whitespace in iface lines (network-#26)' do
fixture = fixture_data('iface_whitespace')
data = described_class.parse_file('', fixture)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/provider/network_config/redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ def fixture_data(file)
:netmask => '255.255.255.0',
:method => 'static',
:mtu => '1500',
:mode => nil,
:options => {
:mode => nil,
:options => {
'BONDING_OPTS' => %(mode=4 miimon=100 xmit_hash_policy=layer3+4)
}

Expand Down

0 comments on commit 1be5bcd

Please sign in to comment.