32 lines
2.4 KiB
Python
32 lines
2.4 KiB
Python
import os,json,subprocess,shutil,sqlite3
|
|
WORK='/opt/im-admin/deploy/knowledge-sections-20261105';DATA='/opt/im-admin/deploy/im-admin/data'
|
|
assert json.load(open(WORK+'/deployment-result.json'))['deployed']
|
|
assert len(json.load(open(WORK+'/verification-result.json'))['services_checked'])==3
|
|
state=json.load(open(WORK+'/prepared.json'))
|
|
names=[state['candidate'],'im-admin-knowledge-sections-api-bridge-20261105','im-admin-knowledge-sections-gateway-bridge-20261105']
|
|
remaining=subprocess.check_output(['docker','ps','-a','--format','{{.Names}}'],text=True).splitlines()
|
|
for name in names:
|
|
if name in remaining:
|
|
subprocess.run(['docker','stop','--time','35',name],check=True,stdout=subprocess.DEVNULL)
|
|
subprocess.run(['docker','rm',name],check=True,stdout=subprocess.DEVNULL)
|
|
candidate=WORK+'/candidate-data'
|
|
assert os.path.realpath(candidate)==candidate and candidate.startswith(WORK+'/') and os.path.basename(candidate)=='candidate-data'
|
|
if os.path.exists(candidate):shutil.rmtree(candidate)
|
|
runtime=DATA+'/group-identity/knowledge-sections-bridge-runtime.json'
|
|
if os.path.isfile(runtime):os.unlink(runtime)
|
|
for name in ['knowledge-sections-preflight-20261105.py','knowledge-sections-backup-20261105.py','knowledge-sections-source-before-20261105.json','knowledge-sections-release-20261105.tgz','knowledge-sections-release-20261105.json']:
|
|
p='/home/ps/'+name
|
|
if os.path.isfile(p):os.unlink(p)
|
|
with sqlite3.connect('file:'+DATA+'/backend.db?mode=ro',uri=True) as c:
|
|
assert c.execute("SELECT COUNT(*) FROM sqlite_master WHERE type='trigger' AND name='iam_deploy_knowledge_sections_20261105'").fetchone()[0]==0
|
|
jobs=dict(c.execute('SELECT status,COUNT(*) FROM knowledge_job GROUP BY status'))
|
|
reviews=dict(c.execute('SELECT status,COUNT(*) FROM knowledge_review_job GROUP BY status'))
|
|
result={'temporary_containers_removed':True,'candidate_database_tokens_and_key_copy_removed':True,'claim_hold_removed':True,'production_data_and_backup_retained':True,'jobs_after_resume':jobs,'review_jobs':reviews}
|
|
with open(WORK+'/cleanup-result.json','w') as f:json.dump(result,f,indent=2)
|
|
for name in ['prepared.json','candidate-checks.json','candidate-http-result.json','deployment-result.json','traffic-checks.json','verification-result.json','cleanup-result.json']:
|
|
p=WORK+'/'+name
|
|
if os.path.exists(p):
|
|
export='/home/ps/knowledge-sections-'+name
|
|
shutil.copy2(p,export);os.chown(export,1000,1000);os.chmod(export,0o600)
|
|
print(json.dumps(result))
|