Bug 8854: Add config of ODL log file size/rollover 94/60294/19
authorJanki Chhatbar <jchhatba@redhat.com>
Mon, 24 Jul 2017 09:32:09 +0000 (15:02 +0530)
committerDaniel Farrell <dfarrell@redhat.com>
Tue, 25 Jul 2017 17:50:54 +0000 (13:50 -0400)
The default ODL logging config uses 10 small log files. This makes
searching for errors difficult. Add the ability to configure the maximum
size of karaf.log and the number of rollover logs to keep. Default to
values that make it normal to end up with a single large log file but
still allow pruning from the tail when logs rollover.

Change-Id: Ibcdd0c6634fc37180a9880e03abfd24f1eb84a10
Signed-Off-By: Janki Chhatbar <jchhatba@redhat.com>
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
README.markdown
manifests/config.pp
manifests/init.pp
manifests/params.pp
spec/acceptance/class_spec.rb
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb

index 91de61e244282fbf00efa2fe33a220b986c0a2d0..978da525579f8cb2de60a215800dcff607736fa8 100644 (file)
@@ -293,6 +293,29 @@ org.opendaylight.ovsdb.lib | INFO
 
 The main log output file is `/opt/opendaylight/data/log/karaf.log`.
 
+##### `log_max_size`
+
+Maximum size of OpenDaylight's log file, `/opt/opendaylight/data/log/karaf.log`.
+
+Once this size is reached, the log will be rolled over, with up to
+`log_max_rollover` log rollovers preserved in total.
+
+Default: `10GB`
+
+Valid options: A valid size as a string with unit specified.
+
+##### `log_max_rollover`
+
+Maximum number of OpenDaylight karaf.log rollovers to keep.
+
+Note that if this is set to 1, log rollovers will result in loosing newly
+logged data. It's recommended to use values greater than one to prune from
+the end of the log.
+
+Default: `2`
+
+Valid options: An integer greater than 0.
+
 ##### `enable_ha`
 
 Enable or disable ODL High Availablity.
index 0f1bf962aa0f7649cca8411e068177638bd16ecf..f6f837bac9e8ff7b8828b5f852a86ba8d9e3b098 100644 (file)
@@ -39,6 +39,22 @@ class opendaylight::config {
     }
   }
 
