summaryrefslogtreecommitdiffstats
path: root/glustolibs-misc
diff options
context:
space:
mode:
Diffstat (limited to 'glustolibs-misc')
-rwxr-xr-xglustolibs-misc/glustolibs/misc/misc_libs.py161
-rw-r--r--glustolibs-misc/setup.py32
2 files changed, 130 insertions, 63 deletions
diff --git a/glustolibs-misc/glustolibs/misc/misc_libs.py b/glustolibs-misc/glustolibs/misc/misc_libs.py
index 7b8010cd9..9f9225929 100755
--- a/glustolibs-misc/glustolibs/misc/misc_libs.py
+++ b/glustolibs-misc/glustolibs/misc/misc_libs.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2016 Red Hat, Inc. <http://www.redhat.com>
+# Copyright (C) 2015-2020 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,15 +16,16 @@
""" Description: Helper module for misc libs. """
-from glusto.core import Glusto as g
-from glustolibs.gluster.lib_utils import is_rhel7
import os
import sys
import time
+from glusto.core import Glusto as g
+from glustolibs.gluster.lib_utils import is_rhel6, is_rhel7
+
def create_dirs(list_of_nodes, list_of_dir_paths):
- """Creates directories on nodes.
+ """Create directories on nodes.
Args:
list_of_nodes (list): Nodes on which dirs has to be created.
@@ -55,7 +56,7 @@ def create_dirs(list_of_nodes, list_of_dir_paths):
def path_exists(list_of_nodes, list_of_paths):
- """check if paths exists on nodes.
+ """Check if paths exist on nodes.
Args:
list_of_nodes (list): List of nodes.
@@ -88,10 +89,10 @@ def path_exists(list_of_nodes, list_of_paths):
def upload_scripts(list_of_nodes, list_of_scripts_abs_path,
upload_dir="/usr/share/glustolibs/io/scripts/", user=None):
- """Uploads specified scripts to all the nodes.
+ """Upload specified scripts to all the nodes.
Args:
- list_of_nodes (list): Nodes on which scripts has to be uploaded.
+ list_of_nodes (list): Nodes on which scripts have to be uploaded.
list_of_scripts_abs_path (list): List of absolute path of all
scripts that are to be uploaded from local node.
upload_dir (optional[str]): Name of the dir under which
@@ -157,7 +158,7 @@ def yum_add_repos(list_of_nodes, list_of_yum_repos):
"""Add yum repo files on all the nodes.
Args:
- list_of_nodes (list): Nodes on which yum repo files has to be added.
+ list_of_nodes (list): Nodes on which yum repo files have to be added.
list_of_yum_repos (list): List of yum repos
Returns:
@@ -190,7 +191,7 @@ def yum_install_packages(list_of_nodes, yum_packages):
"""Install the specified yum packages on all nodes.
Args:
- list_of_nodes (list): Nodes on which yum packages has to be installed.
+ list_of_nodes (list): Nodes on which yum packages have to be installed.
yum_packages (list): List of yum packages.
Returns:
@@ -221,7 +222,7 @@ def yum_remove_packages(list_of_nodes, yum_packages):
"""Remove the specified yum packages on all nodes.
Args:
- list_of_nodes (list): Nodes on which yum packages has to be removed.
+ list_of_nodes (list): Nodes on which yum packages have to be removed.
yum_packages (list): List of yum packages.
Returns:
@@ -252,7 +253,7 @@ def pip_install_packages(list_of_nodes, python_packages):
"""Install the specified python packages on all the specified nodes.
Args:
- list_of_nodes (list): Nodes on which python packages has to be
+ list_of_nodes (list): Nodes on which python packages have to be
installed.
python_packages (list): List of python packages.
@@ -320,7 +321,7 @@ def install_testing_tools(list_of_nodes, testing_tools):
def install_arequal(list_of_nodes):
- """Installs arequal on nodes in /usr/bin/.
+ """Install arequal on nodes in /usr/bin/.
Args:
nodes(list): List of nodes on which arequal-checksum needs to be
@@ -340,8 +341,8 @@ def install_arequal(list_of_nodes):
list_of_nodes = [list_of_nodes]
try:
- arequal_repo = (g.config['dependencies']['testing_tools']['arequal']
- ['repo'])
+ arequal_repo = (g.config['dependencies']['testing_tools']
+ ['arequal']['repo'])
except KeyError:
arequal_repo = ("https://copr.fedorainfracloud.org/coprs/nigelbabu/"
"arequal/repo/epel-7/nigelbabu-arequal-epel-7.repo")
@@ -378,11 +379,10 @@ def install_arequal(list_of_nodes):
def are_nodes_online(nodes):
- """
- check whether nodes are online or not
+ """Check whether nodes are online or not.
Args:
- nodes ( str|list ) : Node/Nodes to check whether online or not
+ nodes (str|list): Node(s) to check whether online or not.
Returns:
tuple : Tuple containing two elements (ret, node_results).
@@ -394,7 +394,7 @@ def are_nodes_online(nodes):
then the result contains True else False.
"""
- if isinstance(nodes, str):
+ if not isinstance(nodes, list):
nodes = [nodes]
node_results = {}
@@ -414,17 +414,15 @@ def are_nodes_online(nodes):
def reboot_nodes(nodes):
- """
- reboot the nodes and checks whether nodes are offline or not
+ """Reboot the nodes and check whether nodes are offline or not.
Args:
- nodes ( str|list ) : Node/Nodes to reboot
+ nodes (str|list): Node(s) to reboot.
Returns:
- bool : '_rc' is of type 'bool', True if all nodes
- comes offline after reboot. False otherwise.
+ bool: True if all nodes come offline after reboot. False otherwise.
"""
- if isinstance(nodes, str):
+ if not isinstance(nodes, list):
nodes = [nodes]
cmd = "reboot"
@@ -454,12 +452,11 @@ def reboot_nodes(nodes):
return _rc
-def reboot_nodes_and_wait_to_come_online(nodes, timeout=300):
- """
- reboot the node and wait for node to come online
+def reboot_nodes_and_wait_to_come_online(nodes, timeout=600):
+ """Reboot node(s) and wait for it to become online.
Args:
- nodes ( str|list ) : Node/Nodes to reboot
+ nodes (str|list): Node(s) to reboot.
Kwargs:
timeout (int): timeout value in seconds to wait for node
@@ -508,11 +505,10 @@ def reboot_nodes_and_wait_to_come_online(nodes, timeout=300):
def are_nodes_offline(nodes):
- """
- check whether nodes are offline or not
+ """Check whether nodes are offline or not.
Args:
- nodes ( str|list ) : Node/Nodes to check whether offline or not
+ nodes (str|list): Node(s) to check whether offline or not.
Returns:
tuple : Tuple containing two elements (ret, node_results).
@@ -524,7 +520,7 @@ def are_nodes_offline(nodes):
then the result contains True else False.
"""
- if isinstance(nodes, str):
+ if not isinstance(nodes, list):
nodes = [nodes]
node_results = {}
@@ -544,7 +540,7 @@ def are_nodes_offline(nodes):
def drop_caches(hosts):
- """Drops Kernel Cache on a list of hosts
+ """Drop Kernel Cache on a list of hosts
(in order to run reads/renames etc on a cold cache).
Args:
@@ -552,12 +548,12 @@ def drop_caches(hosts):
dropped (Servers/ Clients)
Returns:
- bool : True , post successful completion.Else,False.
+ bool: True , post successful completion.Else,False.
"""
cmd = "echo 3 > /proc/sys/vm/drop_caches"
results = g.run_parallel(hosts, cmd)
_rc = True
- for host, ret_values in results.iteritems():
+ for host, ret_values in results.items():
retcode, _, _ = ret_values
if retcode != 0:
g.log.error("Unable to drop cache on host %s", host)
@@ -567,24 +563,23 @@ def drop_caches(hosts):
def daemon_reload(node):
- """
- Reloads the Daemons when unit files are changed
+ """Reload the Daemons when unit files are changed.
Args:
- node : Node on which daemon has to be reloaded
+ node (str): Node on which daemon has to be reloaded.
Returns:
- bool : True, On successful daemon reload
+ bool: True, On successful daemon reload
False, Otherwise
"""
- if is_rhel7([node]):
- cmd = "systemctl daemon-reload"
+ if is_rhel6([node]):
+ cmd = 'service glusterd reload'
ret, _, _ = g.run(node, cmd)
if ret != 0:
g.log.error("Failed to reload the daemon")
return False
else:
- cmd = 'service glusterd reload'
+ cmd = "systemctl daemon-reload"
ret, _, _ = g.run(node, cmd)
if ret != 0:
g.log.error("Failed to reload the daemon")
@@ -592,10 +587,9 @@ def daemon_reload(node):
return True
-def git_clone_and_compile(hosts, link, dir_name,
- compile_option='False'):
- """This function clones a repo and depending
- on kwargs compiles it.
+def git_clone_and_compile(hosts, link, dir_name, compile_option='False'):
+ """Clone and compile a repo.
+
Args:
hosts (list|str): List of hosts where the repo needs to be cloned.
link (str): Link to the repo that needs to be cloned.
@@ -610,12 +604,12 @@ def git_clone_and_compile(hosts, link, dir_name,
bool : True on successfull cloning (and compilation)
False otherwise.
"""
- if isinstance(hosts, str):
+ if not isinstance(hosts, list):
hosts = [hosts]
- cmd = ("cd /root; git clone %s %s;" % (link, dir_name))
+ cmd = "cd /root; git clone %s %s;" % (link, dir_name)
if compile_option:
- cmd = cmd + (("cd /root/%s; make") % dir_name)
+ cmd = cmd + ("cd /root/%s; make" % dir_name)
for host in hosts:
ret, _, _ = g.run(host, cmd)
@@ -625,3 +619,72 @@ def git_clone_and_compile(hosts, link, dir_name,
else:
g.log.info("Successfully cloned/compiled repo on %s" % host)
return True
+
+
+def kill_process(mnode, process_ids='', process_names=''):
+ """Kills the given set of process running in the specified node
+
+ Args:
+ mnode (str): Node at which the command has to be executed
+ process_ids (list|str): List of pid's to be terminated
+ process_names(list|str): List of Process names to be terminated
+
+ Returns:
+ bool : True on successful termination of all the processes
+ False, otherwise
+ Example:
+ >>> kill_process("10.70.43.68", process_ids=27664)
+ True/False
+ >>> kill_process("10.70.43.68", process_names=["glustershd",
+ "glusterd"])
+ True/False
+ """
+ if process_names:
+ process_ids = []
+ if not isinstance(process_names, list):
+ process_names = [process_names]
+
+ for process in process_names:
+ ret, pids, _ = g.run(mnode,
+ "ps -aef | grep -i '%s' | grep -v 'grep' | "
+ "awk '{ print $2 }'" % process)
+ pids = pids.split("\n")[:-1]
+ if not pids:
+ g.log.error("Getting pid for process %s failed" % process)
+ return False
+ for pid in pids:
+ if pid:
+ process_ids.append(pid)
+
+ if process_ids and not isinstance(process_ids, list):
+ process_ids = [process_ids]
+
+ # Kill process
+ for pid in process_ids:
+ ret, _, _ = g.run(mnode, "kill -9 %s" % str(pid))
+ if ret:
+ g.log.error("Failed to kill process with pid %s" % str(pid))
+ return False
+ return True
+
+
+def bring_down_network_interface(mnode, timeout=150):
+ """Brings the network interface down for a defined time
+
+ Args:
+ mnode (str): Node at which the interface has to be bought down
+ timeout (int): Time duration (in secs) for which network has to
+ be down
+
+ Returns:
+ network_status(object): Returns a process object
+
+ Example:
+ >>> bring_down_network_interface("10.70.43.68", timout=100)
+ """
+ interface = "eth0" if is_rhel7(mnode) else "ens3"
+ cmd = "ifconfig {0} down\nsleep {1}\nifconfig {0} up".format(interface,
+ timeout)
+ _, _, _ = g.run(mnode, "echo \"{}\"> 'test.sh'".format(cmd))
+ network_status = g.run_async(mnode, "sh test.sh")
+ return network_status
diff --git a/glustolibs-misc/setup.py b/glustolibs-misc/setup.py
index e515d1273..5f65d5184 100644
--- a/glustolibs-misc/setup.py
+++ b/glustolibs-misc/setup.py
@@ -1,5 +1,5 @@
-#!/usr/bin/python
-# Copyright (c) 2016 Red Hat, Inc.
+#!/usr/bin/env python
+# Copyright (c) 2016-2019 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,24 +25,28 @@ setup(
name=name,
version=version,
description='Glusto - Red Hat Gluster Libraries',
- license='GPLv2+',
+ license='GPLv3+',
author='Red Hat, Inc.',
author_email='gluster-devel@gluster.org',
url='http://www.gluster.org',
packages=find_packages(),
classifiers=[
- 'Development Status :: 4 - Beta'
- 'Environment :: Console'
- 'Intended Audience :: Developers'
- 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)'
- 'Operating System :: POSIX :: Linux'
- 'Programming Language :: Python'
- 'Programming Language :: Python :: 2'
- 'Programming Language :: Python :: 2.6'
- 'Programming Language :: Python :: 2.7'
- 'Topic :: Software Development :: Testing'
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: GNU General Public License v3 or '
+ 'later (GPLv3+)',
+ 'Operating System :: POSIX :: Linux',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Topic :: Software Development :: Testing',
],
install_requires=['glusto'],
- dependency_links=['http://github.com/loadtheaccumulator/glusto/tarball/master#egg=glusto'],
+ dependency_links=[
+ 'http://github.com/loadtheaccumulator/glusto/tarball/master#egg=glusto'
+ ],
namespace_packages = ['glustolibs']
)