INTPAK-117 Fixes configuring Java Opts
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper.rb
index 27b3773d419e15f5bb3c246bdd9ea0b65a1c4633..5d60a6500c40fefbe989f979d602fd8f7585e0d2 100644 (file)
@@ -13,7 +13,9 @@ RSpec::Puppet::Coverage.filters.push(*custom_filters)
 #
 
 # Tests that are common to all possible configurations
-def generic_tests()
+def generic_tests(options = {})
+  java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
+
   # Confirm that module compiles
   it { should compile }
   it { should compile.with_all_deps }
@@ -59,6 +61,17 @@ def generic_tests()
       'group'   => 'odl',
     )
   }
+
+  it {
+    should contain_file_line('Karaf Java Options').with(
+      'ensure' => 'present',
+      'path'   => '/opt/opendaylight/bin/karaf',
+      'line'   => "JAVA_OPTS=#{java_opts}",
+      'match'  => '^JAVA_OPTS=.*$',
+      'after'  => '^PROGNAME=.*$'
+    )
+  }
+
 end
 
 # Shared tests that specialize in testing log file size and rollover
@@ -70,35 +83,34 @@ def log_settings(options = {})
 
   if log_mechanism == 'console'
     it {
-      should contain_file_line('rootlogger').with(
+      should contain_file_line('consoleappender').with(
         'path'  => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-        'line'  => 'log4j.rootLogger=INFO, stdout, osgi:*',
-        'match' => '^log4j.rootLogger.*$',
-      )
-    }
-    it {
-      should contain_file_line('logappender').with(
-        'path'               => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-        'line'               => 'log4j.appender.stdout.direct=true',
-        'after'              => 'log4j.appender.stdout=org.apache.log4j.ConsoleAppender',
-        'match'              => '^log4j.appender.stdout.direct.*$'
+        'line'  => 'karaf.log.console=INFO',
+        'after' => 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter',
+        'match' => '^karaf.log.console.*$'
       )
     }
   else
-    it {
-      should contain_file_line('logmaxsize').with(
-        'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-        'line'   => "log4j.appender.out.maxFileSize=#{log_max_size}",
-        'match'  => '^log4j.appender.out.maxFileSize.*$',
-      )
-    }
-    it {
-      should contain_file_line('logmaxrollover').with(
-        'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-        'line'   => "log4j.appender.out.maxBackupIndex=#{log_max_rollover}",
-        'match'  => '^log4j.appender.out.maxBackupIndex.*$',
-      )
-    }
+  it {
+    should contain_file_line('logmaxsize').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => "log4j2.appender.rolling.policies.size.size = #{log_max_size}",
+      'match'  => '^log4j2.appender.rolling.policies.size.size.*$',
+    )
+  }
+  it {
+    should contain_file_line('rolloverstrategy').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
+    )
+  }
+  it {
+    should contain_file_line('logmaxrollover').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => "log4j2.appender.rolling.strategy.max = #{log_max_rollover}",
+      'match'  => '^log4j2.appender.rolling.strategy.max.*$',
+    )
+  }
   end
 end
 
@@ -139,7 +151,7 @@ def odl_rest_port_tests(options = {})
   # Extract params
   # NB: This default value should be the same as one 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)
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
   # Confirm properties of ODL REST port config file
   # NB: These hashes don't work with Ruby 1.8.7, but we
@@ -163,6 +175,15 @@ def odl_rest_port_tests(options = {})
       should_not contain_augeas('ODL REST IP')
     }
   end
+
+  it {
+    should contain_file_line('set pax bind port').with(
+        'ensure'  => 'present',
+        'path'    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
+        'line'    => "org.osgi.service.http.port = #{odl_rest_port}",
+        'require' => 'File[org.ops4j.pax.web.cfg]'
+    )
+  }
 end
 
 def log_level_tests(options = {})
@@ -174,16 +195,27 @@ def log_level_tests(options = {})
   if log_levels.empty?
     # Should contain log level config file
     it {
-      should_not contain_file_line('logger-org.opendaylight.ovsdb')
+      should_not contain_file_line('logger-org.opendaylight.ovsdb-level')
+    }
+    it {
+      should_not contain_file_line('logger-org.opendaylight.ovsdb-name')
     }
   else
     # Verify each custom log level config entry
     log_levels.each_pair do |logger, level|
+      underscored_version = "#{logger}".gsub('.', '_')
       it {
-        should contain_file_line("logger-#{logger}").with(
+        should contain_file_line("logger-#{logger}-level").with(
+          'ensure' => 'present',
+          'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+          'line' => "log4j2.logger.#{underscored_version}.level = #{level}",
+          'match'  => "log4j2.logger.#{underscored_version}.level = .*$"
+        )
+        should contain_file_line("logger-#{logger}-name").with(
           'ensure' => 'present',
           'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-          'line' => "log4j.logger.#{logger}=#{level}",
+          'line' => "log4j2.logger.#{underscored_version}.name = #{logger}",
+          'match'  => "log4j2.logger.#{underscored_version}.name = .*$"
         )
       }
     end
@@ -253,7 +285,7 @@ end
 def rpm_install_tests(options = {})
   # Extract params
   rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-oxygen-epel-7-$basearch-devel')
-  java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
+
 
   # Default to CentOS 7 Yum repo URL
 
@@ -281,15 +313,6 @@ def rpm_install_tests(options = {})
       'ensure'   => 'present',
     )
   }
-
-  it {
-    should contain_file_line('java_options_systemd').with(
-      'ensure' => 'present',
-      'path' => '/usr/lib/systemd/system/opendaylight.service',
-      'line' => "Environment=_JAVA_OPTIONS=\'#{java_opts}\'",
-      'after' => 'ExecStart=/opt/opendaylight/bin/start',
-    )
-  }
 end
 
 def deb_install_tests(options = {})
@@ -458,7 +481,7 @@ def odl_tls_tests(options = {})
   tls_key_file = options.fetch(:tls_key_file, nil)
   tls_cert_file = options.fetch(:tls_cert_file, nil)
   tls_ca_cert_file = options.fetch(:tls_ca_cert_file, nil)
-  odl_rest_port = options.fetch(:odl_rest_port, 8080)
+  odl_rest_port = options.fetch(:odl_rest_port, 8181)
 
   if enable_tls
     if tls_keystore_password.nil?