Binds OpenFlow and OVSDB IPs
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper_acceptance.rb
index d4607fecc89ed26e5e4c44e426e251424d6acbdc..389fabc6843b731c0b983b18eb0996ea1a860a95 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
 
@@ -53,7 +58,7 @@ def install_odl(options = {})
   # 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'])
-  odl_rest_port = options.fetch(:odl_rest_port, 8080)
+  odl_rest_port = options.fetch(:odl_rest_port, 8181)
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
   log_levels = options.fetch(:log_levels, {})
   enable_ha = options.fetch(:enable_ha, false)
@@ -64,9 +69,13 @@ def install_odl(options = {})
   password = options.fetch(:password, 'admin')
   log_max_size = options.fetch(:log_max_size, '10GB')
   log_max_rollover = options.fetch(:log_max_rollover, 2)
+  log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
   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)
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -87,9 +96,13 @@ def install_odl(options = {})
       password => #{password},
       log_max_size => '#{log_max_size}',
       log_max_rollover => #{log_max_rollover},
+      log_rollover_fileindex => #{log_rollover_fileindex},
       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},
     }
     EOS
 
@@ -106,7 +119,8 @@ end
 
 # Shared function that handles generic validations
 # These should be common for all odl class param combos
-def generic_validations()
+def generic_validations(options = {})
+  java_opts = options.fetch(:java_opts, [])
   # Verify ODL's directory
   describe file('/opt/opendaylight/') do
     it { should be_directory }
@@ -157,6 +171,21 @@ def generic_validations()
     it { should be_grouped_into 'odl' }
   end
 
+  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
+  else
+    java_options = ['-Djava.net.preferIPv6Addresses=true'] + java_opts
+  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_options.join(" ")}/ }
+  end
+
   # Should contain ODL NB port config file
   describe file('/opt/opendaylight/etc/jetty.xml') do
     it { should be_file }
@@ -209,17 +238,31 @@ def generic_validations()
 end
 
 # Shared function for validations related to log file settings
-def log_file_settings_validations(options = {})
+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_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
+  log_mechanism = options.fetch(:log_mechanism, 'file')
 
-  describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
-    it { should be_file }
-    it { should be_owned_by 'odl' }
-    it { should be_grouped_into 'odl' }
-    its(:content) { should match /^log4j.appender.out.maxFileSize=#{log_max_size}/ }
-    its(:content) { should match /^log4j.appender.out.maxBackupIndex=#{log_max_rollover}/ }
+  if log_mechanism == 'console'
+    describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
+      it { should be_file }
+      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
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      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
 end
 
@@ -247,7 +290,7 @@ 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, 8080)
+  odl_rest_port = options.fetch(:odl_rest_port, 8181)
 
   describe file('/opt/opendaylight/etc/jetty.xml') do
     it { should be_file }
@@ -255,6 +298,56 @@ def port_config_validations(options = {})
     it { should be_grouped_into 'odl' }
     its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
   end
+
+  describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
+    it { should be_file }
+    it { should be_owned_by 'odl' }
+    it { should be_grouped_into 'odl' }
+    its(:content) { should match /org.osgi.service.http.port = #{odl_rest_port}/ }
+  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
+  # TODO: Remove this possible source of bugs^^
+  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
@@ -280,11 +373,13 @@ def log_level_validations(options = {})
     end
     # Verify each custom log level config entry
     log_levels.each_pair do |logger, level|
+      underscored_version = "#{logger}".gsub('.', '_')
       describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
         it { should be_file }
         it { should be_owned_by 'odl' }
         it { should be_grouped_into 'odl' }
-        its(:content) { should match /^log4j.logger.#{logger}=#{level}/ }
+        its(:content) { should match /^log4j2.logger.#{underscored_version}.level = #{level}/ }
+        its(:content) { should match /^log4j2.logger.#{underscored_version}.name = #{logger}/ }
       end
     end
   end
@@ -379,13 +474,17 @@ def username_password_validations(options = {})
   # 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:8080/restconf'
+  odl_check_url = 'http://127.0.0.1:8181/restconf'
 
   describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
     it { should be_file }
   end
 
-  describe command("sleep 180 && curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
+  describe command("loop_count=0; until [[ \$loop_count -ge 300 ]]; do curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds for ODL to become active\"") do
+    its(:exit_status) { should eq 0 }
+  end
+
+  describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
     its(:exit_status) { should eq 0 }
   end
 end
@@ -406,23 +505,41 @@ def snat_mechanism_validations(options = {})
 end
 
 # Shared function for validations related to SFC
-def sfc_validations()
+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^^
 
-  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 /<use-of-tunnels>true<\/use-of-tunnels>/ }
+  extra_features = options.fetch(:extra_features, [])
+  if extra_features.include? 'odl-netvirt-sfc'
+    sfc_enabled = true
+  else
+    sfc_enabled = false
   end
 
   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
     it { should be_file }
     it { should be_owned_by 'odl' }
     it { should be_grouped_into 'odl' }
-    its(:content) { should match /<gpe-extension-enabled>true<\/gpe-extension-enabled>/ }
+    its(:content) { should match /<gpe-extension-enabled>#{sfc_enabled}<\/gpe-extension-enabled>/ }
+  end
+end
+
+# Shared function for validations related to tos value for DSCP marking
+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)
+
+  if inherit_dscp_marking
+    describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /<default-tunnel-tos>inherit<\/default-tunnel-tos>/ }
+    end
   end
 end
 
@@ -432,11 +549,17 @@ def websocket_address_validations(options = {})
   # TODO: Remove this possible source of bugs^^
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
 
-  describe file('/opt/opendaylight/etc/opendaylight/karaf/10-rest-connector.xml') do
-    it { should be_file }
-    it { should be_owned_by 'odl' }
-    it { should be_grouped_into 'odl' }
-    its(:content) { should match /<websocket-address>#{odl_bind_ip}<\/websocket-address>/ }
+  if not odl_bind_ip.eql? '0.0.0.0'
+    describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /^websocket-address=#{odl_bind_ip}/ }
+    end
+  else
+    describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
+      it { should be_file }
+    end
   end
 end
 
@@ -445,7 +568,7 @@ def tls_validations(options = {})
   #   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, 8080)
+  odl_rest_port = options.fetch(:odl_rest_port, 8181)
 
   describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
     it { should be_file }
@@ -456,6 +579,7 @@ def tls_validations(options = {})
     its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
     its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
     its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
+    its(:content) { should match /org.osgi.service.http.enabled = false/ }
   end
 
   describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
@@ -489,3 +613,18 @@ 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
+  # TODO: Remove this possible source of bugs^^
+
+  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