Add RSpec tests for install_method param 99/55399/1
authorDaniel Farrell <dfarrell@redhat.com>
Fri, 13 Feb 2015 20:16:28 +0000 (15:16 -0500)
committerDaniel Farrell <dfarrell@redhat.com>
Wed, 19 Apr 2017 19:18:39 +0000 (15:18 -0400)
- Pull RPM-based install logic into dedicated fn
- Add tarball-based install logic
- Closes #44

Change-Id: I52aa83ef201a202db1c37686fcbce3fb433f9f57
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb

index b47980d98f8f9ac299939f5bfeca658463d3dc94..635298d9b519168e6b34c7f7f3db073e2128a13f 100644 (file)
@@ -95,7 +95,7 @@ describe 'opendaylight' do
 
   # All Karaf feature tests
   describe 'Karaf feature tests' do
-    # All Karaf feature tests assume CentOS 7
+    # Non-OS-type tests assume CentOS 7
     #   See issue #43 for reasoning:
     #   https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
     osfamily = 'RedHat'
@@ -103,10 +103,10 @@ describe 'opendaylight' do
     operatingsystemmajrelease = '7'
     # This is the CentOS 7 Yum repo URL
     yum_repo = 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/epel-7-$basearch/'
-    describe "using default features" do
+    describe 'using default features' do
       # NB: This list should be the same as the one in opendaylight::params
       default_features = ['config', 'standard', 'region', 'package', 'kar', 'ssh', 'management']
