Skip to content

Commit 1be5bcd

Browse files
committed
Merge pull request #133 from trovitsys/fix_jessie
Ignore new Debian Jessie's features
2 parents 1d69665 + 2d58129 commit 1be5bcd

File tree

8 files changed

+50
-20
lines changed

8 files changed

+50
-20
lines changed

.rubocop.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ Metrics/ClassLength:
3131
Enabled: false
3232

3333
# dealbreaker:
34-
Style/TrailingComma:
34+
Style/TrailingCommaInLiteral:
35+
Enabled: false
36+
Style/TrailingCommaInArguments:
3537
Enabled: false
3638
Style/ClosingParenthesisIndentation:
3739
Enabled: false

lib/puppet/provider/network_config/interfaces.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def to_hash
7979

8080
def squeeze_options
8181
@options.each_with_object({}) do |(key, value), hash|
82-
if value.size <= 1
83-
hash[key] = value.pop
84-
else
85-
hash[key] = value
86-
end
82+
hash[key] = if value.size <= 1
83+
value.pop
84+
else
85+
value
86+
end
8787
hash
8888
end
8989
end
@@ -123,7 +123,6 @@ def self.parse_file(_filename, contents)
123123
# parsed.
124124
status = :none
125125
current_interface = nil
126-
127126
lines = contents.split("\n")
128127
# TODO: Join lines that end with a backslash
129128

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

139+
when /^source|^source-directory/
140+
# ignore source|source-directory sections, it makes this provider basically useless
141+
# with Debian Jessie. Please refer to man 5 interfaces
142+
next
143+
140144
when /^auto|^allow-auto/
141145
# Parse out any auto sections
142146
interfaces = line.split(' ')

lib/puppet/provider/network_config/redhat.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
has_feature :provider_options
2020

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

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

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

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

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

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

126126
# The FileMapper mixin expects an array of providers, so we return the
127127
# single interface wrapped in an array

lib/puppet/provider/network_route/redhat.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def self.format_file(_filename, providers)
8383
[:network, :netmask, :gateway, :interface].each do |prop|
8484
fail Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil?
8585
end
86-
if provider.network == 'default'
87-
contents << "#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
88-
else
89-
contents << "#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
90-
end
86+
contents << if provider.network == 'default'
87+
"#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
88+
else
89+
"#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"
90+
end
9191
end
9292
contents.join
9393
end

lib/puppet/type/network_config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
# is 42 with a 802.1q header and 46 without.
9292
min_mtu = 42
9393
max_mtu = 65_536
94-
unless (min_mtu..max_mtu).include?(value.to_i)
94+
unless (min_mtu..max_mtu).cover?(value.to_i)
9595
fail ArgumentError, "#{value} is not in the valid mtu range (#{min_mtu} .. #{max_mtu})"
9696
end
9797
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file describes the network interfaces available on your system
2+
# and how to activate them. For more information, see interfaces(5).
3+
4+
source /etc/network/interfaces.d/*
5+
source-directory /etc/network/custom-ifaces
6+
7+
# The loopback network interface
8+
auto lo
9+
iface lo inet loopback
10+
11+
# The primary network interface
12+
allow-hotplug eth0
13+
iface eth0 inet dhcp

spec/unit/provider/network_config/interfaces_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def fixture_data(file)
5151
:options => {},)
5252
end
5353

54+
it 'should ignore source and source-directory lines' do
55+
fixture = fixture_data('jessie_source_stanza')
56+
data = described_class.parse_file('', fixture)
57+
expect(data.find { |h| h[:name] == 'eth0' }).to eq(:family => 'inet',
58+
:method => 'dhcp',
59+
:mode => :raw,
60+
:name => 'eth0',
61+
:hotplug => true,
62+
:options => {},)
63+
end
64+
5465
it 'should ignore variable whitespace in iface lines (network-#26)' do
5566
fixture = fixture_data('iface_whitespace')
5667
data = described_class.parse_file('', fixture)

spec/unit/provider/network_config/redhat_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def fixture_data(file)
399399
:netmask => '255.255.255.0',
400400
:method => 'static',
401401
:mtu => '1500',
402-
:mode => nil,
403-
:options => {
402+
:mode => nil,
403+
:options => {
404404
'BONDING_OPTS' => %(mode=4 miimon=100 xmit_hash_policy=layer3+4)
405405
}
406406

0 commit comments

Comments
 (0)