|
3 | 3 |
|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | | -import time |
7 | 6 | from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath |
8 | 7 | from random import randint |
9 | 8 | from typing import ( |
@@ -693,18 +692,14 @@ def _initialize(self, *args: Any, **kwargs: Any) -> None: |
693 | 692 | assert self._connection_info, "call setConnectionInfo before use remote node" |
694 | 693 | try: |
695 | 694 | super()._initialize(*args, **kwargs) |
696 | | - except TcpConnectionException as e: |
| 695 | + except TcpConnectionException: |
697 | 696 | try: |
698 | | - vm_logs = self._collect_logs_using_non_ssh_executor() |
699 | | - if vm_logs: |
700 | | - self.log.info( |
701 | | - f"Collected information using non-ssh executor:\n{vm_logs}" |
702 | | - ) |
| 697 | + self._collect_logs_using_non_ssh_executor() |
703 | 698 | except Exception as log_error: |
704 | 699 | self.log.debug( |
705 | 700 | f"Failed to collect logs using non-ssh executor: {log_error}" |
706 | 701 | ) |
707 | | - raise e |
| 702 | + raise |
708 | 703 |
|
709 | 704 | def get_working_path(self) -> PurePath: |
710 | 705 | return self._get_remote_working_path() |
@@ -748,17 +743,27 @@ def check_sudo_password_required(self) -> None: |
748 | 743 | raise RequireUserPasswordException("Reset password failed") |
749 | 744 | self._check_password_and_store_prompt() |
750 | 745 |
|
751 | | - def _collect_logs_using_non_ssh_executor(self) -> Optional[str]: |
| 746 | + def _collect_logs_using_non_ssh_executor(self) -> None: |
752 | 747 | """ |
753 | 748 | Collects information using the NonSshExecutor feature. |
754 | 749 | This is used when the connection to the node is not stable. |
755 | 750 | """ |
756 | 751 | from lisa.features import NonSshExecutor |
757 | 752 |
|
| 753 | + COMMANDS_TO_EXECUTE = [ |
| 754 | + "ip addr show", |
| 755 | + "ip link show", |
| 756 | + "systemctl status NetworkManager --no-pager --plain", |
| 757 | + "systemctl status network --no-pager --plain", |
| 758 | + "systemctl status systemd-networkd --no-pager --plain", |
| 759 | + "ping -c 3 -n 8.8.8.8", |
| 760 | + ] |
| 761 | + |
758 | 762 | if self.features.is_supported(NonSshExecutor): |
759 | 763 | non_ssh_executor = self.features[NonSshExecutor] |
760 | | - out = non_ssh_executor.execute() |
761 | | - return "\n".join(out) |
| 764 | + out = non_ssh_executor.execute(commands=COMMANDS_TO_EXECUTE) |
| 765 | + out = "\n\n".join(out) |
| 766 | + self.log.info(f"Collected information using NonSshExecutor:\n{out}") |
762 | 767 | else: |
763 | 768 | self.log.debug( |
764 | 769 | f"NonSshExecutor is not supported on {self.name}, " |
@@ -821,15 +826,15 @@ def get_password(self, generate: bool = True) -> str: |
821 | 826 | if not self._connection_info.password: |
822 | 827 | if not generate: |
823 | 828 | raise RequireUserPasswordException( |
824 | | - "The password is not set, and generate is False." |
| 829 | + "The password is not set and generation is disabled." |
825 | 830 | ) |
826 | 831 | self.log.debug("password is not set, generating a strong password.") |
827 | 832 | if not self._reset_password(): |
828 | 833 | raise RequireUserPasswordException("Reset password failed") |
829 | 834 | password = self._connection_info.password |
830 | 835 | if not password: |
831 | 836 | raise RequireUserPasswordException( |
832 | | - "The password is not set, and generate is False." |
| 837 | + "The password has neither been set nor generated." |
833 | 838 | ) |
834 | 839 | return password |
835 | 840 |
|
|
0 commit comments