[node-patches] Change in ovirt-node[master]: Don't write rsyslog.conf from a template

rbarry at redhat.com rbarry at redhat.com
Thu Aug 14 19:41:02 UTC 2014


Ryan Barry has uploaded a new change for review.

Change subject: Don't write rsyslog.conf from a template
......................................................................

Don't write rsyslog.conf from a template

This breaks with journald on systemd systems. We won't be able
to use TCP rsysloggers or ipv6 until augeas is fixed, but that's
deemed an acceptable loss

Change-Id: I23368ddffe2675575f7ab71831f9b4d5bf280cb7
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=985213
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/config/defaults.py
M src/ovirtnode/log.py
2 files changed, 65 insertions(+), 91 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/31/31531/1

diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 9a2195d..31291d8 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -28,6 +28,7 @@
 from ovirt.node.utils.system import Bootloader
 import glob
 import os
+import re
 
 """
 Classes and functions related to model of the configuration of oVirt Node.
@@ -967,18 +968,58 @@
         valid.Port()(port)
 
     def transaction(self):
-        return self.__legacy_transaction()
+        aug = utils.AugeasWrapper()
 
-    def __legacy_transaction(self):
+        def __get_index():
+            index = None
+            m = aug.match("/files/etc/rsyslog.conf/*/action/hostname")
+            group = m[0] if m else aug.match(
+                    '/files/etc/rsyslog.conf/entry[last()]')[0]
+            pat = re.compile(r'.*?entry\[(\d+)\].*')
+            if group:
+                index = int(pat.sub(r'\1', group))
+            elif aug.get("/augeas/files/etc/rsyslog.conf/error"):
+                self.logger.error("Augeas could not parse rsyslog.conf. "
+                                  "Please check "
+                                  "/augeas/files/etc/rsyslog.conf/error "
+                                  "with augtool")
+                raise RuntimeError("Augeas could not parse rsyslog.conf")
+            else:
+                index = int(pat.sub(r'\1', group)) + 1
+            return index
+
+        def _clear_config():
+            self.logger.info("Clearing rsyslog config")
+            aug.remove_many(aug.match("/files/etc/rsyslog.conf/entry[%d]" %
+                            __get_index()))
+
+        def configure_rsyslog(server, port):
+            config_dict = {"/selector/facility": "*",
+                           "/selector/level": "*",
+                           "/action/hostname": server,
+                           "/action/port": port}
+            
+            path = "/files/etc/rsyslog.conf/entry[%d]" % __get_index()
+            aug.set_many(config_dict, basepath=path)
+
+            try:
+                system.service("rsyslog", "restart")
+            except:
+                _clear_config()
+                raise RuntimeError("Failed to restart rsyslog, please check "
+                                   "the options passed")
+
         cfg = dict(self.retrieve())
         server, port = (cfg["server"], cfg["port"])
 
         class CreateRsyslogConfig(utils.Transaction.Element):
-            title = "Setting syslog server and port"
+            if server:
+                title = "Configuring remote syslog"
+            else:
+                title = "Disabling remote syslog"
 
             def commit(self):
-                import ovirtnode.log as olog
-                olog.ovirt_rsyslog(server, port, "udp")
+                configure_rsyslog(server, port or "514")
 
         tx = utils.Transaction("Configuring syslog")
         tx.append(CreateRsyslogConfig())
diff --git a/src/ovirtnode/log.py b/src/ovirtnode/log.py
index a5a0457..7e629f2 100755
--- a/src/ovirtnode/log.py
+++ b/src/ovirtnode/log.py
@@ -23,85 +23,18 @@
 import logging
 import ovirtnode.ovirtfunctions as _functions
 from ovirt.node.utils import system
-from ovirt.node.config.defaults import Netconsole
+from ovirt.node.config.defaults import Netconsole, Syslog
 
 logger = logging.getLogger(__name__)
 
 
-RSYSLOG_FILE = "/etc/rsyslog.conf"
-
-RSYSLOG_CONFIG_TEMPLATE = """
-#ovirt rsyslog config file
-
-#### MODULES ####
-# provides support for local system logging (e.g. via logger command)
-$ModLoad imuxsock.so
-# provides kernel logging support (previously done by rklogd)
-$ModLoad imklog.so
-
-#### GLOBAL DIRECTIVES ####
-# Use default timestamp format
-$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
-
-#### RULES ####
-# Log anything (except mail) of level info or higher.
-# Don't log private authentication messages!
-*.info;mail.none;authpriv.none;cron.none                /var/log/messages
-
-# The authpriv file has restricted access.
-authpriv.*                                              /var/log/secure
-
-# Log all the mail messages in one place.
-mail.*                                                  -/var/log/maillog
-
-# Log cron stuff
-cron.*                                                  /var/log/cron
-
-# Everybody gets emergency messages
-*.emerg                                                 *
-
-# Save news errors of level crit and higher in a special file.
-uucp,news.crit                                          /var/log/spooler
-
-# Save boot messages also to boot.log
-local7.*                                                /var/log/boot.log
-
-$WorkDirectory /var/spool/rsyslog
-$ActionQueueFileName ovirtNode
-$ActionQueueMaxDiskSpace 10m
-$ActionQueueSaveOnShutdown on
-$ActionQueueType LinkedList
-$ActionResumeRetryCount -1
-%(disable)s*.* %(delim)s%(server)s:%(port)s
-"""
-
-
 def ovirt_rsyslog(server, port, protocol):
-    if server == "":
-        disable = "#"
-    else:
-        disable = ""
-    if protocol == "tcp":
-        DELIM = "@@"
-    else:
-        DELIM = "@"
-
-    if _functions.is_valid_ipv6(server):
-        server = "[" + server + "]"
-
-    rsyslog_dict = {
-        "disable": disable,
-        "delim": DELIM,
-        "server": server,
-        "port": port
-    }
-    rsyslog_config_out = RSYSLOG_CONFIG_TEMPLATE % rsyslog_dict
-    rsyslog_config = open(RSYSLOG_FILE, "w")
-    rsyslog_config.write(rsyslog_config_out)
-    rsyslog_config.close()
-    _functions.system_closefds("/sbin/service rsyslog restart &> /dev/null")
-    if _functions.ovirt_store_config("/etc/rsyslog.conf"):
-        logger.info("Syslog Configuration Updated")
+    s = Syslog()
+    s.update(server=server, port=port)
+    try:
+        s.transaction().run()
+    except:
+        return False
     return True
 
 
@@ -119,7 +52,7 @@
     rsyslog_config = open(RSYSLOG_FILE)
     for line in rsyslog_config:
         if "@" in line:
-            #strip excess details
+            # strip excess details
             line = line.replace("*.* ", "")
             line = line.replace("@", "")
             try:
@@ -142,14 +75,14 @@
 def syslog_auto():
     host = ""
     port = ""
-    if (not "OVIRT_SYSLOG_SERVER" in _functions.OVIRT_VARS and
-        not "OVIRT_SYSLOG_PORT" in _functions.OVIRT_VARS):
+    if ("OVIRT_SYSLOG_SERVER" not in _functions.OVIRT_VARS and
+            "OVIRT_SYSLOG_PORT" not in _functions.OVIRT_VARS):
         logger.info("Attempting to locate remote syslog server...")
         try:
             port, host = _functions.find_srv("syslog", "udp")
         except:
             pass
-        if not host is "" and not port is "":
+        if host is not "" and port is not "":
             logger.info("Found! Using syslog server " + host + ":" + port)
             ovirt_rsyslog(host, port, "udp")
             return True
@@ -157,7 +90,7 @@
             logger.warn("Syslog server not found!")
             return False
     elif ("OVIRT_SYSLOG_SERVER" in _functions.OVIRT_VARS and
-          not "OVIRT_SYSLOG_PORT" in _functions.OVIRT_VARS):
+          "OVIRT_SYSLOG_PORT" not in _functions.OVIRT_VARS):
         logger.info("Using default syslog port 514")
         ovirt_rsyslog(_functions.OVIRT_VARS["OVIRT_SYSLOG_SERVER"],
                       "514", "udp")
@@ -174,22 +107,22 @@
 def netconsole_auto():
     host = ""
     port = ""
-    if (not "OVIRT_NETCONSOLE_SERVER" in _functions.OVIRT_VARS and not
-        "OVIRT_NETCONSOLE_PORT" in _functions.OVIRT_VARS):
+    if ("OVIRT_NETCONSOLE_SERVER" not in _functions.OVIRT_VARS and
+            "OVIRT_NETCONSOLE_PORT" not in _functions.OVIRT_VARS):
         logger.info("Attempting to locate remote netconsole server...")
         try:
             port, host = _functions.find_srv("netconsole", "udp")
         except:
             pass
-        if not host is "" and not port is "":
+        if host is not "" and port is not "":
             logger.info("Found! Using netconsole server " + host + ":" + port)
             ovirt_netconsole(host, port)
             return True
         else:
             logger.warn("Netconsole server not found!")
             return False
-    elif ("OVIRT_NETCONSOLE_SERVER" in _functions.OVIRT_VARS and not
-          "OVIRT_NETCONSOLE_PORT" in _functions.OVIRT_VARS):
+    elif ("OVIRT_NETCONSOLE_SERVER" in _functions.OVIRT_VARS and
+          "OVIRT_NETCONSOLE_PORT" not in _functions.OVIRT_VARS):
         logger.info("Using default netconsole port 6666.")
         ovirt_netconsole(_functions.OVIRT_VARS["OVIRT_NETCONSOLE_SERVER"],
                          "6666")
@@ -205,8 +138,8 @@
 
 def logrotate_auto():
     logroate_max_size = _functions.OVIRT_VARS["OVIRT_LOGROTATE_MAX_SIZE"]
-    if not logroate_max_size is "":
-        logger.info("Found! Using logroate_max_size " + logroate_max_size)
+    if logroate_max_size is not "":
+        logger.info("Found! Using logrotate_max_size " + logroate_max_size)
         from ovirt.node.config import defaults
         try:
             model = defaults.Logrotate()


-- 
To view, visit http://gerrit.ovirt.org/31531
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23368ddffe2675575f7ab71831f9b4d5bf280cb7
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