Deploy Windows gateway as persistent scheduled task and verify public ADB
This commit is contained in:
1 parent
c38f067bea
commit
3fb894c1a1
9 files changed
+193
-13
No files matched your search
+18
-9
@@ -17,8 +17,9 @@ from e2e import ROOT, free_port, wait_until
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--adb-server", required=True)
|
||||
parser.add_argument("--serial", required=True)
|
||||
parser.add_argument("--adb-server")
|
||||
parser.add_argument("--serial")
|
||||
parser.add_argument("--existing-device", help="Use a deployed gateway device; do not start a temporary agent")
|
||||
parser.add_argument("--adb", default="adb")
|
||||
parser.add_argument("--bin-dir", type=Path, default=ROOT / "bin")
|
||||
parser.add_argument("--rust-dir", type=Path)
|
||||
@@ -26,6 +27,11 @@ def main():
|
||||
parser.add_argument("--connect-address", help="Optional origin host:port; TLS still verifies relay hostname")
|
||||
parser.add_argument("--credentials-dir", type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.existing_device and not args.relay_url:
|
||||
parser.error('--existing-device requires --relay-url')
|
||||
if not args.existing_device and (not args.adb_server or not args.serial):
|
||||
parser.error('provide --adb-server and --serial, or use --existing-device')
|
||||
device_id = args.existing_device or 'smoke-phone'
|
||||
suffix = ".exe" if os.name == "nt" else ""
|
||||
rust_dir = args.rust_dir or args.bin_dir
|
||||
relay_port, local_port = free_port(), free_port()
|
||||
@@ -36,13 +42,15 @@ def main():
|
||||
if not args.relay_url.startswith('wss://'):
|
||||
raise SystemExit('External relay smoke test requires wss://')
|
||||
if args.credentials_dir:
|
||||
for role in ('agent', 'client'):
|
||||
for role in (('client',) if args.existing_device else ('agent', 'client')):
|
||||
for line in (args.credentials_dir / (role + '.env')).read_text().splitlines():
|
||||
name, separator, value = line.partition('=')
|
||||
if separator and name in ('ADS_AGENT_TOKEN', 'ADS_CLIENT_TOKEN'):
|
||||
env[name] = value
|
||||
if not env.get('ADS_AGENT_TOKEN') or not env.get('ADS_CLIENT_TOKEN'):
|
||||
if not env.get('ADS_CLIENT_TOKEN') or (not args.existing_device and not env.get('ADS_AGENT_TOKEN')):
|
||||
raise SystemExit('External relay requires role tokens in env or --credentials-dir')
|
||||
if args.existing_device:
|
||||
env.pop('ADS_AGENT_TOKEN', None)
|
||||
else:
|
||||
env["ADS_AGENT_TOKEN"] = secrets.token_hex(32)
|
||||
env["ADS_CLIENT_TOKEN"] = secrets.token_hex(32)
|
||||
@@ -79,7 +87,7 @@ def main():
|
||||
response = connection.getresponse()
|
||||
if response.status != 200:
|
||||
raise ConnectionError(f'Device query failed: HTTP {response.status}')
|
||||
return any(device['id'] == 'smoke-phone' and device['busy'] for device in json.load(response))
|
||||
return any(device['id'] == device_id and device['busy'] for device in json.load(response))
|
||||
finally:
|
||||
connection.close()
|
||||
request = urllib.request.Request(f"http://127.0.0.1:{relay_port}/v1/devices",
|
||||
@@ -93,11 +101,12 @@ def main():
|
||||
network_args = [] if args.relay_url else ['--allow-insecure']
|
||||
if args.connect_address:
|
||||
network_args += ['--connect-address', args.connect_address]
|
||||
start("agent", [(rust_dir / f"ads-agent{suffix}").resolve(), "--server", server_url,
|
||||
*network_args, "--device", "smoke-phone", "--adb-server", args.adb_server,
|
||||
"--adb-serial", args.serial])
|
||||
if not args.existing_device:
|
||||
start("agent", [(rust_dir / f"ads-agent{suffix}").resolve(), "--server", server_url,
|
||||
*network_args, "--device", device_id, "--adb-server", args.adb_server,
|
||||
"--adb-serial", args.serial])
|
||||
start("client", [(rust_dir / f"ads-client{suffix}").resolve(), "--server", server_url,
|
||||
*network_args, "--device", "smoke-phone", "--listen", endpoint,
|
||||
*network_args, "--device", device_id, "--listen", endpoint,
|
||||
"--no-auto-connect"])
|
||||
wait_until(leased, "remote phone lease", seconds=20)
|
||||
print(adb("connect", endpoint).stdout.strip(), flush=True)
|
||||
|
||||
Reference in new issue
Block a user