fix: bind noop acceptance to post-upgrade passive baseline and preserve failed attempt
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -108,12 +108,92 @@ def unsubmitted_preparation(payload):
|
||||
return dict(persisted_plans=count)
|
||||
|
||||
|
||||
def accept(case,resume_unsubmitted=False):
|
||||
def no_change_source(cases,target):
|
||||
"""A new passive sample must follow an independently read verified upgrade."""
|
||||
m=cloud.contract
|
||||
checkpoint=m.protected_json(cases/'apt_native_update/checkpoint.json')
|
||||
require(checkpoint.get('verified') is True,'verified native upgrade required before no-change acceptance')
|
||||
job=checkpoint['plan']['jobs'][0]
|
||||
current=cloud.Backend().call('jobs.get',dict(tenant_id=target['tenant_id'],job_id=job['job_id']))
|
||||
require(current==checkpoint['result'] and current['state']=='succeeded' and
|
||||
current['result']['evidence']['postconditions_passed'] is True,
|
||||
'same authoritative completed native upgrade')
|
||||
apt=current['result']['evidence']['apt']
|
||||
require(apt['packages']==[dict(name='rmm-mvp-test',architecture='all',version='1.1')] and
|
||||
apt['test_acceptance'] is True and len(apt['native_record_sha256'])==64,
|
||||
'accepted native fixture1.1 postcondition required')
|
||||
return apt['snapshot_sha256'],m.now()
|
||||
|
||||
|
||||
def require_no_change_planning(device,data,snapshot_sha256,after):
|
||||
m=cloud.contract
|
||||
observation=next(x for x in device['inventory']['observations'] if x['scope']=='linux.apt.planning')
|
||||
m.require(m.timestamp(observation['observed_at'])>=after and
|
||||
data['fixture_package']==dict(version='1.1',status='install ok installed') and
|
||||
data['baseline_sha256']==snapshot_sha256,
|
||||
'not_configured:post_upgrade_passive_fixture1.1_baseline_required')
|
||||
|
||||
|
||||
def no_effect_retry_proof(payload):
|
||||
import sqlite3
|
||||
require(payload['case'] in ('ensure_package','apply_updates'),'fixed no-change case')
|
||||
require(all(str(uuid.UUID(payload[k]))==payload[k] for k in ('grant_id','job_id','attempt_id')),'canonical fixed identifiers')
|
||||
with sqlite3.connect('file:/var/lib/rmm-helper/consumption.sqlite?mode=ro',uri=True) as db:
|
||||
require(db.execute('PRAGMA integrity_check').fetchone()[0]=='ok','ledger integrity')
|
||||
require(db.execute('SELECT count(*) FROM consumed WHERE result IS NULL').fetchone()[0]==0 and
|
||||
db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0]==0,
|
||||
'closed fault-free Root ledger')
|
||||
row=db.execute('SELECT c.job,c.attempt,c.result,e.outcome FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE c.grant_id=?',(payload['grant_id'],)).fetchone()
|
||||
require(row is not None and row[:2]==(payload['job_id'],payload['attempt_id']) and row[2]==row[3],
|
||||
'same terminal consumed no-effect attempt')
|
||||
result=json.loads(row[2])
|
||||
require(result['state']=='failed' and result['error_code']=='STATUS_FINGERPRINT' and
|
||||
result['evidence']['postconditions_passed'] is False and result['evidence']['apt']=={},
|
||||
'definitive pre-hook status mismatch only')
|
||||
base=Path('/var/lib/rmm-apt-transaction');active=base/'active'
|
||||
if not active.exists() or json.loads((active/'context.json').read_bytes())['grant_id']!=payload['grant_id']:
|
||||
active=base/'history'/payload['grant_id']
|
||||
require(active.is_dir() and not active.is_symlink(),'original handoff retained')
|
||||
context=json.loads((active/'context.json').read_bytes())
|
||||
require(all(context[k]==payload[k] for k in ('grant_id','job_id','attempt_id')) and
|
||||
not any((active/name).exists() for name in ('hook-armed.json','launch.json','sandbox-ready.json','sandbox-result.json',
|
||||
'native-prechecks.json','host-reboot-before.json','host-namespaces.json')),
|
||||
'original status failure never launched sandbox or armed hook')
|
||||
return dict(verified_no_effect=True,grant_id=payload['grant_id'],job_id=payload['job_id'],attempt_id=payload['attempt_id'],
|
||||
result_sha256=hashlib.sha256(row[2].encode() if isinstance(row[2],str) else row[2]).hexdigest(),
|
||||
context_sha256=hashlib.sha256((active/'context.json').read_bytes()).hexdigest())
|
||||
|
||||
|
||||
def no_change_retry_folder(case,cases,target):
|
||||
m=cloud.contract;old=m.protected_json(cases/case/'checkpoint.json')
|
||||
require(case in ('ensure_package','apply_updates') and old['stage']=='failed' and
|
||||
all(old[k]==target[k] for k in target),'same fixed terminal no-change case')
|
||||
job=old['plan']['jobs'][0]
|
||||
current=cloud.Backend().call('jobs.get',dict(tenant_id=target['tenant_id'],job_id=job['job_id']))
|
||||
counts=prior.prior.evidence('gate',job_id=job['job_id'])
|
||||
require(current==old['result'] and current['state']=='failed' and current['result']['error_code']=='STATUS_FINGERPRINT' and
|
||||
counts==old['postapproval']==dict(jobs=1,outbox=1,permits=1,unresolved=0),
|
||||
'original approved single terminal status mismatch retained')
|
||||
proof=cloud.bootstrap.rpc('linux-vm.conf',no_effect_retry_proof,dict(case=case,grant_id=current['result']['grant_id'],
|
||||
job_id=job['job_id'],attempt_id=job['payload']['attempt_id']))
|
||||
require(proof['verified_no_effect'] is True,'readonly original no-effect proof')
|
||||
new=cases/'no-change-retry';new.mkdir(mode=0o700,exist_ok=True)
|
||||
m.write_private(new/(case+'-prior-no-effect.json'),dict(checkpoint_sha256=hashlib.sha256((cases/case/'checkpoint.json').read_bytes()).hexdigest(),proof=proof))
|
||||
return new
|
||||
|
||||
|
||||
def accept(case,resume_unsubmitted=False,new_noop_after_definitive_no_effect=False):
|
||||
m=cloud.contract;target=prior.prior.identity()
|
||||
require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt')
|
||||
ready,session=runtime_session();cases=session/'cases';cases.mkdir(mode=0o700,exist_ok=True)
|
||||
require(session!=BASE/'configured-reconcile-runtime' or case!='apt_configure_recovery',
|
||||
'configured historical1.0 is never executed again; next action is separate native1.1 upgrade')
|
||||
no_change=case in ('ensure_package','apply_updates')
|
||||
require(not new_noop_after_definitive_no_effect or (no_change and session==BASE/'configured-reconcile-runtime' and not resume_unsubmitted),
|
||||
'explicit no-effect retry only for qualified runtime no-change cases')
|
||||
source=no_change_source(cases,target) if no_change else None
|
||||
if new_noop_after_definitive_no_effect:
|
||||
cases=no_change_retry_folder(case,cases,target)
|
||||
if session!=BASE and case=='apt_configure_recovery':
|
||||
original=m.protected_json(STATE/case/'checkpoint-capacity-terminal.json')
|
||||
old_job=original['plan']['jobs'][0]
|
||||
@@ -137,10 +217,17 @@ def accept(case,resume_unsubmitted=False):
|
||||
device=cloud.Backend().call('inventory.get_device',{k:target[k] for k in ('tenant_id','asset_id')})
|
||||
try:
|
||||
data=prior.adapters.planning_from_device(device,recovery=case=='apt_configure_recovery')
|
||||
if source:require_no_change_planning(device,data,*source)
|
||||
break
|
||||
except m.GuardError:
|
||||
require(time.monotonic()<deadline,'fresh stored exact planning unavailable; no job submitted');time.sleep(3)
|
||||
request=recovery_request(device,target) if case=='apt_configure_recovery' else m.case_input(case,target,planning=data)
|
||||
if source:
|
||||
observation=next(x for x in device['inventory']['observations'] if x['scope']=='linux.apt.planning')
|
||||
m.write_private(cases/(case+'-post-upgrade-planning.json'),dict(snapshot_sha256=source[0],after=source[1].isoformat(),
|
||||
observed_at=observation['observed_at'],baseline_sha256=data['baseline_sha256'],status_fingerprint=data['status_fingerprint'],
|
||||
fixture_package=data['fixture_package']))
|
||||
request['reason']+='; Verify already installed fixture1.1 without executing a transaction; fresh baseline after accepted native upgrade'
|
||||
if data['host_reboot_required']:
|
||||
request['reason']+='; Host reboot already required; flag unchanged; no reboot in this job'
|
||||
if request is not None and session==BASE/'capacity-recovery':
|
||||
@@ -162,11 +249,14 @@ def close():
|
||||
def main():
|
||||
p=argparse.ArgumentParser(description=__doc__);p.add_argument('action',choices=('enable','accept','finish','close'));p.add_argument('--case',choices=CASES)
|
||||
p.add_argument('--resume-unsubmitted-ui',action='store_true',help='Preserve a failed preparation only after proving no plan was persisted')
|
||||
p.add_argument('--new-noop-after-definitive-no-effect',action='store_true',help='New UI plan in a separate folder only after proving the retained STATUS_FINGERPRINT attempt had no effect')
|
||||
args=p.parse_args();os.umask(0o077);STATE.mkdir(mode=0o700,exist_ok=True)
|
||||
if args.action in ('accept','finish'):
|
||||
require(args.case is not None,'one fixed case required')
|
||||
if args.action=='accept':accept(args.case,args.resume_unsubmitted_ui)
|
||||
else:prior.finish(args.case,folder_root=runtime_session()[1]/'cases')
|
||||
if args.action=='accept':accept(args.case,args.resume_unsubmitted_ui,args.new_noop_after_definitive_no_effect)
|
||||
else:
|
||||
require(not args.new_noop_after_definitive_no_effect or args.case in ('ensure_package','apply_updates'),'fixed no-change result only')
|
||||
prior.finish(args.case,folder_root=runtime_session()[1]/'cases'/('no-change-retry' if args.new_noop_after_definitive_no_effect else ''))
|
||||
else:(enable if args.action=='enable' else close)()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user