From 7e52991e0f97f3567cf1ffe0befd8b251d3f6db7 Mon Sep 17 00:00:00 2001 From: Sachin Prabhu Date: Wed, 26 Jun 2024 16:00:09 +0100 Subject: [PATCH] testhelper/smbclient: set different client guids The smbclient high level calls make use of a global configuration which ends up reusing the client guid. This doesn't work for us in our multi client testing. Make use of some low level calls at the point of setting up the connection so that we use different client guids for each connection. This particular workaround requires setting the connection cache bypassing the methods available in the smbclient module. Setting this as a separate commit to highlight the part which may break if the underlying implementation is changed in the future. Signed-off-by: Sachin Prabhu --- testhelper/smbclient.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testhelper/smbclient.py b/testhelper/smbclient.py index fb8f7fb..ad45f8e 100644 --- a/testhelper/smbclient.py +++ b/testhelper/smbclient.py @@ -1,6 +1,8 @@ from smbprotocol.exceptions import SMBException # type: ignore import smbclient # type: ignore +from smbprotocol.connection import Connection # type: ignore import typing +import uuid class SMBClient: @@ -17,10 +19,11 @@ def __init__( self.server = hostname self.share = share self.port = port + self.connection_cache: dict = {} self.client_params = { "username": username, "password": passwd, - "connection_cache": {}, + "connection_cache": self.connection_cache, } self.prepath = f"\\\\{self.server}\\{self.share}\\" self.connected = False @@ -34,6 +37,12 @@ def connect(self) -> None: if self.connected: return try: + # Manually setup connection to avoid re-using guid through + # the global configuration + connection_key = f"{self.server.lower()}:{self.port}" + connection = Connection(uuid.uuid4(), self.server, self.port) + connection.connect() + self.connection_cache[connection_key] = connection smbclient.register_session( self.server, port=self.port, **self.client_params ) @@ -44,7 +53,7 @@ def connect(self) -> None: def disconnect(self) -> None: self.connected = False smbclient.reset_connection_cache( - connection_cache=self.client["connection_cache"] + connection_cache=self.connection_cache ) def _check_connected(self, action: str) -> None: