From a2ce966d3ea9fb7a9cdf0bfb8d48d43c18b955a6 Mon Sep 17 00:00:00 2001 From: Vasu Kulkarni Date: Wed, 18 May 2016 14:32:59 -0700 Subject: [PATCH] Systemd script to test ceph init files Signed-off-by: Vasu Kulkarni --- tasks/systemd.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tasks/systemd.py diff --git a/tasks/systemd.py b/tasks/systemd.py new file mode 100644 index 0000000000000..f74db4a2bdfb1 --- /dev/null +++ b/tasks/systemd.py @@ -0,0 +1,103 @@ +""" +Systemd test +""" +import contextlib +import logging +import re +import time + +from cStringIO import StringIO +from teuthology.orchestra import run + +log = logging.getLogger(__name__) + + +@contextlib.contextmanager +def task(ctx, config): + """ + - tasks: + ceph-deploy: + systemd: + + Test ceph systemd services can start, stop and restart and + check for any failed services and report back errors + """ + for remote, roles in ctx.cluster.remotes.iteritems(): + 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'): + log.info("Ceph services in failed state") + + # test overall service stop and start + 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()) + if r.stdout.getvalue().find('Active: inactive'): + log.info("Sucessfully 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'): + log.info("Sucessfully 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()) + time.sleep(4) + # test individual services start stop + name = remote.shortname + mon_name = 'ceph-mon@' + name + '.service' + mds_name = 'ceph-mds@' + name + '.service' + mon_role_name = 'mon.' + name + mds_role_name = 'mds.' + name + m_osd = re.search('--id (\d+) --setuser ceph', r.stdout.getvalue()) + if m_osd: + osd_service = 'ceph-osd@{m}.service'.format(m=m_osd.group(1)) + remote.run(args=['sudo', 'systemctl', 'status', + osd_service]) + remote.run(args=['sudo', 'systemctl', 'stop', + osd_service]) + 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'): + log.info("Sucessfully stopped single osd ceph service") + else: + log.info("Failed to stop ceph osd services") + remote.run(args=['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]) + r = remote.run(args=['sudo', 'systemctl', 'status', 'ceph.target'], + stdout=StringIO(), check_status=False) + if r.stdout.getvalue().find('Active: inactive'): + log.info("Sucessfully stopped single mon ceph service") + else: + log.info("Failed to stop ceph mon service") + remote.run(args=['sudo', 'systemctl', 'start', mon_name]) + time.sleep(4) + if mds_role_name in roles: + remote.run(args=['sudo', 'systemctl', 'status', mds_name]) + remote.run(args=['sudo', 'systemctl', 'stop', mds_name]) + r = remote.run(args=['sudo', 'systemctl', 'status', 'ceph.target'], + stdout=StringIO(), check_status=False) + if r.stdout.getvalue().find('Active: inactive'): + log.info("Sucessfully stopped single ceph mds service") + else: + log.info("Failed to stop ceph mds service") + remote.run(args=['sudo', 'systemctl', 'start', mds_name]) + time.sleep(4) + yield -- 2.39.5