Skip to content

Commit

Permalink
squash: post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Feb 12, 2025
1 parent 0279b55 commit 053ff39
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 88 deletions.
11 changes: 4 additions & 7 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,21 +549,18 @@ def handle_reboot(self) -> bool:
self.guest.push(self.test_data_path)

try:
rebooted = self.guest.reboot(
hard=False,
command=reboot_command,
timeout=timeout)
rebooted = self.guest.reboot(hard=False, command=reboot_command, timeout=timeout)

except tmt.utils.RunError:
if reboot_command is not None:
self.logger.fail(
f"Failed to reboot guest using the custom command '{reboot_command}'.")
f"Failed to reboot guest using the custom command '{reboot_command}'."
)

raise

except tmt.steps.provision.RebootModeNotSupportedError:
self.logger.warning(
"Guest does not support soft reboot, trying hard reboot.")
self.logger.warning("Guest does not support soft reboot, trying hard reboot.")

rebooted = self.guest.reboot(hard=True, timeout=timeout)

Expand Down
98 changes: 53 additions & 45 deletions tmt/steps/provision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,16 @@ def format_guest_full_name(name: str, role: Optional[str]) -> str:


class RebootModeNotSupportedError(ProvisionError):
""" A requested reboot mode is not supported by the guest """
"""A requested reboot mode is not supported by the guest"""

def __init__(
self,
message: Optional[str] = None,
guest: Optional['Guest'] = None,
hard: bool = False,
*args: Any,
**kwargs: Any) -> None:

self,
message: Optional[str] = None,
guest: Optional['Guest'] = None,
hard: bool = False,
*args: Any,
**kwargs: Any,
) -> None:
if message is not None:
pass

Expand Down Expand Up @@ -1565,31 +1565,34 @@ def stop(self) -> None:

@overload
def reboot(
self,
hard: Literal[True] = True,
command: None = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: Literal[True] = True,
command: None = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
pass

@overload
def reboot(
self,
hard: Literal[False] = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: Literal[False] = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
pass

def reboot(
self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
"""
Reboot the guest, and wait for the guest to recover.
Expand Down Expand Up @@ -2394,12 +2397,14 @@ def stop(self) -> None:
# Remove the ssh socket
self._unlink_ssh_master_socket_path()

def perform_reboot(self,
action: Callable[[], Any],
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
fetch_boot_time: bool = True) -> bool:
def perform_reboot(
self,
action: Callable[[], Any],
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
fetch_boot_time: bool = True,
) -> bool:
"""
Perform the actual reboot and wait for the guest to recover.
Expand Down Expand Up @@ -2488,22 +2493,24 @@ def check_boot_time() -> None:

@overload
def reboot(
self,
hard: Literal[True] = True,
command: None = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: Literal[True] = True,
command: None = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
pass

@overload
def reboot(
self,
hard: Literal[False] = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: Literal[False] = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
pass

def reboot(
Expand Down Expand Up @@ -2550,7 +2557,8 @@ def reboot(
lambda: self.execute(actual_command),
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
tick_increase=tick_increase,
)

def remove(self) -> None:
"""
Expand Down
21 changes: 9 additions & 12 deletions tmt/steps/provision/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,35 @@ def reboot(
# ignore[union-attr]: mypy still considers `self.hard_reboot` as possibly
# being `None`, missing the explicit check above.
return self.perform_reboot(
lambda: self._run_guest_command(
self.hard_reboot.to_shell_command()), # type: ignore[union-attr]
lambda: self._run_guest_command(self.hard_reboot.to_shell_command()), # type: ignore[union-attr]
timeout=timeout,
tick=tick,
tick_increase=tick_increase,
fetch_boot_time=False)
fetch_boot_time=False,
)

if command is not None:
return super().reboot(
hard=False,
command=command,
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
tick_increase=tick_increase,
)

if self.soft_reboot is not None:
self.debug(f"Soft reboot using the soft reboot command '{self.soft_reboot}'.")

# ignore[union-attr]: mypy still considers `self.soft_reboot` as possibly
# being `None`, missing the explicit check above.
return self.perform_reboot(
lambda: self._run_guest_command(
self.soft_reboot.to_shell_command()), # type: ignore[union-attr]
lambda: self._run_guest_command(self.soft_reboot.to_shell_command()), # type: ignore[union-attr]
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
tick_increase=tick_increase,
)

return super().reboot(
hard=False,
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
return super().reboot(hard=False, timeout=timeout, tick=tick, tick_increase=tick_increase)

def start(self) -> None:
"""
Expand Down
13 changes: 7 additions & 6 deletions tmt/steps/provision/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ def stop(self) -> None:
self.debug(f"Doing nothing to stop guest '{self.primary_address}'.")

def reboot(
self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
# No localhost reboot allowed!
self.debug(f"Doing nothing to reboot guest '{self.primary_address}'.")

Expand Down
3 changes: 2 additions & 1 deletion tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,8 @@ def reboot(
timeout=timeout,
tick=tick,
tick_increase=tick_increase,
fetch_boot_time=False)
fetch_boot_time=False,
)

return super().reboot(
hard=False,
Expand Down
25 changes: 14 additions & 11 deletions tmt/steps/provision/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ def start(self) -> None:
)
)

def reboot(self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE) -> bool:
def reboot(
self,
hard: bool = False,
command: Optional[Union[Command, ShellScript]] = None,
timeout: Optional[int] = None,
tick: float = tmt.utils.DEFAULT_WAIT_TICK,
tick_increase: float = tmt.utils.DEFAULT_WAIT_TICK_INCREASE,
) -> bool:
"""
Reboot the guest, and wait for the guest to recover.
Expand Down Expand Up @@ -285,17 +287,18 @@ def reboot(self,
self.podman(Command('container', 'restart', self.container))

return self.reconnect(
timeout=timeout or CONNECTION_TIMEOUT,
tick=tick,
tick_increase=tick_increase)
timeout=timeout or CONNECTION_TIMEOUT, tick=tick, tick_increase=tick_increase
)

if command:
raise tmt.utils.ProvisionError(
"Custom reboot command not supported in podman provision.")
"Custom reboot command not supported in podman provision."
)

raise tmt.steps.provision.RebootModeNotSupportedError(
f"Guest '{self.multihost_name}' does not support soft reboot."
" Containers can only be stopped and started again (hard reboot).")
" Containers can only be stopped and started again (hard reboot)."
)

def _run_ansible(
self,
Expand Down
12 changes: 6 additions & 6 deletions tmt/steps/provision/testcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,13 @@ def reboot(
timeout=timeout,
tick=tick,
tick_increase=tick_increase,
fetch_boot_time=False)
fetch_boot_time=False,
)

if command:
return super().reboot(
command=command,
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
command=command, timeout=timeout, tick=tick, tick_increase=tick_increase
)

if self._instance is None:
raise tmt.utils.ProvisionError("No instance initialized.")
Expand All @@ -1188,7 +1187,8 @@ def reboot(
lambda: self._instance.reboot(soft=True), # type: ignore[union-attr]
timeout=timeout,
tick=tick,
tick_increase=tick_increase)
tick_increase=tick_increase,
)


@tmt.steps.provides_method('virtual.testcloud')
Expand Down

0 comments on commit 053ff39

Please sign in to comment.