-      context "and not passing extra features" do
+      context 'and not passing extra features' do
         let(:facts) {{
           :osfamily => osfamily,
           :operatingsystem => operatingsystem,
@@ -124,7 +124,7 @@ describe 'opendaylight' do
         karaf_feature_tests(default_features)
       end
 
-      context "and passing extra features" do
+      context 'and passing extra features' do
         let(:facts) {{
           :osfamily => osfamily,
           :operatingsystem => operatingsystem,
@@ -132,7 +132,7 @@ describe 'opendaylight' do
         }}
 
         # These are real but arbitrarily chosen features
-        extra_features = ["odl-base-all", "odl-ovsdb-all"]
+        extra_features = ['odl-base-all', 'odl-ovsdb-all']
         let(:params) {{
           :extra_features => extra_features,
         }}
@@ -147,9 +147,9 @@ describe 'opendaylight' do
       end
     end
 
-    describe "overriding default features" do
-      default_features = ["standard", "ssh"]
-      context "and not passing extra features" do
+    describe 'overriding default features' do
+      default_features = ['standard', 'ssh']
+      context 'and not passing extra features' do
         let(:facts) {{
           :osfamily => osfamily,
           :operatingsystem => operatingsystem,
@@ -169,7 +169,7 @@ describe 'opendaylight' do
         karaf_feature_tests(default_features)
       end
 
-      context "and passing extra features" do
+      context 'and passing extra features' do
         let(:facts) {{
           :osfamily => osfamily,
           :operatingsystem => operatingsystem,
@@ -177,7 +177,7 @@ describe 'opendaylight' do
         }}
 
         # These are real but arbitrarily chosen features
-        extra_features = ["odl-base-all", "odl-ovsdb-all"]
+        extra_features = ['odl-base-all', 'odl-ovsdb-all']
         let(:params) {{
           :default_features => default_features,
           :extra_features => extra_features,
@@ -193,4 +193,64 @@ describe 'opendaylight' do
       end
     end
   end
+
+  # All install method tests
+  describe 'install method 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'
+    # This is the CentOS 7 Yum repo URL
+    yum_repo = 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/epel-7-$basearch/'
+
+    # All tests for RPM install method
+    context 'RPM' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+          :install_method => 'rpm',
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests(yum_repo)
+
+      # Run test that specialize in checking Karaf feature installs
+      # Note that this function is defined in spec_helper
+      install_method_tests('rpm', yum_repo)
+    end
+
+    # All tests for tarball install method
+    describe 'tarball' do
+      describe 'using default tarball_url' do
+        tarball_url = 'https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz'
+        context 'using default unitfile_url' do
+          unitfile_url = 'https://github.com/dfarrell07/opendaylight-systemd/archive/master/opendaylight-unitfile.tar.gz'
+          let(:facts) {{
+            :osfamily => osfamily,
+            :operatingsystem => operatingsystem,
+            :operatingsystemmajrelease => operatingsystemmajrelease,
+          }}
+
+          let(:params) {{
+              :install_method => 'tarball',
+          }}
+
+          # Run shared tests applicable to all supported OSs
+          # Note that this function is defined in spec_helper
+          generic_tests(yum_repo)
+
+          # Run test that specialize in checking Karaf feature installs
+          # Note that this function is defined in spec_helper
+          install_method_tests('tarball', yum_repo, tarball_url, unitfile_url)
+        end
+      end
+    end
+  end
 end
index a5bbd7a5e2e6e10a655aab60ea014aedd3be50f0..1aff33cb327dbf939772c4bca829667c59d5fba7 100644 (file)
@@ -21,32 +21,13 @@ def generic_tests(yum_repo)
   it { should contain_class('opendaylight::service').that_comes_before('opendaylight') }
   it { should contain_class('opendaylight').that_requires('opendaylight::service') }
 
-  # Confirm presense of other resources
+  # Confirm presense of generic resources
   it { should contain_service('opendaylight') }
-  it { should contain_yumrepo('opendaylight') }
-  it { should contain_package('opendaylight') }
   it { should contain_file('org.apache.karaf.features.cfg') }
 
-  # Confirm relationships between other resources
-  it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
-  it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
-
-  # Confirm properties of other resources
+  # Confirm properties of generic resources
   # NB: These hashes don't work with Ruby 1.8.7, but we
   #   don't support 1.8.7 so that's okay. See issue #36.
-  it {
-    should contain_yumrepo('opendaylight').with(
-      'enabled'     => '1',
-      'gpgcheck'    => '0',
-      'descr'       => 'OpenDaylight SDN controller',
-      'baseurl'     => yum_repo,
-    )
-  }
-  it {
-    should contain_package('opendaylight').with(
-      'ensure'      => 'present',
-    )
-  }
   it {
     should contain_service('opendaylight').with(
       'ensure'      => 'running',
@@ -65,6 +46,9 @@ end
 
 # Shared tests that specialize in testing Karaf feature installs
 def karaf_feature_tests(features)
+  # Confirm properties of other resources
+  # NB: These hashes don't work with Ruby 1.8.7, but we
+  #   don't support 1.8.7 so that's okay. See issue #36.
   it {
     should contain_file('org.apache.karaf.features.cfg').with(
       'ensure'      => 'file',
@@ -74,6 +58,71 @@ def karaf_feature_tests(features)
   }
 end
 
+def install_method_tests(method, yum_repo, tarball_url='', unitfile_url='')
+  case method
+  when 'rpm'
+    # Confirm presense of RPM-related resources
+    it { should contain_yumrepo('opendaylight') }
+    it { should contain_package('opendaylight') }
+    it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
+    it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
+
+    # Confirm properties of RPM-related resources
+    # NB: These hashes don't work with Ruby 1.8.7, but we
+    #   don't support 1.8.7 so that's okay. See issue #36.
+    it {
+      should contain_yumrepo('opendaylight').with(
+        'enabled'     => '1',
+        'gpgcheck'    => '0',
+        'descr'       => 'OpenDaylight SDN controller',
+        'baseurl'     => yum_repo,
+      )
+    }
+    it {
+      should contain_package('opendaylight').with(
+        'ensure'      => 'present',
+      )
+    }
+  when 'tarball'
+    if tarball_url == ''
+      fail('Expected tarball_url param')
+    end
+
+    if unitfile_url == ''
+      fail('Expected unitfile_url param')
+    end
+
+    # Confirm presense of tarball-related resources
+    it { should contain_archive('opendaylight-0.2.2') }
+    it { should contain_archive('opendaylight-systemd') }
+
+    # Confirm properties of tarball-related resources
+    # NB: These hashes don't work with Ruby 1.8.7, but we
+    #   don't support 1.8.7 so that's okay. See issue #36.
+    it {
+      should contain_archive('opendaylight-0.2.2').with(
+        'ensure'           => 'present',
+        'url'              => tarball_url,
+        'target'           => '/opt/',
+        'checksum'         => false,
+        'strip_components' => 1,
+      )
+    }
+    it {
+      should contain_archive('opendaylight-systemd').with(
+        'ensure'           => 'present',
+        'url'              => unitfile_url,
+        'target'           => '/usr/lib/systemd/system/',
+        'root_dir'         => '.',
+        'checksum'         => false,
+        'strip_components' => 1,
+      )
+    }
+  else
+    fail("Unexpected install method: #{method}")
+  end
+end
+
 # Shared tests for unsupported OSs
 def unsupported_os_tests(expected_err_msg)
   # Confirm that classes fail on unsupported OSs