Skip to content

Commit 40a630b

Browse files
Set terminal-no-fork as default (#594)
* Tests with default terminal-no-fork * style * dev * dev * Defualt terminal * dev * Warning for old terminnal * Version * Cosmetic changes flake8 * redefinition * log debug * dev * style * tuple for Python3.8 * dev * fix test helpers * f * f * style * style
1 parent e7a80b8 commit 40a630b

21 files changed

Lines changed: 524 additions & 211 deletions

moler/asyncio_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def cleanup_remaining_tasks(loop, logger):
801801
# https://stackoverflow.com/questions/30765606/whats-the-correct-way-to-clean-up-after-an-interrupted-event-loop
802802
# https://medium.com/python-pandemonium/asyncio-coroutine-patterns-beyond-await-a6121486656f
803803
# Handle shutdown gracefully by waiting for all tasks to be cancelled
804-
all_tasks = [task for task in asyncio.Task.all_tasks(loop=loop)]
804+
805805
not_done_tasks = [task for task in asyncio.Task.all_tasks(loop=loop) if not task.done()]
806806
if not_done_tasks:
807807
logger.info("cancelling all remaining tasks")

moler/cmd/unix/ctrl_c.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"""
55

66
__author__ = 'Marcin Usielski'
7-
__copyright__ = 'Copyright (C) 2019-2025, Nokia'
7+
__copyright__ = 'Copyright (C) 2019-2026, Nokia'
88
__email__ = 'marcin.usielski@nokia.com'
99

1010
import re
1111
from moler.cmd.commandchangingprompt import CommandChangingPrompt
12-
from moler.cmd.commandtextualgeneric import CommandTextualGeneric
1312

1413

1514
class CtrlC(CommandChangingPrompt):

moler/cmd/unix/ip_maddr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
__author__ = 'Marcin Usielski'
7-
__copyright__ = 'Copyright (C) 2025, Nokia'
7+
__copyright__ = 'Copyright (C) 2025-2026, Nokia'
88
__email__ = 'marcin.usielski@nokia.com'
99

1010
import re
@@ -33,7 +33,7 @@ def build_command_string(self) -> str:
3333
Build command string from parameters passed to object.
3434
:return: String representation of command to send over connection to device.
3535
"""
36-
cmd = f"ip maddr"
36+
cmd = "ip maddr"
3737
if self.options:
3838
cmd = f"{cmd} {self.options}"
3939
self.ret_required = True if self.options == 'show' else False

moler/cmd/unix/telnet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"""
55

66
__author__ = 'Marcin Usielski'
7-
__copyright__ = 'Copyright (C) 2018-2024, Nokia'
7+
__copyright__ = 'Copyright (C) 2018-2026, Nokia'
88
__email__ = 'marcin.usielski@nokia.com'
99

10-
import re
1110

1211
from moler.cmd.unix.generictelnetssh import GenericTelnetSsh
1312
from moler.exceptions import ParsingDone

moler/config/__init__.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Moler related configuration
44
"""
55
__author__ = "Grzegorz Latuszek, Marcin Usielski, Michal Ernst, Tomasz Krol"
6-
__copyright__ = "Copyright (C) 2018-2022, Nokia"
6+
__copyright__ = "Copyright (C) 2018-2026, Nokia"
77
__email__ = "grzegorz.latuszek@nokia.com, marcin.usielski@nokia.com, michal.ernst@nokia.com, tomasz.krol@nokia.com"
88
import os
99
from contextlib import contextmanager
@@ -267,22 +267,7 @@ def load_logger_from_config(config):
267267
log_cfg.configure_moler_main_logger()
268268

269269

270-
def _config_rotating(config):
271-
if "KIND" in config["LOGGER"]:
272-
print(
273-
"Warning! Please update LOGGER to new style. 'KIND' should now exist in LOG_ROTATION section."
274-
) # Logger is not available here.
275-
log_cfg.set_kind(config["LOGGER"]["KIND"])
276-
if "INTERVAL" in config["LOGGER"]:
277-
print(
278-
"Warning! Please update LOGGER to new style. 'INTERVAL' should now exist in LOG_ROTATION section."
279-
) # Logger is not available here.
280-
log_cfg.set_interval(config["LOGGER"]["INTERVAL"])
281-
if "BACKUP_COUNT" in config["LOGGER"]:
282-
print(
283-
"Warning! Please update LOGGER to new style. 'BACKUP_COUNT' should now exist in LOG_ROTATION section."
284-
) # Logger is not available here.
285-
log_cfg.set_backup_count(config["LOGGER"]["BACKUP_COUNT"])
270+
def _update_config_log_rotation(config: dict) -> None:
286271
if "LOG_ROTATION" in config["LOGGER"]:
287272
log_rotation = config["LOGGER"]["LOG_ROTATION"]
288273
if "KIND" in log_rotation:
@@ -300,6 +285,25 @@ def _config_rotating(config):
300285
log_cfg.set_compressed_file_extension(
301286
log_rotation["COMPRESSED_FILE_EXTENSION"]
302287
)
288+
289+
290+
def _config_rotating(config):
291+
if "KIND" in config["LOGGER"]:
292+
print(
293+
"Warning! Please update LOGGER to new style. 'KIND' should now exist in LOG_ROTATION section."
294+
) # Logger is not available here.
295+
log_cfg.set_kind(config["LOGGER"]["KIND"])
296+
if "INTERVAL" in config["LOGGER"]:
297+
print(
298+
"Warning! Please update LOGGER to new style. 'INTERVAL' should now exist in LOG_ROTATION section."
299+
) # Logger is not available here.
300+
log_cfg.set_interval(config["LOGGER"]["INTERVAL"])
301+
if "BACKUP_COUNT" in config["LOGGER"]:
302+
print(
303+
"Warning! Please update LOGGER to new style. 'BACKUP_COUNT' should now exist in LOG_ROTATION section."
304+
) # Logger is not available here.
305+
log_cfg.set_backup_count(config["LOGGER"]["BACKUP_COUNT"])
306+
_update_config_log_rotation(config)
303307
if "CONSOLE_LOGS" in config["LOGGER"]:
304308
for logger_name in config["LOGGER"]["CONSOLE_LOGS"]:
305309
log_cfg.add_console_log(logger_name)

moler/config/connections.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,35 @@ def terminal_nofork_thd_conn_st(name=None):
229229
return io_conn
230230

231231
# TODO: unify passing logger to io_conn (logger/logger_name)
232-
connection_factory.register_construction(io_type="terminal",
232+
connection_factory.register_construction(io_type="terminal_fork",
233233
variant="threaded",
234234
constructor=terminal_thd_conn_mt)
235235

236236
# TODO: unify passing logger to io_conn (logger/logger_name)
237-
connection_factory.register_construction(io_type="terminal",
237+
connection_factory.register_construction(io_type="terminal_fork",
238238
variant="multi-threaded",
239239
constructor=terminal_thd_conn_mt)
240240

241241
# TODO: unify passing logger to io_conn (logger/logger_name)
242-
connection_factory.register_construction(io_type="terminal",
242+
connection_factory.register_construction(io_type="terminal_fork",
243243
variant="single-threaded",
244244
constructor=terminal_thd_conn_st)
245245

246+
# TODO: unify passing logger to io_conn (logger/logger_name)
247+
connection_factory.register_construction(io_type="terminal",
248+
variant="threaded",
249+
constructor=terminal_nofork_thd_conn_mt)
250+
251+
# TODO: unify passing logger to io_conn (logger/logger_name)
252+
connection_factory.register_construction(io_type="terminal",
253+
variant="multi-threaded",
254+
constructor=terminal_nofork_thd_conn_mt)
255+
256+
# TODO: unify passing logger to io_conn (logger/logger_name)
257+
connection_factory.register_construction(io_type="terminal",
258+
variant="single-threaded",
259+
constructor=terminal_nofork_thd_conn_st)
260+
246261
# TODO: unify passing logger to io_conn (logger/logger_name)
247262
connection_factory.register_construction(io_type="terminal_no_fork",
248263
variant="threaded",

moler/device/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
__copyright__ = 'Copyright (C) 2018, Nokia'
1010
__email__ = 'grzegorz.latuszek@nokia.com'
1111

12+
1213
from moler.device.textualdevice import TextualDevice
1314
from moler.device.device import DeviceFactory
15+
16+
__all__ = ['TextualDevice', 'DeviceFactory']

moler/device/proxy_pc.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
__author__ = 'Marcin Usielski'
9-
__copyright__ = 'Copyright (C) 2024-2025, Nokia'
9+
__copyright__ = 'Copyright (C) 2024-2026, Nokia'
1010
__email__ = 'marcin.usielski@nokia.com'
1111
import six
1212
import abc
@@ -70,19 +70,6 @@ def _prepare_sm_data(self, sm_params):
7070
self._prepare_newline_chars()
7171
self._send_transitions_to_sm(self._stored_transitions)
7272

73-
def _prepare_transitions(self):
74-
"""
75-
Prepare transitions to change states.
76-
:return: None
77-
"""
78-
79-
stored_is_proxy_pc = self._use_proxy_pc
80-
self._use_proxy_pc = True
81-
super(ProxyPc, self)._prepare_transitions()
82-
self._use_proxy_pc = stored_is_proxy_pc
83-
transitions = self._prepare_transitions_with_proxy_pc()
84-
self._add_transitions(transitions=transitions)
85-
8673
def _prepare_dicts_for_sm(self, sm_params):
8774
"""
8875
Prepare transitions to change states.

moler/device/textualdevice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def _stop_prompts_observers(self):
11581158
break
11591159
time.sleep(self._tick_to_check_runner)
11601160
event.remove_event_occurred_callback()
1161-
except Exception as e:
1161+
except Exception:
11621162
pass
11631163

11641164
def build_trigger_to_state(self, state):

moler/event_awaiter.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,30 @@ def start_command_after_event(cls, cmds: Sequence, events: Sequence, event_timeo
126126
except IndexError:
127127
cmd.start()
128128
else:
129-
events_after_command = event
130-
if event is None:
131-
events_after_command = ()
132-
elif isinstance(event, ConnectionObserver):
133-
events_after_command = (event,)
134-
for event in events_after_command:
135-
event.start()
136-
for cmd_item in cmds_items:
137-
cmd_item.start()
138-
for event in events_after_command:
139-
event.await_done(timeout=event_timeout)
140-
if sleep_after_event > 0.:
141-
MolerTest.sleep(sleep_after_event)
129+
cls._execute_after(
130+
event=event,
131+
cmds_items=cmds_items,
132+
event_timeout=event_timeout,
133+
sleep_after_event=sleep_after_event
134+
)
135+
136+
@classmethod
137+
def _execute_after(cls, event, cmds_items, event_timeout, sleep_after_event) -> None:
138+
"""
139+
Execute the given command after the given event is done.
140+
141+
:return: None
142+
"""
143+
events_after_command = event
144+
if event is None:
145+
events_after_command = ()
146+
elif isinstance(event, ConnectionObserver):
147+
events_after_command = (event,)
148+
for event in events_after_command:
149+
event.start()
150+
for cmd_item in cmds_items:
151+
cmd_item.start()
152+
for event in events_after_command:
153+
event.await_done(timeout=event_timeout)
154+
if sleep_after_event > 0.:
155+
MolerTest.sleep(sleep_after_event)

0 commit comments

Comments
 (0)