Account for Synology EA streams in exact CMS predecessor inventory
This commit is contained in:
@@ -61,6 +61,35 @@ def cms_foundation():
|
||||
return {**expected, 'infra/.env.synology':sha256_file(env)}
|
||||
|
||||
|
||||
def cms_without_synology_metadata(files, label):
|
||||
"""Partition only NAS EA streams attached to a present application file.
|
||||
|
||||
Synology exposes these files to POSIX but hides them from SMB. They are
|
||||
never application payload or build input. Unknown paths remain rejected.
|
||||
"""
|
||||
application = {}
|
||||
metadata = {}
|
||||
for rel, digest in files.items():
|
||||
parts = PurePosixPath(rel).parts
|
||||
if '@eaDir' not in parts:
|
||||
application[rel] = digest
|
||||
continue
|
||||
if (len(parts) != 3 or parts[0] not in ('admin', 'server')
|
||||
or parts[1] != '@eaDir' or not parts[2].endswith('@SynoEAStream')):
|
||||
die(label + ' has an unrecognized Synology metadata path: ' + rel)
|
||||
sibling = parts[0] + '/' + parts[2][:-len('@SynoEAStream')]
|
||||
cms_release_path(sibling)
|
||||
if sibling not in files:
|
||||
die(label + ' has orphaned Synology metadata: ' + rel)
|
||||
metadata[rel] = digest
|
||||
return application, metadata
|
||||
|
||||
|
||||
def cms_application_inventory():
|
||||
files = collect_exact_files(CMS_ROOT, ('admin', 'server', *CMS_DEPENDENCY_FILES), 'CMS installed app')
|
||||
return cms_without_synology_metadata(files, 'CMS installed app')
|
||||
|
||||
|
||||
def cms_installed_release():
|
||||
for row in load_state(FAILED_STATE_FILE):
|
||||
if row.get('component') in ('dc-cms-release','dc-cms-autodeploy') and row.get('started_apply') and not str(row.get('rollback_status','')).startswith('ok:'):
|
||||
@@ -78,8 +107,11 @@ def cms_installed_release():
|
||||
# Initial transition is independently anchored in the exact live CMS source.
|
||||
descriptor = {'sourceCommit':CMS_BASELINE['sourceCommit'],'runNumber':0,'releaseId':'dc-cms-4c6f133'}
|
||||
expected = {**CMS_BASELINE['filesSha256'], **{p:CMS_BASELINE['foundationSha256'][p] for p in CMS_DEPENDENCY_FILES}}
|
||||
if collect_exact_files(CMS_ROOT, ('admin','server',*CMS_DEPENDENCY_FILES), 'CMS installed app') != expected:
|
||||
die('CMS installed application differs from its canonical predecessor')
|
||||
actual, _ = cms_application_inventory()
|
||||
if actual != expected:
|
||||
delta = {'missing':sorted(set(expected)-set(actual)), 'unexpected':sorted(set(actual)-set(expected)),
|
||||
'changed':sorted(p for p in set(actual)&set(expected) if actual[p]!=expected[p])}
|
||||
die('CMS installed application differs from its canonical predecessor: ' + json.dumps(delta, sort_keys=True))
|
||||
cms_foundation()
|
||||
return descriptor
|
||||
|
||||
@@ -135,13 +167,13 @@ def preflight_cms_release(payload, entries, identity):
|
||||
previous = cms_installed_release()
|
||||
if d['runNumber'] <= previous['runNumber'] or d['sourceCommit'] == previous['sourceCommit']:
|
||||
die('CMS release is stale or already installed')
|
||||
installed = collect_exact_files(CMS_ROOT,('admin','server',*CMS_DEPENDENCY_FILES),'CMS rollback source')
|
||||
installed, metadata = cms_application_inventory()
|
||||
# v1 is additive: deleting an application file requires a reviewed transition.
|
||||
if not set(installed) <= set(entries):die('CMS v1 release cannot remove existing application files')
|
||||
cms_healthchecks()
|
||||
return {'descriptor':d,'entries':list(entries),'predecessor':previous['sourceCommit'],
|
||||
'runtime':cms_runtime_snapshot(),'otherServices':cms_other_services(),
|
||||
'foundation':cms_foundation(),'data':cms_preserved_data(),'installedFiles':installed}
|
||||
'foundation':cms_foundation(),'data':cms_preserved_data(),'installedFiles':installed,'installedMetadata':metadata}
|
||||
|
||||
|
||||
def build_cms_release(before):
|
||||
@@ -164,9 +196,17 @@ def run_cms_release_compose():
|
||||
|
||||
|
||||
def cms_image_files(identity):
|
||||
script="const fs=require('fs'),p=require('path'),c=require('crypto'),r={};for(const d of ['admin','server'])for(const n of fs.readdirSync('/app/'+d)){const f='/app/'+d+'/'+n;if(!fs.lstatSync(f).isFile())throw Error('unexpected runtime path');r[d+'/'+n]=c.createHash('sha256').update(fs.readFileSync(f)).digest('hex')}process.stdout.write(JSON.stringify(r))"
|
||||
script="""const fs=require('fs'),c=require('crypto'),r={};
|
||||
for(const d of ['admin','server'])for(const n of fs.readdirSync('/app/'+d)){
|
||||
const rel=d+'/'+n,f='/app/'+rel,s=fs.lstatSync(f);
|
||||
if(s.isFile())r[rel]=c.createHash('sha256').update(fs.readFileSync(f)).digest('hex');
|
||||
else if(n==='@eaDir'&&s.isDirectory())for(const m of fs.readdirSync(f)){
|
||||
const q=f+'/'+m;if(!fs.lstatSync(q).isFile())throw Error('unexpected runtime metadata path');
|
||||
r[rel+'/'+m]=c.createHash('sha256').update(fs.readFileSync(q)).digest('hex');
|
||||
}else throw Error('unexpected runtime path');
|
||||
}process.stdout.write(JSON.stringify(r))"""
|
||||
proc=subprocess.run([str(DOCKER),'exec',identity,'node','-e',script],capture_output=True,text=True,check=True,timeout=30)
|
||||
return json.loads(proc.stdout)
|
||||
return cms_without_synology_metadata(json.loads(proc.stdout), 'CMS running image')[0]
|
||||
|
||||
|
||||
def accept_cms_release(before, *, rollback=False):
|
||||
@@ -180,7 +220,8 @@ def accept_cms_release(before, *, rollback=False):
|
||||
expected_foundation=before['foundation'] if rollback else {**CMS_FOUNDATION,'infra/.env.synology':before['foundation']['infra/.env.synology']}
|
||||
if cms_other_services()!=before['otherServices'] or cms_foundation()!=expected_foundation or cms_preserved_data()!=before['data']:
|
||||
die('CMS release changed preserved applications or project data')
|
||||
actual=collect_exact_files(CMS_ROOT,('admin','server',*CMS_DEPENDENCY_FILES),'CMS installed app')
|
||||
actual, metadata=cms_application_inventory()
|
||||
if metadata != before['installedMetadata']:die('CMS release changed preserved Synology metadata')
|
||||
if rollback:
|
||||
if actual!=before['installedFiles']:die('CMS rollback source mismatch')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user