From 4ad82f5f765d56d402cfb7388a65dbded3898a2b Mon Sep 17 00:00:00 2001 From: Ganesh Murthy Date: Tue, 17 May 2016 16:40:53 -0400 Subject: [PATCH] DISPATCH-155 - Allow multiple connectors from router to same broker. Thanks Jakub Scholz for patch --- python/qpid_dispatch_internal/management/agent.py | 14 ++++++-------- tests/system_test.py | 12 ++++++++++-- tests/system_tests_management.py | 2 +- tests/system_tests_qdmanage.py | 11 ++++++++--- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/python/qpid_dispatch_internal/management/agent.py b/python/qpid_dispatch_internal/management/agent.py index e6c664c46e..77e3416135 100644 --- a/python/qpid_dispatch_internal/management/agent.py +++ b/python/qpid_dispatch_internal/management/agent.py @@ -319,11 +319,11 @@ def _identifier(self): return self.attributes.get('applicationName') -def _host_port_identifier(entity): - for attr in ['host', 'port']: # Set default values if need be +def _host_port_name_identifier(entity): + for attr in ['host', 'port', 'name']: # Set default values if need be entity.attributes.setdefault( attr, entity.entity_type.attribute(attr).missing_value()) - return "%s:%s" % (entity.attributes['host'], entity.attributes['port']) + return "%s:%s:%s" % (entity.attributes['host'], entity.attributes['port'], entity.attributes['name']) class ListenerEntity(EntityAdapter): @@ -333,7 +333,7 @@ def create(self): return config_listener def _identifier(self): - return _host_port_identifier(self) + return _host_port_name_identifier(self) def __str__(self): return super(ListenerEntity, self).__str__().replace("Entity(", "ListenerEntity(") @@ -341,8 +341,6 @@ def __str__(self): def _delete(self): self._qd.qd_connection_manager_delete_listener(self._dispatch, self._implementations[0].key) - def _identifier(self): return _host_port_identifier(self) - class ConnectorEntity(EntityAdapter): def create(self): config_connector = self._qd.qd_dispatch_configure_connector(self._dispatch, self) @@ -353,7 +351,7 @@ def _delete(self): self._qd.qd_connection_manager_delete_connector(self._dispatch, self._implementations[0].key) def _identifier(self): - return _host_port_identifier(self) + return _host_port_name_identifier(self) def __str__(self): return super(ConnectorEntity, self).__str__().replace("Entity(", "ConnectorEntity(") @@ -469,7 +467,7 @@ def __str__(self): class ConnectionEntity(EntityAdapter): def _identifier(self): - return self.attributes.get('host') + return self.attributes.get('host') + ":" + str(self.attributes.get('identity')) def __str__(self): return super(ConnectionEntity, self).__str__().replace("Entity(", "ConnectionEntity(") diff --git a/tests/system_test.py b/tests/system_test.py index f97b2bcaa7..f4d070fa2e 100755 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -437,10 +437,18 @@ def hostports(self): return address_list def is_connected(self, port, host='127.0.0.1'): - """If router has a connection to host:port return the management info. + """If router has a connection to host:port:identity return the management info. Otherwise return None""" try: - return self.management.read(name="connection/%s:%s" % (host, port)) + ret_val = False + response = self.management.query(type="org.apache.qpid.dispatch.connection") + index_name = response.attribute_names.index('name') + index_identity = response.attribute_names.index('identity') + for result in response.results: + outs = 'connection/%s:%s:%s' % (host, port, str(result[index_identity])) + if result[index_name] == outs: + ret_val = True + return ret_val except: return False diff --git a/tests/system_tests_management.py b/tests/system_tests_management.py index 1f6d4860d3..662e11bfc0 100644 --- a/tests/system_tests_management.py +++ b/tests/system_tests_management.py @@ -257,7 +257,7 @@ def test_dummy(self): self.assertEqual(str(self.router.ports[0]), entity.port) entity = self.node.read( - type=LISTENER, identity='listener/0.0.0.0:%s' % self.router.ports[1]) + type=LISTENER, identity='listener/0.0.0.0:%s:l1' % self.router.ports[1]) self.assertEqual('l1', entity.name) self.assertEqual(str(self.router.ports[1]), entity.port) diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py index 56216750d0..b8837b3edf 100644 --- a/tests/system_tests_qdmanage.py +++ b/tests/system_tests_qdmanage.py @@ -212,10 +212,15 @@ def test_create_delete_connector(self): # Re-create the connector and then try wait_connectors self.create(long_type, name, str(QdmanageTest.inter_router_port)) - full_name = 'connection/0.0.0.0:' + str(QdmanageTest.inter_router_port) - output = json.loads(self.run_qdmanage('READ --type=org.apache.qpid.dispatch.connection --name ' + full_name)) - self.assertEquals(full_name, output['name']) + results = json.loads(self.run_qdmanage('QUERY --type=org.apache.qpid.dispatch.connection')) + + created = False + for result in results: + name = result['name'] + if 'connection/0.0.0.0:%s:' % QdmanageTest.inter_router_port in name: + created = True + self.assertTrue(created) def test_zzz_add_connector(self): port = self.get_port()