[node-patches] Change in ovirt-node[master]: logrotate: autoinstall options interval/max size

dougsland at redhat.com dougsland at redhat.com
Mon May 25 01:53:22 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: logrotate: autoinstall options interval/max size
......................................................................

logrotate: autoinstall options interval/max size

Provide auto-install options for logrotate interval and max size.
oVirt Node users now are able to configure the logrotate interval and
max size via auto-install option. The parameters can be used together
or separated. If separated, default value for logrotate_max_size is
1024 and default value for logrotate_interval is daily.

Change-Id: I7205019714cbe359834fe9ecf1d79513c5dbfd93
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1153417
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M scripts/ovirt-init-functions.sh.in
M src/ovirt/node/config/defaults.py
M src/ovirt/node/presets.py
3 files changed, 47 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/69/41369/1

diff --git a/scripts/ovirt-init-functions.sh.in b/scripts/ovirt-init-functions.sh.in
index 3a185ec..9c27192 100644
--- a/scripts/ovirt-init-functions.sh.in
+++ b/scripts/ovirt-init-functions.sh.in
@@ -201,6 +201,29 @@
     esac
 }
 
+# Configure log rotate
+configure_logrotate() {
+    if [[ -n "${logrotate_interval}" && -n "${logrotate_max_size}" ]]
+    then
+        python << EOP
+from ovirt.node.config.defaults import Logrotate
+Logrotate().update(max_size="${logrotate_max_size}", interval="${logrotate_interval}")
+EOP
+    elif [ -n "${logrotate_interval}" ]
+    then
+        python << EOP
+from ovirt.node.config.defaults import Logrotate
+Logrotate().configure_interval(interval="${logrotate_interval}")
+EOP
+    elif [ -n "${logrotate_max_size}" ]
+    then
+        python << EOP
+from ovirt.node.config.defaults import Logrotate
+Logrotate().configure_max_size(max_size="${logrotate_max_size}")
+EOP
+fi
+}
+
 start_ovirt_early () {
     {
         log "Starting ovirt-early"
@@ -239,6 +262,7 @@
     #   disable_aes_ni=[y|n]
     #   use_strong_rng=<bytes>
     #   nfsv4_domain=domain
+    #   logrotate_interval=weekly|daily|monthly
     #   logrotate_max_size=number
     #   reboot_delay=number
 
@@ -419,6 +443,9 @@
     # keyboard=layout
     # default keyboard layout
     keyboard_layout=
+
+    #logrotate_interval=weekly|daily|monthly
+    logrotate_interval=
 
     #logrotate_max_size=number
     logrotate_max_size=
@@ -784,6 +811,9 @@
             keyboard*)
             keyboard_layout=${i#keyboard=}
             ;;
+            logrotate_interval=*)
+            logrotate_interval=${i#logrotate_interval=}
+            ;;
             logrotate_max_size=*)
             logrotate_max_size=${i#logrotate_max_size=}
             ;;
@@ -828,6 +858,9 @@
         esac
     done
 
+    # Check logrotate arguments
+    configure_logrotate
+
     # Disable USB power-saving
     echo -1 > /sys/module/usbcore/parameters/autosuspend
 
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index c393b94..808959d 100755
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-from ovirt.node import base, exceptions, valid, utils, config, log
+from ovirt.node import base, exceptions, valid, utils, config, log, presets
 from ovirt.node.config.network import NicConfig
 from ovirt.node.exceptions import InvalidData
 from ovirt.node.utils import storage, process, fs, AugeasWrapper, console, \
@@ -1497,14 +1497,19 @@
 
     @NodeConfigFileSection.map_and_update_defaults_decorator
     def update(self, max_size, interval):
+        if max_size is None:
+            max_size = presets.LOGROTATE_MAX_SIZE
+
         valid.Number([0, None])(max_size)
         if interval not in ["daily", "weekly", "monthly", None]:
             raise InvalidData("Update interval must be a valid logrotate "
                               "schedule period or None")
 
+        if interval is None:
+            interval = presets.LOGROTATE_INTERVAL
+
         return {"OVIRT_LOGROTATE_MAX_SIZE": max_size,
-                "OVIRT_LOGROTATE_INTERVAL": "daily" if interval is None
-                else interval}
+                "OVIRT_LOGROTATE_INTERVAL": interval}
 
     def configure_interval(self, interval):
         self.update(None, interval)
@@ -1514,8 +1519,8 @@
 
     def transaction(self):
         cfg = dict(self.retrieve())
-        max_size = cfg["max_size"] or 1024
-        interval = cfg["interval"] or "daily"
+        max_size = cfg["max_size"] or presets.LOGROTATE_MAX_SIZE
+        interval = cfg["interval"] or presets.LOGROTATE_INTERVAL
 
         class CreateLogrotateConfig(utils.Transaction.Element):
             title = "Setting logrotate maximum logfile size"
diff --git a/src/ovirt/node/presets.py b/src/ovirt/node/presets.py
index c788577..d39730d 100644
--- a/src/ovirt/node/presets.py
+++ b/src/ovirt/node/presets.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
-# presets.py - Copyright (C) 2014 Red Hat, Inc.
+# presets.py - Copyright (C) 2014-2015 Red Hat, Inc.
 # Written by Fabian Deutsch <fabiand at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -27,3 +27,6 @@
 ROOT_SIZE = 4096
 
 TUI_BRAND_COLOR = "dark blue"
+
+LOGROTATE_MAX_SIZE = "1024"
+LOGROTATE_INTERVAL = "daily"


-- 
To view, visit https://gerrit.ovirt.org/41369
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7205019714cbe359834fe9ecf1d79513c5dbfd93
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list