summaryrefslogtreecommitdiffstats
path: root/examples/test_glusterd_ops.py
diff options
context:
space:
mode:
authorShwethaHP <spandura@redhat.com>2017-12-07 07:02:51 +0530
committerJonathan Holloway <jholloway@redhat.com>2018-01-16 06:19:06 +0000
commitc39a42140f328d12a605f5480d0e3c7a2d4c6308 (patch)
tree4fbc8e411f13b471aacb5604a9039b2ec8573ebb /examples/test_glusterd_ops.py
parent63890db6fa339aded7aaa86d99543570befc43da (diff)
Adding example files to demonstrate how to use functions available in
glustolibs-gluster libs Change-Id: I44f559dd0477f97278b1444e7a6d292ca58b99dc Signed-off-by: ShwethaHP <spandura@redhat.com>
Diffstat (limited to 'examples/test_glusterd_ops.py')
-rw-r--r--examples/test_glusterd_ops.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/examples/test_glusterd_ops.py b/examples/test_glusterd_ops.py
new file mode 100644
index 0000000..39cad71
--- /dev/null
+++ b/examples/test_glusterd_ops.py
@@ -0,0 +1,112 @@
+""" This Module demostrates how to use functions available in gluster_init
+ module
+"""
+from glusto.core import Glusto as g
+from glustolibs.gluster.gluster_base_class import GlusterBaseClass
+from glustolibs.gluster.exceptions import ExecutionError
+from glustolibs.gluster.gluster_init import (
+ is_glusterd_running, restart_glusterd, start_glusterd, stop_glusterd)
+
+
+class DemoGlusterInitClass(GlusterBaseClass):
+ """Demonstrating all the functions available in gluster_init module
+ """
+ @classmethod
+ def setUpClass(cls):
+ """
+ """
+ # Read all the cluster config from the g.config and assign it to
+ # class variables
+ GlusterBaseClass.setUpClass.im_func(cls)
+
+ def setUp(self):
+ """setUp required for tests
+ """
+ # Calling GlusterBaseClass setUp
+ GlusterBaseClass.setUp.im_func(self)
+
+ # Check if glusterd is running on all servers(expected: active)
+ g.log.info("Check if glusterd is running on all servers %s"
+ "(expected: active)", self.servers)
+ ret = is_glusterd_running(self.servers)
+ if ret == 0:
+ g.log.info("Glusterd is running on all servers %s", self.servers)
+ elif ret == 1:
+ g.log.info("Glusterd is not running on all the servers %s",
+ self.servers)
+ elif ret == -1:
+ g.log.info("Glusterd is not running on all the servers %s. "
+ "PID is alive", self.servers)
+
+ def test_glusterd_services(self):
+ """Test restart, stop, start of glusterd
+ """
+ # restart glusterd on all servers
+ g.log.info("Restart glusterd on all servers %s", self.servers)
+ ret = restart_glusterd(self.servers)
+ self.assertTrue(ret, ("Failed to restart glusterd on all servers %s",
+ self.servers))
+ g.log.info("Successfully restarted glusterd on all servers %s",
+ self.servers)
+
+ # Check if glusterd is running on all servers(expected: active)
+ g.log.info("Check if glusterd is running on all servers %s"
+ "(expected: active)", self.servers)
+ ret = is_glusterd_running(self.servers)
+ self.assertEqual(ret, 0, ("Glusterd is not running on all servers %s",
+ self.servers))
+ g.log.info("Glusterd is running on all the servers %s", self.servers)
+
+ # Stop glusterd on all servers
+ g.log.info("Stop glusterd on all servers %s", self.servers)
+ ret = stop_glusterd(self.servers)
+ self.assertTrue(ret, ("Failed to stop glusterd on all servers %s",
+ self.servers))
+ g.log.info("Successfully stopped glusterd on all servers %s",
+ self.servers)
+
+ # Check if glusterd is running on all servers(expected: not running)
+ g.log.info("Check if glusterd is running on all servers %s"
+ "(expected: not running)", self.servers)
+ ret = is_glusterd_running(self.servers)
+ self.assertNotEqual(ret, 0, ("Glusterd is still running on some "
+ "servers %s", self.servers))
+ g.log.info("Glusterd not running on any servers %s as expected.",
+ self.servers)
+
+ # Start glusterd on all servers
+ g.log.info("Start glusterd on all servers %s", self.servers)
+ ret = start_glusterd(self.servers)
+ self.assertTrue(ret, ("Failed to start glusterd on all servers %s",
+ self.servers))
+ g.log.info("Successfully started glusterd on all servers %s",
+ self.servers)
+
+ # Check if glusterd is running on all servers(expected: active)
+ g.log.info("Check if glusterd is running on all servers %s"
+ "(expected: active)", self.servers)
+ ret = is_glusterd_running(self.servers)
+ self.assertEqual(ret, 0, ("Glusterd is not running on all servers %s",
+ self.servers))
+ g.log.info("Glusterd is running on all the servers %s", self.servers)
+
+ def tearDown(self):
+ """restart glusterd on all servers during teardown
+ """
+ # restart glusterd on all servers
+ g.log.info("Restart glusterd on all servers %s", self.servers)
+ ret = restart_glusterd(self.servers)
+ if not ret:
+ raise ExecutionError("Failed to restart glusterd on all "
+ "servers %s", self.servers)
+ g.log.info("Successfully restarted glusterd on all servers %s",
+ self.servers)
+
+ # Calling GlusterBaseClass tearDown
+ GlusterBaseClass.tearDown.im_func(self)
+
+ @classmethod
+ def tearDownClass(cls):
+ """
+ """
+ GlusterBaseClass.tearDownClass.im_func(cls)