]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
make it easier to test our new helper by extracting it
authorAlfredo Deza <alfredo@deza.pe>
Mon, 22 Jul 2013 21:51:53 +0000 (17:51 -0400)
committerAlfredo Deza <alfredo@deza.pe>
Mon, 22 Jul 2013 21:51:53 +0000 (17:51 -0400)
ceph_deploy/mon.py

index 0748569170eb28a9222b17878e384c5decc5b629..f57a06797e1b47878d772f5f9b852c1e5fd4b72f 100644 (file)
@@ -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