commit b2c3a5a1a2e3f37e7a2e7459f507f9e7b109b5af
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Tue Dec 4 14:40:11 2012 +0100
Logs: splitting slave logs into directories
Since slaves are now running as daemons they will be mostly run once for
multiple runs of the controller. This results in logs from individual
controller runs and recipes being logged in the same files on the slave
machines. This behaviour is confusing and unwanted.
This commit fixes that by making the slave logging change location every
time the rpc method hello() is called. For this I added another
classmethod to the class Logs- relocate_log_folder(). This function acts
in a similar way to the contructor of the class but only redirects the
paths. This pats makes the following logs structure:
.../<time>/{debug, info} - logs from the slave daemon unrelated to the
recipe execution, currently only startup information, new folder is
created every time the slave is launched
.../<time>_<recipename>/{debug,info} - logs generated by the result, new
folder is created every time the hello() method is called
To avoid timestamp conflict of two identically named recipes being
launched in the same second, we wait for one second after the creation
of the log folder.
Finally I also removed the Logs class attribute file_handlers, it wasn't
used for anything and I probably forgot to remove it the last time I was
doing changes to the Logs class.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Common/Logs.py | 23 +++++++++++++++++++++--
lnst/Controller/NetTestController.py | 3 ++-
lnst/Slave/NetTestSlave.py | 11 +++++++++--
3 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/lnst/Common/Logs.py b/lnst/Common/Logs.py
index 799f5da..4932c85 100644
--- a/lnst/Common/Logs.py
+++ b/lnst/Common/Logs.py
@@ -148,7 +148,6 @@ class LoggingFile(object):
class Logs:
- file_handlers = []
formatter = None
logFolder = None
loggers = []
@@ -167,7 +166,6 @@ class Logs:
nameExtend = ""
else:
nameExtend = "_" + nameExtend
- cls.file_handlers = []
cls.formatter = MultilineFormater(
'%(asctime)s| %(address)17.17s%(module)15.15s'
':%(lineno)4.4d| %(levelname)s: '
@@ -187,6 +185,25 @@ class Logs:
recipe_path, to_display)
@classmethod
+ def relocate_log_folder(cls, date=None, log_folder=None, nameExtend=None):
+ root_logger = logging.getLogger()
+ if log_folder != None:
+ cls.logFolder = log_folder
+ else:
+ cls.logFolder = os.path.join(os.path.dirname(sys.argv[0]), './Logs')
+
+ if date is None:
+ cls.date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
+ else:
+ cls.date = date
+
+ if nameExtend != None:
+ cls.nameExtend = "_" + nameExtend
+ else:
+ cls.nameExtend = ""
+ cls.log_root_folder = cls.set_logging_root_path(None, True)
+
+ @classmethod
def save_state(cls):
cls.state = {"logFolder": cls.logFolder, "date": cls.date}
@@ -199,6 +216,7 @@ class Logs:
handlers = list(logger.handlers)
for handler in handlers:
if isinstance(handler, logging.FileHandler):
+ handler.close()
logger.removeHandler(handler)
cls.loggers = cls.loggers[:1]
@@ -243,6 +261,7 @@ class Logs:
handlers = list(root_logger.handlers)
for handler in handlers:
if isinstance(handler, logging.FileHandler):
+ handler.close()
root_logger.removeHandler(handler)
(file_debug, file_info) = cls._create_file_handler(cls.root_path)
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 1fcc496..d673822 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -45,6 +45,7 @@ class NetTestController:
self._remote_capture_files = {}
self._config = config
self._log_root_path = Logs.get_logging_root_path()
+ self._recipe_path = recipe_path
if check_process_running("libvirtd"):
self._machine_pool = MachinePool(config.get_option('environment',
@@ -307,7 +308,7 @@ class NetTestController:
url = "http://%s:%d" % (hostname, port)
rpc = ServerProxy(url, allow_none = True)
info["rpc"] = rpc
- if self._rpc_call(machine_id, 'hello') != "hello":
+ if self._rpc_call(machine_id, 'hello', self._recipe_path) !=
"hello":
msg = "Unable to establish RPC connection to machine %s. " \
% hostname
msg += "Handshake failed"
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 7092753..229aabf 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -14,6 +14,7 @@ jpirko(a)redhat.com (Jiri Pirko)
import signal
import select, logging
import os
+from time import sleep
from xmlrpclib import Binary
from tempfile import NamedTemporaryFile
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
@@ -41,7 +42,7 @@ class NetTestSlaveXMLRPC:
self._packet_captures = {}
self._netconfig = NetConfig()
self._command_context = command_context
-
+ self._config = config
self._capture_files = {}
self._copy_targets = {}
@@ -52,11 +53,17 @@ class NetTestSlaveXMLRPC:
self._resource_table = {}
- def hello(self):
+ def hello(self, recipe_path):
self.clear_resource_table()
self._cache.del_old_entries()
self.reset_file_transfers()
+ log_dir = self._config.get_option('environment', 'log_dir')
+ recipe_name = os.path.splitext(os.path.split(recipe_path)[1])[0]
+ Logs.relocate_log_folder(date=None, log_folder=log_dir,
+ nameExtend=recipe_name)
+ sleep(1)
+
if check_process_running("NetworkManager"):
logging.error("=============================================")
logging.error("NetworkManager is running on a slave machine!")