Skip to content

Commit

Permalink
testhelper/smbclient: set different client guids
Browse files Browse the repository at this point in the history
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 <sp@spui.uk>
  • Loading branch information
spuiuk committed Jun 27, 2024
1 parent f430c87 commit e0c9908
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions testhelper/smbclient.py
Original file line number Diff line number Diff line change
@@ -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

rw_chunk_size = 1 << 21 # 2MB

Expand All @@ -19,10 +21,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
Expand All @@ -36,6 +39,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
)
Expand All @@ -46,7 +55,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:
Expand Down

0 comments on commit e0c9908

Please sign in to comment.