You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2014/10/22 20:43:29 UTC
svn commit: r1633674 - in /qpid/dispatch/trunk:
python/qpid_dispatch_internal/management/
python/qpid_dispatch_internal/router/ src/ tests/
Author: aconway
Date: Wed Oct 22 18:43:28 2014
New Revision: 1633674
URL: http://svn.apache.org/r1633674
Log:
NO-JIRA: Test and logging fixes
- Enable source file:line logging option for all tests
- Log file:line in python source correctly
- Fix python tests to use module name instead of __main__
Modified:
qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py
qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py
qpid/dispatch/trunk/src/log.c
qpid/dispatch/trunk/src/python_embedded.c
qpid/dispatch/trunk/tests/router_engine_test.py
qpid/dispatch/trunk/tests/system_test.py
qpid/dispatch/trunk/tests/system_tests_broker.py
qpid/dispatch/trunk/tests/system_tests_management.py
qpid/dispatch/trunk/tests/system_tests_one_router.py
qpid/dispatch/trunk/tests/system_tests_qdmanage.py
qpid/dispatch/trunk/tests/system_tests_qdstat.py
qpid/dispatch/trunk/tests/system_tests_two_routers.py
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/management/agent.py Wed Oct 22 18:43:28 2014
@@ -48,7 +48,7 @@ Adding/removing/updating entities from C
4. unlocks the router.
"""
-import re
+import re, traceback
from itertools import ifilter, chain
from traceback import format_exc
from threading import Lock
@@ -239,8 +239,7 @@ class EntityCache(object):
self.agent = agent
self.qd = self.agent.qd
self.schema = agent.schema
-
- def log(self, *args): self.agent.log(*args)
+ self.log = self.agent.log
def map_filter(self, function, test):
"""Filter with test then apply function."""
@@ -337,11 +336,16 @@ class Agent(object):
self.entities = EntityCache(self)
self.name = self.identity = 'self'
self.type = 'org.amqp.management' # AMQP management node type
+ self.request_lock = Lock()
+ self.log_adapter = None
for attributes in attribute_maps or []:
+ # Note calls self.log, log messages are dropped.
self.add_entity(self.create_entity(attributes))
- self.request_lock = Lock()
- def log(self, *args): pass # Replaced in activate.
+ def log(self, level, text):
+ if self.log_adapter:
+ info = traceback.extract_stack(limit=2)[0] # Caller frame info
+ self.log_adapter.log(level, text, info[0], info[1])
SEP_RE = re.compile(r'-|\.')
@@ -349,7 +353,7 @@ class Agent(object):
"""Register the management address to receive management requests"""
self.io = [IoAdapter(self.receive, address),
IoAdapter(self.receive, address, True)] # Global
- self.log = LogAdapter("AGENT").log
+ self.log_adapter = LogAdapter("AGENT")
def entity_class(self, entity_type):
"""Return the class that implements entity_type"""
Modified: qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py (original)
+++ qpid/dispatch/trunk/python/qpid_dispatch_internal/router/engine.py Wed Oct 22 18:43:28 2014
@@ -70,7 +70,6 @@ class RouterEngine:
self.routing_table_engine = RoutingTableEngine(self, self.node_tracker)
-
##========================================================================================
## Adapter Entry Points - invoked from the adapter
##========================================================================================
@@ -221,7 +220,8 @@ class RouterEngine:
"""
Emit a log message to the host's event log
"""
- self.log_adapter.log(level, text)
+ info = traceback.extract_stack(limit=2)[0] # Caller frame info
+ self.log_adapter.log(level, text, info[0], info[1])
def send(self, dest, msg):
Modified: qpid/dispatch/trunk/src/log.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/log.c?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/log.c (original)
+++ qpid/dispatch/trunk/src/log.c Wed Oct 22 18:43:28 2014
@@ -317,7 +317,6 @@ void qd_log_initialize(void)
log_source_lock = sys_mutex();
default_log_source = qd_log_source(SOURCE_DEFAULT);
- // Only report errors until we have configured the logging system.
default_log_source->mask = levels[INFO].mask;
default_log_source->timestamp = 1;
default_log_source->source = 0;
@@ -354,6 +353,10 @@ qd_error_t qd_log_entity(qd_entity_t *en
copy.timestamp = qd_entity_bool(entity, "timestamp");
QD_ERROR_RET();
+ if (qd_entity_has(entity, "source"))
+ copy.source = qd_entity_bool(entity, "source");
+ QD_ERROR_RET();
+
if (qd_entity_has(entity, "output")) {
log_sink_free_lh(copy.sink); /* DEFAULT source may already have a sink */
char* output = qd_entity_string(entity, "output"); QD_ERROR_RET();
Modified: qpid/dispatch/trunk/src/python_embedded.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/python_embedded.c?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/python_embedded.c (original)
+++ qpid/dispatch/trunk/src/python_embedded.c Wed Oct 22 18:43:28 2014
@@ -340,15 +340,17 @@ static void LogAdapter_dealloc(LogAdapte
static PyObject* qd_python_log(PyObject *self, PyObject *args)
{
int level;
- const char* text;
+ const char *text;
+ const char *file;
+ int line;
- if (!PyArg_ParseTuple(args, "is", &level, &text))
+ if (!PyArg_ParseTuple(args, "issi", &level, &text, &file, &line))
return 0;
LogAdapter *self_ptr = (LogAdapter*) self;
//char *logmod = PyString_AS_STRING(self_ptr->module_name);
- qd_log(self_ptr->log_source, level, "%s", text);
+ qd_log_impl(self_ptr->log_source, level, file, line, "%s", text);
Py_INCREF(Py_None);
return Py_None;
Modified: qpid/dispatch/trunk/tests/router_engine_test.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/router_engine_test.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/router_engine_test.py (original)
+++ qpid/dispatch/trunk/tests/router_engine_test.py Wed Oct 22 18:43:28 2014
@@ -27,6 +27,7 @@ sys.path.append(os.path.join(os.path.dir
from qpid_dispatch_internal.router.engine import NeighborEngine, PathEngine, NodeTracker
from qpid_dispatch_internal.router.data import LinkState, MessageHELLO
from qpid_dispatch.management.entity import Entity
+from system_test import main_module
class Adapter(object):
def __init__(self, domain):
@@ -661,4 +662,4 @@ class PathTest(unittest.TestCase):
if __name__ == '__main__':
- unittest.main()
+ unittest.main(main_module())
Modified: qpid/dispatch/trunk/tests/system_test.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_test.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_test.py (original)
+++ qpid/dispatch/trunk/tests/system_test.py Wed Oct 22 18:43:28 2014
@@ -52,7 +52,7 @@ export PYTHONPATH="$PYTHONPATH:/usr/loca
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib64"
"""
-import os, time, socket, random, subprocess, shutil, unittest
+import os, time, socket, random, subprocess, shutil, unittest, __main__
from copy import copy
import proton
from proton import Message
@@ -321,7 +321,8 @@ class Qdrouterd(Process):
"""
self.config = copy(config)
if not [l for l in config if l[0] == 'log']:
- config.append(('log', {'module':'DEFAULT', 'level':'info', 'output':name+'.log'}))
+ config.append(
+ ('log', {'module':'DEFAULT', 'level':'trace', 'source': 'true', 'output':name+'.log'}))
if not pyinclude and os.environ['QPID_DISPATCH_HOME']:
pyinclude = os.path.join(os.environ['QPID_DISPATCH_HOME'], 'python')
super(Qdrouterd, self).__init__(
@@ -621,3 +622,13 @@ class TestCase(unittest.TestCase, Tester
def assertIn(self, item, items):
assert item in items, "%s not in %s" % (item, items)
+
+def main_module():
+ """
+ Return the module name of the __main__ module - i.e. the filename with the
+ path and .py extension stripped. Useful to run the tests in the current file but
+ using the proper module prefix instead of '__main__', as follows:
+ if __name__ == '__main__':
+ unittest.main(module=main_module())
+ """
+ return os.path.splitext(os.path.basename(__main__.__file__))[0]
Modified: qpid/dispatch/trunk/tests/system_tests_broker.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_broker.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_broker.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_broker.py Wed Oct 22 18:43:28 2014
@@ -52,9 +52,6 @@ class DistributedQueueTest(system_test.T
def common_router_conf(self, name, mode='standalone'):
"""Common router configuration for the tests"""
return Qdrouterd.Config([
- # ('log', {'module':'DEFAULT', 'level':'info', 'output':name+".log"}),
- # ('log', {'module':'ROUTER', 'level':'trace'}),
- # ('log', {'module':'MESSAGE', 'level':'trace'}),
('container', {'container-name':name}),
('router', {'mode': mode, 'router-id': name})
])
@@ -108,4 +105,4 @@ class DistributedQueueTest(system_test.T
self.verify_equal_spread(addrs, addrs)
if __name__ == '__main__':
- unittest.main()
+ unittest.main(system_test.main_module())
Modified: qpid/dispatch/trunk/tests/system_tests_management.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_management.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_management.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_management.py Wed Oct 22 18:43:28 2014
@@ -42,9 +42,7 @@ class ManagementTest(system_test.TestCas
super(ManagementTest, cls).setUpClass()
# Stand-alone router
name = cls.__name__
- cls.log_file = name+".log"
conf = Qdrouterd.Config([
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':cls.log_file}),
('router', { 'mode': 'standalone', 'router-id': name}),
('listener', {'name': 'l0', 'port':cls.get_port(), 'role':'normal'}),
# Extra listeners to exercise managment query
@@ -149,7 +147,6 @@ class ManagementTest(system_test.TestCas
Create a waypoint that leads out and back from a second router.
"""
conf = Qdrouterd.Config([
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':'wp-router.log'}),
('router', {'mode': 'standalone', 'router-id': 'wp-router'}),
('listener', {'port':self.get_port(), 'role':'normal'}),
('fixed-address', {'prefix':'foo'})
@@ -272,13 +269,11 @@ class ManagementTest(system_test.TestCas
"""Test node entity in a pair of linked routers"""
# Pair of linked interior routers
conf1 = Qdrouterd.Config([
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':'router1.log'}),
('router', { 'mode': 'interior', 'router-id': 'router1'}),
('listener', {'port':self.get_port(), 'role':'normal'}),
('listener', {'port':self.get_port(), 'role':'inter-router'})
])
conf2 = Qdrouterd.Config([
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':'router2.log'}),
('router', { 'mode': 'interior', 'router-id': 'router2'}),
('listener', {'port':self.get_port(), 'role':'normal'}),
('connector', {'port':conf1.sections('listener')[1]['port'], 'role':'inter-router'})
@@ -326,4 +321,4 @@ class ManagementTest(system_test.TestCas
for a in ['linkType', 'linkDir', 'owningAddr']: self.assertIn(a, result[LINK])
if __name__ == '__main__':
- unittest.main()
+ unittest.main(system_test.main_module())
Modified: qpid/dispatch/trunk/tests/system_tests_one_router.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_one_router.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_one_router.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_one_router.py Wed Oct 22 18:43:28 2014
@@ -19,7 +19,7 @@
import unittest
from proton import Message, PENDING, ACCEPTED, REJECTED, RELEASED
-from system_test import TestCase, Messenger, Qdrouterd
+from system_test import TestCase, Messenger, Qdrouterd, main_module
class RouterTest(TestCase):
"""System tests involving a single router"""
@@ -30,7 +30,6 @@ class RouterTest(TestCase):
super(RouterTest, cls).setUpClass()
name = "test-router"
config = Qdrouterd.Config([
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':name+".log"}),
('container', {'worker-threads': 4, 'container-name': 'Qpid.Dispatch.Router.A'}),
('router', {'mode': 'standalone', 'router-id': 'QDR'}),
('listener', {'port': cls.tester.get_port()}),
@@ -841,4 +840,4 @@ class RouterTest(TestCase):
if __name__ == '__main__':
- unittest.main()
+ unittest.main(main_module())
Modified: qpid/dispatch/trunk/tests/system_tests_qdmanage.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_qdmanage.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_qdmanage.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_qdmanage.py Wed Oct 22 18:43:28 2014
@@ -18,7 +18,7 @@
#
import re, json, unittest
-from system_test import TestCase, Process, Qdrouterd
+from system_test import TestCase, Process, Qdrouterd, main_module
from subprocess import PIPE, STDOUT
@@ -139,4 +139,4 @@ class QdmanageTest(TestCase):
self.assertEqual(name_type(qall), name_type(qattr))
if __name__ == '__main__':
- unittest.main()
+ unittest.main(main_module())
Modified: qpid/dispatch/trunk/tests/system_tests_qdstat.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_qdstat.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_qdstat.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_qdstat.py Wed Oct 22 18:43:28 2014
@@ -65,4 +65,4 @@ class QdstatTest(system_test.TestCase):
if __name__ == '__main__':
- unittest.main()
+ unittest.main(system_test.main_module())
Modified: qpid/dispatch/trunk/tests/system_tests_two_routers.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_two_routers.py?rev=1633674&r1=1633673&r2=1633674&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_two_routers.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_two_routers.py Wed Oct 22 18:43:28 2014
@@ -19,7 +19,7 @@
import unittest, os
from proton import Message, PENDING, ACCEPTED, REJECTED, RELEASED, SSLDomain, SSLUnavailable
-from system_test import TestCase, Qdrouterd
+from system_test import TestCase, Qdrouterd, main_module
class RouterTest(TestCase):
@@ -32,7 +32,6 @@ class RouterTest(TestCase):
def router(name, client_server, connection):
config = Qdrouterd.Config(ssl_config(client_server, connection) + [
- ('log', {'module':'DEFAULT', 'level':'trace', 'output':name+".log"}),
('container', {'worker-threads': 4, 'container-name': 'Qpid.Dispatch.Router.%s'%name}),
('router', {'mode': 'interior', 'router-id': 'QDR.%s'%name}),
('listener', {'port': cls.tester.get_port()}),
@@ -802,4 +801,4 @@ except SSLUnavailable:
self.skipTest("Proton SSL support unavailable.")
if __name__ == '__main__':
- unittest.main()
+ unittest.main(main_module())
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org