Skip to content

Commit

Permalink
pro
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-usielski committed Oct 29, 2024
1 parent c1110a5 commit 896326e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 68 deletions.
2 changes: 0 additions & 2 deletions moler/device/adbremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ def _prepare_state_hops_without_proxy_pc(self):
AdbRemote.adb_shell_root: AdbRemote.unix_local,
},
AdbRemote.unix_remote: {
TextualDevice.not_connected: AdbRemote.unix_local,
AdbRemote.unix_local_root: AdbRemote.unix_local,
AdbRemote.adb_shell_root: AdbRemote.adb_shell,
},
Expand Down Expand Up @@ -461,7 +460,6 @@ def _prepare_state_hops_with_proxy_pc(self):
},
AdbRemote.unix_remote: {
AdbRemote.unix_local: AdbRemote.proxy_pc,
TextualDevice.not_connected: AdbRemote.proxy_pc,
AdbRemote.unix_local_root: AdbRemote.proxy_pc,
AdbRemote.adb_shell_root: AdbRemote.adb_shell,
},
Expand Down
2 changes: 2 additions & 0 deletions moler/device/proxy_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self, sm_params, name=None, io_connection=None, io_type=None, varia
io_constructor_kwargs=io_constructor_kwargs,
sm_params=sm_params, initial_state=initial_state,
lazy_cmds_events=lazy_cmds_events)
from pprint import pformat
print(f"ProxyPc {self.name} sm config: {pformat(self._configurations)}")

def _get_default_sm_configuration(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions moler/device/proxy_pc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, sm_params, name=None, io_connection=None, io_type=None, varia
sm_params=sm_params, initial_state=initial_state,
lazy_cmds_events=lazy_cmds_events)
self._log(level=logging.WARNING, msg="Experimental device. May be deleted at any moment. Please don't use it in your scripts.")
from pprint import pformat
print(f"ProxyPc3 {self.name} sm config: {pformat(self._configurations)}")

def _prepare_sm_data(self, sm_params):
self._prepare_dicts_for_sm(sm_params=sm_params)
Expand Down
124 changes: 62 additions & 62 deletions moler/device/unixremote3.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,68 +113,68 @@ def __init__(
)
self._log(level=logging.WARNING, msg="Experimental device. May be deleted at any moment. Please don't use it in your scripts.")

def _prepare_sm_data(self, sm_params):
self._prepare_dicts_for_sm(sm_params=sm_params)

self._prepare_newline_chars()
self._send_transitions_to_sm(self._stored_transitions)

def _prepare_transitions(self):
"""
Prepare transitions to change states.
:return: None.
"""

stored_is_proxy_pc = self._use_proxy_pc
self._use_proxy_pc = True
super(UnixRemote3, self)._prepare_transitions()
self._use_proxy_pc = stored_is_proxy_pc
transitions = self._prepare_transitions_with_proxy_pc()
self._add_transitions(transitions=transitions)

def _prepare_dicts_for_sm(self, sm_params):
"""
Prepare transitions to change states.
:return: None.
"""

self._prepare_transitions()
transitions = self._stored_transitions
state_hops = self._prepare_state_hops_with_proxy_pc()

default_sm_configurations = self._get_default_sm_configuration()

if not self._use_proxy_pc:
(connection_hops, transitions) = remove_state_from_sm(
source_sm=default_sm_configurations[UnixRemote3.connection_hops],
source_transitions=transitions,
state_to_remove=UnixRemote3.proxy_pc,
)
state_hops = remove_state_hops_from_sm(
source_hops=state_hops, state_to_remove=UnixRemote3.proxy_pc
)
default_sm_configurations[UnixRemote3.connection_hops] = connection_hops

self._stored_transitions = transitions
self._update_dict(self._state_hops, state_hops)

self._configurations = self._prepare_sm_configuration(
default_sm_configurations, sm_params
)
self._overwrite_prompts()
self._validate_device_configuration()
self._prepare_state_prompts()

def _get_default_sm_configuration(self):
"""
Create State Machine default configuration.
:return: default sm configuration.
"""
config = super(UnixRemote3, self)._get_default_sm_configuration()
default_config = self._get_default_sm_configuration_with_proxy_pc()

self._update_dict(config, default_config)
return config
# def _prepare_sm_data(self, sm_params):
# self._prepare_dicts_for_sm(sm_params=sm_params)

# self._prepare_newline_chars()
# self._send_transitions_to_sm(self._stored_transitions)

# def _prepare_transitions(self):
# """
# Prepare transitions to change states.
# :return: None.
# """

