From: Alfredo Deza Date: Mon, 22 Jul 2013 21:51:53 +0000 (-0400) Subject: make it easier to test our new helper by extracting it X-Git-Tag: v1.2~27^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0d574761a2b08b0fa9acf60e02ac6a718afa0324;p=ceph-deploy.git make it easier to test our new helper by extracting it --- diff --git a/ceph_deploy/mon.py b/ceph_deploy/mon.py index 0748569..f57a067 100644 --- a/ceph_deploy/mon.py +++ b/ceph_deploy/mon.py @@ -1,6 +1,7 @@ import ConfigParser import logging import re +import subprocess from cStringIO import StringIO @@ -147,9 +148,9 @@ def mon_create(args): raise exc.GenericError('Failed to create %d monitors' % errors) -def destroy_mon(cluster, paths): +def destroy_mon(cluster, paths, is_running): import os - import subprocess + import subprocess # noqa import socket import time retries = 5 @@ -157,30 +158,6 @@ def destroy_mon(cluster, paths): hostname = socket.gethostname().split('.')[0] path = paths.mon.path(cluster, hostname) - def is_running(args): - """ - Run a command to check the status of a mon, return a boolean. - - We heavily depend on the format of the output, if that ever changes - we need to modify this. - Check daemon status for 3 times - output of the status should be similar to:: - - mon.mira094: running {"version":"0.61.5"} - - or when it fails:: - - mon.mira094: dead {"version":"0.61.5"} - mon.mira094: not running {"version":"0.61.5"} - """ - proc = subprocess.Popen( - args=args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - result = proc.communicate() - return ': running' in ' '.join(result) - if os.path.exists(path): # remove from cluster proc = subprocess.Popen( @@ -254,6 +231,7 @@ def mon_destroy(args): destroy_mon_r( cluster=args.cluster, paths=paths, + is_running=is_running, ) sudo.close() @@ -273,6 +251,7 @@ def mon(args): else: LOG.error('subcommand %s not implemented', args.subcommand) + @priority(30) def make(parser): """ @@ -296,3 +275,36 @@ def make(parser): parser.set_defaults( func=mon, ) + +# +# Helpers +# + + +def is_running(args): + """ + Run a command to check the status of a mon, return a boolean. + + We heavily depend on the format of the output, if that ever changes + we need to modify this. + Check daemon status for 3 times + output of the status should be similar to:: + + mon.mira094: running {"version":"0.61.5"} + + or when it fails:: + + mon.mira094: dead {"version":"0.61.5"} + mon.mira094: not running {"version":"0.61.5"} + """ + proc = subprocess.Popen( + args=args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + result = proc.communicate() + result_string = ' '.join(result) + for run_check in [': running', ' start/running']: + if run_check in result_string: + return True + return False