[node-patches] Change in ovirt-node[master]: Make the logrotate interval configurable
rbarry at redhat.com
rbarry at redhat.com
Wed Mar 26 18:33:05 UTC 2014
Ryan Barry has uploaded a new change for review.
Change subject: Make the logrotate interval configurable
......................................................................
Make the logrotate interval configurable
Previously, we only gave the option for size to be checked. Let
the period be checked as well, users can rotate logs daily if
desired. "size" and intervals are exclusive in EL6 other than
"minsize", so we can't get to the desired conclusion, but we can
prep by adding an option in the UI.
Change-Id: Ifb2639225f8b793b302e36a2c7639cb0769d4df4
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1046417
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M logrotate/ovirt-logrotate.conf
M src/ovirt/node/config/defaults.py
M src/ovirt/node/setup/core/logging_page.py
3 files changed, 42 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/30/26130/1
diff --git a/logrotate/ovirt-logrotate.conf b/logrotate/ovirt-logrotate.conf
index 9d6ec9f..a8a321d 100644
--- a/logrotate/ovirt-logrotate.conf
+++ b/logrotate/ovirt-logrotate.conf
@@ -2,6 +2,7 @@
rotate 3
compress
missingok
- size 1M
+ minsize 1M
+ daily
create
}
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 1fc06c2..c98ac3b 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -1283,20 +1283,33 @@
>>> from ovirt.node.utils import fs
>>> n = Logrotate(fs.FakeFs.File("dst"))
>>> max_size = "42"
- >>> n.update(max_size)
+ >>> n.update(max_size, None)
>>> n.retrieve().items()
- [('max_size', '42')]
+ [('interval', 'daily'), ('max_size', '42')]
+ >>> interval = "weekly"
+ >>> n.update(max_size, interval)
+ >>> n.retrieve().items()
+ [('interval', 'weekly'), ('max_size', '42')]
"""
+
# FIXME this key is new!
- keys = ("OVIRT_LOGROTATE_MAX_SIZE",)
+ keys = ("OVIRT_LOGROTATE_MAX_SIZE", "OVIRT_LOGROTATE_INTERVAL")
@NodeConfigFileSection.map_and_update_defaults_decorator
- def update(self, max_size):
+ def update(self, max_size, interval):
valid.Number([0, None])(max_size)
+ if not interval in ["daily", "weekly", "monthly", None]:
+ raise InvalidData("Update interval must be a valid logrotate "
+ "schedule period or None")
+
+ return {"OVIRT_LOGROTATE_MAX_SIZE": max_size,
+ "OVIRT_LOGROTATE_INTERVAL": "daily" if interval is None
+ else interval}
def transaction(self):
cfg = dict(self.retrieve())
max_size = cfg["max_size"]
+ interval = cfg["interval"]
class CreateLogrotateConfig(utils.Transaction.Element):
title = "Setting logrotate maximum logfile size"
@@ -1308,8 +1321,21 @@
max_size)
ovirt_store_config("/etc/logrotate.d/ovirt-node")
+ class SetLogrotateInterval(utils.Transaction.Element):
+ title = "Setting logrotate interval"
+
+ def commit(self):
+ from ovirtnode.ovirtfunctions import ovirt_store_config
+ aug = utils.AugeasWrapper()
+ aug.set("/files/etc/logrotate.d/ovirt-node/rule/schedule",
+ interval)
+ ovirt_store_config("/etc/logrotate.d/ovirt-node")
+
tx = utils.Transaction("Configuring logrotate")
- tx.append(CreateLogrotateConfig())
+ if max_size:
+ tx.append(CreateLogrotateConfig())
+ if interval:
+ tx.append(SetLogrotateInterval())
return tx
diff --git a/src/ovirt/node/setup/core/logging_page.py b/src/ovirt/node/setup/core/logging_page.py
index 34c2573..a122f79 100644
--- a/src/ovirt/node/setup/core/logging_page.py
+++ b/src/ovirt/node/setup/core/logging_page.py
@@ -29,6 +29,9 @@
class Plugin(plugins.NodePlugin):
_model = None
+ _intervals = [("daily", "Daily"),
+ ("weekly", "Weekly"),
+ ("monthly", "Monthly")]
def name(self):
return _("Logging")
@@ -43,6 +46,7 @@
model = {}
model["logrotate.max_size"] = logrotate["max_size"] or "1024"
+ model["logrotate.interval"] = logrotate["interval"] or "daily"
model["rsyslog.address"] = syslog["server"] or ""
model["rsyslog.port"] = syslog["port"] or "514"
@@ -56,6 +60,8 @@
"""Validators validate the input on change and give UI feedback
"""
return {"logrotate.max_size": valid.Number(bounds=[0, None]),
+ "logrotate.interval": valid.Options(dict(
+ self._intervals).keys()),
"rsyslog.address": (valid.Empty() | valid.FQDNOrIPAddress()),
"rsyslog.port": valid.Port(),
"netconsole.address": (valid.Empty() |
@@ -69,6 +75,8 @@
ws = [ui.Header("header[0]", _("Logging")),
ui.Entry("logrotate.max_size", _("Logrotate Max Log ") +
_("Size (KB):")),
+ ui.Options("logrotate.interval", _("Interval"),
+ self._intervals),
ui.Divider("divider[0]")
]
@@ -117,7 +125,7 @@
txs = utils.Transaction(_("Updating logging related configuration"))
# If any logrotate key changed ...
- logrotate_keys = ["logrotate.max_size"]
+ logrotate_keys = ["logrotate.max_size", "logrotate.interval"]
if changes.contains_any(logrotate_keys):
# Get all logrotate values fomr the effective model
model = defaults.Logrotate()
--
To view, visit http://gerrit.ovirt.org/26130
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb2639225f8b793b302e36a2c7639cb0769d4df4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>
More information about the node-patches
mailing list