Improve test coverage 43/55643/1
authorsrisankethu <sanketh.uppalapati@research.iiit.ac.in>
Wed, 28 Dec 2016 21:00:39 +0000 (02:30 +0530)
committerDaniel Farrell <dfarrell@redhat.com>
Wed, 19 Apr 2017 19:18:40 +0000 (15:18 -0400)
Fixes https://github.com/dfarrell07/puppet-opendaylight/issues/116

Change-Id: I0efed8be2b941f9347d438481628272869529d0b
Signed-off-by: srisankethu <sanketh.uppalapati@research.iiit.ac.in>
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
manifests/install.pp
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb

index 7514818e332876294a98c0ed5aa6baade25ce140..f89a1fb33588b2f3aadc08dffdbaee6ba6bbadc3 100644 (file)
@@ -30,7 +30,7 @@ class opendaylight::install {
     }
     ->
     # Configure the systemd file to force ipv4 binds (instead of ipv6)
-    file_line { 'odl_start_ipv4 ':
+    file_line { 'odl_start_ipv4':
       ensure => present,
       path   => '/usr/lib/systemd/system/opendaylight.service',
       line   => 'Environment=_JAVA_OPTIONS=\'-Djava.net.preferIPv4Stack=true\'',
index 8cf4d843cf175e59a0e0bcfcec9e6f1ee1201be0..f05ac7313374bc6d4e6dc1ad32f62ad715f47ad9 100644 (file)
@@ -46,6 +46,11 @@ describe 'opendaylight' do
             # 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 OVSDB HA config
+            # NB: Only testing defaults here, specialized enabling HA tests elsewhere
+            # Note that this function is defined in spec_helper
+            enable_ha_tests
           end
         end
 
@@ -105,6 +110,11 @@ describe 'opendaylight' do
             # 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 OVSDB HA config
+            # NB: Only testing defaults here, specialized enabling HA tests elsewhere
+            # Note that this function is defined in spec_helper
+            enable_ha_tests
           end
         end
 
@@ -180,6 +190,11 @@ describe 'opendaylight' do
             # 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 OVSDB HA config
+            # NB: Only testing defaults here, specialized enabling HA tests elsewhere
+            # Note that this function is defined in spec_helper
+            enable_ha_tests
           end
         end
 
@@ -505,7 +520,7 @@ describe 'opendaylight' do
       }}
 
       let(:params) {{
-        :enable_l3 => false ,
+        :enable_l3 => false,
       }}
 
       # Run shared tests applicable to all supported OSs
@@ -538,6 +553,77 @@ describe 'opendaylight' do
     end
   end
 
+  # All OVSDB HA enable/disable tests
+  describe 'OVSDB HA 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_ha 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 OVSDB HA config
+      # Note that this function is defined in spec_helper
+      enable_ha_tests
+    end
+
+    context 'using false for enable_ha' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :enable_ha => 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 OVSDB HA config
+      # Note that this function is defined in spec_helper
+      enable_ha_tests(enable_ha: false)
+    end
+
+    context 'using true for enable_ha' do
+      context 'using ha_node_count >=2' do
+        let(:facts) {{
+          :osfamily => osfamily,
+          :operatingsystem => operatingsystem,
+          :operatingsystemmajrelease => operatingsystemmajrelease,
+        }}
+
+        let(:params) {{
+          :enable_ha => true,
+          :ha_node_ips => ['0.0.0.0', '127.0.0.1']
+        }}
+
+        # 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 OVSDB HA config
+        # Note that this function is defined in spec_helper
+        enable_ha_tests(enable_ha: true, ha_node_ips: ['0.0.0.0', '127.0.0.1'])
+      end
+    end
+  end
+
+
   # All install method tests
   describe 'install method tests' do
     # Non-OS-type tests assume CentOS 7
