Allow for disabling repository configuration 59/55659/1
authorAlex Schultz <aschultz@redhat.com>
Thu, 16 Mar 2017 23:57:10 +0000 (17:57 -0600)
committerDaniel Farrell <dfarrell@redhat.com>
Wed, 19 Apr 2017 19:18:40 +0000 (15:18 -0400)
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.

Change-Id: Iae079ba98c6f2a63e5c4d0cc11c2ffb8cdca0515
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
Gemfile
manifests/init.pp
manifests/install.pp
manifests/params.pp
manifests/repos.pp [new file with mode: 0644]
metadata.json
spec/classes/opendaylight_repos_spec.rb [new file with mode: 0644]
spec/spec_helper.rb

diff --git a/Gemfile b/Gemfile
index d672f2404880589d89721a82983b5a2c81137c7e..f19e87e3935aae85c27965d931f36e4b1b17e79b 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -8,6 +8,7 @@ group :test do
   gem "metadata-json-lint"
   gem "travis"
   gem "travis-lint"
+  gem "rspec-puppet-facts", :require => false
 end
 
 group :local_only do
index 563291d7107768c6e8e4e00944c74b5b78511f87..187e7aedd5aa35ad9ec659b3d8408bfcbfbb076f 100644 (file)
 #   Sets routing node for VPP deployments. Defaults to ''.
 # [*java_opts*]
 #   Sets Java options for ODL in a string format. Defaults to '-Djava.net.preferIPv4Stack=true'.
