Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 23 additions & 6 deletions strategies/tftpstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import threading
import time
from contextlib import contextmanager
from urllib.parse import urlparse

import attr
from labgrid.driver import TFTPProviderDriver
Expand All @@ -16,6 +17,21 @@

logger = logging.getLogger(__name__)


def _split_staged(staged):
"""Return (bootfile, server_ip) for a file staged by TFTPProviderDriver.

Exporter configs following current openwrt-tests set the TFTPProvider
``external`` to a full ``tftp://<host>/<path>/`` URL; older ones use a
plain relative path. U-Boot needs the bare path as ``bootfile``: given the
URL verbatim it asks the server for a file literally named ``tftp://...``.
"""
parsed = urlparse(staged)
if parsed.scheme == "tftp":
return parsed.path.lstrip("/"), parsed.hostname
return staged, None


TFTP_DOWNLOAD_TIMEOUT = 120
TFTP_RETRY_INTERVAL = 5
DEFAULT_UBOOT_RETRIES = 2
Expand Down Expand Up @@ -467,17 +483,20 @@ def _power_cycle_for_uboot(self):
def _transition_to_uboot_once(self):
"""Power-cycle the node and activate the U-Boot console."""
self.target.activate(self.tftp)
staged_file = self.tftp.stage(self.target.env.config.get_image_path("root"))
staged_file, url_server_ip = _split_staged(
self.tftp.stage(self.target.env.config.get_image_path("root"))
)

staged_initrd = None
try:
initrd_path = self.target.env.config.get_image_path("initrd")
staged_initrd = self.tftp.stage(initrd_path)
staged_initrd, _ = _split_staged(self.tftp.stage(initrd_path))
logger.info("Staged initrd image: %s", staged_initrd)
except KeyError:
pass

tftp_server_ip = self._resolve_tftp_server_ip()
# Precedence: TFTP_SERVER_IP env, exporter external_ip, host of the URL.
tftp_server_ip = self._resolve_tftp_server_ip() or url_server_ip

self.target.deactivate(self.console)
self.target.activate(self.power)
Expand Down Expand Up @@ -505,9 +524,7 @@ def transition_to_uboot_with_retry(self):
cooldown = _read_int_env(
"LG_MESH_UBOOT_RETRY_COOLDOWN", DEFAULT_UBOOT_RETRY_COOLDOWN
)
budget = _read_int_env(
"LG_MESH_UBOOT_RETRY_BUDGET", DEFAULT_UBOOT_RETRY_BUDGET
)
budget = _read_int_env("LG_MESH_UBOOT_RETRY_BUDGET", DEFAULT_UBOOT_RETRY_BUDGET)
_retry_action(
self._transition_to_uboot_once,
lambda: self.transition(Status.off),
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ def _launch_boot_subprocess(
stop_file,
]

logger.info(
"Launching boot subprocess for %s (budget %ds)", place, boot_budget
)
logger.info("Launching boot subprocess for %s (budget %ds)", place, boot_budget)
child_env = dict(os.environ)
child_env["LG_MESH_BOOT_BUDGET"] = str(boot_budget)

Expand Down
Loading