Merge "Bump Puppet version 4.x to 5.x"
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper.rb
index 1baf7176a07bae0cb07f920fb3ed44032ebd9218..564be8d980bb9e3e148924b648c3cd2ab5f3f9bf 100644 (file)
@@ -14,7 +14,9 @@ RSpec::Puppet::Coverage.filters.push(*custom_filters)
 
 # Tests that are common to all possible configurations
 def generic_tests(options = {})
-  java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
+  java_opts = options.fetch(:java_opts, '')
+  odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
+  inactivity_probe = options.fetch(:inactivity_probe, :undef)
 
   # Confirm that module compiles
   it { should compile }
@@ -63,23 +65,64 @@ def generic_tests(options = {})
   }
 
   it {
+    if odl_bind_ip =~ /.*:.*/
+        java_options = '-Djava.net.preferIPv6Addresses=true'
+    else
+        java_options = '-Djava.net.preferIPv4Stack=true'
+    end
+
     should contain_file_line('Karaf Java Options').with(
       'ensure' => 'present',
       'path'   => '/opt/opendaylight/bin/karaf',
-      'line'   => "EXTRA_JAVA_OPTS=#{java_opts}",
+      'line'   => "EXTRA_JAVA_OPTS=\"#{java_options}\"",
       'match'  => '^EXTRA_JAVA_OPTS=.*$',
       'after'  => '^PROGNAME=.*$'
     )
   }
 
+  it {
+    should contain_file('org.opendaylight.ovsdb.library.cfg').with(
+      'ensure'  => 'file',
+      'path'    => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
+      'owner'   => 'odl',
+      'group'   => 'odl',
+      'content' =>  /ovsdb-listener-ip = #{odl_bind_ip}/
+    )
+  }
+
+  it {
+    should contain_file('default-openflow-connection-config.xml').with(
+      'ensure'  => 'file',
+      'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
+      'owner'   => 'odl',
+      'group'   => 'odl',
+      'content' =>  /<address>#{odl_bind_ip}<\/address>/
+    )
+  }
+
+  unless inactivity_probe == :undef
+    it {
+      should contain_file('Configure inactivity probe timer').with(
+        'ensure'  => 'file',
+        'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
+        'owner'   => 'odl',
+        'group'   => 'odl',
+        'content' =>  /<controller-inactivity-probe>#{inactivity_probe}<\/controller-inactivity-probe>/
+      )
+    }
+  end
+
 end
 
 # Shared tests that specialize in testing log file size and rollover
 def log_settings(options = {})
   # Extraxt params. The dafault value should be same as in opendaylight::params
-  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_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
+  log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
   log_mechanism = options.fetch(:log_mechanism, 'file')
+  enable_paxosgi_logger = options.fetch(:enable_paxosgi_logger, false)
 
   if log_mechanism == 'console'
     it {
@@ -90,35 +133,94 @@ def log_settings(options = {})
         'match' => '^karaf.log.console.*$'
       )
     }
+    it {
+      should contain_file_line('direct').with(
+        'path'  => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'  => 'log4j2.appender.console.direct = true',
+        'after' => 'karaf.log.console=INFO',
+        'match' => '^log4j2.appender.console.direct.*$'
+      )
+    }
   else
+
+    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.*$',
+      )
+    }
+    it {
+      should contain_file_line('logrolloverfileindex').with(
+        'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'   => "log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}",
+        'match'  => '^log4j2.appender.rolling.strategy.fileIndex.*$',
+      )
+    }
+  end
   it {
-    should contain_file_line('logmaxsize').with(
+    should contain_file_line('logpattern').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.*$',
+      'line'   => "log4j2.pattern = #{log_pattern}",
+      'match'  => '^log4j2.pattern.*$',
     )
   }
+  if enable_paxosgi_logger == true
+      presence = 'present'
+  else
+      presence = 'absent'
+  end
+
   it {
-    should contain_file_line('rolloverstrategy').with(
+    should contain_file_line('paxosgiappenderref').with(
+      'ensure' => presence,
       'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-      'line'   => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
+      'line'   => "log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi",
     )
   }
   it {
-    should contain_file_line('logmaxrollover').with(
+    should contain_file_line('paxosgisection').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.*$',
+      'line'   => "# OSGi appender",
+    )
+  }
+  it {
+    should contain_file_line('paxosgitype').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => "log4j2.appender.osgi.type = PaxOsgi",
+    )
+  }
+  it {
+    should contain_file_line('paxosginame').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => "log4j2.appender.osgi.name = PaxOsgi",
+    )
+  }
+  it {
+    should contain_file_line('paxosgifilter').with(
+      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      'line'   => "log4j2.appender.osgi.filter = *",
     )
   }