index 2452841f773c8fd500700912d0791a6a6894fae2..18ea6a6e123e176f0971d8d8bd2048db65281f3a 100644 (file)
@@ -14,12 +14,14 @@ custom_filters = [
   'Class[Java::Params]',
   'Class[Stdlib::Stages]',
   'Class[Stdlib]',
+  'Exec[Configure ODL OVSDB Clustering]',
   'Exec[download archive opendaylight.tar.gz and check sum]',
   'Exec[download archive opendaylight-systemd.tar.gz and check sum]',
   'Exec[opendaylight unpack]',
   'Exec[opendaylight-systemd unpack]',
   'Exec[rm-on-error-opendaylight.tar.gz]',
   'Exec[rm-on-error-opendaylight-systemd.tar.gz]',
+  'Exec[reload_systemd_units]',
   'Exec[update-java-alternatives]',
   'Package[curl]',
   'Stage[deploy]',
@@ -227,6 +229,33 @@ def enable_l3_tests(options = {})
   end
 end
 
+def enable_ha_tests(options = {})
+  # Extract params
+  enable_ha = options.fetch(:enable_ha, false)
+  ha_node_ips = options.fetch(:ha_node_ips, [])
+  ha_node_index = options.fetch(:ha_node_index, '')
+  # HA_NODE_IPS size
+  ha_node_count = ha_node_ips.size
+
+  if enable_ha
+    # Confirm ODL OVSDB HA is enabled
+    if ha_node_count >=2
+      # Check for HA_NODE_COUNT >= 2
+      it {
+        should contain_file('opendaylight/jolokia.xml').with(
+          'ensure'  => 'file',
+          'path'  => '/opt/opendaylight/deploy/jolokia.xml',
+          'owner' => 'odl',
+          'group' => 'odl'
+        )
+      }
+    else
+      # Check for HA_NODE_COUNT < 2
+      fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
+    end
+  end
+end
+
 def tarball_install_tests(options = {})
   # Extract params
   # NB: These default values should be the same as ones in opendaylight::params
@@ -390,6 +419,15 @@ def rpm_install_tests(options = {})
       'ensure'   => 'present',
     )
   }
+
+  it {
+    should contain_file_line('odl_start_ipv4').with(
+      'ensure' => 'present',
+      'path' => '/usr/lib/systemd/system/opendaylight.service',
+      'line' => 'Environment=_JAVA_OPTIONS=\'-Djava.net.preferIPv4Stack=true\'',
+      'after' => 'ExecStart=/opt/opendaylight/bin/start',
+    )
+  }
 end
 
 # Shared tests for unsupported OSs
@@ -417,6 +455,11 @@ def enable_sg_tests(sg_mode='stateful', os_release)
   # NB: This default value should be the same as one in opendaylight::params
   # TODO: Remove this possible source of bugs^^
 
+  it { should contain_file('/opt/opendaylight/etc/opendaylight') }
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
+
   if os_release != '7.3' and sg_mode == 'stateful'
     # Confirm sg_mode becomes learn
     it {
index c88eb1dd573be678533ef3a770a3eb363d8b978b..1257f502dfdd8a577831e508eae2706eb7c9499e 100644 (file)
@@ -63,6 +63,9 @@ 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_ha = options.fetch(:enable_ha, false)
+  ha_node_ips = options.fetch(:ha_node_ips, [])
+  ha_node_index = options.fetch(:ha_node_index, '')
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -74,6 +77,9 @@ def install_odl(options = {})
       extra_features => #{extra_features},
       odl_rest_port=> #{odl_rest_port},
       enable_l3=> #{enable_l3},
+      enable_ha=> #{enable_ha},
+      ha_node_ips=> #{ha_node_ips},
+      ha_node_index=> #{ha_node_index},
       log_levels=> #{log_levels},
     }
     EOS
@@ -306,6 +312,33 @@ def enable_l3_validations(options = {})
   end
 end
 
+# Shared function for validations related to ODL OVSDB HA config
+def enable_ha_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_ha = options.fetch(:enable_ha, false)
+  ha_node_ips = options.fetch(:ha_node_ips, [])
+  ha_node_index = options.fetch(:ha_node_index, '')
+  # HA_NODE_IPS size
+  ha_node_count = ha_node_ips.size
+
+  if enable_ha
+    # Confirm ODL OVSDB HA is enabled
+    if ha_node_count >=2
+      # Check for HA_NODE_COUNT >= 2
+      describe file('/opt/opendaylight/deploy/jolokia.xml') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+    end
+    else
+      # Check for HA_NODE_COUNT < 2
+      fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
+    end
+  end
+end
+
 # Shared function that handles validations specific to RPM-type installs
 def rpm_validations()
   rpm_repo = ENV['RPM_REPO']