From 1ea825c6434dd667f8b98287841e15b1f0d78301 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Wed, 10 Aug 2011 16:06:45 -0700 Subject: [PATCH] teuthology-nuke: split the big main function It was getting a bit big, but now all the functions fit on one screen each. Signed-off-by: Greg Farnum --- teuthology/nuke.py | 106 +++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/teuthology/nuke.py b/teuthology/nuke.py index 200fc713ed72f..b6907e32acae3 100644 --- a/teuthology/nuke.py +++ b/teuthology/nuke.py @@ -32,39 +32,7 @@ def parse_args(): args = parser.parse_args() return args -def main(): - from gevent import monkey; monkey.patch_all() - from orchestra import monkey; monkey.patch_all() - - import logging - import time - - log = logging.getLogger(__name__) - - ctx = parse_args() - - loglevel = logging.INFO - if ctx.verbose: - loglevel = logging.DEBUG - - logging.basicConfig( - level=loglevel, - ) - - from teuthology.misc import read_config - read_config(ctx) - - log.info('\n '.join(['targets:', ] + yaml.safe_dump(ctx.config['targets'], default_flow_style=False).splitlines())) - - if ctx.owner is None: - from teuthology.misc import get_user - ctx.owner = get_user() - - from teuthology.task.internal import check_lock, connect - check_lock(ctx, None) - connect(ctx, None) - - log.info('Unmount cfuse and killing daemons...') +def shutdown_daemons(ctx, log): from orchestra import run nodes = {} for remote in ctx.cluster.remotes.iterkeys(): @@ -102,8 +70,9 @@ def main(): for name, proc in nodes.iteritems(): log.info('Waiting for %s to finish shutdowns...', name) proc.exitstatus.get() - log.info('All daemons killed.') +def find_kernel_mounts(ctx, log): + from orchestra import run nodes = {} log.info('Looking for kernel mounts to handle...') for remote in ctx.cluster.remotes.iterkeys(): @@ -122,9 +91,15 @@ def main(): kernel_mounts.append(remote) except run.CommandFailedError: # no mounts! log.debug('no kernel mount on %s', remote.name) + + return kernel_mounts + +def remove_kernel_mounts(ctx, kernel_mounts, log): """ properly we should be able to just do a forced unmount, - but that doesn't seem to be working, so we'll reboot instead + but that doesn't seem to be working, so you should reboot instead + """ + from orchestra import run nodes = {} for remote in kernel_mounts: log.info('clearing kernel mount from %s', remote.name) @@ -133,15 +108,20 @@ def main(): 'grep', 'ceph', '/etc/mtab', run.Raw('|'), 'grep', '-o', "on /.* type", run.Raw('|'), 'grep', '-o', "/.* ", run.Raw('|'), - 'xargs', 'sudo', 'umount', '-f', run.Raw(';') + 'xargs', 'sudo', 'umount', '-f', run.Raw(';'), 'fi' - ] + ], wait=False ) nodes[remote] = proc - """ + + for remote, proc in nodes: + proc.exitstatus.get() + +def reboot_kernel_mounts(ctx, kernel_mounts, log): + from orchestra import run + import time nodes = {} - for remote in kernel_mounts: log.info('rebooting %s', remote.name) proc = remote.run( # note use of -n to force a no-sync reboot @@ -159,9 +139,9 @@ def main(): time.sleep(5) #if we try and reconnect too quickly, it succeeds! reconnect(ctx, 300) #allow 5 minutes for the reboots - +def remove_testing_tree(ctx, log): + from orchestra import run nodes = {} - log.info('Clearing filesystem of test data...') for remote in ctx.cluster.remotes.iterkeys(): proc = remote.run( args=[ @@ -174,4 +154,48 @@ def main(): for name, proc in nodes.iteritems(): log.info('Waiting for %s to clear filesystem...', name) proc.exitstatus.get() + +def main(): + from gevent import monkey; monkey.patch_all() + from orchestra import monkey; monkey.patch_all() + + import logging + + log = logging.getLogger(__name__) + + ctx = parse_args() + + loglevel = logging.INFO + if ctx.verbose: + loglevel = logging.DEBUG + + logging.basicConfig( + level=loglevel, + ) + + from teuthology.misc import read_config + read_config(ctx) + + log.info('\n '.join(['targets:', ] + yaml.safe_dump(ctx.config['targets'], default_flow_style=False).splitlines())) + + if ctx.owner is None: + from teuthology.misc import get_user + ctx.owner = get_user() + + from teuthology.task.internal import check_lock, connect + check_lock(ctx, None) + connect(ctx, None) + + log.info('Unmount cfuse and killing daemons...') + shutdown_daemons(ctx, log) + log.info('All daemons killed.') + + log.info('Dealing with any kernel mounts...') + kernel_mounts = find_kernel_mounts(ctx, log) + #remove_kernel_mounts(ctx, kernel_mounts, log) + reboot_kernel_mounts(ctx, kernel_mounts, log) + log.info('All kernel mounts gone.') + + log.info('Clearing filesystem of test data...') + remove_testing_tree(ctx, log) log.info('Filesystem Cleared.') -- 2.39.5