Merge "Bump Puppet version 4.x to 5.x"
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper_acceptance.rb
index f7ef25313f33989ed0041f04f4711cded267bdca..8a8aa07888e5575e5e308bca43daa2b4375cca99 100644 (file)
@@ -1,11 +1,16 @@
 require 'beaker-rspec/spec_helper'
 require 'beaker-rspec/helpers/serverspec'
+require 'beaker-puppet'
+
+include Beaker::DSL::InstallUtils::FOSSUtils
+include Beaker::DSL::InstallUtils::ModuleUtils
+include Beaker::DSL::Helpers::PuppetHelpers
 
 # Install Puppet on all Beaker hosts
 unless ENV['BEAKER_provision'] == 'no'
   hosts.each do |host|
     # Install Puppet
-    install_puppet_agent_on(host, puppet_collection: "pc1")
+    install_puppet_agent_on(host, {:puppet_collection => "pc1"})
   end
 end
 
@@ -49,7 +54,6 @@ def install_odl(options = {})
 
   # NB: These param defaults should match the ones used by the opendaylight
   #   class, which are defined in opendaylight::params
-  # TODO: Remove this possible source of bugs^^
   # Extract params if given, defaulting to odl class defaults if not
   extra_features = options.fetch(:extra_features, ['odl-restconf'])
   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
@@ -62,13 +66,19 @@ def install_odl(options = {})
   ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
   username = options.fetch(:username, 'admin')
   password = options.fetch(:password, 'admin')
-  log_max_size = options.fetch(:log_max_size, '10GB')
-  log_max_rollover = options.fetch(:log_max_rollover, 2)
+  log_max_size = options.fetch(:log_max_size, '500MB')
+  log_max_rollover = options.fetch(:log_max_rollover, 4)
+  log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
+  log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
+  enable_paxosgi_logger = options.fetch(:enable_paxosgi_logger, false)
   snat_mechanism = options.fetch(:snat_mechanism, 'controller')
   enable_tls = options.fetch(:enable_tls, false)
   tls_keystore_password = options.fetch(:tls_keystore_password, 'dummypass')
   log_mechanism = options.fetch(:log_mechanism, 'file')
   inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
+  stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
+  inactivity_probe = options.fetch(:inactivity_probe, :undef)
+  java_opts = options.fetch(:java_opts, '')
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -89,11 +99,17 @@ def install_odl(options = {})
       password => #{password},
       log_max_size => '#{log_max_size}',
       log_max_rollover => #{log_max_rollover},
+      log_pattern => '#{log_pattern}',
+      log_rollover_fileindex => #{log_rollover_fileindex},
+      enable_paxosgi_logger => #{enable_paxosgi_logger},
       snat_mechanism => #{snat_mechanism},
       enable_tls => #{enable_tls},
       tls_keystore_password => #{tls_keystore_password},
       log_mechanism => #{log_mechanism},
       inherit_dscp_marking => #{inherit_dscp_marking},
+      stats_polling_enabled => #{stats_polling_enabled},
+      inactivity_probe => #{inactivity_probe},
+      java_opts => '#{java_opts}',
     }
     EOS
 
@@ -111,8 +127,6 @@ end
 # Shared function that handles generic validations
 # These should be common for all odl class param combos
 def generic_validations(options = {})
-  java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
-
   # Verify ODL's directory
   describe file('/opt/opendaylight/') do
     it { should be_directory }
@@ -163,12 +177,24 @@ def generic_validations(options = {})
     it { should be_grouped_into 'odl' }
   end
 
+  java_opts = options.fetch(:java_opts, '')
+  odl_bind_ip = options.fetch(:odl_bind_ip, '127.0.0.1')
+  if odl_bind_ip == '127.0.0.1'
+    java_options = ['-Djava.net.preferIPv4Stack=true', java_opts].join(' ').strip
+  else
+    java_options = ['-Djava.net.preferIPv6Addresses=true', java_opts].join(' ').strip
+  end
+
   # Should contain karaf file with Java options set
   describe file('/opt/opendaylight/bin/karaf') do
     it { should be_file }
     it { should be_owned_by 'odl' }
     it { should be_grouped_into 'odl' }