# stored_is_proxy_pc = self._use_proxy_pc
# self._use_proxy_pc = True
# super(UnixRemote3, self)._prepare_transitions()
# self._use_proxy_pc = stored_is_proxy_pc
# transitions = self._prepare_transitions_with_proxy_pc()
# self._add_transitions(transitions=transitions)

# def _prepare_dicts_for_sm(self, sm_params):
# """
# Prepare transitions to change states.
# :return: None.
# """

# self._prepare_transitions()
# transitions = self._stored_transitions
# state_hops = self._prepare_state_hops_with_proxy_pc()

# default_sm_configurations = self._get_default_sm_configuration()

# if not self._use_proxy_pc:
# (connection_hops, transitions) = remove_state_from_sm(
# source_sm=default_sm_configurations[UnixRemote3.connection_hops],
# source_transitions=transitions,
# state_to_remove=UnixRemote3.proxy_pc,
# )
# state_hops = remove_state_hops_from_sm(
# source_hops=state_hops, state_to_remove=UnixRemote3.proxy_pc
# )
# default_sm_configurations[UnixRemote3.connection_hops] = connection_hops

# self._stored_transitions = transitions
# self._update_dict(self._state_hops, state_hops)

# self._configurations = self._prepare_sm_configuration(
# default_sm_configurations, sm_params
# )
# self._overwrite_prompts()
# self._validate_device_configuration()
# self._prepare_state_prompts()

# def _get_default_sm_configuration(self):
# """
# Create State Machine default configuration.
# :return: default sm configuration.
# """
# config = super(UnixRemote3, self)._get_default_sm_configuration()
# default_config = self._get_default_sm_configuration_with_proxy_pc()

# self._update_dict(config, default_config)
# return config

def _overwrite_prompts(self):
"""
Expand Down
9 changes: 5 additions & 4 deletions test/device/test_SM_adb_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from moler.device import DeviceFactory


# adb_remotes = ['ADB_REMOTE', 'ADB_REMOTE3']
adb_remotes = ['ADB_REMOTE'] # TODO: add ADB_REMOTE3 when it will be implemented
adb_remotes_proxy_pc = ['ADB_REMOTE_PROXY_PC']
adb_remotes = ['ADB_REMOTE',] # 'ADB_REMOTE3']
adb_remotes_proxy_pc = ['ADB_REMOTE_PROXY_PC',] # 'ADB_REMOTE_PROXY_PC3']

@pytest.mark.parametrize("device_name", adb_remotes)
def test_adb_remote_device(device_name, device_connection, adb_remote_output):
Expand All @@ -27,11 +26,13 @@ def test_adb_remote_device_proxy_pc(device_name, device_connection, adb_remote_o

iterate_over_device_states(device=adb_remote)

# @pytest.mark.parametrize("devices", [adb_remotes])
# @pytest.mark.parametrize("devices", [adb_remotes_proxy_pc])
# def test_unix_sm_identity(devices):
# dev0 = DeviceFactory.get_device(name=devices[0])
# dev1 = DeviceFactory.get_device(name=devices[1])

# print(f"tests: {dev0.name}, {dev1.name}")

# assert dev0._stored_transitions == dev1._stored_transitions
# assert dev0._state_hops == dev1._state_hops
# assert dev0._state_prompts == dev1._state_prompts
Expand Down
28 changes: 28 additions & 0 deletions test/resources/device_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,32 @@ DEVICES:
# ADB_SHELL:
# execute_command: adb_shell # default value; default command is: adb shell
# command_params:
# serial_number: 'f57e6b77' # to create: adb -s f57e6b77 shell

# ADB_REMOTE_PROXY_PC3:
# DEVICE_CLASS: moler.device.adbremote3.AdbRemote3
# INITIAL_STATE: UNIX_LOCAL
# CONNECTION_HOPS:
# UNIX_LOCAL:
# PROXY_PC:
# execute_command: ssh
# command_params:
# expected_prompt: "proxy_pc#"
# host: proxy_pc_host
# login: proxy_pc_login
# password: password
# set_timeout: null
# PROXY_PC:
# UNIX_REMOTE:
# execute_command: ssh # default value
# command_params:
# expected_prompt: 'remote#'
# host: remote_host
# login: remote_login
# password: passwd4remote
# set_timeout: null
# UNIX_REMOTE:
# ADB_SHELL:
# execute_command: adb_shell # default value; default command is: adb shell
# command_params:
# serial_number: 'f57e6b77' # to create: adb -s f57e6b77 shell

0 comments on commit 896326e

Please sign in to comment.