summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs
diff options
context:
space:
mode:
authorSri Vignesh <sselvan@redhat.com>2019-05-02 09:07:55 +0530
committervamahaja <vamahaja@redhat.com>2019-08-12 16:12:49 +0530
commitcb815f13c7eab15e89a01e835337a0a5745bf118 (patch)
tree801c82de10bf5bc7afa9b729922d7cc1a6bad53a /openshift-storage-libs
parentaed2e7e9543969c604a61af020c8a5fbaf38cd04 (diff)
Move "node reboot" logic from test case to library
Separate node reboot functionality from single test case to re-use it at other places. Update test case accordingly. Change-Id: Ib9a7f15d29237e4f21aafc408c074e799e706740 Signed-off-by: Sri Vignesh <sselvan@redhat.com> Signed-off-by: vamahaja <vamahaja@redhat.com>
Diffstat (limited to 'openshift-storage-libs')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/node_ops.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/node_ops.py b/openshift-storage-libs/openshiftstoragelibs/node_ops.py
new file mode 100644
index 0000000..fb4aaa2
--- /dev/null
+++ b/openshift-storage-libs/openshiftstoragelibs/node_ops.py
@@ -0,0 +1,47 @@
+import time
+
+from glusto.core import Glusto as g
+
+from openshiftstoragelibs import exceptions
+from openshiftstoragelibs import waiter
+
+
+def node_reboot_by_command(node, timeout=600, wait_step=10):
+ """Reboot node and wait to start for given timeout.
+
+ Args:
+ node (str) : Node which needs to be rebooted.
+ timeout (int) : Seconds to wait before node to be started.
+ wait_step (int): Interval in seconds to wait before checking
+ status of node again.
+ """
+ cmd = "sleep 3; /sbin/shutdown -r now 'Reboot triggered by Glusto'"
+ ret, out, err = g.run(node, cmd)
+ if ret != 255:
+ err_msg = "failed to reboot host '%s' error %s" % (node, err)
+ g.log.error(err_msg)
+ raise AssertionError(err_msg)
+
+ try:
+ g.ssh_close_connection(node)
+ except Exception as e:
+ g.log.error("failed to close connection with host %s "
+ "with error: %s" % (node, e))
+ raise
+
+ # added sleep as node will restart after 3 sec
+ time.sleep(3)
+
+ for w in waiter.Waiter(timeout=timeout, interval=wait_step):
+ try:
+ if g.rpyc_get_connection(node, user="root"):
+ g.rpyc_close_connection(node, user="root")
+ return
+ except Exception as err:
+ g.log.info("exception while getting connection: '%s'" % err)
+
+ if w.expired:
+ error_msg = ("exceeded timeout %s sec, node '%s' is "
+ "not reachable" % (timeout, node))
+ g.log.error(error_msg)
+ raise exceptions.ExecutionError(error_msg)