1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-26 11:06:44 +03:00

nixos/test-driver: Use consistent naming and types

Specifies the "last try" parameter in all methods called by `retry`.
Doing this clarifies its presence, and makes it easier to use it in the
future if needed.
This commit is contained in:
Victor Engmark 2023-10-27 19:50:03 +13:00
parent 4f4a498296
commit 8f2bc9842e
No known key found for this signature in database

View file

@ -352,7 +352,7 @@ class Machine:
timing out. timing out.
""" """
def check_active(_: Any) -> bool: def check_active(_last_try: bool) -> bool:
state = self.get_unit_property(unit, "ActiveState", user) state = self.get_unit_property(unit, "ActiveState", user)
if state == "failed": if state == "failed":
raise Exception(f'unit "{unit}" reached state "{state}"') raise Exception(f'unit "{unit}" reached state "{state}"')
@ -637,7 +637,7 @@ class Machine:
""" """
output = "" output = ""
def check_success(_: Any) -> bool: def check_success(_last_try: bool) -> bool:
nonlocal output nonlocal output
status, output = self.execute(command, timeout=timeout) status, output = self.execute(command, timeout=timeout)
return status == 0 return status == 0
@ -652,7 +652,7 @@ class Machine:
""" """
output = "" output = ""
def check_failure(_: Any) -> bool: def check_failure(_last_try: bool) -> bool:
nonlocal output nonlocal output
status, output = self.execute(command, timeout=timeout) status, output = self.execute(command, timeout=timeout)
return status != 0 return status != 0
@ -712,9 +712,9 @@ class Machine:
""" """
matcher = re.compile(regexp) matcher = re.compile(regexp)
def tty_matches(last: bool) -> bool: def tty_matches(last_try: bool) -> bool:
text = self.get_tty_text(tty) text = self.get_tty_text(tty)
if last: if last_try:
self.log( self.log(
f"Last chance to match /{regexp}/ on TTY{tty}, " f"Last chance to match /{regexp}/ on TTY{tty}, "
f"which currently contains: {text}" f"which currently contains: {text}"
@ -739,7 +739,7 @@ class Machine:
Waits until the file exists in the machine's file system. Waits until the file exists in the machine's file system.
""" """
def check_file(_: Any) -> bool: def check_file(_last_try: bool) -> bool:
status, _ = self.execute(f"test -e {filename}") status, _ = self.execute(f"test -e {filename}")
return status == 0 return status == 0
@ -754,7 +754,7 @@ class Machine:
(default `localhost`). (default `localhost`).
""" """
def port_is_open(_: Any) -> bool: def port_is_open(_last_try: bool) -> bool:
status, _ = self.execute(f"nc -z {addr} {port}") status, _ = self.execute(f"nc -z {addr} {port}")
return status == 0 return status == 0
@ -774,7 +774,7 @@ class Machine:
"-uU" if is_datagram else "-U", "-uU" if is_datagram else "-U",
] ]
def socket_is_open(_: Any) -> bool: def socket_is_open(_last_try: bool) -> bool:
status, _ = self.execute(f"nc {' '.join(nc_flags)} {addr}") status, _ = self.execute(f"nc {' '.join(nc_flags)} {addr}")
return status == 0 return status == 0
@ -791,7 +791,7 @@ class Machine:
(default `localhost`). (default `localhost`).
""" """
def port_is_closed(_: Any) -> bool: def port_is_closed(_last_try: bool) -> bool:
status, _ = self.execute(f"nc -z {addr} {port}") status, _ = self.execute(f"nc -z {addr} {port}")
return status != 0 return status != 0
@ -984,13 +984,13 @@ class Machine:
::: :::
""" """
def screen_matches(last: bool) -> bool: def screen_matches(last_try: bool) -> bool:
variants = self.get_screen_text_variants() variants = self.get_screen_text_variants()
for text in variants: for text in variants:
if re.search(regex, text) is not None: if re.search(regex, text) is not None:
return True return True
if last: if last_try:
self.log(f"Last OCR attempt failed. Text was: {variants}") self.log(f"Last OCR attempt failed. Text was: {variants}")
return False return False
@ -1008,7 +1008,7 @@ class Machine:
# to match multiline regexes. # to match multiline regexes.
console = io.StringIO() console = io.StringIO()
def console_matches(_: Any) -> bool: def console_matches(_last_try: bool) -> bool:
nonlocal console nonlocal console
try: try:
# This will return as soon as possible and # This will return as soon as possible and
@ -1154,7 +1154,7 @@ class Machine:
Wait until it is possible to connect to the X server. Wait until it is possible to connect to the X server.
""" """
def check_x(_: Any) -> bool: def check_x(_last_try: bool) -> bool:
cmd = ( cmd = (
"journalctl -b SYSLOG_IDENTIFIER=systemd | " "journalctl -b SYSLOG_IDENTIFIER=systemd | "
+ 'grep "Reached target Current graphical"' + 'grep "Reached target Current graphical"'