Repository: qpid-dispatch Updated Branches: refs/heads/master b88814170 -> ee856b3b9
DISPATCH-179 - Patch from Ganesh Murthy. Also fixed incorrect types reported from router_core agent. Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/ee856b3b Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/ee856b3b Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/ee856b3b Branch: refs/heads/master Commit: ee856b3b93c10d4d597531d94d64e3ddb7c6c50f Parents: b888141 Author: Ted Ross <[email protected]> Authored: Fri Apr 8 14:20:57 2016 -0400 Committer: Ted Ross <[email protected]> Committed: Fri Apr 8 14:20:57 2016 -0400 ---------------------------------------------------------------------- src/router_core/agent_config_address.c | 2 +- src/router_core/agent_config_auto_link.c | 2 +- src/router_core/agent_config_link_route.c | 2 +- tests/system_tests_link_routes.py | 126 ++++++++++++++++++++++++- tools/qdmanage | 30 +++++- 5 files changed, 152 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ee856b3b/src/router_core/agent_config_address.c ---------------------------------------------------------------------- diff --git a/src/router_core/agent_config_address.c b/src/router_core/agent_config_address.c index 3d46f40..c9436f8 100644 --- a/src/router_core/agent_config_address.c +++ b/src/router_core/agent_config_address.c @@ -67,7 +67,7 @@ static void qdr_config_address_insert_column_CT(qdr_address_config_t *addr, int } case QDR_CONFIG_ADDRESS_TYPE: - qd_compose_insert_string(body, "org.apache.qpid.dispatch.config.address"); + qd_compose_insert_string(body, "org.apache.qpid.dispatch.router.config.address"); break; case QDR_CONFIG_ADDRESS_PREFIX: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ee856b3b/src/router_core/agent_config_auto_link.c ---------------------------------------------------------------------- diff --git a/src/router_core/agent_config_auto_link.c b/src/router_core/agent_config_auto_link.c index b4cacc3..b59d77c 100644 --- a/src/router_core/agent_config_auto_link.c +++ b/src/router_core/agent_config_auto_link.c @@ -73,7 +73,7 @@ static void qdr_config_auto_link_insert_column_CT(qdr_auto_link_t *al, int col, break; case QDR_CONFIG_AUTO_LINK_TYPE: - qd_compose_insert_string(body, "org.apache.qpid.dispatch.config.autoLink"); + qd_compose_insert_string(body, "org.apache.qpid.dispatch.router.config.autoLink"); break; case QDR_CONFIG_AUTO_LINK_ADDR: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ee856b3b/src/router_core/agent_config_link_route.c ---------------------------------------------------------------------- diff --git a/src/router_core/agent_config_link_route.c b/src/router_core/agent_config_link_route.c index 25ab442..b07c916 100644 --- a/src/router_core/agent_config_link_route.c +++ b/src/router_core/agent_config_link_route.c @@ -68,7 +68,7 @@ static void qdr_config_link_route_insert_column_CT(qdr_link_route_t *lr, int col } case QDR_CONFIG_LINK_ROUTE_TYPE: - qd_compose_insert_string(body, "org.apache.qpid.dispatch.config.linkRoute"); + qd_compose_insert_string(body, "org.apache.qpid.dispatch.router.config.linkRoute"); break; case QDR_CONFIG_LINK_ROUTE_PREFIX: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ee856b3b/tests/system_tests_link_routes.py ---------------------------------------------------------------------- diff --git a/tests/system_tests_link_routes.py b/tests/system_tests_link_routes.py index 6f3ca61..d7f673a 100644 --- a/tests/system_tests_link_routes.py +++ b/tests/system_tests_link_routes.py @@ -19,9 +19,9 @@ import unittest from time import sleep -from subprocess import PIPE +from subprocess import PIPE, STDOUT -from system_test import TestCase, Qdrouterd, main_module, TIMEOUT +from system_test import TestCase, Qdrouterd, main_module, TIMEOUT, Process from proton import Message from proton.reactor import AtMostOnce @@ -119,6 +119,39 @@ class LinkRoutePatternTest(TestCase): assert p.returncode == 0, "qdstat exit status %s, output:\n%s" % (p.returncode, out) return out + def run_qdmanage(self, cmd, input=None, expect=Process.EXIT_OK, address=None): + p = self.popen( + ['qdmanage'] + cmd.split(' ') + ['--bus', address or self.address(), '--indent=-1', '--timeout', str(TIMEOUT)], + stdin=PIPE, stdout=PIPE, stderr=STDOUT, expect=expect) + out = p.communicate(input)[0] + try: + p.teardown() + except Exception, e: + raise Exception("%s\n%s" % (e, out)) + return out + + def test_aaa_qdmanage_query_link_route(self): + """ + qdmanage converts short type to long type and this test specifically tests if qdmanage is actually doing + the type conversion correctly by querying with short type and long type. + """ + cmd = 'QUERY --type=linkRoute' + out = self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) + + # Make sure there is a dir of in and out. + self.assertTrue('"dir": "in"' in out) + self.assertTrue('"dir": "out"' in out) + self.assertTrue('"connection": "broker"' in out) + + # Use the long type and make sure that qdmanage does not mess up the long type + cmd = 'QUERY --type=org.apache.qpid.dispatch.router.config.linkRoute' + out = self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) + + # Make sure there is a dir of in and out. + self.assertTrue('"dir": "in"' in out) + self.assertTrue('"dir": "out"' in out) + self.assertTrue('"connection": "broker"' in out) + def test_bbb_qdstat_link_routes_routerB(self): """ Runs qdstat on router B to make sure that router B has two link routes, one 'in' and one 'out' @@ -160,7 +193,7 @@ class LinkRoutePatternTest(TestCase): apply_options = AtMostOnce() - # Sender to to org.apache.dev + # Sender to org.apache.dev blocking_sender = blocking_connection.create_sender(address="org.apache.dev", options=apply_options) msg = Message(body=hello_world_1) # Send a message @@ -316,5 +349,92 @@ class LinkRoutePatternTest(TestCase): #blocking_receiver.close() blocking_connection.close() + + def test_zzz_qdmanage_delete_link_route(self): + """ + We are deleting the link route using qdmanage short name. This should be the last test to run + """ + + # First delete linkRoutes on QDR.B + local_node = Node.connect(self.routers[1].addresses[0], timeout=TIMEOUT) + result_list = local_node.query(type='org.apache.qpid.dispatch.router.config.linkRoute').results + + identity_1 = result_list[0][1] + identity_2 = result_list[1][1] + + cmd = 'DELETE --type=linkRoute --identity=' + identity_1 + self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) + + cmd = 'DELETE --type=linkRoute --identity=' + identity_2 + self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) + + cmd = 'QUERY --type=linkRoute' + out = self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) + self.assertEquals(out.rstrip(), '[]') + + sleep(1) + + # linkRoutes now gone on QDR.B but remember that it still exist on QDR.C + # We will now try to create a receiver on address org.apache.dev on QDR.C. + # Since the linkRoute on QDR.B is gone, QDR.C + # will not allow a receiver to be created since there is no route to destination. + # Connects to listener #2 on QDR.C + addr = self.routers[2].addresses[1] + + timeout_exception = False + blocking_connection = BlockingConnection(addr, timeout=3) + + try: + blocking_connection.create_receiver(address="org.apache.dev") + except Exception as e: + self.assertTrue("timed out: Opening link" in e.message) + timeout_exception = True + + self.assertTrue(timeout_exception) + + # Now delete linkRoutes on QDR.C to eradicate linkRoutes completely + local_node = Node.connect(addr, timeout=TIMEOUT) + result_list = local_node.query(type='org.apache.qpid.dispatch.router.config.linkRoute').results + + identity_1 = result_list[0][1] + identity_2 = result_list[1][1] + + cmd = 'DELETE --type=linkRoute --identity=' + identity_1 + self.run_qdmanage(cmd=cmd, address=addr) + + cmd = 'DELETE --type=linkRoute --identity=' + identity_2 + self.run_qdmanage(cmd=cmd, address=addr) + + cmd = 'QUERY --type=linkRoute' + out = self.run_qdmanage(cmd=cmd, address=addr) + self.assertEquals(out.rstrip(), '[]') + + blocking_connection = BlockingConnection(addr, timeout=3) + + # Receive on org.apache.dev (this address used to be linkRouted but not anymore since we deleted linkRoutes + # on both QDR.C and QDR.B) + blocking_receiver = blocking_connection.create_receiver(address="org.apache.dev") + + apply_options = AtMostOnce() + hello_world_1 = "Hello World_1!" + # Sender to org.apache.dev + blocking_sender = blocking_connection.create_sender(address="org.apache.dev", options=apply_options) + msg = Message(body=hello_world_1) + + # Send a message + blocking_sender.send(msg) + received_message = blocking_receiver.receive(timeout=5) + self.assertEqual(hello_world_1, received_message.body) + + # Connect to the router acting like the broker (QDR.A) and check the deliveriesIngress and deliveriesEgress + local_node = Node.connect(self.routers[2].addresses[1], timeout=TIMEOUT) + + self.assertEqual(u'QDR.C', local_node.query(type='org.apache.qpid.dispatch.router', + attribute_names=['routerId']).results[0][0]) + + self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address', + name='M0org.apache.dev').deliveriesEgress, + "deliveriesEgress is wrong") + if __name__ == '__main__': unittest.main(main_module()) http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ee856b3b/tools/qdmanage ---------------------------------------------------------------------- diff --git a/tools/qdmanage b/tools/qdmanage index 6954872..26f17b7 100755 --- a/tools/qdmanage +++ b/tools/qdmanage @@ -36,9 +36,8 @@ def attr_split(attrstr): return nv class QdManage(): - def __init__(self): - + self.prefix = 'org.apache.qpid.dispatch.' self.operations = ['QUERY', 'CREATE', 'READ', 'UPDATE', 'DELETE', 'GET-TYPES', 'GET-OPERATIONS', 'GET-ATTRIBUTES', 'GET-ANNOTATIONS', 'GET-MGMT-NODES', 'GET-SCHEMA', 'GET-LOG'] @@ -60,10 +59,17 @@ class QdManage(): op.add_option_group(connection_options(op)) self.op = op + def clean_opts(self): + attr_type = self.opts.type + if attr_type: + self.opts.type = self.long_type(attr_type) + def run(self, argv): # Make all args unicode to avoid encoding arg values as AMQP bytes. self.opts, self.args = self.op.parse_args([unicode(x) for x in argv[1:]]) - if self.opts.indent == -1: self.opts.indent = None + self.clean_opts() + if self.opts.indent == -1: + self.opts.indent = None if len(self.args) == 0: raise UsageError("No operation specified") self.node = Node.connect( opts_url(self.opts), self.opts.router, self.opts.timeout, opts_ssl_domain(self.opts)) @@ -92,12 +98,27 @@ class QdManage(): except ValueError: print result + def long_type(self, type): + if not type or "." in type: + return type + + if type in ('linkRoute', 'address', 'autoLink'): + return self.prefix + "router.config." + type + + return self.prefix + type + def call_node(self, method, *argnames, **kwargs): """Call method on node, use opts named in argnames""" names = set(argnames) + + attributes = kwargs.get('attributes') + if attributes and attributes.get('type'): + attributes['type'] = self.long_type(attributes['type']) + for k in self.opts.__dict__: if k in names and hasattr(self.opts, k): kwargs[k] = getattr(self.opts, k) + return getattr(self.node, method)(**kwargs) def call_bulk(self, func): @@ -114,7 +135,8 @@ class QdManage(): def query(self): """query [ATTR...] Print attributes of entities.""" - if self.args: self.opts.attribute_names = self.args + if self.args: + self.opts.attribute_names = self.args result = self.call_node('query', 'type', 'attribute_names') self.print_json(result.get_dicts(clean=True)) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
