This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/main by this push:
new c4f7ee463 PROTON-2706: [Python] Allow setting the container id
c4f7ee463 is described below
commit c4f7ee4636ccb9574edb7ed13cb004d3589153db
Author: Andrew Stitcher <[email protected]>
AuthorDate: Wed Apr 5 12:50:30 2023 -0400
PROTON-2706: [Python] Allow setting the container id
You can set the container id either on the Container class or using the
connect call.
This closes #388
---
python/proton/_reactor.py | 4 ++--
python/tests/proton_tests/reactor.py | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/python/proton/_reactor.py b/python/proton/_reactor.py
index 6b86968b1..69a28138c 100644
--- a/python/proton/_reactor.py
+++ b/python/proton/_reactor.py
@@ -1202,7 +1202,7 @@ class Container(Reactor):
self.ssl = None
self.global_handler = GlobalOverrides(kwargs.get('global_handler',
self.global_handler))
self.trigger = None
- self.container_id = str(_generate_uuid())
+ self.container_id = kwargs.get('container_id',
str(_generate_uuid()))
self.allow_insecure_mechs = True
self.allowed_mechs = None
self.sasl_enabled = True
@@ -1362,7 +1362,7 @@ class Container(Reactor):
**kwargs
) -> Connection:
conn = self.connection(handler)
- conn.container = self.container_id or str(_generate_uuid())
+ conn.container = kwargs.get('container_id', self.container_id)
conn.offered_capabilities = kwargs.get('offered_capabilities')
conn.desired_capabilities = kwargs.get('desired_capabilities')
conn.properties = kwargs.get('properties')
diff --git a/python/tests/proton_tests/reactor.py
b/python/tests/proton_tests/reactor.py
index 1b885fb7a..fbc376b1e 100644
--- a/python/tests/proton_tests/reactor.py
+++ b/python/tests/proton_tests/reactor.py
@@ -441,6 +441,7 @@ class ContainerTest(Test):
self.port = free_tcp_port()
self.client_addr = None
self.peer_hostname = None
+ self.peer_container_id = None
def on_start(self, event):
self.listener = event.container.listen("%s:%s" % (self.host,
self.port))
@@ -448,6 +449,7 @@ class ContainerTest(Test):
def on_connection_opened(self, event):
self.client_addr = event.connected_address
self.peer_hostname = event.connection.remote_hostname
+ self.peer_container_id = event.connection.remote_container
def on_connection_closing(self, event):
event.connection.close()
@@ -492,6 +494,23 @@ class ContainerTest(Test):
assert server_handler.peer_hostname == "localhost",
server_handler.peer_hostname
assert client_handler.server_addr.rsplit(':', 1)[1] ==
str(server_handler.port)
+ def test_container_id_1(self):
+ server_handler = ContainerTest._ServerHandler("localhost")
+ container = Container(server_handler, container_id='container123')
+ conn = container.connect(url="localhost:%s" % (server_handler.port),
+ handler=ContainerTest._ClientHandler(),)
+ container.run()
+ assert server_handler.peer_container_id == 'container123',
server_handler.peer_container_id
+
+ def test_container_id_2(self):
+ server_handler = ContainerTest._ServerHandler("localhost")
+ container = Container(server_handler, container_id='Not_this_id')
+ conn = container.connect(url="localhost:%s" % (server_handler.port),
+ handler=ContainerTest._ClientHandler(),
+ container_id='container456')
+ container.run()
+ assert server_handler.peer_container_id == 'container456',
server_handler.peer_container_id
+
def test_virtual_host(self):
ensureCanTestExtendedSASL()
server_handler = ContainerTest._ServerHandler("localhost")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]