Skip to content

Commit bd02302

Browse files
committed
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 <[email protected]>
1 parent 97e596f commit bd02302

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

testhelper/smbclient.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from smbprotocol.exceptions import SMBException # type: ignore
22
import smbclient # type: ignore
3+
from smbprotocol.connection import Connection # type: ignore
34
import typing
5+
import uuid
46

57
rw_chunk_size = 1 << 21 # 2MB
68

@@ -19,10 +21,11 @@ def __init__(
1921
self.server = hostname
2022
self.share = share
2123
self.port = port
24+
self.connection_cache: dict = {}
2225
self.client_params = {
2326
"username": username,
2427
"password": passwd,
25-
"connection_cache": {},
28+
"connection_cache": self.connection_cache,
2629
}
2730
self.prepath = f"\\\\{self.server}\\{self.share}\\"
2831
self.connected = False
@@ -36,6 +39,12 @@ def connect(self) -> None:
3639
if self.connected:
3740
return
3841
try:
42+
# Manually setup connection to avoid re-using guid through
43+
# the global configuration
44+
connection_key = f"{self.server.lower()}:{self.port}"
45+
connection = Connection(uuid.uuid4(), self.server, self.port)
46+
connection.connect()
47+
self.connection_cache[connection_key] = connection
3948
smbclient.register_session(
4049
self.server, port=self.port, **self.client_params
4150
)
@@ -46,7 +55,7 @@ def connect(self) -> None:
4655
def disconnect(self) -> None:
4756
self.connected = False
4857
smbclient.reset_connection_cache(
49-
connection_cache=self.client_params["connection_cache"]
58+
connection_cache=self.connection_cache
5059
)
5160

5261
def _check_connected(self, action: str) -> None:

0 commit comments

Comments
 (0)