qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r1655521 - in /qpid/dispatch/trunk/tests: system_test.py system_tests_management.py
Date Thu, 29 Jan 2015 03:43:08 GMT
Author: aconway
Date: Thu Jan 29 03:43:08 2015
New Revision: 1655521

URL: http://svn.apache.org/r1655521
Log:
NO-JIRA: Separate router for logging test.

Avoid messing with log output from other tests.
- Re-use routers rather than starting new routers for special tests.
- Wait on demand for routers to be ready.
- Add test to verify querying a remote router via an intermediate router.

Modified:
    qpid/dispatch/trunk/tests/system_test.py
    qpid/dispatch/trunk/tests/system_tests_management.py

Modified: qpid/dispatch/trunk/tests/system_test.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_test.py?rev=1655521&r1=1655520&r2=1655521&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_test.py (original)
+++ qpid/dispatch/trunk/tests/system_test.py Thu Jan 29 03:43:08 2015
@@ -299,6 +299,9 @@ class Qdrouterd(Process):
             """Return list of sections named name"""
             return [p for n, p in self if n == name]
 
+        @property
+        def router_id(self): return self.sections("router")[0]["routerId"]
+
         def defaults(self):
             """Fill in default values in gconfiguration"""
             for name, props in self:
@@ -316,11 +319,13 @@ class Qdrouterd(Process):
 
     def __init__(self, name=None, config=Config(), pyinclude=None, wait=True):
         """
-        @param name: name used for for output files.
+        @param name: name used for for output files, default to routerId from config.
         @param config: router configuration
         @keyword wait: wait for router to be ready (call self.wait_ready())
         """
         self.config = copy(config)
+        if not name: name = self.config.router_id
+        assert name
         default_log = [l for l in config if (l[0] == 'log' and l[1]['module'] == 'DEFAULT')]
         if not default_log:
             config.append(
@@ -331,9 +336,11 @@ class Qdrouterd(Process):
             ['qdrouterd', '-c', config.write(name), '-I', pyinclude],
             name=name, expect=Process.RUNNING)
         self._management = None
+        self._wait_ready = False
         if wait:
             self.wait_ready()
 
+
     @property
     def management(self):
         """Return a management agent proxy for this router"""
@@ -400,8 +407,11 @@ class Qdrouterd(Process):
 
     def wait_ready(self):
         """Wait for ports and connectors to be ready"""
-        wait_ports(self.ports)
-        self.wait_connectors()
+        if not self._wait_ready:
+            self._wait_ready = True
+            wait_ports(self.ports)
+            self.wait_connectors()
+        return self
 
     def wait_connected(self, router_id):
         """Wait till this router is connected to router with router-id"""

Modified: qpid/dispatch/trunk/tests/system_tests_management.py
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_management.py?rev=1655521&r1=1655520&r2=1655521&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_management.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_management.py Thu Jan 29 03:43:08 2015
@@ -46,28 +46,65 @@ def short_name(name):
         return name[len(PREFIX):]
     return name
 
-class ManagementTest(system_test.TestCase): # pylint: disable=too-many-public-methods
+
+class ManagementTest(system_test.TestCase):
 
     @classmethod
     def setUpClass(cls):
         super(ManagementTest, cls).setUpClass()
+        cls.all_routers = []
         # Stand-alone router
-        name = cls.__name__
-        conf = Qdrouterd.Config([
-            ('router', { 'mode': 'standalone', 'routerId': name}),
+        conf0=Qdrouterd.Config([
+            ('router', { 'mode': 'standalone', 'routerId': 'router0'}),
             ('listener', {'name': 'l0', 'port':cls.get_port(), 'role':'normal'}),
             # Extra listeners to exercise managment query
             ('listener', {'name': 'l1', 'port':cls.get_port(), 'role':'normal'}),
             ('listener', {'name': 'l2', 'port':cls.get_port(), 'role':'normal'})
         ])
-        cls.router = cls.tester.qdrouterd('%s'%name, conf)
-        cls.router.wait_ready()
+        cls._router = cls.tester.qdrouterd(config=conf0, wait=False)
+
+        # Pair of linked interior routers
+        conf1 = Qdrouterd.Config([
+            ('router', { 'mode': 'interior', 'routerId': 'router1'}),
+            ('listener', {'port':cls.get_port(), 'role':'normal'}),
+            ('listener', {'port':cls.get_port(), 'role':'inter-router'})
+        ])
+        conf2 = Qdrouterd.Config([
+            ('router', { 'mode': 'interior', 'routerId': 'router2'}),
+            ('listener', {'port':cls.get_port(), 'role':'normal'}),
+            ('connector', {'port':conf1.sections('listener')[1]['port'], 'role':'inter-router'})
+        ])
+        cls._routers = [cls.tester.qdrouterd(config=c, wait=False) for c in [conf1, conf2]]
+
+        # Stand-alone router for logging tests (avoid interfering with logging for other
tests.)
+        conflog=Qdrouterd.Config([
+            ('router', { 'mode': 'standalone', 'routerId': 'logrouter'}),
+            ('listener', {'port':cls.get_port(), 'role':'normal'}),
+        ])
+        cls._logrouter = cls.tester.qdrouterd(config=conflog, wait=False)
+
+
+    @property
+    def router(self): return self.__class__._router.wait_ready()
+
+    @property
+    def logrouter(self): return self.__class__._logrouter.wait_ready()
+
+    @property
+    def routers(self):
+        """Wait on demand and return the linked interior routers"""
+        if not self._routers:
+            self._routers = self.__class__._routers
+            self._routers[0].wait_connected('router2')
+            self._routers[1].wait_connected('router1')
+        return self._routers
 
     def setUp(self):
         super(ManagementTest, self).setUp()
-        self.node = self.cleanup(Node(self.router.addresses[0]))
+        self._routers = None # Wait on demand
         self.maxDiff = None
         self.longMessage = True
+        self.node = self.cleanup(Node(self.router.addresses[0]))
 
     def test_bad_query(self):
         """Test that various badly formed queries get the proper response"""
@@ -132,18 +169,19 @@ class ManagementTest(system_test.TestCas
         # Connect via the new listener
         node3 = self.cleanup(Node(Url(port=port)))
         router = node3.query(type=ROUTER).get_entities()
-        self.assertEqual(self.__class__.router.name, router[0]['routerId'])
+        self.assertEqual(self.router.name, router[0]['routerId'])
 
     def test_log(self):
         """Create, update and query log entities"""
 
-        default = self.node.read(identity='log/DEFAULT')
+        node = self.cleanup(Node(self.logrouter.addresses[0]))
+        default = node.read(identity='log/DEFAULT')
         self.assertEqual(default.attributes,
                          {u'identity': u'log/DEFAULT',
                           u'enable': u'trace+',
                           u'module': u'DEFAULT',
                           u'name': u'log/DEFAULT',
-                          u'output': u'ManagementTest.log',
+                          u'output': u'logrouter.log',
                           u'source': True,
                           u'timestamp': True,
                           u'type': u'org.apache.qpid.dispatch.log'})
@@ -152,7 +190,7 @@ class ManagementTest(system_test.TestCas
         def check_log(log, error=True, debug=False):
             """Cause an error and check for expected error and debug logs"""
             bad_type = "nosuch"
-            self.assertRaises(ManagementError, self.node.create, type=bad_type, name=bad_type)
+            self.assertRaises(ManagementError, node.create, type=bad_type, name=bad_type)
             f = self.cleanup(open(log))
             logstr = f.read()
             def assert_expected(expect, regex, logstr):
@@ -169,7 +207,7 @@ class ManagementTest(system_test.TestCas
             log = os.path.abspath("test_log.log%s" % log_count[0])
             attributes["output"] = log
             attributes["identity"] = "log/AGENT"
-            self.node.update(attributes)
+            node.update(attributes)
             check_log(log, error, debug)
 
         # Expect error but no debug
@@ -188,13 +226,13 @@ class ManagementTest(system_test.TestCas
 
         # Check defaults are picked up
         update_check_log(dict(enable="default"), error=True, debug=True)
-        self.node.update(dict(identity="log/DEFAULT", enable="debug"))
+        node.update(dict(identity="log/DEFAULT", enable="debug"))
         update_check_log(dict(enable="DEFAULT"), error=False, debug=True)
-        self.node.update(dict(identity="log/DEFAULT", enable="error"))
+        node.update(dict(identity="log/DEFAULT", enable="error"))
         update_check_log(dict(enable="default"), error=True, debug=False)
 
         # Invalid values
-        self.assertRaises(ManagementError, self.node.update, dict(identity="log/AGENT", enable="foo"))
+        self.assertRaises(ManagementError, node.update, dict(identity="log/AGENT", enable="foo"))
 
     def test_create_fixed_address(self):
         self.assert_create_ok(FIXED_ADDRESS, 'fixed1', dict(prefix='fixed1'))
@@ -344,36 +382,11 @@ class ManagementTest(system_test.TestCas
 
     def test_router_node(self):
         """Test node entity in a pair of linked routers"""
-        # Pair of linked interior routers
-        conf1 = Qdrouterd.Config([
-            ('router', { 'mode': 'interior', 'routerId': 'router1'}),
-            ('listener', {'port':self.get_port(), 'role':'normal'}),
-            ('listener', {'port':self.get_port(), 'role':'inter-router'})
-        ])
-        conf2 = Qdrouterd.Config([
-            ('router', { 'mode': 'interior', 'routerId': 'router2'}),
-            ('listener', {'port':self.get_port(), 'role':'normal'}),
-            ('connector', {'port':conf1.sections('listener')[1]['port'], 'role':'inter-router'})
-        ])
-        routers = [self.qdrouterd('router1', conf1, wait=False),
-                   self.qdrouterd('router2', conf2, wait=False)]
-        for r in routers: r.wait_ready()
-        routers[0].wait_connected('router2')
-        routers[1].wait_connected('router1')
-
-        nodes = [self.cleanup(Node(Url(r.addresses[0]))) for r in routers]
-
-        class RNodes(list):
-            def __call__(self):
-                self[:] = sum([n.query(type=NODE).get_entities() for n in nodes], [])
-                return self
-        rnodes = RNodes()
-
-        assert retry(lambda: len(rnodes()) >= 2)
+        nodes = [self.cleanup(Node(Url(r.addresses[0]))) for r in self.routers]
+        rnodes = sum([n.query(type=NODE).get_entities() for n in nodes], [])
         self.assertEqual(['Rrouter2', 'Rrouter1'], [r.addr for r in rnodes])
-        # FIXME aconway 2014-10-15: verify nextHop and validOrigins updated correctly
-        self.assertEqual([u'amqp:/_topo/0/router2/$management', u'amqp:/_topo/0/router1/$management'],
-                         sum([n.get_mgmt_nodes() for n in nodes], []))
+        self.assertEqual(['0', '0'], [r.nextHop for r in rnodes])
+        self.assertEqual([[], []], [r.validOrigins for r in rnodes])
 
         # Test that all entities have a consitent identity format: type/name
         entities = list(chain(
@@ -384,6 +397,16 @@ class ManagementTest(system_test.TestCas
             else:
                 self.assertRegexpMatches(e.identity, "^%s/" % short_name(e.type), e)
 
+    def test_remote_node(self):
+        """Test that we can access management info of remote nodes using get_mgmt_nodes addresses"""
+        nodes = [self.cleanup(Node(Url(r.addresses[0]))) for r in self.routers]
+        remotes = sum([n.get_mgmt_nodes() for n in nodes], [])
+        self.assertEqual([u'amqp:/_topo/0/router2/$management', u'amqp:/_topo/0/router1/$management'],
remotes)
+        # Query router2 indirectly via router1
+        remote_url = Url(self.routers[0].addresses[0], path=Url(remotes[0]).path)
+        remote = self.cleanup(Node(remote_url))
+        self.assertEqual(["router2"], [r.routerId for r in remote.query(type=ROUTER).get_entities()])
+
     def test_get_types(self):
         types = self.node.get_types()
         self.assertIn(CONFIGURATION, types[LISTENER])
@@ -440,16 +463,6 @@ class ManagementTest(system_test.TestCas
         r.expect = Process.EXIT_FAIL
         self.assertTrue(r.wait() != 0)
 
-
-    def test_config_many_logs(self):
-        """Regression test for DISPATCH-93, multiple log entries in config file cause errors"""
-        conf = Qdrouterd.Config([
-            ('listener', {'port': self.get_port(), 'role':'normal'}),
-            ('log', { 'module': 'AGENT', 'enable': 'debug+'}),
-            ('log', { 'module': 'MESSAGE', 'enable': 'trace+'})])
-        router = self.qdrouterd("multi_log_conf", conf, wait=True)
-
-
     def test_get_schema(self):
         schema = dictify(QdSchema().dump())
         # FIXME aconway 2015-01-26: improve node API.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message