Skip to content

Commit 7d23235

Browse files
committed
Merge pull request #161 from igalic/ipv6r
fix "absent" options
2 parents a2175a1 + 22b2e4f commit 7d23235

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

lib/puppet/provider/network_route/redhat.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ def self.format_file(_filename, providers)
8686
else
8787
"#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface}"
8888
end
89-
contents << if provider.options == :absent
90-
"\n"
91-
else
92-
" #{provider.options}\n"
93-
end
89+
contents << (provider.options == :absent ? "\n" : " #{provider.options}\n")
9490
end
9591
contents.join
9692
end

lib/puppet/provider/network_route/routes.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def self.format_file(_filename, providers)
9191
raise Puppet::Error, "#{provider.name} is missing the required parameter 'gateway'." if provider.gateway.nil?
9292
raise Puppet::Error, "#{provider.name} is missing the required parameter 'interface'." if provider.interface.nil?
9393

94-
contents << "#{provider.network} #{provider.netmask} #{provider.gateway} #{provider.interface} #{provider.options}\n"
94+
contents << "#{provider.network} #{provider.netmask} #{provider.gateway} #{provider.interface}"
95+
contents << (provider.options == :absent ? "\n" : " #{provider.options}\n")
9596
end
9697

9798
contents.join

spec/unit/provider/network_route/routes_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,54 @@ def fixture_data(file)
107107
expect { content }.to raise_exception
108108
end
109109

110+
it 'should fail if the gateway property is not defined' do
111+
route2_provider.unstub(:gateway)
112+
route2_provider.stubs(:gateway).returns nil
113+
expect { content }.to raise_exception
114+
end
115+
end
116+
end
117+
describe 'when formatting simple files' do
118+
let(:route1_provider) do
119+
stub('route1_provider',
120+
name: '172.17.67.0',
121+
network: '172.17.67.0',
122+
netmask: '255.255.255.0',
123+
gateway: '172.18.6.2',
124+
interface: 'vlan200',
125+
options: :absent,
126+
)
127+
end
128+
129+
let(:route2_provider) do
130+
stub('lo_provider',
131+
name: '172.28.45.0',
132+
network: '172.28.45.0',
133+
netmask: '255.255.255.0',
134+
gateway: '172.18.6.2',
135+
interface: 'eth0',
136+
options: :absent,
137+
)
138+
end
139+
140+
let(:content) { described_class.format_file('', [route1_provider, route2_provider]) }
141+
142+
describe 'writing the route line' do
143+
it 'should write only fields' do
144+
expect(content.scan(/^172.17.67.0 .*$/).length).to eq(1)
145+
expect(content.scan(/^172.17.67.0 .*$/).first.split(/\s/, 5).length).to eq(4)
146+
end
147+
148+
it 'should have the correct fields appended' do
149+
expect(content.scan(/^172.17.67.0 .*$/).first).to include('172.17.67.0 255.255.255.0 172.18.6.2 vlan200')
150+
end
151+
152+
it 'should fail if the netmask property is not defined' do
153+
route2_provider.unstub(:netmask)
154+
route2_provider.stubs(:netmask).returns nil
155+
expect { content }.to raise_exception
156+
end
157+
110158
it 'should fail if the gateway property is not defined' do
111159
route2_provider.unstub(:gateway)
112160
route2_provider.stubs(:gateway).returns nil

0 commit comments

Comments
 (0)