Skip to content

Commit 861416b

Browse files
committed
Allow for disabling repository configuration
This change moves the repository configuration to it's own class so it can be included externally and excludeded if necessary. As part of this change, the inclusion of rspec-puppet-facts was done to simplify testing support os configurations. See https://github.com/mcanevet/rspec-puppet-facts for details on how to work with rspec-puppet-facts. By default it uses the metadata.json for the supported operating systems. Since 14.04 is not a supported configuration based on the failure in ::opendaylight, this has also been updated to reference 16.04 as a supported version.
1 parent 8355b01 commit 861416b

File tree

8 files changed

+150
-46
lines changed

8 files changed

+150
-46
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ group :test do
88
gem "metadata-json-lint"
99
gem "travis"
1010
gem "travis-lint"
11+
gem "rspec-puppet-facts", :require => false
1112
end
1213

1314
group :local_only do

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# Sets routing node for VPP deployments. Defaults to ''.
3434
# [*java_opts*]
3535
# Sets Java options for ODL in a string format. Defaults to '-Djava.net.preferIPv4Stack=true'.
36+
# [*manage_repositories*]
37+
# (Boolean) Should this module manage the apt or yum repositories for the
38+
# package installation.
39+
# Defaults to true
3640
#
3741
class opendaylight (
3842
$default_features = $::opendaylight::params::default_features,
@@ -48,6 +52,7 @@
4852
$security_group_mode = $::opendaylight::params::security_group_mode,
4953
$vpp_routing_node = $::opendaylight::params::vpp_routing_node,
5054
$java_opts = $::opendaylight::params::java_opts,
55+
$manage_repositories = $::opendaylight::params::manage_repositories,
5156
) inherits ::opendaylight::params {
5257

5358
# Validate OS family

manifests/install.pp

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,29 @@
66
# system state should be functionally equivalent.
77
#
88
class opendaylight::install {
9-
if $::osfamily == 'RedHat' {
10-
# Add OpenDaylight's Yum repository
11-
yumrepo { $opendaylight::rpm_repo:
12-
# 'ensure' isn't supported with Puppet <3.5
13-
# Seems to default to present, but docs don't say
14-
# https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
15-
# https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
16-
baseurl => "http://cbs.centos.org/repos/nfv7-${opendaylight::rpm_repo}/\$basearch/os/",
17-
descr => 'OpenDaylight SDN Controller',
18-
enabled => 1,
19-
# NB: RPM signing is an active TODO, but is not done. We will enable
20-
# this gpgcheck once the RPM supports it.
21-
gpgcheck => 0,
22-
before => Package['opendaylight'],
23-
}
249

25-
# Install the OpenDaylight RPM
26-
package { 'opendaylight':
27-
ensure => present,
28-
require => Yumrepo[$opendaylight::rpm_repo],
29-
}
30-
->
10+
if $::opendaylight::manage_repositories {
11+
require ::opendaylight::repos
12+
}
13+
14+
package { 'opendaylight':
15+
ensure => present,
16+
}
17+
18+
if $::osfamily == 'RedHat' {
3119
# Configure the systemd file with Java options
3220
file_line { 'java_options_systemd':
33-
ensure => present,
34-
path => '/usr/lib/systemd/system/opendaylight.service',
35-
line => "Environment=_JAVA_OPTIONS=\'${opendaylight::java_opts}\'",
36-
match => '^Environment.*',
37-
after => 'ExecStart=/opt/opendaylight/bin/start',
21+
ensure => present,
22+
path => '/usr/lib/systemd/system/opendaylight.service',
23+
line => "Environment=_JAVA_OPTIONS=\'${::opendaylight::java_opts}\'",
24+
match => '^Environment.*',
25+
after => 'ExecStart=/opt/opendaylight/bin/start',
26+
require => Package['opendaylight'],
3827
}
3928
->
4029
exec {'reload_systemd_units':
4130
command => 'systemctl daemon-reload',
4231
path => '/bin'
4332
}
4433
}
45-
46-
elsif $::osfamily == 'Debian'{
47-
48-
include apt
49-
50-
# Add ODL ppa repository
51-
apt::ppa{ $opendaylight::deb_repo: }
52-
53-
# Install Opendaylight .deb pkg
54-
package { 'opendaylight':
55-
ensure => present,
56-
require => Apt::Ppa[$opendaylight::deb_repo],
57-
}
58-
59-
Apt::Ppa[$opendaylight::deb_repo] -> Package['opendaylight']
60-
}
61-
else {
62-
fail("Unknown operating system method: ${::osfamily}")
63-
}
6434
}

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
$security_group_mode = 'stateful'
2222
$vpp_routing_node = ''
2323
$java_opts = '-Djava.net.preferIPv4Stack=true'
24+
$manage_repositories = true
2425
}

manifests/repos.pp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# == Class: opendaylight::repos
2+
#
3+
# Manages the installation of the OpenDaylight repositories for RedHat and
4+
# Debian
5+
#
6+
# === Parameters
7+
#
8+
# [*deb_repo*]
9+
# The name of the debppa repo to configure. Ignored if on a RHEL based system.
10+
# Defaults to $::opendaylight::deb_repo
11+
#
12+
# [*rpm_repo*]
13+
# The name of the rpm repo to configure. Ignored if on a Debian based system
14+
# Defaults to $::opendaylight::rpm_repo
15+
#
16+
# [*rpm_repo_enabled*]
17+
# Flag to indicate if the the rpm repo should be enabled or disabled.
18+
# Defualts to 1.
19+
#
20+
# [*rpm_repo_gpgcheck*]
21+
# Flag to indicate if the rpm repo should be configured with gpgcheck.
22+
# Defaults to 0.
23+
#
24+
class opendaylight::repos (
25+
$deb_repo = $::opendaylight::deb_repo,
26+
$rpm_repo = $::opendaylight::rpm_repo,
27+
$rpm_repo_enabled = 1,
28+
$rpm_repo_gpgcheck = 0,
29+
) inherits ::opendaylight {
30+
if $::osfamily == 'RedHat' {
31+
# Add OpenDaylight's Yum repository
32+
yumrepo { $rpm_repo:
33+
# 'ensure' isn't supported with Puppet <3.5
34+
# Seems to default to present, but docs don't say
35+
# https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
36+
# https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
37+
baseurl => "http://cbs.centos.org/repos/nfv7-${rpm_repo}/\$basearch/os/",
38+
descr => 'OpenDaylight SDN Controller',
39+
enabled => $rpm_repo_enabled,
40+
# NB: RPM signing is an active TODO, but is not done. We will enable
41+
# this gpgcheck once the RPM supports it.
42+
gpgcheck => $rpm_repo_gpgcheck,
43+
}
44+
} elsif ($::osfamily == 'Debian') {
45+
include ::apt
46+
47+
# Add ODL ppa repository
48+
apt::ppa{ $deb_repo: }
49+
} else {
50+
fail("Unknown operating system method: ${::osfamily}")
51+
}
52+
}

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
{
5252
"operatingsystem": "Ubuntu",
5353
"operatingsystemrelease": [
54-
"14.04"
54+
"16.04"
5555
]
5656
}
5757
],
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require 'spec_helper'
2+
3+
describe 'opendaylight::repos' do
4+
shared_examples_for "opendaylight::repos on Debian" do
5+
context "with defaults" do
6+
it { should contain_class('opendaylight::repos') }
7+
it { should contain_class('apt') }
8+
it { should contain_apt__ppa('ppa:odl-team/boron') }
9+
end
10+
11+
context "with custom deb_repo" do
12+
let(:params) do
13+
{ :deb_repo => 'ppa:foo/testing' }
14+
end
15+
16+
it { should contain_apt__ppa('ppa:foo/testing') }
17+
end
18+
end
19+
shared_examples_for "opendaylight::repos on RedHat" do
20+
context "with defaults" do
21+
it { should contain_class('opendaylight::repos') }
22+
it {
23+
should contain_yumrepo('opendaylight-5-testing').with(
24+
:baseurl => 'http://cbs.centos.org/repos/nfv7-opendaylight-5-testing/$basearch/os/',
25+
:enabled => 1,
26+
:gpgcheck => 0,
27+
)
28+
}
29+
end
30+
31+
context "with custom rpm repo options" do
32+
let(:params) do
33+
{
34+
:rpm_repo => 'testing',
35+
:rpm_repo_enabled => 0,
36+
:rpm_repo_gpgcheck => 1,
37+
}
38+
end
39+
it {
40+
should contain_yumrepo('testing').with(
41+
:baseurl => 'http://cbs.centos.org/repos/nfv7-testing/$basearch/os/',
42+
:enabled => 0,
43+
:gpgcheck => 1,
44+
)
45+
}
46+
47+
end
48+
end
49+
50+
describe "on unsupported os" do
51+
context "when on Solaris" do
52+
let(:facts) do
53+
{:osfamily => 'Solaris', :operatingsystem => 'Solaris'}
54+
end
55+
56+
57+
it 'should fail' do
58+
expect { is_expected.to raise_error(Puppet::Error) }
59+
end
60+
end
61+
end
62+
63+
on_supported_os.each do |os, facts|
64+
context "on #{os}" do
65+
let (:facts) do
66+
facts
67+
end
68+
69+
it_behaves_like "opendaylight::repos on #{facts[:osfamily]}"
70+
end
71+
end
72+
73+
end

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'puppetlabs_spec_helper/module_spec_helper'
2+
require 'rspec-puppet-facts'
3+
include RspecPuppetFacts
24

35
# Customize filters to ignore 3rd-party code
46
# If the coverage report shows not-our-code results, add it here

0 commit comments

Comments
 (0)