Skip to content

Commit

Permalink
Remove state from state machine dict - UnixRemote conditionally delet…
Browse files Browse the repository at this point in the history
…es PROXY_PC (#547)

* Remove state from state machine dict

* upload-artifact@v4

* fix

* delte transitions

* tuple annotations

* start dev unixremote3

* dev

* dev

* style

* rd

* tests

* test

* t2

* fix formattig

* warning

* warning

* review#2

* after review
  • Loading branch information
marcin-usielski authored Oct 21, 2024
1 parent 3be2085 commit a40c5f0
Show file tree
Hide file tree
Showing 10 changed files with 1,110 additions and 57 deletions.
18 changes: 13 additions & 5 deletions moler/device/textualdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ def __init__(
self.logger = logging.getLogger(f"moler.connection.{self.name}")
self.configure_logger(name=self.name, propagate=False)

self._prepare_transitions()
self._prepare_state_hops()
self._configure_state_machine(sm_params)
self._prepare_newline_chars()
self._stored_transitions = {}
self._prepare_sm_data(sm_params=sm_params)

# TODO: Need test to ensure above sentence for all connection
self.io_connection.notify(
Expand Down Expand Up @@ -157,6 +155,13 @@ def __init__(
# same line.
self._sleep_after_state_change = 0.5

def _prepare_sm_data(self, sm_params):
self._prepare_transitions()
self._prepare_state_hops()
self._configure_state_machine(sm_params)
self._prepare_newline_chars()
self._send_transitions_to_sm(self._stored_transitions)

def set_all_prompts_on_line(self, value=True):
"""
Set True to check all prompts on line. False to interrupt after 1st prompt (default).
Expand Down Expand Up @@ -993,7 +998,10 @@ def _collect_events_for_state(self, state):

return events

def _add_transitions(self, transitions):
def _add_transitions(self, transitions: dict):
self._update_dict(self._stored_transitions, transitions)

def _send_transitions_to_sm(self, transitions: dict) -> None:
for source_state in transitions.keys():
for dest_state in transitions[source_state].keys():
self._update_SM_states(dest_state)
Expand Down
1 change: 0 additions & 1 deletion moler/device/unixlocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def _execute_command_to_change_state(self, source_state, dest_state, timeout=-1)

command_name = configurations["execute_command"]
command_params = configurations["command_params"]

command_timeout = self.calc_timeout_for_command(timeout, command_params)
command_params_without_timeout = self._parameters_without_timeout(
parameters=command_params
Expand Down
74 changes: 39 additions & 35 deletions moler/device/unixremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

__author__ = 'Grzegorz Latuszek, Marcin Usielski, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2019, Nokia'
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
__email__ = '[email protected], [email protected], [email protected]'

from moler.device.proxy_pc import ProxyPc
Expand All @@ -25,41 +25,41 @@ class UnixRemote(ProxyPc):
Example of device in yaml configuration file:
- with PROXY_PC:
UNIX_1:
DEVICE_CLASS: moler.device.unixremote.UnixRemote
CONNECTION_HOPS:
PROXY_PC:
UNIX_REMOTE:
execute_command: ssh # default value
command_params:
expected_prompt: unix_remote_prompt
host: host_ip
login: login
password: password
UNIX_REMOTE:
PROXY_PC:
execute_command: exit # default value
command_params:
expected_prompt: proxy_pc_prompt
UNIX_LOCAL:
PROXY_PC:
execute_command: ssh # default value
command_params:
expected_prompt: proxy_pc_prompt
host: host_ip
login: login
password: password
DEVICE_CLASS: moler.device.unixremote.UnixRemote
CONNECTION_HOPS:
PROXY_PC:
UNIX_REMOTE:
execute_command: ssh # default value
command_params:
expected_prompt: unix_remote_prompt
host: host_ip
login: login
password: password
UNIX_REMOTE:
PROXY_PC:
execute_command: exit # default value
command_params:
expected_prompt: proxy_pc_prompt
UNIX_LOCAL:
PROXY_PC:
execute_command: ssh # default value
command_params:
expected_prompt: proxy_pc_prompt
host: host_ip
login: login
password: password
-without PROXY_PC:
UNIX_1:
DEVICE_CLASS: moler.device.unixremote.UnixRemote
CONNECTION_HOPS:
UNIX_LOCAL:
UNIX_REMOTE:
execute_command: ssh # default value
command_params:
expected_prompt: unix_remote_prompt
host: host_ip
login: login
password: password
DEVICE_CLASS: moler.device.unixremote.UnixRemote
CONNECTION_HOPS:
UNIX_LOCAL:
UNIX_REMOTE:
execute_command: ssh # default value
command_params:
expected_prompt: unix_remote_prompt
host: host_ip
login: login
password: password
"""
Expand Down Expand Up @@ -417,7 +417,6 @@ def _prepare_state_hops_without_proxy_pc(self):
UnixRemote.not_connected: UnixRemote.unix_remote,
UnixRemote.unix_local: UnixRemote.unix_remote,
UnixRemote.unix_local_root: UnixRemote.unix_remote,
UnixRemote.proxy_pc: UnixRemote.unix_remote,
}
}
return state_hops
Expand All @@ -429,7 +428,12 @@ def _configure_state_machine(self, sm_params):
:return: None.
"""
super(UnixRemote, self)._configure_state_machine(sm_params)
self._overwrite_prompts()

def _overwrite_prompts(self):
"""
Overwrite prompts for some states to easily configure the SM.
"""
if self._use_proxy_pc:
self._configurations[UnixRemote.connection_hops][UnixRemote.unix_remote_root][UnixRemote.unix_remote][
"command_params"]["expected_prompt"] = \
Expand Down
Loading

0 comments on commit a40c5f0

Please sign in to comment.