Skip to content

Commit

Permalink
Add finally clause to make sure sd-card mux is reverted back to dut m…
Browse files Browse the repository at this point in the history
…ode in very use
  • Loading branch information
kimpaller committed Jan 16, 2025
1 parent d164a4e commit 481e7d3
Showing 1 changed file with 56 additions and 50 deletions.
106 changes: 56 additions & 50 deletions nebula/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,26 +279,32 @@ def recover_board( # noqa:C901
return

except (ne.LinuxNotReached, TimeoutError):
log.warn("Linux is not accessible")
log.warning("Linux is not accessible")
try:
if self.usbsdmux:
log.info("Will try to recover using usb-sd mux...")
self.power.power_down_board()
if sdcard:
# TODO: Recover using SD card boot files
pass
else:
self.usbsdmux.update_boot_files_from_external(
bootbin_loc=bootbinpath,
kernel_loc=uimagepath,
devicetree_loc=devtreepath,
extlinux_loc=extlinux_path,
scr_loc=scr_path,
preloader_loc=preloader_path,
try:
log.info("Will try to recover using usb-sd mux...")
self.power.power_down_board()
if sdcard:
self.usbsdmux.update_boot_files_from_sdcard_itself()
else:
self.usbsdmux.update_boot_files_from_external(
bootbin_loc=bootbinpath,
kernel_loc=uimagepath,
devicetree_loc=devtreepath,
extlinux_loc=extlinux_path,
scr_loc=scr_path,
preloader_loc=preloader_path,
)
# if devtreepath:
# self.usbsdmux.update_devicetree_for_mux(devtreepath)
except Exception as e:
log.error(
"Updating boot files using usbsdmux failed to complete"
)
# if devtreepath:
# self.usbsdmux.update_devicetree_for_mux(devtreepath)
self.usbsdmux.set_mux_mode("dut")
raise e
finally:
self.usbsdmux.set_mux_mode("dut")

# powercycle board
log.info("Power cycling to boot")
Expand Down Expand Up @@ -357,7 +363,7 @@ def recover_board( # noqa:C901
except Exception as e:

if self.jtag:
log.warn("Recovery failed. Will try JTAG")
log.warning("Recovery failed. Will try JTAG")
self.board_reboot_jtag_uart(
system_top_bit_path,
uimagepath,
Expand Down Expand Up @@ -567,37 +573,37 @@ def board_reboot_sdmux_pdu(
):
"""Manager when sdcardmux, pdu is available"""

# Flush UART
self.monitor[0]._read_until_stop() # Flush
self.monitor[0].start_log(logappend=True)
# Check if Linux is accessible
log.info("Checking if Linux is accessible")
try:
# Flush UART
self.monitor[0]._read_until_stop() # Flush
self.monitor[0].start_log(logappend=True)
# Check if Linux is accessible
log.info("Checking if Linux is accessible")
try:
out = self.monitor[0].get_uart_command_for_linux("uname -a", "Linux")
if not out:
raise ne.LinuxNotReached
except Exception as e:
# raise LinuxNotReached for other exceptions
log.info(str(e))
out = self.monitor[0].get_uart_command_for_linux("uname -a", "Linux")
if not out:
raise ne.LinuxNotReached

# Get IP over UART
except Exception as e:
# raise LinuxNotReached for other exceptions
log.info(str(e))
raise ne.LinuxNotReached

# Get IP over UART
ip = self.monitor[0].get_ip_address()
if not ip:
self.monitor[0].request_ip_dhcp()
ip = self.monitor[0].get_ip_address()
if not ip:
self.monitor[0].request_ip_dhcp()
ip = self.monitor[0].get_ip_address()
if not ip:
raise ne.NetworkNotFunctional
if ip != self.net.dutip:
log.info("DUT IP changed to: " + str(ip))
self.net.dutip = ip
self.driver.uri = "ip:" + ip
# Update config file
self.help.update_yaml(
self.configfilename, "network-config", "dutip", ip, self.board_name
)
if not ip:
raise ne.NetworkNotFunctional
if ip != self.net.dutip:
log.info("DUT IP changed to: " + str(ip))
self.net.dutip = ip
self.driver.uri = "ip:" + ip
# Update config file
self.help.update_yaml(
self.configfilename, "network-config", "dutip", ip, self.board_name
)

try:
log.info("Update board over usb-sd-mux")
if sdcard:
self.usbsdmux.update_boot_files_from_sdcard_itself()
Expand All @@ -614,14 +620,14 @@ def board_reboot_sdmux_pdu(
)
# if devtreepath:
# self.usbsdmux.update_devicetree_for_mux(devtreepath)
self.usbsdmux.set_mux_mode("dut")
# powercycle board
log.info("Power cycling to boot")
self.power_cycle_to_boot()

except Exception as e:
log.error("Updating boot files using usbsdmux failed to complete")
raise e
finally:
self.usbsdmux.set_mux_mode("dut")
# powercycle board
log.info("Power cycling to boot")
self.power_cycle_to_boot()

# Check is networking is working
self.network_check()
Expand Down

0 comments on commit 481e7d3

Please sign in to comment.