commit 63cf30fb5e524b35e500780f8dc3cf8d23bf1646
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 8 16:24:42 2013 +0100
NetTestCommand, NetTestController, NetTestSlave: log changes
This commit removes the old Logs code. The class Logs will be replaced
with an instance of class LoggingCtl so I also prepared the class
constructors to recieve it as a parameter.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Common/NetTestCommand.py | 23 +++++------------------
lnst/Controller/NetTestController.py | 23 ++++++++---------------
lnst/Slave/NetTestSlave.py | 20 +++++++-------------
3 files changed, 20 insertions(+), 46 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index c8c807d..49feeae 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -16,7 +16,6 @@ import sys
import signal
import imp
import pickle, traceback
-from lnst.Common.Logs import Logs
from lnst.Common.ExecCmd import exec_cmd, ExecCmdFail
def str_command(command):
@@ -47,12 +46,13 @@ class BgCommandException(Exception):
return "BgCommandError: " + self._str
class BgCommand:
- def __init__(self, bg_id, cmd_cls):
+ def __init__(self, bg_id, cmd_cls, log_ctl):
self._bg_id = bg_id
self._cmd_cls = cmd_cls
self._pid = None
self._read_pipe = None
self._killed = False
+ self._log_ctl = log_ctl
def get_bg_id(self):
return self._bg_id
@@ -66,7 +66,6 @@ class BgCommand:
" id \"%s\", pid \"%d\"" % (self._bg_id, self._pid))
self._read_pipe = read_pipe
return {"passed": True}
- Logs.get_buffer().flush()
os.close(read_pipe)
os.setpgrp()
self._cmd_cls.set_handle_intr()
@@ -78,8 +77,6 @@ class BgCommand:
except:
type, value, tb = sys.exc_info()
result = {"Exception": ''.join(traceback.format_exception(type, value, tb))}
- buf = Logs.get_buffer()
- result["logs"] = buf.flush()
tmp = pickle.dumps(result)
os.write(write_pipe, tmp)
os.close(write_pipe)
@@ -267,10 +264,6 @@ class NetTestCommandWait(NetTestCommandControl):
bg_cmd.wait_for()
result = bg_cmd.get_result()
self._command_context.del_bg_cmd(bg_cmd)
- buf = Logs.get_buffer()
- logs = result["logs"]
- buf.add_buffer(logs)
- del result["logs"]
self.set_result(result)
class NetTestCommandIntr(NetTestCommandControl):
@@ -280,10 +273,6 @@ class NetTestCommandIntr(NetTestCommandControl):
bg_cmd.interrupt()
result = bg_cmd.get_result()
self._command_context.del_bg_cmd(bg_cmd)
- buf = Logs.get_buffer()
- logs = result["logs"]
- buf.add_buffer(logs)
- del result["logs"]
self.set_result(result)
class NetTestCommandKill(NetTestCommandControl):
@@ -293,9 +282,6 @@ class NetTestCommandKill(NetTestCommandControl):
bg_cmd.kill()
result = bg_cmd.get_result()
self._command_context.del_bg_cmd(bg_cmd)
- buf = Logs.get_buffer()
- logs = result["logs"]
- buf.add_buffer(logs)
self.set_result({"passed": True})
def get_command_class(command_context, command, resource_table):
@@ -320,7 +306,8 @@ def get_command_class(command_context, command, resource_table):
return cmd_cls
class NetTestCommand:
- def __init__(self, command_context, command, resource_table):
+ def __init__(self, command_context, command, resource_table, log_ctl):
+ self._log_ctl = log_ctl
self._command_class = get_command_class(command_context, command,
resource_table)
self._command_context = command_context
@@ -330,7 +317,7 @@ class NetTestCommand:
cmd_cls = self._command_class
if "bg_id" in self._command:
bg_id = self._command["bg_id"]
- bg_cmd = BgCommand(bg_id, cmd_cls)
+ bg_cmd = BgCommand(bg_id, cmd_cls, self._log_ctl)
self._command_context.add_bg_cmd(bg_cmd)
return bg_cmd.run()
else:
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 80a132d..c034f33 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -20,7 +20,7 @@ import tempfile
from time import sleep
from xmlrpclib import Binary
from pprint import pprint, pformat
-from lnst.Common.Logs import Logs, log_exc_traceback
+from lnst.Common.Logs import log_exc_traceback
from lnst.Common.XmlRpc import ServerProxy, ServerException
from lnst.Common.NetUtils import MacPool
from lnst.Common.VirtUtils import VirtNetCtl, VirtDomainCtl, BridgeCtl
@@ -38,13 +38,13 @@ def ignore_event(**kwarg):
pass
class NetTestController:
- def __init__(self, recipe_path, cleanup=False,
+ def __init__(self, recipe_path, log_ctl, cleanup=False,
res_serializer=None, config=None):
self._docleanup = cleanup
self._res_serializer = res_serializer
self._remote_capture_files = {}
self._config = config
- self._log_root_path = Logs.get_logging_root_path()
+ self._log_ctl = log_ctl
self._recipe_path = recipe_path
sp = SlavePool(config.get_option('environment', 'pool_dirs'),
@@ -323,18 +323,7 @@ class NetTestController:
info = self._get_machineinfo(machine_id)
address = socket.gethostbyname(info["hostname"])
- slave_root_path = os.path.join(self._log_root_path, address)
- try:
- os.mkdir(slave_root_path)
- except OSError as e:
- if e.errno != 17:
- raise
-
- logger = logging.getLogger(address)
- Logs(Logs.debug, False, logger, log_folder=slave_root_path,
- to_display=False, date="")
-
- info['logger'] = logger
+ info['logger'] = self._log_ctl.add_slave(address)
def _deconfigure_slaves(self):
if 'machines' not in self._recipe:
@@ -358,6 +347,10 @@ class NetTestController:
domain_ctl = info["virt_domain_ctl"]
domain_ctl.detach_interface(dev["hwaddr"])
+ #clean-up slave logger
+ address = socket.gethostbyname(info["hostname"])
+ self._log_ctl.remove_slave(address)
+
# remove dynamically created bridges
networks = self._recipe["networks"]
for net in networks.itervalues():
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 229aabf..bdbf4b7 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -18,7 +18,7 @@ from time import sleep
from xmlrpclib import Binary
from tempfile import NamedTemporaryFile
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
-from lnst.Common.Logs import Logs, log_exc_traceback
+from lnst.Common.Logs import log_exc_traceback
from lnst.Common.PacketCapture import PacketCapture
from lnst.Common.XmlRpc import Server
from lnst.Common.Utils import die_when_parent_die
@@ -37,12 +37,13 @@ class NetTestSlaveXMLRPC:
'''
Exported xmlrpc methods
'''
- def __init__(self, command_context, config):
+ def __init__(self, command_context, config, log_ctl):
self._netconfig = None
self._packet_captures = {}
self._netconfig = NetConfig()
self._command_context = command_context
self._config = config
+ self._log_ctl = log_ctl
self._capture_files = {}
self._copy_targets = {}
@@ -58,10 +59,8 @@ class NetTestSlaveXMLRPC:
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)
+ date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
+ self._log_ctl.set_recipe(recipe_path, expand=date)
sleep(1)
if check_process_running("NetworkManager"):
@@ -78,11 +77,6 @@ class NetTestSlaveXMLRPC:
self._remove_capture_files()
return "bye"
- def get_new_logs(self):
- buffer = Logs.get_buffer()
- logs = buffer.flush()
- return logs
-
def get_devices_by_hwaddr(self, hwaddr):
name_scan = scan_netdevs()
netdevs = []
@@ -164,7 +158,7 @@ class NetTestSlaveXMLRPC:
def run_command(self, command):
try:
cmd_cls = NetTestCommand(self._command_context, command,
- self._resource_table)
+ self._resource_table, self._log_ctl)
return cmd_cls.run()
except:
log_exc_traceback()
@@ -290,7 +284,7 @@ class MySimpleXMLRPCServer(Server):
pass
class NetTestSlave:
- def __init__(self, config, port = DefaultRPCPort):
+ def __init__(self, config, log_ctl, port = DefaultRPCPort):
die_when_parent_die()
command_context = NetTestCommandContext()