-    its(:content) { should match /^EXTRA_JAVA_OPTS=#{java_opts}$/ }
+    its(:content) { should match /^EXTRA_JAVA_OPTS=\"#{java_options}\"/ }
+  end
+
+  describe command do ("ps -ef | grep opendaylight | grep #{java_options}")
+    its(:exit_status) { should eq 0 }
   end
 
   # Should contain ODL NB port config file
@@ -225,9 +251,12 @@ end
 # Shared function for validations related to log file settings
 def log_settings_validations(options = {})
   # Should contain log level config file with correct file size and rollover values
-  log_max_size = options.fetch(:log_max_size, '10GB')
-  log_max_rollover = options.fetch(:log_max_rollover, 2)
+  log_max_size = options.fetch(:log_max_size, '500MB')
+  log_max_rollover = options.fetch(:log_max_rollover, 4)
+  log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
+  log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
   log_mechanism = options.fetch(:log_mechanism, 'file')
+  enable_paxosgi_logger = options.fetch(:enable_paxosgi_logger, false)
 
   if log_mechanism == 'console'
     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
@@ -235,6 +264,7 @@ def log_settings_validations(options = {})
       it { should be_owned_by 'odl' }
       it { should be_grouped_into 'odl' }
       its(:content) { should match /^karaf.log.console=INFO/ }
+      its(:content) { should match /^log4j2.appender.console.direct = true/ }
     end
   else
     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
@@ -244,6 +274,23 @@ def log_settings_validations(options = {})
       its(:content) { should match /^log4j2.appender.rolling.policies.size.size = #{log_max_size}/ }
       its(:content) { should match /^log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy/ }
       its(:content) { should match /^log4j2.appender.rolling.strategy.max = #{log_max_rollover}/ }
+      its(:content) { should match /^log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}/ }
+    end
+  end
+  describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
+    its(:content) { should match /^log4j2.pattern = #{log_pattern}/ }
+    if enable_paxosgi_logger == true
+        its(:content) { should match /^log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi/ }
+        its(:content) { should match /^# OSGi appender/ }
+        its(:content) { should match /^log4j2.appender.osgi.type = PaxOsgi/ }
+        its(:content) { should match /^log4j2.appender.osgi.name = PaxOsgi/ }
+        its(:content) { should match /^log4j2.appender.osgi.filter = */ }
+    else
+        its(:content) { should_not match /^log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi/ }
+        its(:content) { should_not match /^# OSGi appender/ }
+        its(:content) { should_not match /^log4j2.appender.osgi.type = PaxOsgi/ }
+        its(:content) { should_not match /^log4j2.appender.osgi.name = PaxOsgi/ }
+        its(:content) { should_not match /^log4j2.appender.osgi.filter = */ }
     end
   end
 end
@@ -252,7 +299,6 @@ end
 def karaf_config_validations(options = {})
   # NB: These param defaults should match the ones used by the opendaylight
   #   class, which are defined in opendaylight::params
-  # TODO: Remove this possible source of bugs^^
   extra_features = options.fetch(:extra_features, [])
   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
 
@@ -271,7 +317,6 @@ end
 def port_config_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^^
   odl_rest_port = options.fetch(:odl_rest_port, 8181)
 
   describe file('/opt/opendaylight/etc/jetty.xml') do
@@ -289,11 +334,52 @@ def port_config_validations(options = {})
   end
 end
 
+# Shared function for validations related to the ODL bind IP
+def odl_bind_ip_validation(options = {})
+  # NB: This param default should match the one used by the opendaylight
+  #   class, which is defined in opendaylight::params
+  odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
+
+  if odl_bind_ip != '0.0.0.0'
+    describe file('/opt/opendaylight/etc/org.apache.karaf.shell.cfg') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /sshHost = #{odl_bind_ip}/ }
+    end
+
+    describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /ovsdb-listener-ip = #{odl_bind_ip}/ }
+    end
+
+    describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /<address>#{odl_bind_ip}<\/address>/ }
+    end
+
+    describe command("loop_count=0; until [[ \$loop_count -ge 30 ]]; do netstat -punta | grep 8101 | grep #{odl_bind_ip} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds to detect ODL karaf bound to IP\"") do
+      its(:exit_status) { should eq 0 }
+    end
+
+    describe command("loop_count=0; until [[ \$loop_count -ge 60 ]]; do netstat -punta | grep 6653 | grep #{odl_bind_ip} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds to detect ODL karaf bound to IP\"") do
+      its(:exit_status) { should eq 0 }
+    end
+
+    describe command("loop_count=0; until [[ \$loop_count -ge 60 ]]; do netstat -punta | grep 6640 | grep #{odl_bind_ip} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds to detect ODL karaf bound to IP\"") do
+      its(:exit_status) { should eq 0 }
+    end
+  end
+end
+
 # Shared function for validations related to custom logging verbosity
 def log_level_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^^
   log_levels = options.fetch(:log_levels, {})
 
   if log_levels.empty?
@@ -328,7 +414,6 @@ end
 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, [])
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
@@ -410,7 +495,6 @@ end
 def username_password_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^^
   odl_username = options.fetch(:username, 'admin')
   odl_password = options.fetch(:password, 'admin')
   odl_check_url = 'http://127.0.0.1:8181/restconf'
@@ -432,7 +516,6 @@ end
 def snat_mechanism_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^^
   snat_mechanism = options.fetch(:snat_mechanism, 'controller')
 
   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
@@ -447,7 +530,6 @@ end
 def sfc_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^^
 
   extra_features = options.fetch(:extra_features, [])
   if extra_features.include? 'odl-netvirt-sfc'
@@ -468,7 +550,6 @@ end
 def dscp_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^^
 
   inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
 
@@ -485,7 +566,6 @@ end
 def websocket_address_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^^
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
 
   if not odl_bind_ip.eql? '0.0.0.0'
@@ -505,7 +585,6 @@ end
 def tls_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^^
   tls_keystore_password = options.fetch(:tls_keystore_password)
   odl_rest_port = options.fetch(:odl_rest_port, 8181)
 
@@ -552,3 +631,33 @@ def tls_validations(options = {})
     its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }
   end
 end
+
+# Shared function for validations related to OVS statistics polling
+def stats_polling_validations(options = {})
+  # NB: This param default should match the one used by the opendaylight
+  #   class, which is defined in opendaylight::params
+
+  stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
+  describe file('/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg') do
+    it { should be_file }
+    it { should be_owned_by 'odl' }
+    it { should be_grouped_into 'odl' }
+    its(:content) { should match /is-statistics-polling-on=#{stats_polling_enabled}/ }
+  end
+end
+
+# Shared function for validations related to inactivity probe
+def inactivity_probe_validations(options = {})
+  # NB: This param default should match the one used by the opendaylight
+  #   class, which is defined in opendaylight::params
+
+  inactivity_probe = options.fetch(:inactivity_probe, :undef)
+  unless inactivity_probe == :undef
+    describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /<controller-inactivity-probe>#{inactivity_probe}/ }
+    end
+  end
+end