Add infrastructure for allowing additional logfiles
authorMichele Tartara <mtartara@google.com>
Fri, 8 Mar 2013 14:41:38 +0000 (14:41 +0000)
committerMichele Tartara <mtartara@google.com>
Wed, 13 Mar 2013 12:23:28 +0000 (13:23 +0100)
Some daemons will need more than the single logfile that is currently
allowed. This patch introduces the infrastructure to allow this.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/constants.py
test/py/ganeti.constants_unittest.py

index f1f016f..9cbb4fe 100644 (file)
@@ -158,6 +158,13 @@ CONFD = "ganeti-confd"
 RAPI = "ganeti-rapi"
 MASTERD = "ganeti-masterd"
 
+DAEMONS = compat.UniqueFrozenset([
+  NODED,
+  CONFD,
+  RAPI,
+  MASTERD,
+  ])
+
 DAEMONS_PORTS = {
   # daemon-name: ("proto", "default-port")
   NODED: ("tcp", 1811),
@@ -183,6 +190,26 @@ DAEMONS_LOGFILES = \
     dict((daemon, pathutils.GetLogFilename(DAEMONS_LOGBASE[daemon]))
          for daemon in DAEMONS_LOGBASE)
 
+# Some daemons might require more than one logfile.
+
+# These are the only valid reasons for having an extra logfile
+EXTRA_LOGREASON_ACCESS = "access"
+EXTRA_LOGREASON_ERROR = "error"
+
+VALID_EXTRA_LOGREASONS = compat.UniqueFrozenset([
+  EXTRA_LOGREASON_ACCESS,
+  EXTRA_LOGREASON_ERROR,
+  ])
+
+# These are the extra logfiles, grouped by daemon
+DAEMONS_EXTRA_LOGBASE = {}
+
+DAEMONS_EXTRA_LOGFILES = \
+  dict((daemon, dict((extra,
+       pathutils.GetLogFilename(DAEMONS_EXTRA_LOGBASE[daemon][extra]))
+       for extra in DAEMONS_EXTRA_LOGBASE[daemon]))
+         for daemon in DAEMONS_EXTRA_LOGBASE)
+
 DEV_CONSOLE = "/dev/console"
 
 PROC_MOUNTS = "/proc/mounts"
index 9b7edcd..0e21feb 100755 (executable)
@@ -98,6 +98,12 @@ class TestConstants(unittest.TestCase):
     self.assertTrue(constants.DEFAULT_ENABLED_HYPERVISOR in
                     constants.HYPER_TYPES)
 
+  def testExtraLogfiles(self):
+    for daemon in constants.DAEMONS_EXTRA_LOGBASE:
+      self.assertTrue(daemon in constants.DAEMONS)
+      for log_reason in constants.DAEMONS_EXTRA_LOGBASE[daemon]:
+        self.assertTrue(log_reason in constants.VALID_EXTRA_LOGREASONS)
+
 
 class TestExportedNames(unittest.TestCase):
   _VALID_NAME_RE = re.compile(r"^[A-Z][A-Z0-9_]+$")