From fe4d3dd164c2685cb7483c65e2e915f93d13e7e6 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 25 Jan 2012 18:48:31 +0000 Subject: QPID-3603: Set connection.start client-properties argument from python. The client-properties can be specified for old-API, new-API and QMF connections. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-3603-2@1235869 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/test_env.sh.in | 2 +- qpid/extras/qmf/src/py/qmf/console.py | 12 +++++++----- qpid/python/qpid/delegates.py | 6 ++++-- qpid/python/qpid/messaging/driver.py | 5 ++++- qpid/python/qpid/messaging/endpoints.py | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/qpid/cpp/src/tests/test_env.sh.in b/qpid/cpp/src/tests/test_env.sh.in index 100612f978..0cd658bd80 100644 --- a/qpid/cpp/src/tests/test_env.sh.in +++ b/qpid/cpp/src/tests/test_env.sh.in @@ -55,7 +55,7 @@ export RECEIVER_EXEC=$QPID_TEST_EXEC_DIR/receiver export SENDER_EXEC=$QPID_TEST_EXEC_DIR/sender # Path -export PATH=$top_builddir/src:$builddir:$srcdir:$PYTHON_COMMANDS:$QPID_TEST_EXEC_DIR:$PATH +export PATH=$top_builddir/src:$builddir:$srcdir:$PYTHON_COMMANDS:$QPID_TEST_EXEC_DIR:$PYTHON_DIR/commands:$PATH # Modules export TEST_STORE_LIB=$testmoduledir/test_store.so diff --git a/qpid/extras/qmf/src/py/qmf/console.py b/qpid/extras/qmf/src/py/qmf/console.py index e8be643c0f..0de013647c 100644 --- a/qpid/extras/qmf/src/py/qmf/console.py +++ b/qpid/extras/qmf/src/py/qmf/console.py @@ -640,7 +640,7 @@ class Session: return "QMF Console Session Manager (brokers: %d)" % len(self.brokers) - def addBroker(self, target="localhost", timeout=None, mechanisms=None): + def addBroker(self, target="localhost", timeout=None, mechanisms=None, **connectArgs): """ Connect to a Qpid broker. Returns an object of type Broker. Will raise an exception if the session is not managing the connection and the connection setup to the broker fails. @@ -650,7 +650,7 @@ class Session: else: url = BrokerURL(target) broker = Broker(self, url.host, url.port, mechanisms, url.authName, url.authPass, - ssl = url.scheme == URL.AMQPS, connTimeout=timeout) + ssl = url.scheme == URL.AMQPS, connTimeout=timeout, **connectArgs) self.brokers.append(broker) return broker @@ -2240,7 +2240,8 @@ class Broker(Thread): self.typecode = typecode self.data = data - def __init__(self, session, host, port, authMechs, authUser, authPass, ssl=False, connTimeout=None): + def __init__(self, session, host, port, authMechs, authUser, authPass, + ssl=False, connTimeout=None, **connectArgs): """ Create a broker proxy and setup a connection to the broker. Will raise an exception if the connection fails and the session is not configured to retry connection setup (manageConnections = False). @@ -2274,7 +2275,7 @@ class Broker(Thread): self.amqpSessionId = "%s.%d.%d" % (platform.uname()[1], os.getpid(), Broker.nextSeq) Broker.nextSeq += 1 self.last_age_check = time() - + self.connectArgs = connectArgs # thread control self.setDaemon(True) self.setName("Thread for broker: %s:%d" % (host, port)) @@ -2426,7 +2427,8 @@ class Broker(Thread): else: connSock = sock self.conn = Connection(connSock, username=self.authUser, password=self.authPass, - mechanism = self.mechanisms, host=self.host, service="qpidd") + mechanism = self.mechanisms, host=self.host, service="qpidd", + **self.connectArgs) def aborted(): raise Timeout("Waiting for connection to be established with broker") oldAborted = self.conn.aborted diff --git a/qpid/python/qpid/delegates.py b/qpid/python/qpid/delegates.py index 8dbdc37564..685cf49f54 100644 --- a/qpid/python/qpid/delegates.py +++ b/qpid/python/qpid/delegates.py @@ -159,7 +159,8 @@ class Client(Delegate): def __init__(self, connection, username=None, password=None, mechanism=None, heartbeat=None, **kwargs): Delegate.__init__(self, connection) - + self.client_properties=Client.PROPERTIES.copy() + self.client_properties.update(kwargs.get("client_properties",{})) ## ## self.acceptableMechanisms is the list of SASL mechanisms that the client is willing to ## use. If it's None, then any mechanism is acceptable. @@ -215,7 +216,8 @@ class Client(Delegate): mech = "ANONYMOUS" if not mech in mech_list: raise Closed("No acceptable SASL authentication mechanism available") - ch.connection_start_ok(client_properties=Client.PROPERTIES, mechanism=mech, response=initial) + ch.connection_start_ok(client_properties=self.client_properties, + mechanism=mech, response=initial) def connection_secure(self, ch, secure): resp = None diff --git a/qpid/python/qpid/messaging/driver.py b/qpid/python/qpid/messaging/driver.py index 23efeaaa4f..608791927f 100644 --- a/qpid/python/qpid/messaging/driver.py +++ b/qpid/python/qpid/messaging/driver.py @@ -706,7 +706,10 @@ class Engine: mech, initial = self._sasl.start(" ".join(mechs)) except sasl.SASLError, e: raise AuthenticationFailure(text=str(e)) - self.write_op(ConnectionStartOk(client_properties=CLIENT_PROPERTIES, + + client_properties = CLIENT_PROPERTIES.copy() + client_properties.update(self.connection.client_properties) + self.write_op(ConnectionStartOk(client_properties=client_properties, mechanism=mech, response=initial)) def do_connection_secure(self, secure): diff --git a/qpid/python/qpid/messaging/endpoints.py b/qpid/python/qpid/messaging/endpoints.py index 338ac70ecf..5e473557ac 100644 --- a/qpid/python/qpid/messaging/endpoints.py +++ b/qpid/python/qpid/messaging/endpoints.py @@ -160,6 +160,7 @@ class Connection(Endpoint): self.address_ttl = options.get("address_ttl", 60) self.tcp_nodelay = options.get("tcp_nodelay", False) + self.client_properties = options.get("client_properties", {}) self.options = options -- cgit v1.2.1