Deploy scoped SYSTEM nonstart review and record preserved native rollback
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
// Actual dev/test UI interactions only. No approval API, DB write or fetch injection.
|
||||
const fs = require('node:fs'), path = require('node:path'), crypto = require('node:crypto');
|
||||
const assert = require('node:assert/strict');
|
||||
const root = path.resolve(__dirname, '../..');
|
||||
const { chromium } = require(path.join(root, 'web/node_modules/playwright'));
|
||||
function privateJson(file) {
|
||||
const stat = fs.lstatSync(file);
|
||||
assert(stat.isFile() && !stat.isSymbolicLink() && stat.uid === process.getuid() && (stat.mode & 511) === 384 && stat.size <= 2 * 1024 * 1024);
|
||||
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
}
|
||||
function canonical(value) {
|
||||
if (Array.isArray(value)) return '[' + value.map(canonical).join(',') + ']';
|
||||
if (value && typeof value === 'object') return '{' + Object.keys(value).sort().map(k => JSON.stringify(k) + ':' + canonical(value[k])).join(',') + '}';
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
const sha = value => crypto.createHash('sha256').update(value).digest('hex');
|
||||
(async () => {
|
||||
const mode = process.argv[2], expected = privateJson(path.resolve(process.argv[3]));
|
||||
assert(['submit', 'confirm'].includes(mode));
|
||||
assert(expected.profile === 'dev/test' && expected.case === 'windows_system_nonstart_221');
|
||||
const witness = privateJson(path.resolve(expected.witness_path));
|
||||
assert(witness.connection_generation === 221 && witness.agent_checkpoint === 10784 && witness.helper_checkpoint >= 413);
|
||||
assert(witness.agent_last_decision === '0442c732-8226-4c25-9615-7f007e24b269' && witness.helper_last_decision === '193b951b-a3aa-46e2-9f48-1a57f315078e');
|
||||
assert(witness.nonstart.helper_pid === 1304 && witness.nonstart.read_share_error === 32 && witness.nonstart.read_write_share_passed === true);
|
||||
assert(sha(Buffer.from(canonical(witness))) === expected.witness_sha256);
|
||||
assert(sha(Buffer.from(witness.agent_outcome)) === '1f284b66578d61c4364cc0060a67ce9b467e1d661ed8885804391b51a6f18b1a');
|
||||
assert.deepEqual(witness.agent_outcome, witness.helper_outcome);
|
||||
const folder = path.resolve(expected.output_directory), folderStat = fs.lstatSync(folder);
|
||||
assert(folder.startsWith(path.join(root, 'devstate') + path.sep) && folderStat.isDirectory() && !folderStat.isSymbolicLink() && folderStat.uid === process.getuid() && (folderStat.mode & 511) === 448);
|
||||
const login = privateJson(path.join(root, 'credentials/server-browser-login.json'));
|
||||
const versions = path.join(root, 'web/node_modules/.cache/playwright-browsers');
|
||||
const version = fs.readdirSync(versions).find(n => /^chromium-/.test(n));
|
||||
const executablePath = ['chrome-linux/chrome', 'chrome-linux64/chrome'].map(n => path.join(versions, version, n)).find(fs.existsSync);
|
||||
const browser = await chromium.launch({ headless: true, executablePath,
|
||||
env: { ...process.env, HOME: path.join(root, 'web/node_modules/.cache/cloud-acceptance/home') } });
|
||||
try {
|
||||
const page = await browser.newPage({ ignoreHTTPSErrors: false });
|
||||
await page.goto('https://localhost:18443/');
|
||||
await page.getByLabel('Benutzername').fill(login.username);
|
||||
await page.getByLabel('Passwort', { exact: true }).fill(login.password);
|
||||
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
|
||||
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
|
||||
const session = await (await sessionResponse).json();
|
||||
assert(session.principal === 'simulated-testprincipal-a' && session.testsimulation === true && session.approval_origin === 'dev_test_browser_simulation');
|
||||
await page.getByRole('status').filter({ hasText: 'SIMULIERT' }).waitFor();
|
||||
await page.getByRole('row').filter({ hasText: 'a176520e-8a91-4e93-a78b-8e7620f430e0' }).getByRole('button').click();
|
||||
const section = page.getByRole('region', { name: 'Administrativer SYSTEM-Nichtstartabschluss 221', exact: true });
|
||||
await section.waitFor();
|
||||
if (mode === 'submit') {
|
||||
await section.getByLabel('Nativer Nichtstartzeuge 221', { exact: true }).fill(JSON.stringify(witness));
|
||||
await section.getByRole('button', { name: 'Zeugen einreichen und Originale serverseitig prüfen', exact: true }).click();
|
||||
} else {
|
||||
await section.getByRole('button', { name: 'Gespeicherten administrativen Fall prüfen', exact: true }).click();
|
||||
}
|
||||
await section.getByText('Vollständige Originalbelege und Dateibindungen', { exact: true }).click();
|
||||
const preview = section.getByLabel('Geprüfter SYSTEM-Nichtstartzeuge', { exact: true });
|
||||
await preview.waitFor(); const review = JSON.parse(await preview.innerText());
|
||||
assert.deepEqual(review.witness, witness); assert(review.witness_sha256 === expected.witness_sha256);
|
||||
assert(Number.isSafeInteger(review.server_transport_generation) && review.server_transport_generation >= 221);
|
||||
if (expected.server_transport_generation !== undefined) assert(review.server_transport_generation === expected.server_transport_generation);
|
||||
const record = { actual_simulated_ui: true, mode, witness_sha256: review.witness_sha256, server_transport_generation: review.server_transport_generation, request_id: review.request_id, confirmed: false, job_approved: false };
|
||||
if (mode === 'confirm') {
|
||||
const button = section.getByRole('button', { name: 'SIMULIERT: Exakten SYSTEM-Nichtstart 221 bestätigen', exact: true });
|
||||
assert(await button.isDisabled());
|
||||
await section.getByRole('checkbox', { name: 'Ich habe genau den Fall 221', exact: false }).check();
|
||||
await button.click();
|
||||
const link = section.getByRole('link', { name: 'Signierte administrative Quittung herunterladen', exact: true });
|
||||
await link.waitFor(); const downloadEvent = page.waitForEvent('download'); await link.click();
|
||||
const download = await downloadEvent, output = path.join(folder, 'windows-system-nonstart-221-receipt.json');
|
||||
assert(!fs.existsSync(output)); await download.saveAs(output); fs.chmodSync(output, 384);
|
||||
const signed = privateJson(output), receipt = JSON.parse(Buffer.from(signed.payload).toString('utf8'));
|
||||
assert(receipt.domain === 'rmm.dev.windows-system-nonstart-221.v1' && receipt.schema_version === 1);
|
||||
assert.deepEqual(receipt.witness, witness); assert(receipt.witness_sha256 === expected.witness_sha256 && receipt.server_transport_generation === review.server_transport_generation);
|
||||
assert(receipt.confirmed_by === 'simulated-testprincipal-a' && receipt.testsimulation === true && receipt.approval_origin === 'dev_test_browser_simulation');
|
||||
assert(receipt.ready === false && receipt.helper_ready === false && receipt.unlock === false);
|
||||
assert(Date.parse(receipt.valid_until) > Date.now() + 60000 && Date.parse(receipt.valid_until) - Date.parse(receipt.issued_at) <= 300000);
|
||||
const publicRaw = Buffer.from(witness.verification_public_key_hex, 'hex');
|
||||
assert(sha(publicRaw) === receipt.key_id);
|
||||
const publicKey = crypto.createPublicKey({ key: Buffer.concat([Buffer.from('302a300506032b6570032100', 'hex'), publicRaw]), format: 'der', type: 'spki' });
|
||||
assert(crypto.verify(null, Buffer.from(signed.payload), publicKey, Buffer.from(signed.signature)));
|
||||
Object.assign(record, { confirmed: true, receipt_id: receipt.receipt_id, receipt_file: output,
|
||||
canonical_signed_receipt_sha256: sha(Buffer.from(JSON.stringify({ payload: signed.payload, signature: signed.signature }))),
|
||||
ready: false, helper_ready: false, unlock: false });
|
||||
}
|
||||
fs.writeFileSync(path.join(folder, 'system-nonstart-ui-' + mode + '.json'), JSON.stringify(record, null, 2), { mode: 384, flag: 'wx' });
|
||||
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
|
||||
console.log('PASS actual simulated WebUI ' + mode + '; administrative nonstart only, no job approval');
|
||||
} finally { await browser.close(); }
|
||||
})().catch(error => { console.log('SYSTEM_NONSTART_UI_INCOMPLETE:' + error.constructor.name); process.exitCode = 1; });
|
||||
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Freeze only the approved Windows221 server closure; build without deployment."""
|
||||
import argparse
|
||||
import gzip
|
||||
import inspect
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import uuid
|
||||
|
||||
import server_build_only as build
|
||||
|
||||
|
||||
def freeze(source, web):
|
||||
os.umask(0o077)
|
||||
source = source.resolve()
|
||||
web = web.resolve()
|
||||
assert source.is_relative_to(build.ROOT / 'devstate')
|
||||
assert web.is_relative_to(build.ROOT / 'devstate')
|
||||
baseline = build.ROOT / 'devstate/server-build-only/a48f78614e2e/package/source'
|
||||
allowed = {
|
||||
'crates/domain/src/lib.rs',
|
||||
'crates/domain/src/windows_system_nonstart.rs',
|
||||
'crates/server/src/main.rs',
|
||||
'crates/server/src/job_gateway.rs',
|
||||
'crates/server/src/synchronization.rs',
|
||||
'crates/server/src/windows_system_nonstart.rs',
|
||||
'migrations/0021_windows_system_nonstart.sql',
|
||||
'web/src/main.tsx',
|
||||
'web/src/system-nonstart-review.tsx',
|
||||
'web/src/system-nonstart-review.test.tsx',
|
||||
'web/src/system-nonstart-review.test.ts',
|
||||
}
|
||||
def regular_files(folder):
|
||||
result = {}
|
||||
for path in sorted(folder.rglob('*')):
|
||||
assert not path.is_symlink(), 'Frozen closure must not contain symlinks'
|
||||
if path.is_file():
|
||||
assert path.stat().st_size <= 16 * 1024 * 1024
|
||||
result[str(path.relative_to(folder))] = path.read_bytes()
|
||||
return result
|
||||
original = regular_files(baseline)
|
||||
frozen = regular_files(source)
|
||||
assert set(original) <= set(frozen), 'No baseline source removal'
|
||||
changed = {name for name, raw in frozen.items() if original.get(name) != raw}
|
||||
assert changed <= allowed and 'crates/server/src/windows_system_nonstart.rs' in changed
|
||||
assert 'migrations/0021_windows_system_nonstart.sql' in changed
|
||||
assert any(b'windows-system-nonstart-221' in raw for raw in regular_files(web).values())
|
||||
before = build.ssh(inspect.getsource(build.preflight).replace(
|
||||
'PARAMETERS', repr({'builder': build.BUILDER})) + '\nprint(__import__("json").dumps(preflight()))\n')
|
||||
assert before['disk_available_bytes'] > 8 * 1024**3
|
||||
ident = uuid.uuid4().hex[:12]
|
||||
folder = build.ROOT / 'devstate/server-build-only' / ident
|
||||
folder.mkdir(mode=0o700, parents=True)
|
||||
files = {'source/' + name: raw for name, raw in frozen.items()}
|
||||
inputs = {name: build.sha(raw) for name, raw in frozen.items()}
|
||||
assert regular_files(source) == frozen, 'Source closure drift'
|
||||
files['inputs.sha256'] = ''.join(h + ' ' + n + '\n' for n, h in inputs.items()).encode()
|
||||
files['Dockerfile'] = (
|
||||
'FROM ' + build.BUILDER + ' AS build\nWORKDIR /src\n'
|
||||
'COPY source/ /src/\nCOPY inputs.sha256 /tmp/rmm-build-inputs.sha256\n'
|
||||
'RUN 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\n'
|
||||
'FROM ' + before['units']['api']['image'] + '\n'
|
||||
'COPY --from=build /src/target/release/rmm-server /usr/local/bin/rmm-server\n'
|
||||
'COPY --from=build /src/target/release/rmm-time-broker-linux /usr/local/bin/rmm-time-broker-linux\n'
|
||||
).encode()
|
||||
for name, raw in regular_files(web).items():
|
||||
files['web/' + name] = raw
|
||||
manifest = {
|
||||
'schema_version': 1, 'release': 'server221-' + ident,
|
||||
'git_base': subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),
|
||||
'builder': build.BUILDER, 'preflight': before, 'source_files': inputs,
|
||||
'baseline_source_manifest': 'a48f78614e2e', 'changed_source_files': sorted(changed),
|
||||
'web': {n[4:]: build.sha(raw) for n, raw in files.items() if n.startswith('web/')},
|
||||
'file_hashes': {n: build.sha(raw) for n, raw in files.items()},
|
||||
'build_only': True, 'runtime_deployment': False, 'migration_executed': False,
|
||||
}
|
||||
files['manifest.json'] = json.dumps(manifest, sort_keys=True, indent=2).encode()
|
||||
for name, raw in files.items():
|
||||
build.write(folder / '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)
|
||||
build.write(folder / 'package.tar.gz', raw)
|
||||
sealed = dict(release=manifest['release'], sha256=build.sha(raw),
|
||||
manifest_sha256=build.sha(files['manifest.json']), bytes=len(raw), source_count=len(inputs))
|
||||
build.write(folder / 'sealed.json', json.dumps(sealed, sort_keys=True, indent=2).encode())
|
||||
params = {**sealed, 'worker': inspect.getsource(build.worker).replace('PARAMETERS', repr(sealed)) + '\nworker()\n'}
|
||||
result = build.ssh(inspect.getsource(build.stage).replace('PARAMETERS', repr(params))
|
||||
+ '\nprint(__import__("json").dumps(stage()))\n', raw=raw)
|
||||
build.write(folder / 'stage-result.json', json.dumps(result, sort_keys=True, indent=2).encode())
|
||||
print(json.dumps(dict(folder=str(folder), sealed=sealed, stage=result)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source', required=True, type=Path)
|
||||
parser.add_argument('--web', required=True, type=Path)
|
||||
args = parser.parse_args()
|
||||
freeze(args.source, args.web)
|
||||
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Deploy the scoped Windows221 closure build; preserve runtime, jobs and broker."""
|
||||
import argparse
|
||||
import inspect
|
||||
import json
|
||||
from pathlib import Path
|
||||
import server_build_only as build
|
||||
|
||||
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<21}
|
||||
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/'deployment221-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) in (7,8)
|
||||
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/'deployment221-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']
|
||||
schema_before=migrations();assert schema_before in (20,21)
|
||||
w=windows();assert w['generation']>=221 and w['boot']=='a9ad0895-5a96-8f2c-8fb6-cfdc2d5225ea'and w['decision']=='0442c732-8226-4c25-9615-7f007e24b269'and w['checkpoint']==10784 and w['helper_checkpoint']==413 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':schema_before,'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()==20;check_apps(False);once(case/'deployment221-migration-intent.json',{'image':p['image'],'migration':21})
|
||||
log=case/'deployment221-migration.log'
|
||||
with log.open('xb')as stream:r=subprocess.run(compose+['run','--no-deps','-T','--rm','--name','rmm-server221-migrate-21','migrate'],stdout=stream,stderr=subprocess.STDOUT,timeout=60)
|
||||
assert r.returncode==0 and migrations()==21;check_apps(False)
|
||||
assert sql('SELECT count(*) FROM windows_system_nonstart_reviews')=='0' and sql('SELECT count(*) FROM windows_system_nonstart_receipts')=='0'
|
||||
elif p['action']=='apps':
|
||||
assert migrations()==21;check_apps(False);once(case/'deployment221-apps-intent.json',{'image':p['image'],'before':before['actual']})
|
||||
with(case/'deployment221-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()==21;check_apps(True);once(case/'deployment221-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()==21;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-system-nonstart-221')[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/('deployment221-'+p['action']+'-result.json'),result);return result
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('action',choices=('preflight','migrate','apps','web','verify'));parser.add_argument('--build-folder',required=True,type=Path);args=parser.parse_args()
|
||||
folder=args.build_folder.resolve();assert folder.is_relative_to(build.ROOT/'devstate/server-build-only')
|
||||
sealed=json.loads((folder/'sealed.json').read_text());receipt=json.loads((folder/'local-build-receipt.json').read_text());assert sealed['release'].startswith('server221-') and receipt['release']==sealed['release'] and receipt['exit_code']==0 and receipt['runtime_unchanged']
|
||||
p={'case':sealed['release'],'image':receipt['image'],'manifest':sealed['manifest_sha256'],'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=folder/('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