Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def create_clone(self) -> LocalOperations:
clone = __class__(__class__.sm_dummy_conn_params)
clone.conn_params = copy.copy(self.conn_params)
clone._host = self._host
clone._port = self._port
clone._ssh_key = self._ssh_key
clone._username = self._username
return clone
Expand Down
12 changes: 11 additions & 1 deletion src/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __init__(self, conn_params: ConnectionParams):

super().__init__()

self._remote_env_guard = threading.Lock()

if conn_params is __class__.sm_dummy_conn_params:
return

Expand Down Expand Up @@ -102,7 +104,6 @@ def __init__(self, conn_params: ConnectionParams):
self._ssh_cmd += [self._host]

self._remote_env = dict()
self._remote_env_guard = threading.Lock()
return

@property
Expand Down Expand Up @@ -134,14 +135,23 @@ def get_platform(self) -> str:

def create_clone(self) -> RemoteOperations:
assert type(self._ssh_cmd) is list
assert type(self._remote_env) is dict
assert self._remote_env_guard is not None

clone = __class__(__class__.sm_dummy_conn_params)
assert clone._remote_env_guard is not None

clone.conn_params = copy.copy(self.conn_params)
clone._host = self._host
clone._port = self._port
clone._ssh_key = self._ssh_key
clone._ssh_cmd = copy.copy(self._ssh_cmd)
clone._username = self._username

with self._remote_env_guard:
clone._remote_env = self._remote_env.copy()
assert type(clone._remote_env) is dict

return clone

def exec_command(
Expand Down
76 changes: 73 additions & 3 deletions tests/test_os_ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ def name_with_surprize(self, request: pytest.FixtureRequest) -> tagNameWithSurpr
assert type(request.param).__name__ == "tagNameWithSurprize"
return request.param

sm_false_true: typing.List[bool] = [False, True]

@pytest.fixture(
params=[
pytest.param(
x,
id="test_clone" if x else "test_orig",
)
for x in sm_false_true
]
)
def use_clone(self, request: pytest.FixtureRequest) -> bool:
assert isinstance(request, pytest.FixtureRequest)
assert type(request.param) is bool
return request.param

def test_prop__remote(self, os_ops_descr: OsOpsDescr):
assert type(os_ops_descr) is OsOpsDescr
assert isinstance(os_ops_descr.os_ops, OsOperations)
Expand Down Expand Up @@ -191,17 +207,34 @@ def test_get_platform__is_known(self, os_ops_descr: OsOpsDescr):
assert p in {"win32", "linux"}
return

def test_create_clone(self, os_ops_descr: OsOpsDescr):
def test_create_clone(
self,
os_ops_descr: OsOpsDescr,
use_clone: bool,
):
assert type(os_ops_descr) is OsOpsDescr
assert isinstance(os_ops_descr.os_ops, OsOperations)
assert type(use_clone) is bool

os_ops = os_ops_descr.os_ops
os_ops = __class__.helper__get_os_ops(use_clone, os_ops_descr)
assert isinstance(os_ops, OsOperations)

clone = os_ops.create_clone()
assert clone is not None
assert clone is not os_ops
assert type(clone) is type(os_ops)

assert clone.remote == os_ops.remote
assert clone.username == os_ops.username
assert clone.ssh_key == os_ops.ssh_key
assert clone.host == os_ops.host
assert clone.port == os_ops.port

assert clone.get_name() == os_ops.get_name()
assert clone.get_platform() == os_ops.get_platform()

assert clone.environ("PATH") == os_ops.environ("PATH")
assert clone.environ("DUMMY-4231") == os_ops.environ("DUMMY-4231")

return

def test_exec_command_success(self, os_ops_descr: OsOpsDescr):
Expand Down Expand Up @@ -3621,6 +3654,43 @@ def test_set_env__evil(
os_ops.set_env(evil_var, None)
return

@staticmethod
def helper__get_os_ops(
use_clone: bool,
os_ops_descr: OsOpsDescr,
) -> OsOperations:
assert type(os_ops_descr) is OsOpsDescr
assert isinstance(os_ops_descr.os_ops, OsOperations)

if (use_clone):
os_ops = __class__.helper__create_clone_and_formal_check_it(
os_ops_descr.os_ops,
)
else:
os_ops = os_ops_descr.os_ops

assert isinstance(os_ops, OsOperations)
return os_ops

@staticmethod
def helper__create_clone_and_formal_check_it(
os_ops: OsOperations,
) -> OsOperations:
assert isinstance(os_ops, OsOperations)

clone = os_ops.create_clone()
assert clone is not None
assert type(clone) is type(os_ops)

# it is safe
assert clone.remote == os_ops.remote
assert clone.username == os_ops.username
assert clone.ssh_key == os_ops.ssh_key
assert clone.host == os_ops.host
assert clone.port == os_ops.port

return clone

@staticmethod
def helper__bug_check__unknown_os_ops_type(
os_ops: OsOperations,
Expand Down