From ad284b13bce8f5b65e57aff491e76a2eac085f76 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 9 Jul 2019 19:17:53 -0400 Subject: [PATCH] Fix bugs with fencing --- node-daemon/pvcd/fencing.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/node-daemon/pvcd/fencing.py b/node-daemon/pvcd/fencing.py index 32996335..2b74bc12 100644 --- a/node-daemon/pvcd/fencing.py +++ b/node-daemon/pvcd/fencing.py @@ -77,29 +77,32 @@ def migrateFromFencedNode(zk_conn, node_name, logger): logger.out('Moving VMs from dead node "{}" to new hosts'.format(node_name), state='i') dead_node_running_domains = zkhandler.readdata(zk_conn, '/nodes/{}/runningdomains'.format(node_name)).split() for dom_uuid in dead_node_running_domains: - target_node = findTargetHypervisor(zk_conn, 'mem', dom_uuid) - logger.out('Flushing RBD locks for VM "{}"'.format(dom_uuid), state='i') # Get the list of RBD images rbd_list = zkhandler.readdata(zk_conn, '/domains/{}/rbdlist'.format(dom_uuid)).split(',') for rbd in rbd_list: # Check if a lock exists - retcode, stdout, stderr = common.run_os_command('rbd lock list --format json {}'.format(rbd)) - if not retcode: + lock_list_retcode, lock_list_stdout, lock_list_stderr = common.run_os_command('rbd lock list --format json {}'.format(rbd)) + if lock_list_retcode != 0: logger.out('Failed to obtain lock list for volume "{}"'.format(rbd), state='e') continue - lock_list = stdout + try: + lock_list = json.loads(lock_list_stdout) + except: + lock_list = {} + # If there's at least one lock if lock_list: # Loop through the locks for lock, detail in lock_list.items(): # Free the lock - retcode, stdout, stderr = common.run_os_command('rbd lock remove {} "{}" "{}"'.format(rbd, lock, detail['locker'])) - if not retcode: + lock_remove_retcode, lock_remove_stdout, lock_remove_stderr = common.run_os_command('rbd lock remove {} "{}" "{}"'.format(rbd, lock, detail['locker'])) + if lock_remove_retcode != 0: logger.out('Failed to free RBD lock "{}" on volume "{}"'.format(lock, rbd), state='e') continue logger.out('Freed RBD lock "{}" on volume "{}"'.format(lock, rbd), state='o') - + + target_node = common.findTargetHypervisor(zk_conn, 'mem', dom_uuid) logger.out('Migrating VM "{}" to node "{}"'.format(dom_uuid, target_node), state='i') zkhandler.writedata(zk_conn, {