Add ZKSchema loading and validation to Daemon

Also removes some previous hack migrations from pre-0.9.19.

Addresses #129
This commit is contained in:
Joshua Boniface 2021-06-08 22:19:47 -04:00
parent 602dd7b714
commit a4aaf89681
1 changed files with 12 additions and 33 deletions

View File

@ -40,7 +40,7 @@ from queue import Queue
from xml.etree import ElementTree from xml.etree import ElementTree
from rados import Rados from rados import Rados
from daemon_lib.zkhandler import ZKHandler from daemon_lib.zkhandler import ZKHandler, ZKSchema
import pvcnoded.fencing as fencing import pvcnoded.fencing as fencing
import daemon_lib.log as log import daemon_lib.log as log
@ -529,39 +529,18 @@ except Exception as e:
logger.out('ERROR: Failed to connect to Zookeeper cluster: {}'.format(e), state='e') logger.out('ERROR: Failed to connect to Zookeeper cluster: {}'.format(e), state='e')
exit(1) exit(1)
# Create the /config key if it does not exist logger.out('Validating Zookeeper schema', state='i')
try:
zkhandler.read('/config') # Instantiate a zkschema instance with our current schema version
except Exception: zkschema = ZKSchema.load_current(zkhandler)
zkhandler.write([
('/config', ''), # Validate our schema against that version
('/config/primary_node', 'none'), if not zkschema.validate(zkhandler, logger):
('/config/upstream_ip', 'none'), logger.out('Found schema violations, applying', state='i')
('/config/maintenance', 'False'), zkschema.apply(zkhandler)
]) else:
logger.out('Schema successfully validated', state='o')
# MIGRATION - populate the keys from their old values
try:
primary_node = zkhandler.read('/primary_node')
zkhandler.write([
('/config/primary_node', primary_node)
])
except Exception:
pass
try:
upstream_ip = zkhandler.read('/upstream_ip')
zkhandler.write([
('/config/upstream_ip', upstream_ip)
])
except Exception:
pass
try:
maintenance = zkhandler.read('/maintenance')
zkhandler.write([
('/config/maintenance', maintenance)
])
except Exception:
pass
############################################################################### ###############################################################################
# PHASE 5 - Gracefully handle termination # PHASE 5 - Gracefully handle termination