Skip to content
Open
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
2 changes: 1 addition & 1 deletion forge/host_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def main():
print('For a remote VM, forward port 8787 over SSH to reach the loopback dashboard.')
return 0
except (OSError, ValueError, StateError, StoreError, subprocess.SubprocessError) as error:
print('Setup did not finish: ' + (str(error) if isinstance(error, (ValueError, StateError, StoreError)) else 'Host command failed; correct it and rerun setup.'), file=sys.stderr)
print('Setup did not finish: ' + (str(error) if isinstance(error, (ValueError, StateError, StoreError)) else 'Host command failed (' + str(error) + '); correct it and rerun setup.'), file=sys.stderr)
return 1
except KeyboardInterrupt:
print('\nSetup interrupted. Saved connections are retained; rerun setup to continue.', file=sys.stderr)
Expand Down
40 changes: 20 additions & 20 deletions forge/host_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,32 +511,32 @@ def qualify_boundary_engine():
image='sha256:' + '0' * 64).qualify()


def wait_mirror(root, *, timeout=20):
def wait_service(root, module, failure, *, timeout=90):
# Each probe opens and integrity-checks the store, which takes seconds once
# the database is large; give every probe the remaining time, not a fixed slice.
deadline = time.monotonic() + timeout
while True:
result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', 'forge.mirror_daemon',
'--root', str(root), '--check'],
env={**os.environ, 'PYTHONPATH': str(SOURCE)},
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
return
try:
result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', module, '--root', str(root), '--check'],
env={**os.environ, 'PYTHONPATH': str(SOURCE)}, capture_output=True, text=True,
timeout=max(1, deadline - time.monotonic()))
if result.returncode == 0:
return
except subprocess.TimeoutExpired:
pass
if time.monotonic() >= deadline:
raise ValueError('The job mirror service is unhealthy. Inspect forge-mirror.service and rerun the supported update.')
raise ValueError(failure)
time.sleep(.25)


def wait_registry(root, *, timeout=20):
deadline = time.monotonic() + timeout
while True:
result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', 'forge.registry_cache',
'--root', str(root), '--check'],
env={**os.environ, 'PYTHONPATH': str(SOURCE)},
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
return
if time.monotonic() >= deadline:
raise ValueError('The package cache service is unhealthy. Inspect forge-registry.service and rerun the supported update.')
time.sleep(.25)
def wait_mirror(root):
wait_service(root, 'forge.mirror_daemon',
'The job mirror service is unhealthy. Inspect forge-mirror.service and rerun the supported update.')


def wait_registry(root):
wait_service(root, 'forge.registry_cache',
'The package cache service is unhealthy. Inspect forge-registry.service and rerun the supported update.')


def qualify_runner(image, seccomp, profile, *, full=False):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_host_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,16 @@ def test_update_verifies_connected_accounts_when_the_runner_changed(self):
check.assert_not_called()


class ServiceReadinessTests(unittest.TestCase):
def test_slow_probe_is_retried_within_the_overall_deadline(self):
# A large store makes one probe outlast a short per-call timeout.
calls = [subprocess.TimeoutExpired('probe', 5), subprocess.CompletedProcess('probe', 0)]
with patch.object(host_update.subprocess, 'run', side_effect=calls) as run, \
patch.object(host_update.time, 'sleep'):
host_update.wait_mirror('/root')
self.assertEqual(run.call_count, 2)
self.assertGreater(run.call_args.kwargs['timeout'], 5)


if __name__ == '__main__':
unittest.main()
Loading