Skip to content

Commit c1e1601

Browse files
committed
Adds parameterizing dhcp service
closes #105 Signed-off-by: Tim Rozet <[email protected]>
1 parent cffd321 commit c1e1601

File tree

9 files changed

+267
-0
lines changed

9 files changed

+267
-0
lines changed

README.markdown

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ class { 'opendaylight':
231231
}
232232
```
233233

234+
### Disabling ODL DHCP Service
235+
236+
To disable ODL DHCP Service, use the `enable_dhcp` flag. It's enabled by
237+
default.
238+
239+
```puppet
240+
class { 'opendaylight':
241+
enable_dhcp => false,
242+
}
243+
```
244+
234245
## Reference
235246

236247
### Classes
@@ -409,6 +420,31 @@ Default: `'https://github.com/dfarrell07/opendaylight-systemd/archive/master/ope
409420
Valid options: A valid URL to an ODL systemd .service file (archived in a
410421
tarball) as a string.
411422

423+
##### `enable_dhcp`
424+
425+
Enable or disable ODL DHCP Service.
426+
427+
Default: `true`
428+
429+
Valid options: Boolean values `true` and `false`.
430+
431+
The ODL DHCP Service config in `/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml` is set to
432+
the value of the `enable_dhcp` param.
433+
434+
A manifest like
435+
436+
```puppet
437+
class { 'opendaylight':
438+
enable_dhcp => false,
439+
}
440+
```
441+
442+
Would would result in
443+
444+
```
445+
<controller-dhcp-enabled>false</controller-dhcp-enabled>
446+
```
447+
412448
## Limitations
413449

414450
* Tested on Fedora 22, 23, CentOS 7 and Ubuntu 14.04.

manifests/config.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,15 @@
7777
fail("Number of HA nodes less than 2: ${ha_node_count} and HA Enabled")
7878
}
7979
}
80+
81+
# Configure DHCP service
82+
file { 'dhcpservice-impl-default-config.xml':
83+
ensure => file,
84+
path => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
85+
# Set user:group owners
86+
owner => 'odl',
87+
group => 'odl',
88+
# Use a template to populate the content
89+
content => template('opendaylight/dhcpservice-impl-default-config.xml.erb'),
90+
}
8091
}

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
# Array of IPs for each node in the HA cluster.
3030
# [*ha_node_index*]
3131
# Index of ha_node_ips for this node.
32+
# [*enable_dhcp*]
33+
# Enable or disable ODL Netvirt DHCP service. Valid: true, false. Default: true
3234
#
3335
class opendaylight (
3436
$default_features = $::opendaylight::params::default_features,
@@ -44,6 +46,7 @@
4446
$enable_ha = $::opendaylight::params::enable_ha,
4547
$ha_node_ips = $::opendaylight::params::ha_node_ips,
4648
$ha_node_index = $::opendaylight::params::ha_node_index,
49+
$enable_dhcp = $::opendaylight::params::enable_dhcp,
4750
) inherits ::opendaylight::params {
4851

4952
# Validate OS family

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
$enable_ha = false
2222
$ha_node_ips = []
2323
$ha_node_index = ''
24+
$enable_dhcp = true
2425
}

spec/acceptance/class_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,30 @@
164164
enable_l3_validations(enable_l3: true)
165165
end
166166
end
167+
168+
describe 'testing ODL DHCP Service config' do
169+
context 'using enable_dhcp default' do
170+
# Call specialized helper fn to install OpenDaylight
171+
install_odl
172+
173+
# Call specialized helper fn for ODL DHCP Service config validations
174+
enable_dhcp_validations
175+
end
176+
177+
context 'using false for enable_dhcp' do
178+
# Call specialized helper fn to install OpenDaylight
179+
install_odl(enable_dhcp: false)
180+
181+
# Call specialized helper fn for ODL DHCP Service config validations
182+
enable_dhcp_validations(enable_dhcp: false)
183+
end
184+
185+
context 'using true for enable_dhcp' do
186+
# Call specialized helper fn to install OpenDaylight
187+
install_odl(enable_dhcp: true)
188+
189+
# Call specialized helper fn for ODL DHCP Service config validations
190+
enable_dhcp_validations(enable_dhcp: true)
191+
end
192+
end
167193
end

spec/classes/opendaylight_spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
4747
# Note that this function is defined in spec_helper
4848
enable_l3_tests
49+
50+
# Run tests that specialize in checking ODL DHCP Service config
51+
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
52+
# Note that this function is defined in spec_helper
53+
enable_dhcp_tests
4954
end
5055
end
5156

