Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .azure-pipelines/recover_testbed/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def get_pdu_managers(sonichosts, conn_graph_facts):
return pdu_managers


def posix_shell_onie(dut_console, mgmt_ip, image_url):
def posix_shell_onie(dut_console, mgmt_ip, image_url, is_nexus=False):
oldtty = termios.tcgetattr(sys.stdin)
enter_onie_flag = 0
enter_onie_flag = True
gw_ip = list(ipaddress.ip_interface(mgmt_ip).network.hosts())[0]
try:
tty.setraw(sys.stdin.fileno())
Expand All @@ -66,20 +66,25 @@ def posix_shell_onie(dut_console, mgmt_ip, image_url):

x = x.decode('ISO-8859-9')

if "GNU GRUB" in x:
enter_onie_flag += 1
if is_nexus and "loader" in x and ">" in x:
dut_console.remote_conn.send('reboot\n')
continue

if "SONiC-OS-" in x and enter_onie_flag == 1:
# if "GNU GRUB" in x:
# enter_onie_flag += 1
# continue

if "-OS-" in x and enter_onie_flag is True:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if "-OS-" in x and enter_onie_flag:

Copy link
Copy Markdown
Contributor Author

@yutongzhang-microsoft yutongzhang-microsoft Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do some tests, and because of the rule of Python, we can use bool(enter_onie_flag) or use enter_onie_flag is True here. Simply enter_onie_flag will not be considered as a boolean.

# Send arrow key "down" here.
dut_console.remote_conn.send(b'\x1b[B')
continue

if "*ONIE" in x and "Install OS" not in x:
dut_console.remote_conn.send("\n")
enter_onie_flag += 1
enter_onie_flag = False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create constant for the strings like "-OS-", "*ONIE", "Install OS" and others, so that it would be clear to speculate the usage from the constant name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if "ONIE: Starting ONIE Service Discovery" in x:
# "ONIE: Starting ONIE Service Discovery"
if "Discovery" in x:
# TODO: Define a function to send command here
for i in range(5):
dut_console.remote_conn.send('onie-discovery-stop\n')
Expand Down
4 changes: 2 additions & 2 deletions .azure-pipelines/recover_testbed/dut_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import sys
import paramiko
import socket
import glob
import re
import yaml
Expand Down Expand Up @@ -137,7 +136,8 @@ def duthost_ssh(sonichost):
return sonic_username, password, sonic_ip
except AuthenticationException:
continue
except socket.timeout as e:
# Errors such like timeout, connection fails
except Exception as e:
logger.info("Cannot access DUT {} via ssh, error: {}".format(sonichost.hostname, e))
return RC_SOCKET_TIMEOUT
return RC_PASSWORD_FAILED
6 changes: 3 additions & 3 deletions .azure-pipelines/recover_testbed/recover_testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def recover_via_console(sonichost, conn_graph_facts, localhost, mgmt_ip, image_u

if type in ["arista"]:
posix_shell_aboot(dut_console, mgmt_ip, image_url)
# elif type in ["Cisco"]:
# return
elif type in ["mellanox", "nexus", "acs"]:
elif type in ["nexus"]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename variable type to something like device_type? The reason is that it conflicts with python's builtin type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

posix_shell_onie(dut_console, mgmt_ip, image_url, is_nexus=True)
elif type in ["mellanox", "cisco", "acs"]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have some Nokia devices. Are they covered?

posix_shell_onie(dut_console, mgmt_ip, image_url)
else:
return
Expand Down