nixos/test-driver: drop logging from Machine.send_monitor_command
Several machine operations, like `send_chars` and `send_key`, are implemented by calling `send_monitor_command`, possibly multiple times. This generates a huge amount of unnecessary noise in the log, because `send_monitor_command` is a low-level operation and an implementation detail. Here's an excerpt from a highlighted log before and afte the change. Before: [1m[32msubtest: Can generate a PGP key[0m[0m machine: [1m[32msending keys 'gpg --gen-key\n'[0m[0m machine: [1m[32msending monitor command: sendkey g[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey g, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey p[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey p, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey g[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey g, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey spc[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey spc, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey 0x0C[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey 0x0C, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey 0x0C[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey 0x0C, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey g[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey g, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey e[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey e, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey n[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey n, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey 0x0C[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey 0x0C, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey k[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey k, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey e[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey e, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey y[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey y, in 0.00 seconds) machine: [1m[32msending monitor command: sendkey ret[0m[0m machine: [1m[32mwaiting for monitor prompt[0m[0m (finished: waiting for monitor prompt, in 0.00 seconds) (finished: sending monitor command: sendkey ret, in 0.00 seconds) (finished: sending keys 'gpg --gen-key\n', in 0.15 seconds) After: [1m[32msubtest: Can generate a PGP key[0m[0m machine: [1m[32msending keys 'gpg --gen-key\n'[0m[0m (finished: sending keys 'gpg --gen-key\n', in 0.15 seconds)
This commit is contained in:
parent
f5a9697c77
commit
f2929eb949
1 changed files with 25 additions and 23 deletions
|
@ -1,4 +1,4 @@
|
|||
from contextlib import _GeneratorContextManager
|
||||
from contextlib import _GeneratorContextManager, nullcontext
|
||||
from pathlib import Path
|
||||
from queue import Queue
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
|
||||
|
@ -406,7 +406,6 @@ class Machine:
|
|||
return rootlog.nested(msg, my_attrs)
|
||||
|
||||
def wait_for_monitor_prompt(self) -> str:
|
||||
with self.nested("waiting for monitor prompt"):
|
||||
assert self.monitor is not None
|
||||
answer = ""
|
||||
while True:
|
||||
|
@ -420,7 +419,6 @@ class Machine:
|
|||
|
||||
def send_monitor_command(self, command: str) -> str:
|
||||
self.run_callbacks()
|
||||
with self.nested(f"sending monitor command: {command}"):
|
||||
message = f"{command}\n".encode()
|
||||
assert self.monitor is not None
|
||||
self.monitor.send(message)
|
||||
|
@ -685,9 +683,9 @@ class Machine:
|
|||
retry(tty_matches)
|
||||
|
||||
def send_chars(self, chars: str, delay: Optional[float] = 0.01) -> None:
|
||||
with self.nested(f"sending keys '{chars}'"):
|
||||
with self.nested(f"sending keys {repr(chars)}"):
|
||||
for char in chars:
|
||||
self.send_key(char, delay)
|
||||
self.send_key(char, delay, log=False)
|
||||
|
||||
def wait_for_file(self, filename: str) -> None:
|
||||
"""Waits until the file exists in machine's file system."""
|
||||
|
@ -860,8 +858,12 @@ class Machine:
|
|||
if matches is not None:
|
||||
return
|
||||
|
||||
def send_key(self, key: str, delay: Optional[float] = 0.01) -> None:
|
||||
def send_key(
|
||||
self, key: str, delay: Optional[float] = 0.01, log: Optional[bool] = True
|
||||
) -> None:
|
||||
key = CHAR_TO_KEY.get(key, key)
|
||||
context = self.nested(f"sending key {repr(key)}") if log else nullcontext()
|
||||
with context:
|
||||
self.send_monitor_command(f"sendkey {key}")
|
||||
if delay is not None:
|
||||
time.sleep(delay)
|
||||
|
|
Loading…
Reference in a new issue