From a4aaf89681ce2166978d29e5382b9a8ddf686166 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 8 Jun 2021 22:19:47 -0400 Subject: [PATCH] Add ZKSchema loading and validation to Daemon Also removes some previous hack migrations from pre-0.9.19. Addresses #129 --- node-daemon/pvcnoded/Daemon.py | 45 +++++++++------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/node-daemon/pvcnoded/Daemon.py b/node-daemon/pvcnoded/Daemon.py index 676de2b2..45175b13 100644 --- a/node-daemon/pvcnoded/Daemon.py +++ b/node-daemon/pvcnoded/Daemon.py @@ -40,7 +40,7 @@ from queue import Queue from xml.etree import ElementTree from rados import Rados -from daemon_lib.zkhandler import ZKHandler +from daemon_lib.zkhandler import ZKHandler, ZKSchema import pvcnoded.fencing as fencing 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') exit(1) -# Create the /config key if it does not exist -try: - zkhandler.read('/config') -except Exception: - zkhandler.write([ - ('/config', ''), - ('/config/primary_node', 'none'), - ('/config/upstream_ip', 'none'), - ('/config/maintenance', 'False'), - ]) +logger.out('Validating Zookeeper schema', state='i') + +# Instantiate a zkschema instance with our current schema version +zkschema = ZKSchema.load_current(zkhandler) + +# Validate our schema against that version +if not zkschema.validate(zkhandler, logger): + logger.out('Found schema violations, applying', state='i') + 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