+  # Set maximum ODL log file size
+  file_line { 'logmaxsize':
+    ensure => present,
+    path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+    line   => "log4j.appender.out.maxFileSize=${::opendaylight::log_max_size}",
+    match  => '^log4j.appender.out.maxFileSize.*$'
+  }
+
+  # Set maximum number of ODL log file rollovers to preserve
+  file_line { 'logmaxrollover':
+    ensure => present,
+    path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+    line   => "log4j.appender.out.maxBackupIndex=${::opendaylight::log_max_rollover}",
+    match  => '^log4j.appender.out.maxBackupIndex.*$'
+  }
+
   # Configure ODL HA if enabled
   $ha_node_count = count($::opendaylight::ha_node_ips)
   if $::opendaylight::enable_ha {
index 4834b6100a07bbf8cf64f361cbc8e4996b2a487c..c1b96d300779fbc28fd1a8ee75228bbf884ce0f8 100644 (file)
 #   (Boolean) Should this module manage the apt or yum repositories for the
 #   package installation.
 #   Defaults to true
+# [*log_max_size*]
+#   Maxium size of OpenDaylight's log file.
+# [*log_max_rollover*]
+#   Maxium number of OpenDaylight log rollovers to keep.
 #
 # === Deprecated Parameters
 #
@@ -62,6 +66,8 @@ class opendaylight (
   $manage_repositories = $::opendaylight::params::manage_repositories,
   $username            = $::opendaylight::params::username,
   $password            = $::opendaylight::params::password,
+  $log_max_size        = $::opendaylight::params::log_max_size,
+  $log_max_rollover    = $::opendaylight::params::log_max_rollover
 ) inherits ::opendaylight::params {
 
   # Validate OS family
index ee6aaf0d71883623100b42407dfe7bbb67ddcfc9..a133202ef3f683730b46bd0770f2f2b219770b3c 100644 (file)
@@ -25,4 +25,6 @@ class opendaylight::params {
   $manage_repositories = true
   $username = 'admin'
   $password = 'admin'
+  $log_max_size = '10GB'
+  $log_max_rollover = 2
 }
index 0ea10005232627df3e00d0c92d697bd366edbba2..c437257a31d5b4161745683b7cff698cdc25e215 100644 (file)
@@ -74,6 +74,42 @@ describe 'opendaylight class' do
     end
   end
 
+  describe 'log file size and rollover' do
+    context 'using default size and rollover' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl
+
+      # Call specialized helper fn for log file settings validations
+      log_file_settings_validations
+    end
+
+    context 'customising size' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(log_max_size: '1GB')
+
+      # Call specialized helper fn for log file settings validations
+      log_file_settings_validations(log_max_size: '1GB')
+    end
+
+    context 'customising rollover' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(log_max_rollover: 3)
+
+      # Call specialized helper fn for log file settings validations
+      log_file_settings_validations(log_max_rollover: 3)
+    end
+
+    context 'customising size and rollover' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(log_max_size: '1GB',
+                  log_max_rollover: 3)
+
+      # Call specialized helper fn for log file settings validations
+      log_file_settings_validations(log_max_size: '1GB',
+                                    log_max_rollover: 3)
+    end
+  end
+
   describe 'testing REST port config file' do
     context 'using default port' do
       # Call specialized helper fn to install OpenDaylight
index 7c0a1d1e8fc245c66a8c14fa50e3a8fa62a6bd38..96b71558ffadd59bb6a31afee4e952773a004dc6 100644 (file)
@@ -46,6 +46,11 @@ describe 'opendaylight' do
             # NB: Only testing defaults here, specialized enabling HA tests elsewhere
             # Note that this function is defined in spec_helper
             enable_ha_tests
+
+            # Run tests that specialize in checking log file settings
+            # NB: Only testing defaults here, specialized log file settings tests elsewhere
+            # Note that this function is defined in spec_helper
+            log_file_settings
           end
         end
 
@@ -105,6 +110,11 @@ describe 'opendaylight' do
             # NB: Only testing defaults here, specialized enabling HA tests elsewhere
             # Note that this function is defined in spec_helper
             enable_ha_tests
+
+            # Run tests that specialize in checking log file settings
+            # NB: Only testing defaults here, specialized log file settings tests elsewhere
+            # Note that this function is defined in spec_helper
+            log_file_settings
           end
         end
 
@@ -174,6 +184,11 @@ describe 'opendaylight' do
             # NB: Only testing defaults here, specialized enabling HA tests elsewhere
             # Note that this function is defined in spec_helper
             enable_ha_tests
+
+            # Run tests that specialize in checking log file settings
+            # NB: Only testing defaults here, specialized log file settings tests elsewhere
+            # Note that this function is defined in spec_helper
+            log_file_settings
           end
         end
 
@@ -429,6 +444,91 @@ describe 'opendaylight' do
     end
   end
 
+  # All custom log file size and rollover tests
+  describe 'log file size and rollover' 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 default size and rollover' 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 specific to log file settings
+      log_file_settings
+    end
+
+    context 'customizing size' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :log_max_size => '1GB',
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests
+
+      # Run test specific to log file settings
+      log_file_settings(log_max_size: '1GB')
+    end
+
+    context 'customizing rollover' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :log_max_rollover => 3,
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests
+
+      # Run test specific to log file settings
+      log_file_settings(log_max_rollover: 3)
+    end
+
+    context 'customizing size and rollover' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :log_max_size => '1GB',
+        :log_max_rollover => 3,
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests
+
+      # Run test specific to log file settings
+      log_file_settings(log_max_size: '1GB',
+                        log_max_rollover: 3)
+    end
+  end
+
   # All OVSDB HA enable/disable tests
   describe 'OVSDB HA enable/disable tests' do
     # Non-OS-type tests assume CentOS 7
index 0c7d38391c357e9cd92248a25aa220d4ed818900..a2dad80dcf48ed1f864c3bf46a4ae0bd3c45aea5 100644 (file)
@@ -84,6 +84,28 @@ def generic_tests()
   }
 end
 
+# Shared tests that specialize in testing log file size and rollover
+def log_file_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)
+
+  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.*$',
+    )
+  }
+end
+
 # Shared tests that specialize in testing Karaf feature installs
 def karaf_feature_tests(options = {})
   # Extract params
index 2563c60dc83a8bd4e23c66d7c06cb91168d56346..49dbbe0a3524a53cc49383421bc0aa79f5471438 100644 (file)
@@ -69,6 +69,8 @@ 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)
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -78,15 +80,17 @@ def install_odl(options = {})
       deb_repo => '#{deb_repo}',
       default_features => #{default_features},
       extra_features => #{extra_features},
-      odl_rest_port=> #{odl_rest_port},
-      odl_bind_ip=> '#{odl_bind_ip}',
-      enable_ha=> #{enable_ha},
-      ha_node_ips=> #{ha_node_ips},
-      ha_node_index=> #{ha_node_index},
-      ha_db_modules=> #{ha_db_modules},
-      log_levels=> #{log_levels},
-      username=> #{username},
-      password=> #{password},
+      odl_rest_port => #{odl_rest_port},
+      odl_bind_ip => '#{odl_bind_ip}',
+      enable_ha => #{enable_ha},
+      ha_node_ips => #{ha_node_ips},
+      ha_node_index => #{ha_node_index},
+      ha_db_modules => #{ha_db_modules},
+      log_levels => #{log_levels},
+      username => #{username},
+      password => #{password},
+      log_max_size => '#{log_max_size}',
+      log_max_rollover => #{log_max_rollover},
     }
     EOS
 
@@ -205,6 +209,21 @@ def generic_validations()
   end
 end
 
+# Shared function for validations related to log file settings
+def log_file_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)
+
+  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}/ }
+  end
+end
+
 # Shared function for validations related to the Karaf config file
 def karaf_config_validations(options = {})
   # NB: These param defaults should match the ones used by the opendaylight