]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/systemd: get rid of cStringIO for py3
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Fri, 21 Feb 2020 19:59:47 +0000 (20:59 +0100)
committerKefu Chai <kchai@redhat.com>
Wed, 4 Mar 2020 05:09:17 +0000 (13:09 +0800)
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
qa/tasks/systemd.py

index f9a4558ae6a0f826917c64471fa197fc738a9fee..745f503c903fe3e8e61d923d53f5fe2baf416d4b 100644 (file)
@@ -6,12 +6,15 @@ import logging
 import re
 import time
 
-from cStringIO import StringIO
 from teuthology.orchestra import run
 from teuthology.misc import reconnect, get_first_mon, wait_until_healthy
 
 log = logging.getLogger(__name__)
 
+def _remote_service_status(remote, service):
+    status = remote.sh('sudo systemctl status %s' % service,
+                       check_status=False)
+    return status
 
 @contextlib.contextmanager
 def task(ctx, config):
@@ -26,11 +29,10 @@ def task(ctx, config):
     for remote, roles in ctx.cluster.remotes.items():
         remote.run(args=['sudo', 'ps', '-eaf', run.Raw('|'),
                          'grep', 'ceph'])
-        r = remote.run(args=['sudo', 'systemctl', 'list-units', run.Raw('|'),
-                             'grep', 'ceph'], stdout=StringIO(),
-                       check_status=False)
-        log.info(r.stdout.getvalue())
-        if r.stdout.getvalue().find('failed'):
+        units = remote.sh('sudo systemctl list-units | grep ceph',
+                          check_status=False)
+        log.info(units)
+        if units.find('failed'):
             log.info("Ceph services in failed state")
 
         # test overall service stop and start using ceph.target
@@ -38,29 +40,25 @@ def task(ctx, config):
         # and not actual process testing using 'ps'
         log.info("Stopping all Ceph services")
         remote.run(args=['sudo', 'systemctl', 'stop', 'ceph.target'])
-        r = remote.run(args=['sudo', 'systemctl', 'status', 'ceph.target'],
-                       stdout=StringIO(), check_status=False)
-        log.info(r.stdout.getvalue())
+        status = _remote_service_status(remote, 'ceph.target')
+        log.info(status)
         log.info("Checking process status")
-        r = remote.run(args=['sudo', 'ps', '-eaf', run.Raw('|'),
-                             'grep', 'ceph'], stdout=StringIO())
-        if r.stdout.getvalue().find('Active: inactive'):
+        ps_eaf = remote.sh('sudo ps -eaf | grep ceph')
+        if ps_eaf.find('Active: inactive'):
             log.info("Successfully stopped all ceph services")
         else:
             log.info("Failed to stop ceph services")
 
         log.info("Starting all Ceph services")
         remote.run(args=['sudo', 'systemctl', 'start', 'ceph.target'])
-        r = remote.run(args=['sudo', 'systemctl', 'status', 'ceph.target'],
-                       stdout=StringIO())
-        log.info(r.stdout.getvalue())
-        if r.stdout.getvalue().find('Active: active'):
+        status = _remote_service_status(remote, 'ceph.target')
+        log.info(status)
+        if status.find('Active: active'):
             log.info("Successfully started all Ceph services")
         else:
             log.info("info", "Failed to start Ceph services")
-        r = remote.run(args=['sudo', 'ps', '-eaf', run.Raw('|'),
-                             'grep', 'ceph'], stdout=StringIO())
-        log.info(r.stdout.getvalue())
+        ps_eaf = remote.sh('sudo ps -eaf | grep ceph')
+        log.info(ps_eaf)
         time.sleep(4)
 
         # test individual services start stop
@@ -79,23 +77,20 @@ def task(ctx, config):
             remote.run(args=['sudo', 'systemctl', 'stop',
                              osd_service])
             time.sleep(4)  # immediate check will result in deactivating state
-            r = remote.run(args=['sudo', 'systemctl', 'status', osd_service],
-                           stdout=StringIO(), check_status=False)
-            log.info(r.stdout.getvalue())
-            if r.stdout.getvalue().find('Active: inactive'):
+            status = _remote_service_status(remote, osd_service)
+            log.info(status)
+            if status.find('Active: inactive'):
                 log.info("Successfully stopped single osd ceph service")
             else:
                 log.info("Failed to stop ceph osd services")
-            remote.run(args=['sudo', 'systemctl', 'start',
-                             osd_service])
+            remote.sh(['sudo', 'systemctl', 'start', osd_service])
             time.sleep(4)
         if mon_role_name in roles:
             remote.run(args=['sudo', 'systemctl', 'status', mon_name])
             remote.run(args=['sudo', 'systemctl', 'stop', mon_name])
             time.sleep(4)  # immediate check will result in deactivating state
-            r = remote.run(args=['sudo', 'systemctl', 'status', mon_name],
-                           stdout=StringIO(), check_status=False)
-            if r.stdout.getvalue().find('Active: inactive'):
+            status = _remote_service_status(remote, mon_name)
+            if status.find('Active: inactive'):
                 log.info("Successfully stopped single mon ceph service")
             else:
                 log.info("Failed to stop ceph mon service")
@@ -105,9 +100,8 @@ def task(ctx, config):
             remote.run(args=['sudo', 'systemctl', 'status', mgr_name])
             remote.run(args=['sudo', 'systemctl', 'stop', mgr_name])
             time.sleep(4)  # immediate check will result in deactivating state
-            r = remote.run(args=['sudo', 'systemctl', 'status', mgr_name],
-                           stdout=StringIO(), check_status=False)
-            if r.stdout.getvalue().find('Active: inactive'):
+            status = _remote_service_status(remote, mgr_name)
+            if status.find('Active: inactive'):
                 log.info("Successfully stopped single ceph mgr service")
             else:
                 log.info("Failed to stop ceph mgr service")
@@ -117,9 +111,8 @@ def task(ctx, config):
             remote.run(args=['sudo', 'systemctl', 'status', mds_name])
             remote.run(args=['sudo', 'systemctl', 'stop', mds_name])
             time.sleep(4)  # immediate check will result in deactivating state
-            r = remote.run(args=['sudo', 'systemctl', 'status', mds_name],
-                           stdout=StringIO(), check_status=False)
-            if r.stdout.getvalue().find('Active: inactive'):
+            status = _remote_service_status(remote, mds_name)
+            if status.find('Active: inactive'):
                 log.info("Successfully stopped single ceph mds service")
             else:
                 log.info("Failed to stop ceph mds service")