Share helper reconciliation and verify Linux and Windows native fixtures
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -23,7 +23,11 @@ from windows import client_bootstrap as windows
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
STATE = ROOT / 'devstate/shared-core/acceptance'
|
||||
KINDS = ('contracts', 'reconcile')
|
||||
PROFILES = {
|
||||
'original': {'linux': {'contracts':5, 'reconcile':20}, 'windows': {'contracts':4, 'reconcile':20}},
|
||||
'helper-sync-v1': {'linux': {'contracts':5, 'reconcile':21, 'helper-reconcile':22, 'linux-helper':21}, 'windows': {'contracts':4, 'reconcile':21, 'helper-reconcile':22}},
|
||||
}
|
||||
KINDS = ('contracts', 'reconcile') # Historical original qualification only.
|
||||
REMOTE_LINUX = '/var/lib/rmm-shared-core-acceptance'
|
||||
|
||||
|
||||
@@ -36,25 +40,36 @@ def write_new(path, value):
|
||||
contract.write_private(path, value)
|
||||
|
||||
|
||||
def qualified(platform):
|
||||
folder = ROOT/'devstate'/('shared-core' if platform == 'linux' else 'windows-core')
|
||||
manifest = contract.protected_json(folder/'manifest.json')
|
||||
def source_paths(profile):
|
||||
contract.require(profile in PROFILES, 'fixed qualification profile')
|
||||
sources = [ROOT/'Cargo.toml', ROOT/'Cargo.lock', ROOT/'rust-toolchain.toml']
|
||||
for name in ('agent-core', 'domain', 'protocol'):
|
||||
crates = ['agent-core', 'domain', 'protocol']
|
||||
if profile == 'helper-sync-v1': crates.extend(('agent', 'agent-linux', 'privileged-helper'))
|
||||
for name in crates:
|
||||
sources.extend(p for p in (ROOT/'crates'/name).rglob('*') if p.is_file() and (p.suffix == '.rs' or p.name == 'Cargo.toml'))
|
||||
sources.extend((ROOT/'proto').glob('*.proto'))
|
||||
actual = {str(p.relative_to(ROOT)): sha(p.read_bytes()) for p in sources}
|
||||
if profile == 'helper-sync-v1':
|
||||
sources.extend(ROOT/p for p in ('tools/apt-transaction/apt_transaction.py', 'tools/apt-transaction/hook', 'deploy/linux/rmm-apt-helper.service', 'tests/apt_transaction/fixtures/planning-canonical.json'))
|
||||
return sources
|
||||
|
||||
|
||||
def qualified(platform, profile='original'):
|
||||
folder = ROOT/'devstate'/('shared-core' if platform == 'linux' else 'windows-core')
|
||||
if profile != 'original': folder = folder/profile
|
||||
manifest = contract.protected_json(folder/'manifest.json')
|
||||
contract.require(manifest.get('qualification_profile', 'original') == profile, 'bound qualification profile')
|
||||
actual = {str(p.relative_to(ROOT)): sha(p.read_bytes()) for p in source_paths(profile)}
|
||||
contract.require(manifest['source_files'] == actual and manifest['source_before_after_equal'] is True, 'qualified source bindings changed')
|
||||
target = 'x86_64-unknown-linux-gnu' if platform == 'linux' else 'x86_64-pc-windows-gnu'
|
||||
contract.require(manifest['schema_version'] == 1 and manifest['target'] == target and manifest['os_effects'] is False and manifest['native_vm_executed'] is False, 'fixed test-only qualification')
|
||||
contract.require(all(manifest['checks'][n] is True for n in ('rustfmt_check', 'linux_all_target_clippy_warnings_denied', 'windows_all_target_clippy_warnings_denied')), 'qualified checks')
|
||||
artifacts = {}
|
||||
for kind, item in zip(KINDS, manifest['artifacts'], strict=True):
|
||||
for kind, item in zip(PROFILES[profile][platform], manifest['artifacts'], strict=True):
|
||||
path = folder/(kind + ('.exe' if platform == 'windows' else ''))
|
||||
contract.require(item['path'] == str(path.relative_to(ROOT)) and not path.is_symlink() and path.is_file(), 'fixed artifact path')
|
||||
contract.require(stat.S_IMODE(path.stat().st_mode) == 0o600 and path.stat().st_uid == os.getuid(), 'private artifact owner/mode')
|
||||
contract.require(item['binary_sha256'] == sha(path.read_bytes()) and item['size_bytes'] == path.stat().st_size, 'artifact hash/size')
|
||||
contract.require(item['test_count'] == (20 if kind == 'reconcile' else (5 if platform == 'linux' else 4)), 'fixed test count')
|
||||
contract.require(item['test_count'] == PROFILES[profile][platform][kind], 'fixed test count')
|
||||
artifacts[kind] = item
|
||||
return dict(manifest_sha256=sha((folder/'manifest.json').read_bytes()), artifacts=artifacts)
|
||||
|
||||
@@ -67,10 +82,12 @@ def linux_case(payload):
|
||||
ident = str(uuid.UUID(payload['id']))
|
||||
require(ident == payload['id'] and payload['action'] in ('prepare', 'run', 'read'), 'fixed case')
|
||||
entries = payload['artifacts']
|
||||
require(set(entries) == {'contracts', 'reconcile'}, 'two fixed test artifacts')
|
||||
profile=payload.get('profile','original')
|
||||
profiles={'original':{'contracts':5,'reconcile':20},'helper-sync-v1':{'contracts':5,'reconcile':21,'helper-reconcile':22,'linux-helper':21}}
|
||||
require(profile in profiles and set(entries)==set(profiles[profile]), 'fixed qualification artifacts')
|
||||
for kind, item in entries.items():
|
||||
require(len(item['binary_sha256']) == 64 and all(c in '0123456789abcdef' for c in item['binary_sha256']), 'fixed hash')
|
||||
require(item['test_count'] == (5 if kind == 'contracts' else 20), 'fixed test count')
|
||||
require(item['test_count'] == profiles[profile][kind], 'fixed test count')
|
||||
require(os.geteuid() == 0, 'bootstrap root only')
|
||||
def safe(path, directory):
|
||||
m = path.lstat()
|
||||
@@ -84,13 +101,13 @@ def linux_case(payload):
|
||||
case = root/ident
|
||||
if payload['action'] == 'prepare':
|
||||
case.mkdir(mode=0o700)
|
||||
save(case/'intent.json', dict(id=ident, artifacts=entries, linux_manifest_sha256=payload['linux_manifest_sha256'], windows_manifest_sha256=payload['windows_manifest_sha256'], test_only=True))
|
||||
save(case/'intent.json', dict(id=ident, profile=profile, artifacts=entries, linux_manifest_sha256=payload['linux_manifest_sha256'], windows_manifest_sha256=payload['windows_manifest_sha256'], test_only=True))
|
||||
for item in entries.values(): (case/item['binary_sha256']).mkdir(mode=0o700)
|
||||
return dict(prepared=True)
|
||||
safe(case, True); safe(case/'intent.json', False)
|
||||
intent = json.loads((case/'intent.json').read_bytes())
|
||||
require(intent['artifacts'] == entries and intent['linux_manifest_sha256'] == payload['linux_manifest_sha256'] and intent['windows_manifest_sha256'] == payload['windows_manifest_sha256'], 'same native intent')
|
||||
kind = payload['kind']; require(kind in ('contracts', 'reconcile'), 'fixed test kind')
|
||||
require(intent.get('profile','original') == profile and intent['artifacts'] == entries and intent['linux_manifest_sha256'] == payload['linux_manifest_sha256'] and intent['windows_manifest_sha256'] == payload['windows_manifest_sha256'], 'same native intent')
|
||||
kind = payload['kind']; require(kind in profiles[profile], 'fixed test kind')
|
||||
result_path = case/(kind+'-result.json')
|
||||
if payload['action'] == 'read':
|
||||
safe(result_path, False)
|
||||
@@ -123,7 +140,10 @@ def linux_case(payload):
|
||||
WINDOWS = r'''
|
||||
$ErrorActionPreference='Stop'
|
||||
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
|
||||
if ([string]([guid]$p.id) -cne $p.id -or $p.kind -notin @('contracts','reconcile') -or $p.action -notin @('run','read') -or $p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.linux_evidence_sha256 -notmatch '^[0-9a-f]{64}$') {throw 'Fixed native core case'}
|
||||
if (!$p.profile) {$p | Add-Member -NotePropertyName profile -NotePropertyValue 'original'}
|
||||
$kinds=@('contracts','reconcile');if ($p.profile -eq 'helper-sync-v1') {$kinds+=@('helper-reconcile')}
|
||||
if ($p.profile -notin @('original','helper-sync-v1')) {throw 'Fixed qualification profile'}
|
||||
if ([string]([guid]$p.id) -cne $p.id -or $p.kind -notin $kinds -or $p.action -notin @('run','read') -or $p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.linux_evidence_sha256 -notmatch '^[0-9a-f]{64}$') {throw 'Fixed native core case'}
|
||||
$root='C:\ProgramData\RustDiscoveryBootstrap'
|
||||
$case=Join-Path $root ('shared-core-'+$p.id)
|
||||
function Safe([string]$path,[bool]$directory) {
|
||||
@@ -144,11 +164,11 @@ Safe $root $true
|
||||
if (!(Test-Path -LiteralPath $case)) {
|
||||
if ($p.action -ne 'run' -or $p.kind -ne 'contracts') {throw 'Native intent missing'}
|
||||
New-Item -ItemType Directory -Path $case | Out-Null
|
||||
Write-New (Join-Path $case 'intent.json') @{id=$p.id;linux_evidence_sha256=$p.linux_evidence_sha256;test_only=$true}
|
||||
Write-New (Join-Path $case 'intent.json') @{id=$p.id;profile=$p.profile;linux_evidence_sha256=$p.linux_evidence_sha256;test_only=$true}
|
||||
}
|
||||
Safe $case $true
|
||||
$intent=Get-Content -LiteralPath (Join-Path $case 'intent.json') -Raw | ConvertFrom-Json
|
||||
if ($intent.id -cne $p.id -or $intent.linux_evidence_sha256 -cne $p.linux_evidence_sha256) {throw 'Bound Linux-first evidence'}
|
||||
if ((!$intent.profile -and $p.profile -ne 'original') -or ($intent.profile -and $intent.profile -cne $p.profile) -or $intent.id -cne $p.id -or $intent.linux_evidence_sha256 -cne $p.linux_evidence_sha256) {throw 'Bound Linux-first evidence'}
|
||||
$result=Join-Path $case ($p.kind+'-result.json')
|
||||
if ($p.action -eq 'read') {Safe $result $false;Get-Content -LiteralPath $result -Raw;exit 0}
|
||||
Write-New (Join-Path $case ($p.kind+'-started.json')) @{kind=$p.kind;sha256=$p.sha256}
|
||||
@@ -180,7 +200,7 @@ def upload_linux(case, kind, item):
|
||||
|
||||
|
||||
def payload(intent, action, kind=None):
|
||||
return dict(id=intent['id'], action=action, kind=kind, artifacts=intent['linux']['artifacts'], linux_manifest_sha256=intent['linux']['manifest_sha256'], windows_manifest_sha256=intent['windows']['manifest_sha256'])
|
||||
return dict(id=intent['id'], profile=intent.get('profile','original'), action=action, kind=kind, artifacts=intent['linux']['artifacts'], linux_manifest_sha256=intent['linux']['manifest_sha256'], windows_manifest_sha256=intent['windows']['manifest_sha256'])
|
||||
|
||||
|
||||
def verify_result(platform, kind, result, expected):
|
||||
@@ -197,32 +217,34 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('action', choices=('linux', 'windows', 'finish-linux', 'finish-windows'))
|
||||
parser.add_argument('--case-id')
|
||||
parser.add_argument('--profile', choices=tuple(PROFILES), default='original')
|
||||
args = parser.parse_args()
|
||||
if args.action == 'linux':
|
||||
contract.require(args.case_id is None, 'new Linux case chooses fresh UUID')
|
||||
ident = str(uuid.uuid4()); case = STATE/ident
|
||||
intent = dict(id=ident, linux=qualified('linux'), windows=qualified('windows'))
|
||||
intent = dict(id=ident, linux=qualified('linux',args.profile), windows=qualified('windows',args.profile))
|
||||
if args.profile != 'original': intent['profile']=args.profile
|
||||
write_new(case/'intent.json', intent)
|
||||
else:
|
||||
contract.require(args.case_id is not None and str(uuid.UUID(args.case_id)) == args.case_id, 'fixed existing case UUID')
|
||||
case = STATE/args.case_id
|
||||
intent = contract.protected_json(case/'intent.json')
|
||||
contract.require(intent['id'] == args.case_id and intent['linux'] == qualified('linux') and intent['windows'] == qualified('windows'), 'same qualified case source/artifacts')
|
||||
contract.require(intent['id'] == args.case_id and intent.get('profile','original')==args.profile and intent['linux'] == qualified('linux',args.profile) and intent['windows'] == qualified('windows',args.profile), 'same qualified case source/artifacts')
|
||||
platform = 'linux' if args.action.endswith('linux') else 'windows'
|
||||
if platform == 'windows':
|
||||
proof = contract.protected_json(case/'linux-passed.json')
|
||||
contract.require(proof['id'] == intent['id'] and proof['passed'] is True and proof['qualification'] == intent['linux'], 'Linux-first native qualification required')
|
||||
for kind in KINDS: verify_result('linux', kind, proof['results'][kind], intent['linux']['artifacts'][kind])
|
||||
for kind in PROFILES[args.profile]['linux']: verify_result('linux', kind, proof['results'][kind], intent['linux']['artifacts'][kind])
|
||||
linux_sha = sha((case/'linux-passed.json').read_bytes())
|
||||
else: linux_sha = None
|
||||
finish = args.action.startswith('finish-')
|
||||
if not finish:
|
||||
write_new(case/(platform+'-started.json'), dict(id=intent['id'], linux_evidence_sha256=linux_sha))
|
||||
write_new(case/(platform+'-started.json'), dict(id=intent['id'], profile=args.profile, linux_evidence_sha256=linux_sha))
|
||||
if args.action == 'linux':
|
||||
linux.rpc('linux-vm.conf', linux_case, payload(intent, 'prepare'))
|
||||
for kind in KINDS: upload_linux(case, kind, intent['linux']['artifacts'][kind])
|
||||
for kind in PROFILES[args.profile]['linux']: upload_linux(case, kind, intent['linux']['artifacts'][kind])
|
||||
results = {}
|
||||
for kind in KINDS:
|
||||
for kind in PROFILES[args.profile][platform]:
|
||||
if platform == 'linux':
|
||||
result = linux.rpc('linux-vm.conf', linux_case, payload(intent, 'read' if finish else 'run', kind))
|
||||
else:
|
||||
@@ -233,7 +255,7 @@ def main():
|
||||
try:
|
||||
with contextlib.redirect_stdout(captured):
|
||||
if not finish: windows.upload(ROOT/item['path'], 'windows-core-'+kind+'.exe')
|
||||
result = windows.powershell(WINDOWS, dict(id=intent['id'], kind=kind, action='read' if finish else 'run', sha256=item['binary_sha256'], linux_evidence_sha256=linux_sha), timeout=40)
|
||||
result = windows.powershell(WINDOWS, dict(id=intent['id'], profile=args.profile, kind=kind, action='read' if finish else 'run', sha256=item['binary_sha256'], linux_evidence_sha256=linux_sha), timeout=40)
|
||||
finally:
|
||||
write_new(case/('windows-'+kind+'-transport-'+uuid.uuid4().hex+'.json'), dict(sanitized_bootstrap_output=captured.getvalue()))
|
||||
write_new(case/(platform+'-'+kind+'-readback-'+uuid.uuid4().hex+'.json'), result)
|
||||
|
||||
Reference in New Issue
Block a user