-  end
 end
 
 # Shared tests that specialize in testing Karaf feature installs
 def karaf_feature_tests(options = {})
   # Extract params
   # NB: This default list should be the same as the one in opendaylight::params
-  # TODO: Remove this possible source of bugs^^
   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
   extra_features = options.fetch(:extra_features, [])
 
@@ -150,7 +252,6 @@ end
 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, 8181)
   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
   # Confirm properties of ODL REST port config file
@@ -169,6 +270,12 @@ def odl_rest_port_tests(options = {})
         'line'    => "org.ops4j.pax.web.listening.addresses = #{odl_bind_ip}",
         'require' => 'File[org.ops4j.pax.web.cfg]'
       )
+      should contain_file_line('set karaf IP').with(
+        'ensure' => 'present',
+        'path'   => '/opt/opendaylight/etc/org.apache.karaf.shell.cfg',
+        'line'   => "sshHost = #{odl_bind_ip}",
+        'match'  => '^sshHost\s*=.*$',
+      )
     }
   else
     it {
@@ -190,7 +297,6 @@ end
 def log_level_tests(options = {})
   # Extract params
   # NB: This default value should be the same as one in opendaylight::params
-  # TODO: Remove this possible source of bugs^^
   log_levels = options.fetch(:log_levels, {})
 
   if log_levels.empty?
@@ -285,7 +391,7 @@ end
 
 def rpm_install_tests(options = {})
   # Extract params
-  rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-fluorine-epel-7-$basearch-devel')
+  rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-neon-epel-7-$basearch-devel')
 
 
   # Default to CentOS 7 Yum repo URL
@@ -340,7 +446,7 @@ end
 def unsupported_os_tests(options = {})
   # Extract params
   expected_msg = options.fetch(:expected_msg)
-  rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-fluorine-epel-7-$basearch-devel')
+  rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-neon-epel-7-$basearch-devel')
 
   # Confirm that classes fail on unsupported OSs
   it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
@@ -431,7 +537,6 @@ end
 def vpp_routing_node_tests(options = {})
   # Extract params
   # NB: This default list should be the same as the one in opendaylight::params
-  # TODO: Remove this possible source of bugs^^
   routing_node = options.fetch(:routing_node, '')
 
   if routing_node.empty?
@@ -473,7 +578,6 @@ end
 def odl_websocket_address_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_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
@@ -557,11 +661,11 @@ def odl_tls_tests(options = {})
         'group'   => 'odl',
       )
       should contain_file('org.opendaylight.ovsdb.library.cfg').with(
-        'ensure' => 'file',
-        'path'   => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
-        'owner'  => 'odl',
-        'group'  => 'odl',
-        'source' => 'puppet:///modules/opendaylight/org.opendaylight.ovsdb.library.cfg'
+        'ensure'  => 'file',
+        'path'    => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
+        'owner'   => 'odl',
+        'group'   => 'odl',
+        'content' =>  /use-ssl = true/
       )
       should contain_file('/opt/opendaylight/configuration/ssl').with(
         'ensure' => 'directory',
@@ -598,3 +702,26 @@ def odl_tls_tests(options = {})
     }
   end
 end
+
+def stats_polling_enablement_tests(options = {})
+  # Extract params
+  # NB: This default value should be the same as one in opendaylight::params
+  stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
+  # Confirm properties of ODL REST port config file
+  # 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('openflowplugin.cfg').with(
+      'ensure' => 'file',
+      'path'   => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
+      'owner'  => 'odl',
+      'group'  => 'odl',
+    )
+    should contain_file_line('stats-polling').with(
+      'ensure' => 'present',
+      'path'   => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
+      'line'   => "is-statistics-polling-on=#{stats_polling_enabled}",
+      'match'  => '^is-statistics-polling-on=.*$',
+    )
+  }
+end