Add guarded Arrakis DuneGroups cutover and rollback
This commit is contained in:
parent
c111baba8f
commit
2e46113a99
5 changed files with 88 additions and 5 deletions
|
|
@ -30,6 +30,7 @@ jobs:
|
|||
set -euo pipefail
|
||||
gradle --no-daemon -p JarvisConnector test jar
|
||||
gradle --no-daemon -p DuneGroups test jar
|
||||
python3 tools/test_plugin_dunegroups.py -v
|
||||
mkdir dunegroups-artifacts
|
||||
cp JarvisConnector/build/libs/jarvistranslator.jar DuneGroups/build/libs/DuneGroups.jar dunegroups-artifacts/
|
||||
cp tools/{plugin_dunegroups,install-plugin-fleet,write-plugin-manifest,plugin_menu_pack,plugin_backend_abi,plugin_fleet_rollback,plugin_pack_properties,plugin_pillager_abi}.py dunegroups-artifacts/
|
||||
|
|
|
|||
|
|
@ -75,9 +75,10 @@ def verify_dunechest_fleet_target(sid, root, unit, incoming, installed):
|
|||
|
||||
def plan(artifacts, inventory, expected_source):
|
||||
mode=inventory.get('mode')
|
||||
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus','lobby-food','lobby-account'}:
|
||||
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus','lobby-food','lobby-account','arrakis-dunegroups'}:
|
||||
raise ValueError('An explicit supported rollout mode is required')
|
||||
compact_menus=mode=='compact-menus'
|
||||
dunegroups=mode=='arrakis-dunegroups'
|
||||
lobby_food=mode=='lobby-food'
|
||||
lobby_account=mode=='lobby-account'
|
||||
jerboa=mode=='arrakis-jerboa'
|
||||
|
|
@ -108,6 +109,10 @@ def plan(artifacts, inventory, expected_source):
|
|||
allowed_names={'JarvisTranslator'}
|
||||
if inventory.get('menuPack') is not None:
|
||||
raise ValueError('Scoped JARVIS rollout must retain current resource pack configuration')
|
||||
if dunegroups:
|
||||
allowed_names={'JarvisTranslator','DuneGroups'}
|
||||
if inventory.get('menuPack') is not None or inventory.get('privatePrerequisites'):
|
||||
raise ValueError('DuneGroups must retain pack configuration and unrelated runtimes')
|
||||
files, names = {}, set()
|
||||
for entry in manifest['plugins']:
|
||||
name = entry['filename']
|
||||
|
|
@ -174,7 +179,7 @@ def plan(artifacts, inventory, expected_source):
|
|||
uses_menu=not compact_menus and ('dunemenus' in wanted or bool(menu and menu.get('unified') and not (crysknife or dunechest or jerboa)))
|
||||
if menu and menu.get('unified') and not (crysknife or dunechest or jerboa) and 'dunerealmsgui' not in wanted:
|
||||
raise ValueError('Unified pack rollout must select its matching DunerealmsGUI adapter')
|
||||
if not (pillager or crysknife or navigator or dunechest or raw_spice or jerboa or lobby_food or lobby_account) and wanted - {'dunemenus','dunerealmsgui','dunenpc','dunelobby','mcgui'}:
|
||||
if not (pillager or crysknife or navigator or dunechest or raw_spice or jerboa or lobby_food or lobby_account or dunegroups) and wanted - {'dunemenus','dunerealmsgui','dunenpc','dunelobby','mcgui'}:
|
||||
raise ValueError('GUI rollout must retain working Ess/JARVIS/Core/Terrain binaries')
|
||||
if compact_menus:
|
||||
expected_root = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid
|
||||
|
|
@ -187,6 +192,9 @@ def plan(artifacts, inventory, expected_source):
|
|||
if raw_spice and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service'
|
||||
or wanted != {'jarvistranslator'} or selected_prerequisites):
|
||||
raise ValueError('Raw spice rollout may only replace JARVIS on Arrakis')
|
||||
if dunegroups and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service'
|
||||
or wanted != {'jarvistranslator','dunegroups'} or selected_prerequisites):
|
||||
raise ValueError('DuneGroups canary requires the exact Arrakis service and approved plugin pair')
|
||||
if lobby_food and (sid != 'lobby' or root != Path('/opt/dunerealms/lobby') or unit != 'dune-lobby.service'
|
||||
or wanted != {'jarvistranslator'} or selected_prerequisites):
|
||||
raise ValueError('Lobby food rollout may only replace JARVIS on Lobby')
|
||||
|
|
@ -399,6 +407,32 @@ def plan(artifacts, inventory, expected_source):
|
|||
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
|
||||
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
|
||||
configurations = []
|
||||
if dunegroups:
|
||||
from plugin_dunegroups import CONFIG_BASELINE, VENDORS, enable_backend, transition, verify_artifact
|
||||
incoming = {entry['name'].casefold(): entry for entry in chosen}
|
||||
upstream = artifacts / 'upstream'
|
||||
verify_artifact(upstream, expected_source)
|
||||
installed = existing_paths.get('jarvistranslator')
|
||||
if installed is None or 'dunegroups' in existing_paths or 'worldguard' not in existing_paths:
|
||||
raise ValueError('DuneGroups canary requires retained JARVIS, WorldGuard and a first installation')
|
||||
if digest(upstream/'DuneGroups.jar') != incoming['dunegroups']['sha256']:
|
||||
raise ValueError('DuneGroups differs from the canonical build')
|
||||
transition(installed, upstream/'jarvistranslator.jar', Path(incoming['jarvistranslator']['source']))
|
||||
for identity_key, (filename, sha) in VENDORS.items():
|
||||
vendor = existing_paths.get(identity_key)
|
||||
if vendor is None or vendor.name != filename or digest(vendor) != sha:
|
||||
raise ValueError('Unexpected retiring vendor runtime: '+identity_key)
|
||||
previous.append({'filename': filename, 'sha256': sha, 'metadata': metadata(vendor)})
|
||||
replaced = {entry['filename'] for entry in previous}
|
||||
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
|
||||
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
|
||||
config = plugins/'JarvisTranslator/config.yml'
|
||||
if config.is_symlink() or config.parent.is_symlink() or digest(config) != CONFIG_BASELINE:
|
||||
raise ValueError('Unexpected private Arrakis JARVIS config revision')
|
||||
updated = enable_backend(config.read_bytes().decode('utf-8')).encode('utf-8')
|
||||
configurations.append({'path': 'JarvisTranslator/config.yml', 'transform': 'enable-dunegroups',
|
||||
'sha256': hashlib.sha256(updated).hexdigest(),
|
||||
'previousSha256': CONFIG_BASELINE, 'previousMetadata': metadata(config)})
|
||||
if uses_menu or crysknife or dunechest or jerboa:
|
||||
if menu is None:
|
||||
raise ValueError('DuneMenus requires a verified published built menu overlay')
|
||||
|
|
@ -503,8 +537,15 @@ def apply(deployment, backup_root, control=systemctl):
|
|||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
if new_parent:
|
||||
set_owner(target.parent, plugins.stat(), 0o750)
|
||||
target.write_bytes(config['content'].encode())
|
||||
set_owner(target, plugins.stat(), 0o640)
|
||||
if config.get('transform') == 'enable-dunegroups':
|
||||
from plugin_dunegroups import enable_backend
|
||||
if digest(target) != config['previousSha256']:
|
||||
raise ValueError('Private JARVIS config changed after service stop')
|
||||
target.write_bytes(enable_backend(target.read_bytes().decode('utf-8')).encode('utf-8'))
|
||||
restore_metadata(target, config['previousMetadata'])
|
||||
else:
|
||||
target.write_bytes(config['content'].encode())
|
||||
set_owner(target, plugins.stat(), 0o640)
|
||||
if digest(target) != config['sha256']:
|
||||
raise RuntimeError('Written menu configuration hash differs')
|
||||
for old in server['previous']:
|
||||
|
|
|
|||
|
|
@ -4,10 +4,16 @@ import argparse
|
|||
from copy import copy
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import re
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
BASELINE = '883969e04ef6a3436e6ebef54112d16a1311555226b386ae75a8c1199556c7ca'
|
||||
CONFIG_BASELINE = 'c90db002680004ac5784fdb3fdb38a6ccc0e6b9018a3bdcb6abfb109fc5d4a14'
|
||||
VENDORS = {
|
||||
'towny': ('Towny-0.103.2.0.jar', 'c8d7d59984eaf2606fce4192e860f7f969f3384e5a51b26b97225efbbe747c70'),
|
||||
'medievalfactions': ('medieval-factions-11.1.0-all.jar', 'a3d5d448a15c3a864e90db659342782584bc3284b434ff926f21019d51e3350e'),
|
||||
}
|
||||
PREFIX = 'com/dunerealms/jarvis/'
|
||||
REPLACED = {
|
||||
PREFIX + name + '.class' for name in
|
||||
|
|
@ -26,6 +32,18 @@ def digest(path):
|
|||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def enable_backend(config):
|
||||
headers = list(re.finditer(r'(?m)^native:[ \t]*(?:#[^\r\n]*)?(\r?\n)', config))
|
||||
if len(headers) != 1:
|
||||
raise ValueError('Expected exactly one native config section')
|
||||
header = headers[0]
|
||||
nested = re.match(r'(?m)(?:[ \t]+[^\r\n]*\r?\n|[ \t]*\r?\n)*', config[header.end():])[0]
|
||||
key = re.search(r'(?m)^([ ]+)server-key:[ \t]*arrakis[ \t]*(?:#[^\r\n]*)?\r?$', nested)
|
||||
if not key or re.search(r'(?m)^\s+backend\s*:', nested):
|
||||
raise ValueError('Expected the Arrakis native config without a backend override')
|
||||
return config[:header.end()] + key[1] + 'backend: dunegroups' + header[1] + config[header.end():]
|
||||
|
||||
|
||||
def names(archive):
|
||||
records = archive.namelist()
|
||||
if len(set(records)) != len(records):
|
||||
|
|
|
|||
|
|
@ -54,7 +54,10 @@ def rollback_receipt(receipt_path, expected_source, apply=False, run=control, le
|
|||
configs=server.get('configurations',[])
|
||||
for entry in configs:
|
||||
relative=entry['path']
|
||||
if relative not in ('MCGUI/config.yml','DunerealmsGUI/menu-pack.yml'):raise ValueError('Unsafe rollback configuration path')
|
||||
private_jarvis = (relative == 'JarvisTranslator/config.yml' and entry.get('transform') == 'enable-dunegroups'
|
||||
and server['id'] == 'arrakis' and root == Path('/opt/dunerealms/servers/arrakis'))
|
||||
if relative not in ('MCGUI/config.yml','DunerealmsGUI/menu-pack.yml') and not private_jarvis:
|
||||
raise ValueError('Unsafe rollback configuration path')
|
||||
current=plugins/relative
|
||||
if current.is_symlink() or current.parent.is_symlink():raise ValueError('Symlinked rollback configuration')
|
||||
if current.exists() and digest(current) not in (entry['sha256'],entry['previousSha256']):raise ValueError('Configuration changed since deployment')
|
||||
|
|
|
|||
20
tools/test_plugin_dunegroups.py
Normal file
20
tools/test_plugin_dunegroups.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
|
||||
from plugin_dunegroups import enable_backend
|
||||
|
||||
|
||||
class DuneGroupsConfigurationTest(unittest.TestCase):
|
||||
def test_only_backend_line_is_inserted(self):
|
||||
source = 'native: # settings\r\n server-key: arrakis\r\nlimits:\r\n enabled: true\r\n'
|
||||
expected = source.replace(' server-key:', ' backend: dunegroups\r\n server-key:')
|
||||
self.assertEqual(enable_backend(source), expected)
|
||||
|
||||
def test_wrong_server_or_existing_backend_is_rejected(self):
|
||||
for source in ('native:\n server-key: caladan\n',
|
||||
'native:\n backend: legacy\n server-key: arrakis\n'):
|
||||
with self.subTest(source=source), self.assertRaises(ValueError):
|
||||
enable_backend(source)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in a new issue

Staff