diff --git a/testhelper/smbclient.py b/testhelper/smbclient.py index a503241..a4d560d 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_params["connection_cache"] + connection_cache=self.connection_cache ) def _check_connected(self, action: str) -> None: