Skip to content

Commit

Permalink
refactor dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Feb 14, 2025
1 parent 650b68a commit f11d030
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions extremeflash/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def readline_from_serial(ser: serial.Serial) -> str:
return line


def start_ssh(sysupgrade_firmware_path: str, ap_ip: str = "192.168.1.1"):
def start_ssh(sysupgrade_firmware_path: str, ap_ip: str = "192.168.1.1", dryrun: bool=False):
logging.info("SSH waiting for ready signal.")
event_ssh_ready.wait()
if event_abort_ssh.is_set():
Expand All @@ -219,7 +219,7 @@ def start_ssh(sysupgrade_firmware_path: str, ap_ip: str = "192.168.1.1"):

with transport.open_session() as chan:
sysupgrade_command = "sysupgrade -n " + firmware_target_path
if DRYRUN:
if dryrun:
logging.info("dryrun: running sysupgrade with test and rebooting")
sysupgrade_command = sysupgrade_command.replace(
"sysupgrade", "sysupgrade --test"
Expand Down
16 changes: 9 additions & 7 deletions extremeflash/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
# See .helpers file for implementation details


def bootup_set_boot_openwrt(ser: serial.Serial) -> str:
def bootup_set_boot_openwrt(
ser: serial.Serial,
dryrun: bool = False,
) -> str:
# if not event_keep_serial_active.is_set():
# return ""
ser.write(b"printenv\n")
Expand Down Expand Up @@ -131,7 +134,7 @@ def bootup_set_boot_openwrt(ser: serial.Serial) -> str:
write_to_serial(ser, b'setenv bootcmd "run boot_openwrt"\n')
time.sleep(0.5)

if helpers.DRYRUN:
if dryrun:
logging.info("dryrun: Skipping saveenv")
return ""

Expand Down Expand Up @@ -242,6 +245,7 @@ def start_tftp_boot_via_serial(
tftp_ip: ipaddress.IPv4Interface | ipaddress.IPv6Interface,
tftp_file: str,
new_ap_ip: ipaddress.IPv4Interface | ipaddress.IPv6Interface,
dryrun: bool = False,
):
with serial.Serial(port=name, baudrate=115200, timeout=30) as ser:
logging.info(f"Starting to connect to serial port {ser.name}")
Expand All @@ -250,7 +254,7 @@ def start_tftp_boot_via_serial(
bootup_interrupt(ser)
bootup_login(ser)
bootup_login_verification(ser)
model = bootup_set_boot_openwrt(ser)
model = bootup_set_boot_openwrt(ser, dryrun)
boot_via_tftp(ser, tftp_ip, tftp_file, new_ap_ip, model)
boot_wait_for_brlan(ser)
boot_set_ips(ser, new_ap_ip)
Expand All @@ -266,8 +270,6 @@ def main(
ap_ip: Optional[str] = None,
dryrun: bool = False,
):
# TODO: improve DRYRUN
helpers.DRYRUN = dryrun

ap_ip_interface, local_ip_interface = setting_up_ips(local_ip, ap_ip)

Expand All @@ -281,10 +283,10 @@ def main(
try:
serial_thread = Thread(
target=start_tftp_boot_via_serial,
args=[serial_port, local_ip_interface, initramfs_path.name, ap_ip_interface],
args=[serial_port, local_ip_interface, initramfs_path.name, ap_ip_interface, dryrun],
daemon=True,
)
ssh_thread = Thread(target=start_ssh, args=[sysupgrade_path, str(ap_ip_interface.ip)])
ssh_thread = Thread(target=start_ssh, args=[sysupgrade_path, str(ap_ip_interface.ip), dryrun])
logging.debug("Starting serial thread")
serial_thread.start()
logging.debug("Starting ssh thread")
Expand Down

0 comments on commit f11d030

Please sign in to comment.