[lnst] Logs: splitting slave logs into directories
by Jiří Pírko
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!")
11 years, 4 months
[lnst] MachinePool: add warning message when skipping virt matchines
by Jiří Pírko
commit 1877794f4810b7996cef3dba96d3eaab2cc5ab0f
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Tue Dec 4 14:40:10 2012 +0100
MachinePool: add warning message when skipping virt matchines
This commit adds a warning message informing the user about skipping
virtual machines located in machine pool when libvirtd service is not
running.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Controller/MachinePool.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Controller/MachinePool.py b/lnst/Controller/MachinePool.py
index f70edcb..9deb96f 100644
--- a/lnst/Controller/MachinePool.py
+++ b/lnst/Controller/MachinePool.py
@@ -67,6 +67,9 @@ class MachinePool:
parser.parse(machineconfig)
if 'libvirt_domain' not in machine['info'] or self._allow_virtual:
self._pool[machine_id] = machine
+ else:
+ logging.warning("libvirtd not found- Machine Pool skipping "\
+ "machine %s" % machine_id)
def provision_setup(self, setup_requirements):
"""
11 years, 4 months
[lnst] multicast: Removing nonstandard C syntax for binary
by Jiří Pírko
commit efcc013df9eee0c3d7c04a0dbef15858608bf6dd
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Tue Dec 4 14:32:00 2012 +0100
multicast: Removing nonstandard C syntax for binary
The 0bXXXXXX is apparently a C extension and is not part of C standard.
I changed the constant to hex notation (0x4000).
Reported-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
test_tools/multicast/igmp_utils.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/test_tools/multicast/igmp_utils.h b/test_tools/multicast/igmp_utils.h
index 125232b..433fd77 100644
--- a/test_tools/multicast/igmp_utils.h
+++ b/test_tools/multicast/igmp_utils.h
@@ -98,7 +98,7 @@ void ip_header_init(struct iphdr *iph, struct in_addr saddr,
iph->ihl = 6;
iph->tos = 0xc0;
iph->id = htons(0);
- iph->frag_off = htons(0b0100000000000000); /* DF */
+ iph->frag_off = htons(0x4000); /* DF 0b 0100 0000 0000 0000 */
iph->ttl = 1;
iph->protocol = IPPROTO_IGMP;
11 years, 4 months
[PATCH 1/2] MachinePool: add warning message when skipping virt matchines
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit adds a warning message informing the user about skipping
virtual machines located in machine pool when libvirtd service is not
running.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/MachinePool.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lnst/Controller/MachinePool.py b/lnst/Controller/MachinePool.py
index f70edcb..9deb96f 100644
--- a/lnst/Controller/MachinePool.py
+++ b/lnst/Controller/MachinePool.py
@@ -67,6 +67,9 @@ class MachinePool:
parser.parse(machineconfig)
if 'libvirt_domain' not in machine['info'] or self._allow_virtual:
self._pool[machine_id] = machine
+ else:
+ logging.warning("libvirtd not found- Machine Pool skipping "\
+ "machine %s" % machine_id)
def provision_setup(self, setup_requirements):
"""
--
1.7.11.7
11 years, 4 months
[PATCH] multicast: Removing nonstandard C syntax for binary
by Radek Pazdera
The 0bXXXXXX is apparently a C extension and is not part of C standard.
I changed the constant to hex notation (0x4000).
Reported-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
test_tools/multicast/igmp_utils.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test_tools/multicast/igmp_utils.h b/test_tools/multicast/igmp_utils.h
index 125232b..433fd77 100644
--- a/test_tools/multicast/igmp_utils.h
+++ b/test_tools/multicast/igmp_utils.h
@@ -98,7 +98,7 @@ void ip_header_init(struct iphdr *iph, struct in_addr saddr,
iph->ihl = 6;
iph->tos = 0xc0;
iph->id = htons(0);
- iph->frag_off = htons(0b0100000000000000); /* DF */
+ iph->frag_off = htons(0x4000); /* DF 0b 0100 0000 0000 0000 */
iph->ttl = 1;
iph->protocol = IPPROTO_IGMP;
--
1.7.7.6
11 years, 4 months
[lnst] Don't read from result pipe if bg process was killed
by Jiří Pírko
commit 44826b7951eb388dfe38fb5326fdf5d131b0cd22
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Mon Dec 3 16:47:02 2012 +0100
Don't read from result pipe if bg process was killed
If the background process was killed (SIGKILL) the pipe got unreadable
and EOFError exception was raised. This patch fixes that by checking
whether the background process was signalled and returns just the minimal
result data to be able to continue with test execution.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
lnst/Common/NetTestCommand.py | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index 671fe36..c8c807d 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -52,6 +52,7 @@ class BgCommand:
self._cmd_cls = cmd_cls
self._pid = None
self._read_pipe = None
+ self._killed = False
def get_bg_id(self):
return self._bg_id
@@ -95,13 +96,20 @@ class BgCommand:
def kill(self):
logging.debug("Killing background command with id \"%s\", pid \"%d\"" % (self._bg_id, self._pid))
+ self._killed = True
os.killpg(os.getpgid(self._pid), signal.SIGKILL)
def get_result(self):
- tmp = os.read(self._read_pipe, 4096*10)
- result = pickle.loads(tmp)
- if "Exception" in result:
- raise BgCommandException(result["Exception"])
+ result = {}
+ if self._killed:
+ result["logs"] = []
+ result["passed"] = True
+ else:
+ tmp = os.read(self._read_pipe, 4096*10)
+ result = pickle.loads(tmp)
+ if "Exception" in result:
+ raise BgCommandException(result["Exception"])
+
os.close(self._read_pipe)
return result
11 years, 4 months
[lnst] NetTestSlave: Fixing recent regression
by Jiří Pírko
commit 564045e6cebd83700da68a26d864fd4d0496ce57
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Mon Dec 3 11:09:47 2012 +0100
NetTestSlave: Fixing recent regression
The recent changes in packet capture code introduced a regression to
NetTestSlave. It will crash every time bye() method is called and there
are no pcap files available.
Reported-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
lnst/Slave/NetTestSlave.py | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 63f1f10..7092753 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -42,6 +42,8 @@ class NetTestSlaveXMLRPC:
self._netconfig = NetConfig()
self._command_context = command_context
+
+ self._capture_files = {}
self._copy_targets = {}
self._copy_sources = {}
11 years, 4 months
[lnst] ResourceCache: Fixing cache inconsistency resolution
by Jiří Pírko
commit cac6f209ab9591055f99eecb24d61866b626aded
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Mon Dec 3 10:08:07 2012 +0100
ResourceCache: Fixing cache inconsistency resolution
lnst-slave crashed every time an inconsistency between cache index
and the actual cached files happened. More precisely when a file
existed but an appropriate record was not in the index.
It will now be deleted and replaced with a new file from the controller
issuing the request.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
lnst/Common/ResourceCache.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Common/ResourceCache.py b/lnst/Common/ResourceCache.py
index 7cf2f0e..9563d8c 100644
--- a/lnst/Common/ResourceCache.py
+++ b/lnst/Common/ResourceCache.py
@@ -88,7 +88,13 @@ class ResourceCache(object):
raise ResourceCacheError("File already in cache")
entry_dir = "%s/%s" % (self._root, entry_hash)
- os.mkdir(entry_dir)
+ if os.path.exists(entry_dir):
+ try:
+ shutil.rmtree(entry_dir)
+ except OSError as e:
+ if e.errno != 2:
+ raise
+ os.makedirs(entry_dir)
shutil.move(filepath, entry_dir)
entry_path = "%s/%s" % (entry_dir, os.path.basename(filepath))
11 years, 4 months
[PATCH] Don't read from result pipe if bg process was killed
by Jan Tluka
If the background process was killed (SIGKILL) the pipe got unreadable
and EOFError exception was raised. This patch fixes that by checking
whether the background process was signalled and returns just the minimal
result data to be able to continue with test execution.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Common/NetTestCommand.py | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index 671fe36..c8c807d 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -52,6 +52,7 @@ class BgCommand:
self._cmd_cls = cmd_cls
self._pid = None
self._read_pipe = None
+ self._killed = False
def get_bg_id(self):
return self._bg_id
@@ -95,13 +96,20 @@ class BgCommand:
def kill(self):
logging.debug("Killing background command with id \"%s\", pid \"%d\"" % (self._bg_id, self._pid))
+ self._killed = True
os.killpg(os.getpgid(self._pid), signal.SIGKILL)
def get_result(self):
- tmp = os.read(self._read_pipe, 4096*10)
- result = pickle.loads(tmp)
- if "Exception" in result:
- raise BgCommandException(result["Exception"])
+ result = {}
+ if self._killed:
+ result["logs"] = []
+ result["passed"] = True
+ else:
+ tmp = os.read(self._read_pipe, 4096*10)
+ result = pickle.loads(tmp)
+ if "Exception" in result:
+ raise BgCommandException(result["Exception"])
+
os.close(self._read_pipe)
return result
--
1.7.7.6
11 years, 4 months
[PATCH] NetTestSlave: Fixing recent regression
by Radek Pazdera
The recent changes in packet capture code introduced a regression to
NetTestSlave. It will crash every time bye() method is called and there
are no pcap files available.
Reported-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
lnst/Slave/NetTestSlave.py | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 63f1f10..7092753 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -42,6 +42,8 @@ class NetTestSlaveXMLRPC:
self._netconfig = NetConfig()
self._command_context = command_context
+
+ self._capture_files = {}
self._copy_targets = {}
self._copy_sources = {}
--
1.7.7.6
11 years, 4 months