Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit ecf0ad9

Browse files
committed
flashers: extract fls download
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
1 parent cec968e commit ecf0ad9

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,34 @@ def _sq(s: str) -> str:
468468

469469
return " ".join(parts)
470470

471+
def _download_fls_binary(self, console, prompt: str, download_url: str, error_message_prefix: str):
472+
"""Download FLS binary to the target device.
473+
474+
Args:
475+
console: Console object for device interaction
476+
prompt: Login prompt for console interaction
477+
download_url: URL to download the FLS binary from
478+
error_message_prefix: Prefix for error message if download fails
479+
480+
Raises:
481+
FlashRetryableError: If download fails or binary cannot be made executable
482+
"""
483+
console.sendline(f"curl -L {download_url} -o /sbin/fls")
484+
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
485+
console.sendline("echo $?")
486+
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
487+
488+
try:
489+
lines = console.before.decode(errors="ignore").strip().splitlines()
490+
exit_code = int(lines[-1]) if lines else -1
491+
except (IndexError, ValueError) as e:
492+
raise FlashRetryableError(f"{error_message_prefix}, failed to parse exit code") from e
493+
494+
if exit_code != 0:
495+
raise FlashRetryableError(f"{error_message_prefix}, exit code: {exit_code}")
496+
console.sendline("chmod +x /sbin/fls")
497+
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
498+
471499
def _flash_with_fls(
472500
self,
473501
console,
@@ -502,32 +530,12 @@ def _flash_with_fls(
502530

503531
if fls_binary_url:
504532
self.logger.info(f"Downloading FLS binary from custom URL: {fls_binary_url}")
505-
console.sendline(f"curl -L {fls_binary_url} -o /sbin/fls")
506-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
507-
console.sendline("echo $?")
508-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
509-
510-
exit_code = int(console.before.decode(errors="ignore").strip().splitlines()[-1])
511-
512-
if exit_code != 0:
513-
raise FlashRetryableError(f"Failed to download FLS from {fls_binary_url}, exit code: {exit_code}")
514-
console.sendline("chmod +x /sbin/fls")
515-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
533+
self._download_fls_binary(console, prompt, fls_binary_url, f"Failed to download FLS from {fls_binary_url}")
516534
elif fls_version != "":
517535
self.logger.info(f"Downloading FLS version {fls_version} from GitHub releases")
518536
# Download fls binary to the target device (until it is available on the target device)
519537
fls_url = f"https://github.com/jumpstarter-dev/fls/releases/download/{fls_version}/fls-aarch64-linux"
520-
console.sendline(f"curl -L {fls_url} -o /sbin/fls")
521-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
522-
console.sendline("echo $?")
523-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
524-
525-
exit_code = int(console.before.decode(errors="ignore").strip().splitlines()[-1])
526-
527-
if exit_code != 0:
528-
raise FlashRetryableError(f"Failed to download FLS from {fls_url}, exit code: {exit_code}")
529-
console.sendline("chmod +x /sbin/fls")
530-
console.expect(prompt, timeout=EXPECT_TIMEOUT_DEFAULT)
538+
self._download_fls_binary(console, prompt, fls_url, f"Failed to download FLS from {fls_url}")
531539

532540
# Flash the image
533541
flash_cmd = f'fls from-url -i 1.0 -n {tls_args} {header_args} --o-direct "{image_url}" {target_path}'

0 commit comments

Comments
 (0)