0

[fuchsia] Ensure ipv4 addresses can be retrieved

The ipv4 addresses are not always available from ffx immediately
after ffx daemon starting, wait for it for a while.

A drive-by change is to remove the gssapidelegatecredentials which
is never supported by the ssh server in fuchsia.

Cq-Include-Trybots: luci.chrome.try:fuchsia-ava-sherlock-npi,fuchsia-ava-nelson-npi,fuchsia-smoke-sherlock
Bug: 391663618
Change-Id: Ie6d5acd26685d365a4407f72f4228335323fd4ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6398335
Reviewed-by: David Song <wintermelons@google.com>
Auto-Submit: Zijie He <zijiehe@google.com>
Commit-Queue: Zijie He <zijiehe@google.com>
Cr-Commit-Position: refs/heads/main@{#1445003}
This commit is contained in:
Zijie He
2025-04-09 16:08:54 -07:00
committed by Chromium LUCI CQ
parent b885adf9f7
commit 998caa5ab9
4 changed files with 41 additions and 29 deletions
build/fuchsia/test
fuchsia_web/av_testing

@ -19,6 +19,7 @@ from typing import Iterable, List, Optional, Tuple
from dataclasses import dataclass
from compatible_utils import get_ssh_prefix, get_host_arch
from repeating_log import RepeatingLog
def _find_src_root() -> str:
@ -387,19 +388,42 @@ def get_ip_address(target_id: Optional[str], ipv4_only: bool = False):
def get_ssh_address(target_id: Optional[str],
ipv4_only: bool = False) -> Tuple[str, int]:
"""Determines SSH address for given target."""
"""Determines SSH address for given target, this function waits for the
device to be reachable up to 5 minutes, or throws an error if it fails."""
cmd = ['target', 'list']
if ipv4_only:
cmd.append('--no-ipv6')
if target_id:
# target list does not respect -t / --target flag.
cmd.append(target_id)
target = json.loads(
run_ffx_command(cmd=cmd, json_out=True,
capture_output=True).stdout.strip())
addr = target[0]['addresses'][0]
if 'Ip' in addr:
addr = addr['Ip']
# A temporary solution to avoid cycle dependency. The DIR_SRC_ROOT should be
# moved away from common.py.
# pylint: disable=cyclic-import, import-outside-toplevel
import monitors
# The initial ffx target list command may return an empty list or without
# the ipv4 address, wait for a while to allow it detecting the devices and
# their addresses.
with monitors.time_consumption('ffx', 'get_ssh_address',
ipv4_only and 'ipv4' or ''), \
RepeatingLog("Waiting for the ssh address"):
for _ in range(60):
target = json.loads(
run_ffx_command(cmd=cmd, json_out=True,
capture_output=True).stdout.strip())
if target:
addrs = target[0]['addresses']
if addrs:
addr = addrs[0]
if 'Ip' in addr:
addr = addr['Ip']
break
time.sleep(5)
else:
monitors.count('ffx', 'get_ssh_address', ipv4_only and 'ipv4' or '',
'failed').record(1)
raise RuntimeError('No addresses found for target.')
ssh_port = int(addr['ssh_port'])
if ssh_port == 0:
# Returning an unset ssh_port means the default port 22.

@ -55,10 +55,7 @@ class WebpageTestRunner(TestRunner):
def run_test(self):
catch_sigterm()
self._runner.start()
device_ip = get_ip_address(self._target_id, ipv4_only=True)
addr = device_ip.exploded
if device_ip.version == 6:
addr = '[' + addr + ']'
addr = get_ip_address(self._target_id, ipv4_only=True).exploded
addr += ':' + str(self._runner.devtools_port)
if self.port_file:
with open(self.port_file, 'w') as out:

@ -36,4 +36,3 @@ ControlPath=~/.ssh/fx-%C
User fuchsia
IdentitiesOnly yes
IdentityFile ~/.ssh/fuchsia_ed25519
GSSAPIDelegateCredentials no

@ -30,7 +30,7 @@ import monitors
import perf_trace
import version
from chrome_driver_wrapper import ChromeDriverWrapper
from common import get_build_info, get_free_local_port, get_ip_address
from common import get_build_info, get_free_local_port, get_ip_address, ssh_run
from repeating_log import RepeatingLog
@ -196,22 +196,14 @@ def main() -> int:
monitors.tag(
version.chrome_version_str(), build_info.version,
version.chrome_version_str() + '/' + build_info.version)
proxy_host = os.environ.get('GCS_PROXY_HOST')
if proxy_host:
# This is a hacky way to get the ip address of the host machine
# being accessible on the device by the fuchsia managed docker
# image.
host = proxy_host + '0'
else:
# If not running in the managed docker image, replace the last
# byte of the fuchsia device ipv4 address to 1, by default it's
# the ip address of the host machine being accessible on the
# device.
# TODO(40935291): This hacky way should be removed once the
# tests are migrated to the managed docker image.
host = '.'.join(
get_ip_address(os.environ.get('FUCHSIA_NODENAME'),
True).exploded.split('.')[:-1] + ['1'])
# TODO(crbug.com/391663618): Remove the condition once all the hosts
# are migrated into chrome lab.
host = '.'.join(get_ip_address(os.environ.get('FUCHSIA_NODENAME'),
ipv4_only=True).
exploded.split('.')[:-1] +
[os.environ.get('CAMERA_SERIAL_NUMBER') and
'10' or # In chrome lab, the host is at .10.
'1']) # In media lab, the host is at .1.
# Waiting for a change like https://crrev.com/c/6063979 to loose the
# size limitation of the invocation which triggers an upload error