@@ -105,6 +110,11 @@
105110
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
106111
# Note that this function is defined in spec_helper
107112
enable_l3_tests
113+
114+
# Run tests that specialize in checking ODL DHCP Service config
115+
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
116+
# Note that this function is defined in spec_helper
117+
enable_dhcp_tests
108118
end
109119
end
110120

@@ -180,6 +190,11 @@
180190
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
181191
# Note that this function is defined in spec_helper
182192
enable_l3_tests
193+
194+
# Run tests that specialize in checking ODL DHCP Service config
195+
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
196+
# Note that this function is defined in spec_helper
197+
enable_dhcp_tests
183198
end
184199
end
185200

@@ -538,6 +553,73 @@
538553
end
539554
end
540555

556+
# All DHCP Service enable/disable tests
557+
describe 'DHCP Service enable/disable tests' do
558+
# Non-OS-type tests assume CentOS 7
559+
# See issue #43 for reasoning:
560+
# https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
561+
osfamily = 'RedHat'
562+
operatingsystem = 'CentOS'
563+
operatingsystemmajrelease = '7'
564+
context 'using enable_dhcp default' do
565+
let(:facts) {{
566+
:osfamily => osfamily,
567+
:operatingsystem => operatingsystem,
568+
:operatingsystemmajrelease => operatingsystemmajrelease,
569+
}}
570+
571+
let(:params) {{ }}
572+
573+
# Run shared tests applicable to all supported OSs
574+
# Note that this function is defined in spec_helper
575+
generic_tests
576+
577+
# Run test that specialize in checking ODL DHCP Service config
578+
# Note that this function is defined in spec_helper
579+
enable_dhcp_tests
580+
end
581+
582+
context 'using false for enable_dhcp' do
583+
let(:facts) {{
584+
:osfamily => osfamily,
585+
:operatingsystem => operatingsystem,
586+
:operatingsystemmajrelease => operatingsystemmajrelease,
587+
}}
588+
589+
let(:params) {{
590+
:enable_dhcp => false ,
591+
}}
592+
593+
# Run shared tests applicable to all supported OSs
594+
# Note that this function is defined in spec_helper
595+
generic_tests
596+
597+
# Run test that specialize in checking ODL DHCP Service config
598+
# Note that this function is defined in spec_helper
599+
enable_dhcp_tests(enable_dhcp: false)
600+
end
601+
602+
context 'using true for enable_dhcp' do
603+
let(:facts) {{
604+
:osfamily => osfamily,
605+
:operatingsystem => operatingsystem,
606+
:operatingsystemmajrelease => operatingsystemmajrelease,
607+
}}
608+
609+
let(:params) {{
610+
:enable_dhcp => true,
611+
}}
612+
613+
# Run shared tests applicable to all supported OSs
614+
# Note that this function is defined in spec_helper
615+
generic_tests
616+
617+
# Run test that specialize in checking ODL DHCP Service config
618+
# Note that this function is defined in spec_helper
619+
enable_dhcp_tests(enable_dhcp: true)
620+
end
621+
end
622+
541623
# All install method tests
542624
describe 'install method tests' do
543625
# Non-OS-type tests assume CentOS 7

spec/spec_helper.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,38 @@ def enable_l3_tests(options = {})
227227
end
228228
end
229229

230+
# Shared tests that specialize in testing enabling DHCP Service
231+
def enable_dhcp_tests(options = {})
232+
# Extract params
233+
# NB: This default value should be the same as one in opendaylight::params
234+
# TODO: Remove this possible source of bugs^^
235+
enable_dhcp = options.fetch(:enable_dhcp, true)
236+
237+
if [true].include? enable_dhcp
238+
# Confirm ODL DHCP Service is enabled
239+
it {
240+
should contain_file('custom.properties').with(
241+
'ensure' => 'file',
242+
'path' => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
243+
'owner' => 'odl',
244+
'group' => 'odl',
245+
'content' => /controller-dhcp-enabled>true/
246+
)
247+
}
248+
elsif [false].include? enable_dhcp
249+
# Confirm ODL DHCP Service is disabled
250+
it {
251+
should contain_file('custom.properties').with(
252+
'ensure' => 'file',
253+
'path' => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
254+
'owner' => 'odl',
255+
'group' => 'odl',
256+
'content' => /controller-dhcp-enabled>false/
257+
)
258+
}
259+
end
260+
end
261+
230262
def tarball_install_tests(options = {})
231263
# Extract params
232264
# NB: These default values should be the same as ones in opendaylight::params

spec/spec_helper_acceptance.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def install_odl(options = {})
6363
odl_rest_port = options.fetch(:odl_rest_port, 8080)
6464
log_levels = options.fetch(:log_levels, {})
6565
enable_l3 = options.fetch(:enable_l3, 'no')
66+
enable_dhcp = options.fetch(:enable_dhcp, true)
6667

6768
# Build script for consumption by Puppet apply
6869
it 'should work idempotently with no errors' do
@@ -75,6 +76,7 @@ class { 'opendaylight':
7576
odl_rest_port=> #{odl_rest_port},
7677
enable_l3=> #{enable_l3},
7778
log_levels=> #{log_levels},
79+
enable_dhcp=> #{enable_dhcp},
7880
}
7981
EOS
8082

@@ -306,6 +308,21 @@ def enable_l3_validations(options = {})
306308
end
307309
end
308310

311+
# Shared function for validations related to ODL OVSDB L3 config
312+
def enable_dhcp_validations(options = {})
313+
# NB: This param default should match the one used by the opendaylight
314+
# class, which is defined in opendaylight::params
315+
# TODO: Remove this possible source of bugs^^
316+
enable_dhcp = options.fetch(:enable_dhcp, true)
317+
318+
describe file('/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml') do
319+
it { should be_file }
320+
it { should be_owned_by 'odl' }
321+
it { should be_grouped_into 'odl' }
322+
its(:content) { should match /controller-dhcp-enabled>#{enable_dhcp}/ }
323+
end
324+
end
325+
309326
# Shared function that handles validations specific to RPM-type installs
310327
def rpm_validations()
311328
rpm_repo = ENV['RPM_REPO']
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- vi: set et smarttab sw=4 tabstop=4: -->
3+
<!--
4+
Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v1.0 which accompanies this distribution,
8+
and is available at http://www.eclipse.org/legal/epl-v10.html
9+
-->
10+
<snapshot>
11+
<required-capabilities>
12+
<capability>urn:opendaylight:params:xml:ns:yang:dhcpservice:impl?module=dhcpservice-impl&amp;revision=2015-07-10</capability>
13+
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&amp;revision=2013-10-28</capability>
14+
<capability>urn:opendaylight:genius:mdsalutil?module=odl-mdsalutil&amp;revision=2016-04-06</capability>
15+
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:entity-ownership-service?module=opendaylight-entity-ownership-service&amp;revision=2015-08-10</capability>
16+
<capability>urn:opendaylight:params:xml:ns:yang:neutronvpn:api?module=neutronvpn-api&amp;revision=2015-08-12</capability>
17+
<capability>urn:opendaylight:genius:interfacemgr?module=odl-interface&amp;revision=2016-04-06</capability>
18+
</required-capabilities>
19+
<configuration>
20+
21+
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
22+
<modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
23+
<module>
24+
<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:dhcpservice:impl">prefix:dhcpservice-impl</type>
25+
<name>dhcpservice-default</name>
26+
<controller-dhcp-enabled><%= scope.lookupvar('opendaylight::enable_dhcp') %></controller-dhcp-enabled>
27+
<broker>
28+
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
29+
<name>binding-osgi-broker</name>
30+
</broker>
31+
<rpcregistry>
32+
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
33+
<name>binding-rpc-broker</name>
34+
</rpcregistry>
35+
<notification-service>
36+
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-notification-service</type>
37+
<name>binding-notification-broker</name>
38+
</notification-service>
39+
<mdsalutil>
40+
<type xmlns:mdsalutil="urn:opendaylight:genius:mdsalutil">mdsalutil:odl-mdsalutil</type>
41+
<name>mdsalutil-service</name>
42+
</mdsalutil>
43+
<neutronvpn>
44+
<type xmlns:neutronvpn="urn:opendaylight:params:xml:ns:yang:neutronvpn:api">neutronvpn:neutronvpn-api</type>
45+
<name>neutronvpn</name>
46+
</neutronvpn>
47+
<entity-ownership-service>
48+
<type xmlns:entity-ownership="urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:entity-ownership-service">entity-ownership:entity-ownership-service</type>
49+
<name>entity-ownership-service</name>
50+
</entity-ownership-service>
51+
<odlinterface>
52+
<type xmlns:odlif="urn:opendaylight:genius:interfacemgr">odlif:odl-interface</type>
53+
<name>interfacemgr-service</name>
54+
</odlinterface>
55+
</module>
56+
</modules>
57+
</data>
58+
</configuration>
59+
</snapshot>

0 commit comments

Comments
 (0)