Resume through the ordinary unit: one stop path and one status
This commit is contained in:
parent
04fbaee731
commit
995f94b999
6 changed files with 93 additions and 16 deletions
19
STATUS.md
19
STATUS.md
|
|
@ -32,6 +32,25 @@ lacked `worker_source_root`, the defect recorded in `deploy/PIPELINE-AUDIT`, so
|
|||
never reached its assertions and its mocked `docker ps` failure path returned no
|
||||
output; both are fixed and the interruption/recovery order passes again.
|
||||
|
||||
Verifying the fix exposed the second half of the same 404: `deploy/Caddyfile` had no
|
||||
route for `/archipelago/arch-repo-snapshot/*`. The container that failed the run still
|
||||
had one in memory from a file edited on the host, so the views were reachable only
|
||||
until that file was overwritten and the container restarted — which is exactly what
|
||||
rolling out this change did to the previously working `2026-11-12` view. The route is
|
||||
now in `deploy/Caddyfile` (root `/srv/artifacts/arch-repo-snapshot`, outside the
|
||||
generation symlink `current`), and both dates answer 200 over HTTPS for `core.db` and
|
||||
`extra.db`, next to the unchanged `/archipelago/`, `v1/releases.json`,
|
||||
`releases.json`, `pipeline.json`, portal, package and ISO routes.
|
||||
|
||||
A resume is no longer a second unit. `POST /api/control` accepts
|
||||
`{action:start,resume:true}` and writes a request containing only `resume` and
|
||||
`requested_at`; `release-cycle.py` turns that into `--resume` and the run keeps the
|
||||
mode and snapshot it already had, so nothing is pinned twice. Until now a resume ran
|
||||
as the transient `archipelago-cycle-resume.service`, which the portal's stop button
|
||||
and status view did not know about; now one ordinary service unit covers starts,
|
||||
resumes and stops. `resolve_request` in the driver is covered by
|
||||
`tests/cycle-recovery.py`.
|
||||
|
||||
## A stop takes effect immediately, not after two minutes (2026-11-15)
|
||||
|
||||
`archipelago-release-cycle.service` was `Type=oneshot`. systemd does not deliver
|
||||
|
|
|
|||
|
|
@ -74,6 +74,11 @@ dates from inside that container, restarts it once when it still has a stale vie
|
|||
drops a date it cannot serve; the portal additionally requires the pinned date to
|
||||
answer HTTP 200 before it writes the request.
|
||||
|
||||
`{action: "start", "resume": true}` continues the last failed run under the same
|
||||
service unit: the request carries only `resume` and `requested_at`, so the run keeps
|
||||
the mode and the immutable snapshot it was pinned to, and the stop button and the
|
||||
status view keep describing the unit that is actually running.
|
||||
|
||||
Schedule buttons enable or disable the monthly dispatcher timer; the cadence itself
|
||||
(1st of the month, ISO + OSTree) is fixed by the code and is not editable from the
|
||||
portal.
|
||||
|
|
|
|||
|
|
@ -175,13 +175,20 @@ class App:
|
|||
raise ValueError('Pipeline is already running or stopping')
|
||||
if action == 'start':
|
||||
mode = parameters.get('mode', 'iso')
|
||||
if mode not in ('iso', 'ostree'):
|
||||
raise ValueError('Неизвестный режим сборки')
|
||||
# Pin the exact immutable repository before the cycle starts: a
|
||||
# manual build must never silently reuse a different snapshot.
|
||||
pinned = self.snapshot_date(parameters.get('snapshot', 'latest'))
|
||||
parameters = {'mode': mode, 'snapshot': pinned,
|
||||
'requested_at': datetime.now(timezone.utc).isoformat()}
|
||||
request = {'requested_at': datetime.now(timezone.utc).isoformat()}
|
||||
if parameters.get('resume'):
|
||||
# Continue the last failed run. It keeps the mode and the
|
||||
# immutable snapshot it was already pinned to, so this request
|
||||
# must not pin either again; the run stays one ordinary service
|
||||
# unit, which keeps the stop button and the status truthful.
|
||||
request['resume'] = True
|
||||
else:
|
||||
if mode not in ('iso', 'ostree'):
|
||||
raise ValueError('Неизвестный режим сборки')
|
||||
# Pin the exact immutable repository before the cycle starts: a
|
||||
# manual build must never silently reuse a different snapshot.
|
||||
request.update(mode=mode, snapshot=self.snapshot_date(parameters.get('snapshot', 'latest')))
|
||||
parameters = request
|
||||
path = self.archive / 'cycle-request.json'
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
temporary = path.with_suffix('.tmp')
|
||||
|
|
|
|||
|
|
@ -33,6 +33,25 @@ def atomic(path, value):
|
|||
temp.replace(path)
|
||||
|
||||
|
||||
def resolve_request(candidate, age, resume):
|
||||
"""Return the portal request this run may consume, or None.
|
||||
|
||||
A build request pins a mode and one immutable snapshot date. A resume request
|
||||
only asks to continue the last run: it carries neither, because that run keeps
|
||||
its own mode and snapshot identity, and a command-line --resume wins over any
|
||||
request. Requests older than 900 s are discarded so a scheduled run never
|
||||
inherits a forgotten manual start.
|
||||
"""
|
||||
if resume or candidate is None or age is None or not 0 <= age <= 900:
|
||||
return None
|
||||
if candidate.get('resume') is True:
|
||||
return candidate
|
||||
if (candidate.get('mode') in ('iso', 'ostree')
|
||||
and re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}', candidate.get('snapshot', ''))):
|
||||
return candidate
|
||||
return None
|
||||
|
||||
|
||||
def verify_snapshot(snapshot_url):
|
||||
"""Refuse to build from a snapshot the public web server does not serve.
|
||||
|
||||
|
|
@ -100,21 +119,20 @@ def main():
|
|||
except (OSError, json.JSONDecodeError):
|
||||
candidate = None
|
||||
request_path.unlink(missing_ok=True)
|
||||
if args.resume:
|
||||
candidate = None
|
||||
try:
|
||||
age = (datetime.now(timezone.utc) - datetime.fromisoformat(candidate['requested_at'])).total_seconds()
|
||||
except (TypeError, KeyError, ValueError):
|
||||
age = None
|
||||
if (candidate and candidate.get('mode') in ('iso', 'ostree')
|
||||
and re.fullmatch(r'[0-9]{4}-[0-9]{2}-[0-9]{2}', candidate.get('snapshot', ''))
|
||||
and age is not None and 0 <= age <= 900):
|
||||
request = candidate
|
||||
elif candidate is not None:
|
||||
print('ignored stale or invalid portal request', flush=True)
|
||||
request = resolve_request(candidate, age, args.resume)
|
||||
if request and request.get('resume'):
|
||||
# A resume keeps the previous run's mode and snapshot, so the request
|
||||
# carries neither and the run continues from its own state.
|
||||
args.resume = True
|
||||
elif request is None and candidate is not None:
|
||||
print('discarded portal request (stale, invalid, or superseded by --resume)', flush=True)
|
||||
if args.mode != 'auto':
|
||||
mode = args.mode
|
||||
elif request:
|
||||
elif request and request.get('mode'):
|
||||
mode = request['mode']
|
||||
else:
|
||||
mode = 'iso' if datetime.now(timezone.utc).day == 1 else 'ostree'
|
||||
|
|
|
|||
|
|
@ -97,6 +97,20 @@ class Portal(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
app.control('start', {'mode': 'reboot'})
|
||||
self.assertFalse((app.archive / 'cycle-request.json').exists())
|
||||
# A resume keeps the failed run's mode and snapshot: it pins neither,
|
||||
# so the same ordinary service unit and the same stop button apply.
|
||||
asked.clear()
|
||||
control.subprocess.run = lambda argv, **kwargs: subprocess.CompletedProcess(argv, 0, b'', b'')
|
||||
try:
|
||||
resumed = app.control('start', {'action': 'start', 'resume': True})
|
||||
finally:
|
||||
control.subprocess.run = original
|
||||
request = json.loads((app.archive / 'cycle-request.json').read_text())
|
||||
self.assertEqual(request.get('resume'), True)
|
||||
self.assertNotIn('mode', request)
|
||||
self.assertNotIn('snapshot', request)
|
||||
self.assertEqual(asked, [])
|
||||
self.assertEqual(resumed['request'], request)
|
||||
|
||||
def test_snapshot_listing_uses_the_published_manifest(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
|
|
|
|||
|
|
@ -81,4 +81,18 @@ with patch.object(cycle.urllib.request, 'urlopen', return_value=Served(404)), \
|
|||
assert 'not served' in str(error) and 'core.db' in str(error)
|
||||
else:
|
||||
raise AssertionError('Unserved repository snapshot accepted')
|
||||
|
||||
|
||||
# A portal request may pin a fresh build or ask to resume the last run, never both.
|
||||
build = {'mode': 'ostree', 'snapshot': '2026-11-15', 'requested_at': 'stamp'}
|
||||
assert cycle.resolve_request(build, 10, False) is build
|
||||
assert cycle.resolve_request(build, 9 * 60 + 59, False) is build
|
||||
assert cycle.resolve_request(build, 901, False) is None
|
||||
assert cycle.resolve_request(build, None, False) is None
|
||||
assert cycle.resolve_request(build, 10, True) is None
|
||||
assert cycle.resolve_request({'mode': 'reboot', 'snapshot': '2026-11-15'}, 10, False) is None
|
||||
assert cycle.resolve_request({'mode': 'iso', 'snapshot': 'latest'}, 10, False) is None
|
||||
resume = {'resume': True, 'requested_at': 'stamp'}
|
||||
assert cycle.resolve_request(resume, 10, False) is resume
|
||||
assert cycle.resolve_request(resume, 901, False) is None
|
||||
print('CYCLE_RECOVERY_ORDER_AND_OWNERSHIP_PASS')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue