Skip to content

Commit

Permalink
Adds parameterizing dhcp service
Browse files Browse the repository at this point in the history
closes dfarrell07#105

Signed-off-by: Tim Rozet <[email protected]>
  • Loading branch information
trozet committed Aug 5, 2016
1 parent cffd321 commit c1e1601
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ class { 'opendaylight':
}
```

### Disabling ODL DHCP Service

To disable ODL DHCP Service, use the `enable_dhcp` flag. It's enabled by
default.

```puppet
class { 'opendaylight':
enable_dhcp => false,
}
```

## Reference

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

##### `enable_dhcp`

Enable or disable ODL DHCP Service.

Default: `true`

Valid options: Boolean values `true` and `false`.

The ODL DHCP Service config in `/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml` is set to
the value of the `enable_dhcp` param.

A manifest like

```puppet
class { 'opendaylight':
enable_dhcp => false,
}
```

Would would result in

```
<controller-dhcp-enabled>false</controller-dhcp-enabled>
```

## Limitations

* Tested on Fedora 22, 23, CentOS 7 and Ubuntu 14.04.
Expand Down
11 changes: 11 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@
fail("Number of HA nodes less than 2: ${ha_node_count} and HA Enabled")
}
}

# Configure DHCP service
file { 'dhcpservice-impl-default-config.xml':
ensure => file,
path => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
# Set user:group owners
owner => 'odl',
group => 'odl',
# Use a template to populate the content
content => template('opendaylight/dhcpservice-impl-default-config.xml.erb'),
}
}
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# Array of IPs for each node in the HA cluster.
# [*ha_node_index*]
# Index of ha_node_ips for this node.
# [*enable_dhcp*]
# Enable or disable ODL Netvirt DHCP service. Valid: true, false. Default: true
#
class opendaylight (
$default_features = $::opendaylight::params::default_features,
Expand All @@ -44,6 +46,7 @@
$enable_ha = $::opendaylight::params::enable_ha,
$ha_node_ips = $::opendaylight::params::ha_node_ips,
$ha_node_index = $::opendaylight::params::ha_node_index,
$enable_dhcp = $::opendaylight::params::enable_dhcp,
) inherits ::opendaylight::params {

# Validate OS family
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
$enable_ha = false
$ha_node_ips = []
$ha_node_index = ''
$enable_dhcp = true
}
26 changes: 26 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,30 @@
enable_l3_validations(enable_l3: true)
end
end

describe 'testing ODL DHCP Service config' do
context 'using enable_dhcp default' do
# Call specialized helper fn to install OpenDaylight
install_odl

# Call specialized helper fn for ODL DHCP Service config validations
enable_dhcp_validations
end

context 'using false for enable_dhcp' do
# Call specialized helper fn to install OpenDaylight
install_odl(enable_dhcp: false)

# Call specialized helper fn for ODL DHCP Service config validations
enable_dhcp_validations(enable_dhcp: false)
end

context 'using true for enable_dhcp' do
# Call specialized helper fn to install OpenDaylight
install_odl(enable_dhcp: true)

# Call specialized helper fn for ODL DHCP Service config validations
enable_dhcp_validations(enable_dhcp: true)
end
end
end
82 changes: 82 additions & 0 deletions spec/classes/opendaylight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
# Note that this function is defined in spec_helper
enable_l3_tests

# Run tests that specialize in checking ODL DHCP Service config
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
# Note that this function is defined in spec_helper
enable_dhcp_tests
end
end

Expand Down Expand Up @@ -105,6 +110,11 @@
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
# Note that this function is defined in spec_helper
enable_l3_tests

# Run tests that specialize in checking ODL DHCP Service config
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
# Note that this function is defined in spec_helper
enable_dhcp_tests
end
end

Expand Down Expand Up @@ -180,6 +190,11 @@
# NB: Only testing defaults here, specialized enabling L3 tests elsewhere
# Note that this function is defined in spec_helper
enable_l3_tests

# Run tests that specialize in checking ODL DHCP Service config
# NB: Only testing defaults here, specialized enabling DHCP tests elsewhere
# Note that this function is defined in spec_helper
enable_dhcp_tests
end
end

Expand Down Expand Up @@ -538,6 +553,73 @@
end
end

# All DHCP Service enable/disable tests
describe 'DHCP Service enable/disable tests' do
# Non-OS-type tests assume CentOS 7
# See issue #43 for reasoning:
# https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
osfamily = 'RedHat'
operatingsystem = 'CentOS'
operatingsystemmajrelease = '7'
context 'using enable_dhcp default' do
let(:facts) {{
:osfamily => osfamily,
:operatingsystem => operatingsystem,
:operatingsystemmajrelease => operatingsystemmajrelease,
}}

let(:params) {{ }}

# Run shared tests applicable to all supported OSs
# Note that this function is defined in spec_helper
generic_tests

# Run test that specialize in checking ODL DHCP Service config
# Note that this function is defined in spec_helper
enable_dhcp_tests
end

context 'using false for enable_dhcp' do
let(:facts) {{
:osfamily => osfamily,
:operatingsystem => operatingsystem,
:operatingsystemmajrelease => operatingsystemmajrelease,
}}

let(:params) {{
:enable_dhcp => false ,
}}

# Run shared tests applicable to all supported OSs
# Note that this function is defined in spec_helper
generic_tests

# Run test that specialize in checking ODL DHCP Service config
# Note that this function is defined in spec_helper
enable_dhcp_tests(enable_dhcp: false)
end

context 'using true for enable_dhcp' do
let(:facts) {{
:osfamily => osfamily,
:operatingsystem => operatingsystem,
:operatingsystemmajrelease => operatingsystemmajrelease,
}}

let(:params) {{
:enable_dhcp => true,
}}

# Run shared tests applicable to all supported OSs
# Note that this function is defined in spec_helper
generic_tests

# Run test that specialize in checking ODL DHCP Service config
# Note that this function is defined in spec_helper
enable_dhcp_tests(enable_dhcp: true)
end
end

# All install method tests
describe 'install method tests' do
# Non-OS-type tests assume CentOS 7
Expand Down
32 changes: 32 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,38 @@ def enable_l3_tests(options = {})
end
end

# Shared tests that specialize in testing enabling DHCP Service
def enable_dhcp_tests(options = {})
# Extract params
# NB: This default value should be the same as one in opendaylight::params
# TODO: Remove this possible source of bugs^^
enable_dhcp = options.fetch(:enable_dhcp, true)

if [true].include? enable_dhcp
# Confirm ODL DHCP Service is enabled
it {
should contain_file('custom.properties').with(
'ensure' => 'file',
'path' => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
'owner' => 'odl',
'group' => 'odl',
'content' => /controller-dhcp-enabled>true/
)
}
elsif [false].include? enable_dhcp
# Confirm ODL DHCP Service is disabled
it {
should contain_file('custom.properties').with(
'ensure' => 'file',
'path' => '/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml',
'owner' => 'odl',
'group' => 'odl',
'content' => /controller-dhcp-enabled>false/
)
}
end
end

def tarball_install_tests(options = {})
# Extract params
# NB: These default values should be the same as ones in opendaylight::params
Expand Down
17 changes: 17 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def install_odl(options = {})
odl_rest_port = options.fetch(:odl_rest_port, 8080)
log_levels = options.fetch(:log_levels, {})
enable_l3 = options.fetch(:enable_l3, 'no')
enable_dhcp = options.fetch(:enable_dhcp, true)

# Build script for consumption by Puppet apply
it 'should work idempotently with no errors' do
Expand All @@ -75,6 +76,7 @@ class { 'opendaylight':
odl_rest_port=> #{odl_rest_port},
enable_l3=> #{enable_l3},
log_levels=> #{log_levels},
enable_dhcp=> #{enable_dhcp},
}
EOS

Expand Down Expand Up @@ -306,6 +308,21 @@ def enable_l3_validations(options = {})
end
end

# Shared function for validations related to ODL OVSDB L3 config
def enable_dhcp_validations(options = {})
# NB: This param default should match the one used by the opendaylight
# class, which is defined in opendaylight::params
# TODO: Remove this possible source of bugs^^
enable_dhcp = options.fetch(:enable_dhcp, true)

describe file('/opt/opendaylight/etc/opendaylight/karaf/dhcpservice-impl-default-config.xml') do
it { should be_file }
it { should be_owned_by 'odl' }
it { should be_grouped_into 'odl' }
its(:content) { should match /controller-dhcp-enabled>#{enable_dhcp}/ }
end
end

# Shared function that handles validations specific to RPM-type installs
def rpm_validations()
rpm_repo = ENV['RPM_REPO']
Expand Down
59 changes: 59 additions & 0 deletions templates/dhcpservice-impl-default-config.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<snapshot>
<required-capabilities>
<capability>urn:opendaylight:params:xml:ns:yang:dhcpservice:impl?module=dhcpservice-impl&amp;revision=2015-07-10</capability>
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&amp;revision=2013-10-28</capability>
<capability>urn:opendaylight:genius:mdsalutil?module=odl-mdsalutil&amp;revision=2016-04-06</capability>
<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>
<capability>urn:opendaylight:params:xml:ns:yang:neutronvpn:api?module=neutronvpn-api&amp;revision=2015-08-12</capability>
<capability>urn:opendaylight:genius:interfacemgr?module=odl-interface&amp;revision=2016-04-06</capability>
</required-capabilities>
<configuration>

<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
<module>
<type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:dhcpservice:impl">prefix:dhcpservice-impl</type>
<name>dhcpservice-default</name>
<controller-dhcp-enabled><%= scope.lookupvar('opendaylight::enable_dhcp') %></controller-dhcp-enabled>
<broker>
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
<name>binding-osgi-broker</name>
</broker>
<rpcregistry>
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
<name>binding-rpc-broker</name>
</rpcregistry>
<notification-service>
<type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-notification-service</type>
<name>binding-notification-broker</name>
</notification-service>
<mdsalutil>
<type xmlns:mdsalutil="urn:opendaylight:genius:mdsalutil">mdsalutil:odl-mdsalutil</type>
<name>mdsalutil-service</name>
</mdsalutil>
<neutronvpn>
<type xmlns:neutronvpn="urn:opendaylight:params:xml:ns:yang:neutronvpn:api">neutronvpn:neutronvpn-api</type>
<name>neutronvpn</name>
</neutronvpn>
<entity-ownership-service>
<type xmlns:entity-ownership="urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:entity-ownership-service">entity-ownership:entity-ownership-service</type>
<name>entity-ownership-service</name>
</entity-ownership-service>
<odlinterface>
<type xmlns:odlif="urn:opendaylight:genius:interfacemgr">odlif:odl-interface</type>
<name>interfacemgr-service</name>
</odlinterface>
</module>
</modules>
</data>
</configuration>
</snapshot>

0 comments on commit c1e1601

Please sign in to comment.