Deploy reviewed Windows sync alignment with schema 20 server
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
Bind the administrative connection-205 review to original signed history and preserve closed readiness. Include the qualified server dependency closure, UI review, native ARM64 build provenance, and guarded deployment evidence. Migration, API/gateway replacement and TLS checks passed with unchanged job authority, protected mounts and time/database services; native Windows receipt application remains separate.
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Freeze public sources and build ARM64 server/broker only; never deploy/migrate."""
|
||||
import base64
|
||||
import gzip
|
||||
import hashlib
|
||||
import inspect
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import uuid
|
||||
import vm_access_check as access
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
BUILDER='sha256:30ae3d90753bc39b0a98a897784c662aff9598ffab7a98a6298e8aa79145c2ec'
|
||||
|
||||
def sha(raw):return hashlib.sha256(raw).hexdigest()
|
||||
def write(path,raw):
|
||||
path.parent.mkdir(mode=0o700,parents=True,exist_ok=True)
|
||||
with path.open('xb') as f:f.write(raw);f.flush();os.fsync(f.fileno())
|
||||
path.chmod(0o600)
|
||||
def ssh(code,raw=b'',timeout=45):
|
||||
cfg=access.load_config(ROOT/'credentials/server.conf')
|
||||
cmd=['ssh','-F','/dev/null','-T','-p',cfg.get('port','22'),'-o','StrictHostKeyChecking=yes','-o','BatchMode=yes','-o','IdentitiesOnly=yes','-o','ForwardAgent=no','-o','ClearAllForwardings=yes','-o','ConnectTimeout=7','-i',str(Path(cfg['ssh_key_path']).expanduser()),cfg['username']+'@'+cfg['address'],shlex.join(['python3','-I','-c',code])]
|
||||
p=subprocess.run(cmd,input=raw,capture_output=True,timeout=timeout)
|
||||
if p.returncode:raise RuntimeError('Build-only SSH operation failed; public diagnostics retained by caller')
|
||||
return json.loads(p.stdout)
|
||||
def preflight():
|
||||
import json,subprocess,os
|
||||
assert os.uname().machine=='aarch64' and os.geteuid()==0
|
||||
def run(a):return subprocess.check_output(a,stderr=subprocess.DEVNULL,text=True,timeout=15)
|
||||
builder=PARAMETERS['builder'];i=json.loads(run(['docker','image','inspect',builder]))[0]
|
||||
assert i['Id']==builder and i['Architecture']=='arm64' and i['Os']=='linux'
|
||||
units={}
|
||||
for role in ('api','gateway','postgres'):
|
||||
c=json.loads(run(['docker','inspect','rust-discovery-server-'+role+'-1']))[0]
|
||||
units[role]={'id':c['Id'],'image':c['Image'],'started_at':c['State']['StartedAt'],'running':c['State']['Running'],'restart_count':c['RestartCount']}
|
||||
stat=os.statvfs('/opt/rust-discovery/devstate')
|
||||
return {'architecture':'aarch64','builder':builder,'units':units,'disk_available_bytes':stat.f_bavail*stat.f_frsize}
|
||||
def stage():
|
||||
import io,json,hashlib,tarfile,subprocess,os,sys
|
||||
from pathlib import Path
|
||||
p=PARAMETERS;raw=sys.stdin.buffer.read(p['bytes']+1)
|
||||
assert len(raw)==p['bytes'] and hashlib.sha256(raw).hexdigest()==p['sha256']
|
||||
root=Path('/opt/rust-discovery/devstate');case=root/p['release'];case.mkdir(mode=0o700);pkg=case/'package';pkg.mkdir(mode=0o700)
|
||||
files={}
|
||||
with tarfile.open(fileobj=io.BytesIO(raw),mode='r:gz') as archive:
|
||||
for m in archive.getmembers():
|
||||
assert m.isfile() and not m.name.startswith('/') and '..' not in Path(m.name).parts and m.name not in files and m.size<=16*1024*1024
|
||||
files[m.name]=archive.extractfile(m).read()
|
||||
assert len(files)<=1500 and sum(map(len,files.values()))<=32*1024*1024
|
||||
manifest=json.loads(files['manifest.json']);assert hashlib.sha256(files['manifest.json']).hexdigest()==p['manifest_sha256']
|
||||
assert set(files)=={'manifest.json'}|set(manifest['file_hashes'])
|
||||
assert all(hashlib.sha256(files[n]).hexdigest()==h for n,h in manifest['file_hashes'].items())
|
||||
for name,content in files.items():
|
||||
path=pkg/name;path.parent.mkdir(mode=0o700,parents=True,exist_ok=True)
|
||||
with path.open('xb') as stream:stream.write(content);stream.flush();os.fsync(stream.fileno())
|
||||
path.chmod(0o400)
|
||||
with (case/'sealed.json').open('x') as stream:json.dump(p,stream)
|
||||
with (case/'build-worker.py').open('xb') as stream:stream.write(p['worker'].encode())
|
||||
log=(case/'launcher.log').open('xb')
|
||||
process=subprocess.Popen(['python3','-I',str(case/'build-worker.py')],stdin=subprocess.DEVNULL,stdout=log,stderr=subprocess.STDOUT,start_new_session=True,close_fds=True)
|
||||
return {'release':p['release'],'case':str(case),'worker_pid':process.pid,'build_only':True,'runtime_deployment':False,'migration_executed':False}
|
||||
def worker():
|
||||
from pathlib import Path
|
||||
import subprocess,json,hashlib,os
|
||||
p=PARAMETERS;case=Path('/opt/rust-discovery/devstate')/p['release'];pkg=case/'package';out=case/'build.receipt.json'
|
||||
assert not out.exists()
|
||||
def sha(b):return hashlib.sha256(b).hexdigest()
|
||||
manifest=json.loads((pkg/'manifest.json').read_text());assert sha((pkg/'manifest.json').read_bytes())==p['manifest_sha256']
|
||||
assert all(sha((pkg/n).read_bytes())==h for n,h in manifest['file_hashes'].items())
|
||||
def run(a):return subprocess.check_output(a,stderr=subprocess.DEVNULL,text=True,timeout=30)
|
||||
def state():
|
||||
result={}
|
||||
for role in ('api','gateway','postgres'):
|
||||
c=json.loads(run(['docker','inspect','rust-discovery-server-'+role+'-1']))[0]
|
||||
result[role]={'id':c['Id'],'image':c['Image'],'started_at':c['State']['StartedAt'],'running':c['State']['Running'],'restart_count':c['RestartCount']}
|
||||
return result
|
||||
before=state();assert before==manifest['preflight']['units'];tag='rust-discovery-server:'+p['release']
|
||||
with (case/'build.log').open('xb') as log:
|
||||
r=subprocess.run(['docker','build','--network=none','--pull=false','--iidfile',str(case/'image-id'),'-t',tag,str(pkg)],stdout=log,stderr=subprocess.STDOUT,env={**os.environ,'DOCKER_BUILDKIT':'0'},timeout=1800)
|
||||
result={'exit_code':r.returncode,'release':p['release'],'tag':tag,'source_manifest_sha256':p['manifest_sha256'],'build_only':True,'runtime_deployment':False,'migration_executed':False}
|
||||
if r.returncode==0:
|
||||
image=(case/'image-id').read_text().strip();info=json.loads(run(['docker','image','inspect',image]))[0];assert info['Architecture']=='arm64' and info['Os']=='linux'
|
||||
result.update(image=image,architecture='arm64',binaries={})
|
||||
for name in ('rmm-server','rmm-time-broker-linux'):
|
||||
expected=run(['docker','run','--rm','--read-only','--cap-drop=ALL','--security-opt','no-new-privileges','--network','none','--entrypoint','sha256sum',image,'/usr/local/bin/'+name]).split()[0]
|
||||
container=run(['docker','create','--read-only','--network','none','--cap-drop=ALL','--entrypoint','/bin/true',image])
|
||||
try:
|
||||
path=case/name;subprocess.run(['docker','cp',container+':/usr/local/bin/'+name,str(path)],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,timeout=30)
|
||||
finally:run(['docker','rm',container])
|
||||
raw=path.read_bytes();assert raw[:6]==b'\x7fELF\x02\x01' and raw[18:20]==b'\xb7\x00' and sha(raw)==expected
|
||||
path.chmod(0o500);result['binaries'][name]={'path':str(path),'bytes':len(raw),'sha256':expected}
|
||||
assert all(sha((pkg/n).read_bytes())==h for n,h in manifest['file_hashes'].items())
|
||||
result['runtime_before']=before;result['runtime_after']=state();result['runtime_unchanged']=before==result['runtime_after']
|
||||
with out.open('x') as stream:json.dump(result,stream,sort_keys=True,indent=2);stream.flush();os.fsync(stream.fileno())
|
||||
|
||||
def freeze():
|
||||
os.umask(0o077);ident=uuid.uuid4().hex[:12];folder=ROOT/'devstate/server-build-only'/ident;folder.mkdir(mode=0o700,parents=True)
|
||||
before=ssh(inspect.getsource(preflight).replace('PARAMETERS',repr({'builder':BUILDER}))+'\nprint(__import__("json").dumps(preflight()))\n')
|
||||
assert before['disk_available_bytes']>8*1024**3
|
||||
names=subprocess.check_output(['git','ls-files','--cached','--others','--exclude-standard','-z'],cwd=ROOT).decode().split('\0')
|
||||
names=sorted(set(n for n in names if n and (n.startswith(('crates/','proto/','migrations/','tools/','tests/','deploy/linux/','web/src/')) or n in ('Cargo.toml','Cargo.lock','rust-toolchain.toml','web/package.json','web/package-lock.json','web/tsconfig.json','web/index.html','web/vite.config.ts'))))
|
||||
files={}
|
||||
for name in names:
|
||||
p=ROOT/name
|
||||
assert p.is_file() and not p.is_symlink() and '__pycache__' not in p.parts and p.stat().st_size<=16*1024*1024
|
||||
files['source/'+name]=p.read_bytes()
|
||||
assert all((ROOT/n).read_bytes()==files['source/'+n] for n in names),'source snapshot drift'
|
||||
assert b'mod windows_sync_alignment;' in files['source/crates/server/src/main.rs']
|
||||
assert b'pub mod windows_sync_alignment;' in files['source/crates/domain/src/lib.rs']
|
||||
assert 'source/migrations/0020_windows_sync_alignment.sql' in files
|
||||
inputs={n.removeprefix('source/'):sha(b) for n,b in files.items()}
|
||||
files['inputs.sha256']=''.join(h+' '+n+'\n' for n,h in inputs.items()).encode()
|
||||
files['Dockerfile']=('FROM '+BUILDER+' AS build\nWORKDIR /src\nCOPY source/ /src/\nCOPY inputs.sha256 /tmp/rmm-build-inputs.sha256\nRUN sha256sum -c /tmp/rmm-build-inputs.sha256 && cargo clippy --offline --locked -p rmm-server -p rmm-time-broker-linux --all-targets -- -D warnings && cargo build --offline --locked --release -p rmm-server -p rmm-time-broker-linux --bins\nFROM '+before['units']['api']['image']+'\nCOPY --from=build /src/target/release/rmm-server /usr/local/bin/rmm-server\nCOPY --from=build /src/target/release/rmm-time-broker-linux /usr/local/bin/rmm-time-broker-linux\n').encode()
|
||||
for path in sorted((ROOT/'web/dist').rglob('*')):
|
||||
if path.is_file():assert not path.is_symlink();files['web/'+str(path.relative_to(ROOT/'web/dist'))]=path.read_bytes()
|
||||
assert any(n.startswith('web/assets/') and b'windows-sync-alignment' in v for n,v in files.items()),'built WebUI must contain actual new route'
|
||||
manifest={'schema_version':1,'release':'server205-'+ident,'git_base':subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip(),'builder':BUILDER,'preflight':before,'source_files':inputs,'web':{n[4:]:sha(b) for n,b in files.items() if n.startswith('web/')},'file_hashes':{n:sha(b) for n,b in files.items()},'windows_copied_only_not_qualified':True,'build_only':True,'runtime_deployment':False,'migration_executed':False}
|
||||
files['manifest.json']=json.dumps(manifest,sort_keys=True,indent=2).encode()
|
||||
package=folder/'package'
|
||||
for name,raw in files.items():write(package/name,raw)
|
||||
buffer=io.BytesIO()
|
||||
with tarfile.open(fileobj=buffer,mode='w') as archive:
|
||||
for name,raw in sorted(files.items()):
|
||||
member=tarfile.TarInfo(name);member.size=len(raw);member.mode=0o400;archive.addfile(member,io.BytesIO(raw))
|
||||
raw=gzip.compress(buffer.getvalue(),mtime=0);write(folder/'package.tar.gz',raw)
|
||||
sealed={'release':manifest['release'],'sha256':sha(raw),'manifest_sha256':sha(files['manifest.json']),'bytes':len(raw),'source_count':len(inputs)}
|
||||
write(folder/'sealed.json',json.dumps(sealed,sort_keys=True,indent=2).encode())
|
||||
params={**sealed,'worker':inspect.getsource(worker).replace('PARAMETERS',repr(sealed))+'\nworker()\n'}
|
||||
result=ssh(inspect.getsource(stage).replace('PARAMETERS',repr(params))+'\nprint(__import__("json").dumps(stage()))\n',raw=raw)
|
||||
write(folder/'stage-result.json',json.dumps(result,sort_keys=True,indent=2).encode())
|
||||
print(json.dumps({'folder':str(folder),'sealed':sealed,'stage':result}))
|
||||
if __name__=='__main__':freeze()
|
||||
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exact reviewed a48f ARM64 deployment; no jobs, Windows starts, or broker changes."""
|
||||
import argparse
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
import server_build_only as build
|
||||
CASE='server205-a48f78614e2e'
|
||||
IMAGE='sha256:a7fc4243fee414ab6c85c5f4d207b6428005b77ab06903916138a83b4b74e1d4'
|
||||
MANIFEST='7594ab8eda6cd3e75852ed03ed7033da32e8997898dce05b1b7584f8c14c12ff'
|
||||
|
||||
def remote():
|
||||
from pathlib import Path
|
||||
import subprocess,json,os,hashlib,stat,time,ssl,http.client,socket,tempfile
|
||||
p=PARAMETERS;root=Path('/opt/rust-discovery');case=root/'devstate'/p['case'];pkg=case/'package'
|
||||
def sha(raw):return hashlib.sha256(raw).hexdigest()
|
||||
def encoded(v):return json.dumps(v,sort_keys=True,separators=(',',':')).encode()
|
||||
def run(args,timeout=40):return subprocess.check_output(args,stderr=subprocess.DEVNULL,text=True,timeout=timeout).strip()
|
||||
def once(path,value):
|
||||
raw=encoded(value)
|
||||
with path.open('xb') as stream:stream.write(raw);stream.flush();os.fsync(stream.fileno())
|
||||
def docker(role):return json.loads(run(['docker','inspect','rust-discovery-server-'+role+'-1']))[0]
|
||||
def actual(c):return dict(id=c['Id'],image=c['Image'],started_at=c['State']['StartedAt'],restart_count=c['RestartCount'],running=c['State']['Running'])
|
||||
def shape(c):
|
||||
conf,host=c['Config'],c['HostConfig']
|
||||
value={'user':conf['User'],'env':sorted(conf['Env']),'entrypoint':conf['Entrypoint'],'cmd':conf['Cmd'],'working_dir':conf['WorkingDir'],
|
||||
'mounts':sorted(c['Mounts'],key=lambda m:m['Destination']),'binds':sorted(host.get('Binds')or[]),'networks':sorted(c['NetworkSettings']['Networks']),
|
||||
'labels':{k:v for k,v in (conf.get('Labels')or{}).items() if not k.startswith('com.docker.compose.')},
|
||||
'host':{k:host.get(k) for k in ('ReadonlyRootfs','PortBindings','CapDrop','CapAdd','SecurityOpt','RestartPolicy','Privileged','NetworkMode','IpcMode','PidMode','Devices','UsernsMode')}}
|
||||
return sha(encoded(value))
|
||||
def sql(query):return run(['docker','exec','rust-discovery-server-postgres-1','psql','-XqAt','-v','ON_ERROR_STOP=1','-U','postgres','-d','rmm','-c',query],15)
|
||||
def migrations():
|
||||
values=sql("SELECT version,encode(checksum,'hex'),success FROM _sqlx_migrations ORDER BY version").splitlines()
|
||||
actual_map={}
|
||||
for row in values:
|
||||
version,checksum,success=row.split('|');assert success=='t';actual_map[int(version)]=checksum
|
||||
expected={int(x.name[:4]):hashlib.sha384(x.read_bytes()).hexdigest() for x in (pkg/'source/migrations').glob('*.sql')}
|
||||
assert actual_map==expected or actual_map=={k:v for k,v in expected.items() if k<20}
|
||||
return max(actual_map)
|
||||
def counts():
|
||||
return json.loads(sql("SELECT json_build_object('jobs',(SELECT count(*) FROM jobs),'grants',(SELECT count(*) FROM execution_permits),'authorizations',(SELECT count(*) FROM authorizations),'outbox',(SELECT count(*) FROM outbox),'echo_completion',(SELECT count(*) FROM windows_echo_completions),'windows_jobs',(SELECT count(*) FROM jobs WHERE agent_id='63ea15b2-0643-403d-b5b4-cba1288dbea3'),'windows_grants',(SELECT count(*) FROM execution_permits p JOIN jobs j USING(tenant_id,job_id,attempt_id) WHERE j.agent_id='63ea15b2-0643-403d-b5b4-cba1288dbea3'))"))
|
||||
def windows():
|
||||
return json.loads(sql("SELECT json_build_object('generation',i.connection_generation,'boot',i.connection_boot_id,'revoked',i.revoked_at,'journal',s.journal_id,'checkpoint',s.checkpoint,'decision',s.decision_id,'helper_journal',s.helper_journal_id,'helper_checkpoint',s.helper_checkpoint) FROM agent_installations i JOIN agent_sync_state s USING(tenant_id,agent_id) WHERE i.agent_id='63ea15b2-0643-403d-b5b4-cba1288dbea3'"))
|
||||
def passive_units():
|
||||
return {name:run(['systemctl','show',name,'--property=MainPID,ActiveState,SubState,ExecMainStartTimestampMonotonic,NRestarts']) for name in ('rmm-time-broker.service','chrony.service')}
|
||||
def protected_metadata():
|
||||
records={}
|
||||
for base in ('devstate/pki','devstate/api-pki','devstate/jobs','devstate/root-policy'):
|
||||
path=root/base
|
||||
for item in [path,*sorted(path.rglob('*'))]:
|
||||
meta=item.lstat();assert not item.is_symlink() and (stat.S_ISDIR(meta.st_mode)or stat.S_ISREG(meta.st_mode))
|
||||
records[str(item)]={k:getattr(meta,'st_'+k) for k in ('dev','ino','uid','gid','mode','nlink','size','mtime_ns','ctime_ns')}
|
||||
for item in (Path('/run/rmm-time-source'),Path('/run/rmm-time-source/broker.sock')):
|
||||
if item.exists():
|
||||
meta=item.lstat();records[str(item)]={k:getattr(meta,'st_'+k)for k in('dev','ino','uid','gid','mode','nlink')}
|
||||
return sha(encoded(records))
|
||||
def assert_role(role,c):
|
||||
port={'api':'18443','gateway':'18444'}[role];conf,host=c['Config'],c['HostConfig']
|
||||
assert c['State']['Running'] and c['RestartCount']==0 and conf['User']=='10001:10001'
|
||||
assert host['PortBindings']=={'18443/tcp':[{'HostIp':'127.0.0.1','HostPort':port}]} and host['ReadonlyRootfs'] and host['CapDrop']==['ALL'] and host['SecurityOpt']==['no-new-privileges:true']
|
||||
if role=='gateway':assert any(m['Destination']=='/run/rmm-time-source' and m['Source']=='/run/rmm-time-source' and m['RW']is False for m in c['Mounts'])
|
||||
def request(role,path):
|
||||
if role=='api':connection=http.client.HTTPSConnection('localhost',18443,context=ssl.create_default_context(cafile=str(root/'devstate/api-pki/ca.pem')),timeout=3)
|
||||
else:
|
||||
class Checked(http.client.HTTPSConnection):
|
||||
def connect(self):self.sock=self._context.wrap_socket(socket.create_connection(('127.0.0.1',18444),timeout=self.timeout),server_hostname='discovery.ease-technologies.de')
|
||||
connection=Checked('discovery.ease-technologies.de',18444,context=ssl.create_default_context(cafile=str(root/'devstate/pki/ca.pem')),timeout=3)
|
||||
try:connection.request('GET',path);response=connection.getresponse();return response.status,response.read(2*1024*1024)
|
||||
finally:connection.close()
|
||||
assert os.uname().machine=='aarch64' and os.geteuid()==0
|
||||
assert not any(n in os.environ for n in ('DOCKER_HOST','DOCKER_CONTEXT','COMPOSE_FILE','COMPOSE_PROJECT_NAME','COMPOSE_PROFILES'))
|
||||
assert sha((pkg/'manifest.json').read_bytes())==p['manifest']
|
||||
manifest=json.loads((pkg/'manifest.json').read_text());built=json.loads((case/'build.receipt.json').read_text())
|
||||
assert built['exit_code']==0 and built['image']==p['image'] and built['architecture']=='arm64' and built['runtime_unchanged']
|
||||
assert all(sha((pkg/n).read_bytes())==h for n,h in manifest['file_hashes'].items())
|
||||
before_path=case/'deployment205-before.json'
|
||||
if p['action']=='preflight':
|
||||
assert not before_path.exists()
|
||||
current={role:docker(role)for role in('api','gateway','postgres')}
|
||||
assert {r:actual(c)for r,c in current.items()}==built['runtime_after']
|
||||
for role in('api','gateway'):assert_role(role,current[role])
|
||||
assert current['postgres']['HostConfig']['PortBindings']in({},None)
|
||||
labels=current['api']['Config']['Labels'];assert labels['com.docker.compose.project']=='rust-discovery-server'
|
||||
files=labels['com.docker.compose.project.config_files'].split(',');assert len(files)==5
|
||||
assert all(Path(f).is_file() and not Path(f).is_symlink() and Path(f).is_relative_to(root)for f in files)
|
||||
base=['docker','compose','--project-name','rust-discovery-server','--project-directory',str(root/'deploy'),'--env-file',str(root/'devstate/.env')]
|
||||
for f in files:base+=['-f',f]
|
||||
old=json.loads(run(base+['config','--format','json']))
|
||||
overlay=case/'deployment205-images.compose.yaml';raw=('services:\n'+''.join(' '+role+':\n image: '+p['image']+'\n pull_policy: never\n'for role in('api','gateway','migrate'))).encode()
|
||||
if overlay.exists():assert overlay.read_bytes()==raw
|
||||
else:
|
||||
with overlay.open('xb')as stream:stream.write(raw)
|
||||
compose=base+['-f',str(overlay)];new=json.loads(run(compose+['config','--format','json']))
|
||||
expected=json.loads(json.dumps(old))
|
||||
for role in('api','gateway','migrate'):expected['services'][role]['image']=p['image'];expected['services'][role]['pull_policy']='never'
|
||||
assert expected==new,'Unexpected compose semantics change'
|
||||
candidate=json.loads(run(['docker','image','inspect',p['image']]))[0]['Config']
|
||||
for role in('api','gateway'):
|
||||
service=new['services'][role];env=dict(x.split('=',1)for x in(candidate.get('Env')or[]));env.update(service.get('environment')or{})
|
||||
assert sorted(k+'='+str(v)for k,v in env.items())==sorted(current[role]['Config']['Env'])
|
||||
assert service.get('user',candidate.get('User',''))==current[role]['Config']['User']
|
||||
assert (candidate['Entrypoint']if service.get('entrypoint')is None else service['entrypoint'])==current[role]['Config']['Entrypoint']
|
||||
assert (candidate.get('Cmd')if service.get('command')is None else service['command'])==current[role]['Config']['Cmd']
|
||||
assert migrations()==19
|
||||
w=windows();assert w['generation']==205 and w['boot']=='a9ad0895-5a96-8f2c-8fb6-cfdc2d5225ea'and w['decision']=='2af359c5-5b5c-4992-b445-1c00e271a288'and w['checkpoint']==10137 and w['helper_checkpoint']==135 and w['revoked']is None
|
||||
state={'actual':{r:actual(c)for r,c in current.items()},'shape':{r:shape(c)for r,c in current.items()},'compose':compose,'compose_sha256':sha(encoded(new)),'files_sha256':{f:sha(Path(f).read_bytes())for f in files},'overlay_sha256':sha(raw),'counts':counts(),'windows':w,'protected_sha256':protected_metadata(),'passive_units':passive_units(),'web_before':{str(f.relative_to(root/'web/dist')):sha(f.read_bytes())for f in(root/'web/dist').rglob('*')if f.is_file()}}
|
||||
once(before_path,state);return {'preflight':True,'migration':19,'image':p['image'],'compose_only_image_changes':True,'environment_identical':True,'loopback_only':True,'windows':w,'counts':state['counts'],'root_uid':10001,'secrets_logged':False}
|
||||
before=json.loads(before_path.read_text());compose=before['compose']
|
||||
assert all(sha(Path(f).read_bytes())==h for f,h in before['files_sha256'].items())
|
||||
assert sha(Path(compose[-1]).read_bytes())==before['overlay_sha256']
|
||||
assert sha(encoded(json.loads(run(compose+['config','--format','json']))))==before['compose_sha256']
|
||||
assert actual(docker('postgres'))==before['actual']['postgres'] and shape(docker('postgres'))==before['shape']['postgres']
|
||||
assert passive_units()==before['passive_units'] and protected_metadata()==before['protected_sha256']
|
||||
assert counts()==before['counts'] and windows()==before['windows']
|
||||
def check_apps(new):
|
||||
for role in('api','gateway'):
|
||||
c=docker(role);assert_role(role,c);assert shape(c)==before['shape'][role]
|
||||
assert (c['Image']==p['image']and c['Id']!=before['actual'][role]['id'])if new else actual(c)==before['actual'][role]
|
||||
if p['action']=='migrate':
|
||||
assert migrations()==19;check_apps(False);once(case/'deployment205-migration-intent.json',{'image':p['image'],'migration':20})
|
||||
log=case/'deployment205-migration.log'
|
||||
with log.open('xb')as stream:r=subprocess.run(compose+['run','--no-deps','-T','--rm','--name','rmm-server205-migrate-20','migrate'],stdout=stream,stderr=subprocess.STDOUT,timeout=60)
|
||||
assert r.returncode==0 and migrations()==20;check_apps(False)
|
||||
assert sql('SELECT count(*) FROM windows_sync_alignment_reviews')=='0' and sql('SELECT count(*) FROM windows_sync_alignment_receipts')=='0'
|
||||
elif p['action']=='apps':
|
||||
assert migrations()==20;check_apps(False);once(case/'deployment205-apps-intent.json',{'image':p['image'],'before':before['actual']})
|
||||
with(case/'deployment205-apps.log').open('xb')as stream:r=subprocess.run(compose+['up','-d','--no-deps','--no-build','--pull','never','api','gateway'],stdout=stream,stderr=subprocess.STDOUT,timeout=60)
|
||||
assert r.returncode==0
|
||||
for _ in range(30):
|
||||
try:
|
||||
assert request('api','/healthz')==(200,b'ok')and request('gateway','/healthz')==(200,b'ok');break
|
||||
except Exception:time.sleep(.25)
|
||||
else:raise RuntimeError('TLS-validated application health did not become ready')
|
||||
check_apps(True)
|
||||
for role in('api','gateway'):assert run(['docker','exec','rust-discovery-server-'+role+'-1','sha256sum','/usr/local/bin/rmm-server']).split()[0]==built['binaries']['rmm-server']['sha256']
|
||||
elif p['action']=='web':
|
||||
assert migrations()==20;check_apps(True);once(case/'deployment205-web-intent.json',{'web':manifest['web']})
|
||||
current={str(f.relative_to(root/'web/dist')):sha(f.read_bytes())for f in(root/'web/dist').rglob('*')if f.is_file()};assert current==before['web_before']
|
||||
for name,h in sorted(manifest['web'].items(),key=lambda v:v[0]=='index.html'):
|
||||
src=pkg/'web'/name;assert sha(src.read_bytes())==h;dst=root/'web/dist'/name;assert not dst.is_symlink()and dst.parent.resolve()==dst.parent
|
||||
if dst.exists()and sha(dst.read_bytes())==h:continue
|
||||
if name!='index.html':assert not dst.exists()
|
||||
with tempfile.NamedTemporaryFile(dir=dst.parent,delete=False)as stream:
|
||||
temp=Path(stream.name);os.fchmod(stream.fileno(),0o644);stream.write(src.read_bytes());stream.flush();os.fsync(stream.fileno())
|
||||
os.replace(temp,dst)
|
||||
assert request('api','/')[0]==200 and sha(request('api','/')[1])==manifest['web']['index.html']
|
||||
elif p['action']=='verify':
|
||||
assert migrations()==20;check_apps(True)
|
||||
assert all(sha((root/'web/dist'/n).read_bytes())==h for n,h in manifest['web'].items())
|
||||
assert request('api','/healthz')==(200,b'ok')and request('gateway','/healthz')==(200,b'ok')
|
||||
assert request('api','/api/v1/tenants/11111111-1111-4111-8111-111111111111/windows-sync-alignment')[0]==401
|
||||
else:raise RuntimeError('unknown fixed deployment action')
|
||||
assert counts()==before['counts'] and windows()==before['windows'] and passive_units()==before['passive_units'] and protected_metadata()==before['protected_sha256']
|
||||
assert actual(docker('postgres'))==before['actual']['postgres']
|
||||
result={'action':p['action'],'image':p['image'],'migration':migrations(),'api':actual(docker('api')),'gateway':actual(docker('gateway')),'postgres_unchanged':True,'broker_chrony_unchanged':True,'protected_pki_jobkey_policy_metadata_unchanged':True,'counts':counts(),'windows':windows(),'environment_mounts_uid_security_loopback_unchanged':True,'job_authority_created':False}
|
||||
once(case/('deployment205-'+p['action']+'-result.json'),result);return result
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('action',choices=('preflight','migrate','apps','web','verify'));args=parser.parse_args()
|
||||
p={'case':CASE,'image':IMAGE,'manifest':MANIFEST,'action':args.action}
|
||||
code=inspect.getsource(remote).replace('PARAMETERS',repr(p))+'\ntry:\n print(__import__("json").dumps(remote()))\nexcept Exception as error:\n import traceback\n print(__import__("json").dumps({"error_class":type(error).__name__,"frames":[{"function":f.name,"line":f.lineno}for f in traceback.extract_tb(error.__traceback__)]}))\n'
|
||||
result=build.ssh(code,timeout=90)
|
||||
if 'error_class'in result:print(json.dumps(result));raise RuntimeError('Deployment incomplete; redacted frame diagnostics above')
|
||||
target=build.ROOT/'devstate/server-build-only/a48f78614e2e'/('local-deployment-'+args.action+'.json');build.write(target,json.dumps(result,sort_keys=True,indent=2).encode());print(json.dumps(result))
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user