Skip to content

Commit 985e599

Browse files
committed
Merge pull request #165 from rski/route_every_run_update
Fix issue 69, backwards incompatible change
2 parents 7d23235 + 4d82e81 commit 985e599

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55

66
* Drop support for Ruby 1.8.7
77
* voxpupuli namespace release
8+
* (#69) debian default route should now be named 'default', same as redhat
89

910
# Releasing 0.5.0
1011

README.markdown

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ network_config { 'eth1':
4242

4343
Route configuration
4444

45+
Route resources should be named in CIDR notation. If not, they will not be properly mapped to existing routes and puppet will apply them on every run. Default routes should be named 'default'.
46+
4547
For Debian:
4648

4749
```puppet
48-
network_route { '172.17.67.0':
50+
network_route { '172.17.67.0/24':
4951
ensure => 'present',
5052
gateway => '172.18.6.2',
5153
interface => 'vlan200',
@@ -69,7 +71,7 @@ network_route { 'default':
6971
ensure => 'present',
7072
gateway => '10.0.2.2',
7173
interface => 'eth0',
72-
netmask => '0.0.0.0',
74+
netmask => '0.0.0.0',
7375
network => 'default'
7476
}
7577
```

lib/puppet/provider/network_route/routes.rb

+16-9
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ def self.parse_file(_filename, contents)
6666

6767
raise_malformed if route.length < 4
6868

69-
# use the CIDR version of the target as :name
70-
cidr_target = "#{route[0]}/#{IPAddr.new(route[1]).to_i.to_s(2).count('1')}"
71-
72-
route_hash[cidr_target][:network] = route[0]
73-
route_hash[cidr_target][:netmask] = route[1]
74-
route_hash[cidr_target][:gateway] = route[2]
75-
route_hash[cidr_target][:interface] = route[3]
76-
route_hash[cidr_target][:options] = route[4] if route[4]
69+
if route[0] == 'default'
70+
name = 'default'
71+
route_hash[name][:network] = 'default'
72+
route_hash[name][:netmask] = '0.0.0.0'
73+
else
74+
# use the CIDR version of the target as :name
75+
name = "#{route[0]}/#{IPAddr.new(route[1]).to_i.to_s(2).count('1')}"
76+
route_hash[name][:network] = route[0]
77+
route_hash[name][:netmask] = route[1]
78+
end
79+
route_hash[name][:gateway] = route[2]
80+
route_hash[name][:interface] = route[3]
81+
route_hash[name][:options] = route[4] if route[4]
7782
end
7883

7984
route_hash.values
@@ -91,7 +96,9 @@ def self.format_file(_filename, providers)
9196
raise Puppet::Error, "#{provider.name} is missing the required parameter 'gateway'." if provider.gateway.nil?
9297
raise Puppet::Error, "#{provider.name} is missing the required parameter 'interface'." if provider.interface.nil?
9398

94-
contents << "#{provider.network} #{provider.netmask} #{provider.gateway} #{provider.interface}"
99+
netmask = (provider.name == 'default' ? '0.0.0.0' : provider.netmask)
100+
101+
contents << "#{provider.network} #{netmask} #{provider.gateway} #{provider.interface}"
95102
contents << (provider.options == :absent ? "\n" : " #{provider.options}\n")
96103
end
97104

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
172.28.45.0 255.255.255.0 172.18.6.2 vlan200
22
172.17.67.0 255.255.255.0 172.18.6.2 vlan200
33
10.10.10.0 255.255.255.0 172.18.6.2 vlan200
4-
2a01:4f8:211:9d5:53:: ffff:ffff:ffff:ffff:ffff:ffff:: 2a01:4f8:211:9d5::2 vlan200
4+
2a01:4f8:211:9d5:53:: ffff:ffff:ffff:ffff:ffff:ffff:: 2a01:4f8:211:9d5::2 vlan200
5+
default 0.0.0.0 172.18.6.2 vlan200

spec/unit/provider/network_config/interfaces_spec.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ def fixture_data(file)
167167
netmask: '255.255.0.0',
168168
mtu: '1500',
169169
mode: nil,
170-
options: nil
171-
)
170+
options: nil)
172171
end
173172

174173
let(:eth0_1_provider) do
@@ -183,8 +182,7 @@ def fixture_data(file)
183182
netmask: '255.255.0.0',
184183
mtu: '1500',
185184
mode: :vlan,
186-
options: nil
187-
)
185+
options: nil)
188186
end
189187

190188
let(:eth1_provider) do
@@ -205,8 +203,7 @@ def fixture_data(file)
205203
'/bin/touch /tmp/eth1-down1',
206204
'/bin/touch /tmp/eth1-down2',
207205
],
208-
}
209-
)
206+
})
210207
end
211208

212209
let(:lo_provider) do
@@ -220,8 +217,7 @@ def fixture_data(file)
220217
netmask: nil,
221218
mtu: '65536',
222219
mode: nil,
223-
options: nil
224-
)
220+
options: nil)
225221
end
226222

227223
before do

spec/unit/provider/network_config/redhat_spec.rb