+# [*manage_repositories*]
+#   (Boolean) Should this module manage the apt or yum repositories for the
+#   package installation.
+#   Defaults to true
 #
 class opendaylight (
   $default_features    = $::opendaylight::params::default_features,
@@ -48,6 +52,7 @@ class opendaylight (
   $security_group_mode = $::opendaylight::params::security_group_mode,
   $vpp_routing_node    = $::opendaylight::params::vpp_routing_node,
   $java_opts           = $::opendaylight::params::java_opts,
+  $manage_repositories = $::opendaylight::params::manage_repositories,
 ) inherits ::opendaylight::params {
 
   # Validate OS family
index 56c4909e788f02aea0683a97617122b505e7ab02..27ec205aab33c65ea288d536b8134b7f2f3bc02c 100644 (file)
@@ -6,35 +6,24 @@
 # system state should be functionally equivalent.
 #
 class opendaylight::install {
-  if $::osfamily == 'RedHat' {
-    # Add OpenDaylight's Yum repository
-    yumrepo { $opendaylight::rpm_repo:
-      # 'ensure' isn't supported with Puppet <3.5
-      # Seems to default to present, but docs don't say
-      # https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
-      # https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
-      baseurl  => "http://cbs.centos.org/repos/nfv7-${opendaylight::rpm_repo}/\$basearch/os/",
-      descr    => 'OpenDaylight SDN Controller',
-      enabled  => 1,
-      # NB: RPM signing is an active TODO, but is not done. We will enable
-      #     this gpgcheck once the RPM supports it.
-      gpgcheck => 0,
-      before   => Package['opendaylight'],
-    }
 
-    # Install the OpenDaylight RPM
-    package { 'opendaylight':
-      ensure  => present,
-      require => Yumrepo[$opendaylight::rpm_repo],
-    }
-    ->
+  if $::opendaylight::manage_repositories {
+    require ::opendaylight::repos
+  }
+
+  package { 'opendaylight':
+    ensure  => present,
+  }
+
+  if $::osfamily == 'RedHat' {
     # Configure the systemd file with Java options
     file_line { 'java_options_systemd':
-      ensure => present,
-      path   => '/usr/lib/systemd/system/opendaylight.service',
-      line   => "Environment=_JAVA_OPTIONS=\'${opendaylight::java_opts}\'",
-      match  => '^Environment.*',
-      after  => 'ExecStart=/opt/opendaylight/bin/start',
+      ensure  => present,
+      path    => '/usr/lib/systemd/system/opendaylight.service',
+      line    => "Environment=_JAVA_OPTIONS=\'${::opendaylight::java_opts}\'",
+      match   => '^Environment.*',
+      after   => 'ExecStart=/opt/opendaylight/bin/start',
+      require => Package['opendaylight'],
     }
     ~>
     exec {'reload_systemd_units':
@@ -43,23 +32,4 @@ class opendaylight::install {
       refreshonly => true,
     }
   }
-
-  elsif $::osfamily == 'Debian'{
-
-    include apt
-
-    # Add ODL ppa repository
-    apt::ppa{ $opendaylight::deb_repo: }
-
-    # Install Opendaylight .deb pkg
-    package { 'opendaylight':
-      ensure  => present,
-      require => Apt::Ppa[$opendaylight::deb_repo],
-    }
-
-    Apt::Ppa[$opendaylight::deb_repo] -> Package['opendaylight']
-  }
-  else {
-    fail("Unknown operating system method: ${::osfamily}")
-  }
 }
index b6d87ff102460f75d2966c120aabdf1c9ea2adc1..886bf0a9481c2967a178f95bbb928d96a20358b4 100644 (file)
@@ -21,4 +21,5 @@ class opendaylight::params {
   $security_group_mode = 'stateful'
   $vpp_routing_node = ''
   $java_opts = '-Djava.net.preferIPv4Stack=true'
+  $manage_repositories = true
 }
diff --git a/manifests/repos.pp b/manifests/repos.pp
new file mode 100644 (file)
index 0000000..2ef3511
--- /dev/null
@@ -0,0 +1,52 @@
+# == Class: opendaylight::repos
+#
+# Manages the installation of the OpenDaylight repositories for RedHat and
+# Debian
+#
+# === Parameters
+#
+# [*deb_repo*]
+#  The name of the debppa repo to configure. Ignored if on a RHEL based system.
+#  Defaults to $::opendaylight::deb_repo
+#
+# [*rpm_repo*]
+#  The name of the rpm repo to configure. Ignored if on a Debian based system
+#  Defaults to $::opendaylight::rpm_repo
+#
+# [*rpm_repo_enabled*]
+#  Flag to indicate if the the rpm repo should be enabled or disabled.
+#  Defualts to 1.
+#
+# [*rpm_repo_gpgcheck*]
+#  Flag to indicate if the rpm repo should be configured with gpgcheck.
+#  Defaults to 0.
+#
+class opendaylight::repos (
+  $deb_repo          = $::opendaylight::deb_repo,
+  $rpm_repo          = $::opendaylight::rpm_repo,
+  $rpm_repo_enabled  = 1,
+  $rpm_repo_gpgcheck = 0,
+) inherits ::opendaylight {
+  if $::osfamily == 'RedHat' {
+    # Add OpenDaylight's Yum repository
+    yumrepo { $rpm_repo:
+      # 'ensure' isn't supported with Puppet <3.5
+      # Seems to default to present, but docs don't say
+      # https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
+      # https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
+      baseurl  => "http://cbs.centos.org/repos/nfv7-${rpm_repo}/\$basearch/os/",
+      descr    => 'OpenDaylight SDN Controller',
+      enabled  => $rpm_repo_enabled,
+      # NB: RPM signing is an active TODO, but is not done. We will enable
+      #     this gpgcheck once the RPM supports it.
+      gpgcheck => $rpm_repo_gpgcheck,
+    }
+  } elsif ($::osfamily == 'Debian') {
+    include ::apt
+
+    # Add ODL ppa repository
+    apt::ppa{ $deb_repo: }
+  } else {
+    fail("Unknown operating system method: ${::osfamily}")
+  }
+}
index 0eddeb5fde4d187d6d0bd5cff429cb4590c3068e..bfe8c3b61e368bcb9408a4ebf00509c3b3ef53d8 100644 (file)
@@ -51,7 +51,7 @@
         {
             "operatingsystem": "Ubuntu",
             "operatingsystemrelease": [
-                "14.04"
+                "16.04"
             ]
         }
     ],
diff --git a/spec/classes/opendaylight_repos_spec.rb b/spec/classes/opendaylight_repos_spec.rb
new file mode 100644 (file)
index 0000000..638fea1
--- /dev/null
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe 'opendaylight::repos' do
+  shared_examples_for "opendaylight::repos on Debian" do
+    context "with defaults" do
+      it { should contain_class('opendaylight::repos') }
+      it { should contain_class('apt') }
+      it { should contain_apt__ppa('ppa:odl-team/boron') }
+    end
+
+    context "with custom deb_repo" do
+      let(:params) do
+        { :deb_repo => 'ppa:foo/testing' }
+      end
+
+      it { should contain_apt__ppa('ppa:foo/testing') }
+    end
+  end
+  shared_examples_for "opendaylight::repos on RedHat" do
+    context "with defaults" do
+      it { should contain_class('opendaylight::repos') }
+      it {
+        should contain_yumrepo('opendaylight-5-testing').with(
+          :baseurl  => 'http://cbs.centos.org/repos/nfv7-opendaylight-5-testing/$basearch/os/',
+          :enabled  => 1,
+          :gpgcheck => 0,
+        )
+      }
+    end
+
+    context "with custom rpm repo options" do
+      let(:params) do
+        {
+          :rpm_repo => 'testing',
+          :rpm_repo_enabled => 0,
+          :rpm_repo_gpgcheck => 1,
+        }
+      end
+      it {
+        should contain_yumrepo('testing').with(
+          :baseurl  => 'http://cbs.centos.org/repos/nfv7-testing/$basearch/os/',
+          :enabled  => 0,
+          :gpgcheck => 1,
+        )
+      }
+
+    end
+  end
+
+  describe "on unsupported os" do
+    context "when on Solaris" do
+      let(:facts) do
+        {:osfamily => 'Solaris', :operatingsystem => 'Solaris'}
+      end
+
+
+      it 'should fail' do
+        expect { is_expected.to raise_error(Puppet::Error) }
+      end
+    end
+  end
+
+  on_supported_os.each do |os, facts|
+    context "on #{os}" do
+      let (:facts) do
+        facts
+      end
+
+      it_behaves_like "opendaylight::repos on #{facts[:osfamily]}"
+    end
+  end
+
+end
index 7bf984d30f385e9ab4ae5eae53c06f7cfaf60baf..9571e2a2be678b8b42bc8f4b7b9828a92e60e501 100644 (file)
@@ -1,4 +1,6 @@
 require 'puppetlabs_spec_helper/module_spec_helper'
+require 'rspec-puppet-facts'
+include RspecPuppetFacts
 
 # Customize filters to ignore 3rd-party code
 # If the coverage report shows not-our-code results, add it here