Skip to content

Commit 4ff4695

Browse files
committed
Review comments
1 parent 84d4f4a commit 4ff4695

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

lisa/features/non_ssh_executor.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from lisa.feature import Feature
24
from lisa.features.serial_console import SerialConsole
35

@@ -9,32 +11,29 @@ class NonSshExecutor(Feature):
911
execution method for scenarios where SSH connectivity is not possible or desired.
1012
"""
1113

12-
COMMANDS_TO_EXECUTE = [
13-
"ip addr show",
14-
"ip link show",
15-
"systemctl status NetworkManager --no-pager --plain",
16-
"systemctl status network --no-pager --plain",
17-
"systemctl status systemd-networkd --no-pager --plain",
18-
"ping -c 3 -n 8.8.8.8",
19-
]
20-
2114
@classmethod
2215
def name(cls) -> str:
2316
return "NonSshExecutor"
2417

2518
def enabled(self) -> bool:
2619
return True
2720

28-
def execute(self, commands: list[str] = COMMANDS_TO_EXECUTE) -> list[str]:
21+
def execute(self, commands: List[str]) -> List[str]:
2922
"""
3023
Executes a list of commands on the node and returns their outputs.
3124
3225
:param commands: A list of shell commands to execute.
3326
:return: A string containing the output of the executed commands.
3427
"""
3528
out = []
29+
3630
serial_console = self._node.features[SerialConsole]
37-
serial_console.login()
31+
if not serial_console.enabled():
32+
raise NotImplementedError(
33+
"NonSshExecutor requires SerialConsole feature to be enabled."
34+
)
35+
36+
serial_console.ensure_login()
3837
# clear the console before executing commands
3938
serial_console.write("\n")
4039
_ = serial_console.read()

lisa/features/serial_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def check_initramfs(
191191
f"{initramfs_logs} {filesystem_exception_logs}"
192192
)
193193

194-
def login(self) -> None:
194+
def ensure_login(self) -> None:
195195
# Clear the serial console and try to get the login prompt
196196
self.read()
197197
self.write("\n")

lisa/node.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from __future__ import annotations
55

6-
import time
76
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
87
from random import randint
98
from typing import (
@@ -693,18 +692,14 @@ def _initialize(self, *args: Any, **kwargs: Any) -> None:
693692
assert self._connection_info, "call setConnectionInfo before use remote node"
694693
try:
695694
super()._initialize(*args, **kwargs)
696-
except TcpConnectionException as e:
695+
except TcpConnectionException:
697696
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()
703698
except Exception as log_error:
704699
self.log.debug(
705700
f"Failed to collect logs using non-ssh executor: {log_error}"
706701
)
707-
raise e
702+
raise
708703

709704
def get_working_path(self) -> PurePath:
710705
return self._get_remote_working_path()
@@ -748,17 +743,27 @@ def check_sudo_password_required(self) -> None:
748743
raise RequireUserPasswordException("Reset password failed")
749744
self._check_password_and_store_prompt()
750745

751-
def _collect_logs_using_non_ssh_executor(self) -> Optional[str]:
746+
def _collect_logs_using_non_ssh_executor(self) -> None:
752747
"""
753748
Collects information using the NonSshExecutor feature.
754749
This is used when the connection to the node is not stable.
755750
"""
756751
from lisa.features import NonSshExecutor
757752

753+
commands = [
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+
758762
if self.features.is_supported(NonSshExecutor):
759763
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)
765+
out = "\n\n".join(out)
766+
self.log.info(f"Collected information using NonSshExecutor:\n{out}")
762767
else:
763768
self.log.debug(
764769
f"NonSshExecutor is not supported on {self.name}, "
@@ -821,15 +826,15 @@ def get_password(self, generate: bool = True) -> str:
821826
if not self._connection_info.password:
822827
if not generate:
823828
raise RequireUserPasswordException(
824-
"The password is not set, and generate is False."
829+
"The password is not set and generation is disabled."
825830
)
826831
self.log.debug("password is not set, generating a strong password.")
827832
if not self._reset_password():
828833
raise RequireUserPasswordException("Reset password failed")
829834
password = self._connection_info.password
830835
if not password:
831836
raise RequireUserPasswordException(
832-
"The password is not set, and generate is False."
837+
"The password has neither been set nor generated."
833838
)
834839
return password
835840

lisa/sut_orchestrator/azure/features.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import string
88
import time
9-
import uuid
109
from dataclasses import dataclass, field
1110
from functools import partial
1211
from pathlib import Path
@@ -28,7 +27,6 @@
2827
HardwareProfile,
2928
NetworkInterfaceReference,
3029
RunCommandInput,
31-
RunCommandInputParameter,
3230
VirtualMachineExtension,
3331
VirtualMachineUpdate,
3432
)
@@ -3735,7 +3733,6 @@ def _prepare_azure_file_share(
37353733

37363734

37373735
class RunCommand(AzureFeatureMixin, Feature):
3738-
37393736
@classmethod
37403737
def create_setting(
37413738
cls, *args: Any, **kwargs: Any
@@ -3777,7 +3774,7 @@ def execute(self, commands: List[str]) -> str:
37773774

37783775
return result["value"][0]["message"]
37793776

3780-
def _add_echo_before_command(self, commands: List[str]):
3777+
def _add_echo_before_command(self, commands: List[str]) -> List[str]:
37813778
"""
37823779
Adds an echo command before each command in the list to ensure
37833780
that the output of each command is captured in the logs.
@@ -3786,9 +3783,7 @@ def _add_echo_before_command(self, commands: List[str]):
37863783

37873784

37883785
class NonSshExecutor(AzureFeatureMixin, features.NonSshExecutor):
3789-
def execute(
3790-
self, commands: list[str] = features.NonSshExecutor.COMMANDS_TO_EXECUTE
3791-
) -> list[str]:
3786+
def execute(self, commands: List[str]) -> List[str]:
37923787
# RunCommand is faster than SerialConsole. Hence attempt to use it first.
37933788
try:
37943789
output = self._node.features[RunCommand].execute(commands)

0 commit comments

Comments
 (0)