+5-11
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ def fixture_data(file)
356356
netmask: '255.255.255.0',
357357
mtu: '1500',
358358
mode: nil,
359-
options: { 'NM_CONTROLLED' => 'no', 'USERCTL' => 'no' }
360-
)
359+
options: { 'NM_CONTROLLED' => 'no', 'USERCTL' => 'no' })
361360
end
362361

363362
let(:eth0_1_provider) do
@@ -372,8 +371,7 @@ def fixture_data(file)
372371
netmask: '255.255.255.0',
373372
mtu: '1500',
374373
mode: :vlan,
375-
options: { 'NM_CONTROLLED' => 'no', 'USERCTL' => 'no' }
376-
)
374+
options: { 'NM_CONTROLLED' => 'no', 'USERCTL' => 'no' })
377375
end
378376

379377
let(:eth1_provider) do
@@ -388,8 +386,7 @@ def fixture_data(file)
388386
netmask: :absent,
389387
mtu: :absent,
390388
mode: :vlan,
391-
options: :absent,
392-
)
389+
options: :absent)
393390
end
394391

395392
let(:lo_provider) do
@@ -402,8 +399,7 @@ def fixture_data(file)
402399
ipaddress: nil,
403400
netmask: nil,
404401
mode: nil,
405-
options: {}
406-
)
402+
options: {})
407403
end
408404

409405
let(:bond0_provider) do
@@ -418,9 +414,7 @@ def fixture_data(file)
418414
mode: nil,
419415
options: {
420416
'BONDING_OPTS' => %(mode=4 miimon=100 xmit_hash_policy=layer3+4)
421-
}
422-
423-
)
417+
})
424418
end
425419

426420
it 'should fail if multiple interfaces are flushed to one file' do

spec/unit/provider/network_route/redhat_spec.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def fixture_data(file)
7979
netmask: '30',
8080
gateway: '172.18.6.2',
8181
interface: 'vlan200',
82-
options: 'table 200'
83-
)
82+
options: 'table 200')
8483
end
8584

8685
let(:route2_provider) do
@@ -90,8 +89,7 @@ def fixture_data(file)
9089
netmask: '30',
9190
gateway: '172.18.6.2',
9291
interface: 'eth0',
93-
options: 'table 200'
94-
)
92+
options: 'table 200')
9593
end
9694

9795
let(:defaultroute_provider) do
@@ -101,8 +99,7 @@ def fixture_data(file)
10199
netmask: '',
102100
gateway: '10.0.0.1',
103101
interface: 'eth1',
104-
options: 'table 200'
105-
)
102+
options: 'table 200')
106103
end
107104

108105
let(:nooptions_provider) do
@@ -112,8 +109,7 @@ def fixture_data(file)
112109
netmask: '',
113110
gateway: '10.0.0.1',
114111
interface: 'eth2',
115-
options: :absent
116-
)
112+
options: :absent)
117113
end
118114

119115
let(:content) { described_class.format_file('', [route1_provider, route2_provider, defaultroute_provider, nooptions_provider]) }

spec/unit/provider/network_route/routes_spec.rb

+16-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ def fixture_data(file)
2121
interface: 'vlan200')
2222
end
2323

24+
it 'should name default routes "default" and have a 0.0.0.0 netmask' do
25+
fixture = fixture_data('simple_routes')
26+
data = described_class.parse_file('', fixture)
27+
28+
expect(data.find { |h| h[:name] == 'default' })
29+
.to eq(name: 'default',
30+
network: 'default',
31+
netmask: '0.0.0.0',
32+
gateway: '172.18.6.2',
33+
interface: 'vlan200')
34+
end
35+
2436
it 'should parse out simple ipv6 iface lines' do
2537
fixture = fixture_data('simple_routes')
2638
data = described_class.parse_file('', fixture)
@@ -74,8 +86,7 @@ def fixture_data(file)
7486
netmask: '255.255.255.0',
7587
gateway: '172.18.6.2',
7688
interface: 'vlan200',
77-
options: 'table 200'
78-
)
89+
options: 'table 200')
7990
end
8091

8192
let(:route2_provider) do
@@ -85,8 +96,7 @@ def fixture_data(file)
8596
netmask: '255.255.255.0',
8697
gateway: '172.18.6.2',
8798
interface: 'eth0',
88-
options: 'table 200'
89-
)
99+
options: 'table 200')
90100
end
91101

92102
let(:content) { described_class.format_file('', [route1_provider, route2_provider]) }
@@ -122,8 +132,7 @@ def fixture_data(file)
122132
netmask: '255.255.255.0',
123133
gateway: '172.18.6.2',
124134
interface: 'vlan200',
125-
options: :absent,
126-
)
135+
options: :absent)
127136
end
128137

129138
let(:route2_provider) do
@@ -133,8 +142,7 @@ def fixture_data(file)
133142
netmask: '255.255.255.0',
134143
gateway: '172.18.6.2',
135144
interface: 'eth0',
136-
options: :absent,
137-
)
145+
options: :absent)
138146
end
139147

140148
let(:content) { described_class.format_file('', [route1_provider, route2_provider]) }

0 commit comments

Comments
 (0)