summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster
diff options
context:
space:
mode:
authorShwethaHP <spandura@redhat.com>2017-11-30 13:19:11 +0530
committerJonathan Holloway <jholloway@redhat.com>2018-01-16 06:21:33 +0000
commit389862e34225430b06a1d494c1c1e3037f4b6d5d (patch)
treef762786f17070ac88d6ecc1859072d243955fa12 /glustolibs-gluster/glustolibs/gluster
parentc39a42140f328d12a605f5480d0e3c7a2d4c6308 (diff)
Check if servers/nodes which is expected to be passed as list
is str. i.e passing a single node to the function. If it is str, then convert it to list Change-Id: I1abacf62fdbe1ec56fe85c86d8e2a323a2c3971b Signed-off-by: ShwethaHP <spandura@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/gluster_init.py35
-rw-r--r--glustolibs-gluster/glustolibs/gluster/lib_utils.py34
-rw-r--r--glustolibs-gluster/glustolibs/gluster/peer_ops.py12
-rw-r--r--glustolibs-gluster/glustolibs/gluster/tiering_ops.py11
-rw-r--r--glustolibs-gluster/glustolibs/gluster/volume_libs.py15
5 files changed, 70 insertions, 37 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_init.py b/glustolibs-gluster/glustolibs/gluster/gluster_init.py
index 371e187..d45a186 100644
--- a/glustolibs-gluster/glustolibs/gluster/gluster_init.py
+++ b/glustolibs-gluster/glustolibs/gluster/gluster_init.py
@@ -26,13 +26,16 @@ def start_glusterd(servers):
"""Starts glusterd on specified servers if they are not running.
Args:
- servers (list): List of server hosts on which glusterd has to be
- started.
+ servers (str|list): A server|List of server hosts on which glusterd
+ has to be started.
Returns:
bool : True if starting glusterd is successful on all servers.
False otherwise.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
cmd = "pgrep glusterd || service glusterd start"
results = g.run_parallel(servers, cmd)
@@ -52,13 +55,16 @@ def stop_glusterd(servers):
"""Stops the glusterd on specified servers.
Args:
- servers (list): List of server hosts on which glusterd has to be
- stopped.
+ servers (str|list): A server|List of server hosts on which glusterd
+ has to be stopped.
Returns:
bool : True if stopping glusterd is successful on all servers.
False otherwise.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
cmd = "service glusterd stop"
results = g.run_parallel(servers, cmd)
@@ -78,13 +84,16 @@ def restart_glusterd(servers):
"""Restart the glusterd on specified servers.
Args:
- servers (list): List of server hosts on which glusterd has to be
- restarted.
+ servers (str|list): A server|List of server hosts on which glusterd
+ has to be restarted.
Returns:
bool : True if restarting glusterd is successful on all servers.
False otherwise.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
cmd = "service glusterd restart"
results = g.run_parallel(servers, cmd)
@@ -104,8 +113,8 @@ def is_glusterd_running(servers):
"""Checks the glusterd status on specified servers.
Args:
- servers (list): List of server hosts on which glusterd status has to
- be checked.
+ servers (str|list): A server|List of server hosts on which glusterd
+ status has to be checked.
Returns:
0 : if glusterd running
@@ -113,6 +122,9 @@ def is_glusterd_running(servers):
-1 : if glusterd not running and PID is alive
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
cmd1 = "service glusterd status"
cmd2 = "pidof glusterd"
cmd1_results = g.run_parallel(servers, cmd1)
@@ -137,14 +149,17 @@ def env_setup_servers(servers):
"""Set up environment on all the specified servers.
Args:
- servers (list): List of server hosts on which environment has to be
- setup.
+ servers (str|list): A server|List of server hosts on which environment
+ has to be setup.
Returns:
bool : True if setting up environment is successful on all servers.
False otherwise.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
g.log.info("The function isn't implemented fully")
g.log.info("Please setup the bricks manually.")
diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py
index 7f94820..901fa10 100644
--- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py
+++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py
@@ -298,8 +298,8 @@ def list_files(mnode, dir_path, parse_str="", user="root"):
def get_servers_bricks_dict(servers, servers_info):
"""This module returns servers_bricks dictionary.
Args:
- servers (list): List of servers for which we need the
- list of bricks available on it.
+ servers (str|list): A server|List of servers for which we
+ need the list of bricks available on it.
servers_info (dict): dict of server info of each servers
Returns:
OrderedDict: key - server
@@ -308,7 +308,7 @@ def get_servers_bricks_dict(servers, servers_info):
get_servers_bricks_dict(g.config['servers'], g.config['servers_info'])
"""
servers_bricks_dict = OrderedDict()
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
for server in servers:
server_info = servers_info[server]
@@ -330,7 +330,7 @@ def get_servers_used_bricks_dict(mnode, servers):
"""This module returns servers_used_bricks dictionary.
This information is fetched from gluster volume info command.
Args:
- servers (list): List of servers for which we need the
+ servers (str|list): A server|List of servers for which we need the
list of unused bricks on it.
mnode (str): The node on which gluster volume info command has
to be executed.
@@ -342,7 +342,7 @@ def get_servers_used_bricks_dict(mnode, servers):
get_servers_used_bricks_dict(g.config['servers'][0]['host'],
g.config['servers'])
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
servers_used_bricks_dict = OrderedDict()
@@ -378,7 +378,7 @@ def get_servers_unused_bricks_dict(mnode, servers, servers_info):
Args:
mnode (str): The node on which gluster volume info command has
to be executed.
- servers (list): List of servers for which we need the
+ servers (str|list): A server|List of servers for which we need the
list of unused bricks available on it.
servers_info (dict): dict of server info of each servers
Returns:
@@ -389,7 +389,7 @@ def get_servers_unused_bricks_dict(mnode, servers, servers_info):
g.config['servers'],
g.config['servers_info'])
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
dict1 = get_servers_bricks_dict(servers, servers_info)
dict2 = get_servers_used_bricks_dict(mnode, servers)
@@ -416,7 +416,7 @@ def form_bricks_list(mnode, volname, number_of_bricks, servers, servers_info):
volname (str): Volume name for which we require brick-list.
number_of_bricks (int): The number of bricks for which brick list
has to be created.
- servers (list): The list of servers from which the bricks
+ servers (str|list): A server|List of servers from which the bricks
needs to be selected for creating the brick list.
servers_info (dict): dict of server info of each servers.
@@ -428,7 +428,7 @@ def form_bricks_list(mnode, volname, number_of_bricks, servers, servers_info):
form_bricks_path(g.config['servers'](0), "testvol", 6,
g.config['servers'], g.config['servers_info'])
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
dict_index = 0
bricks_list = []
@@ -476,11 +476,13 @@ def is_rhel6(servers):
"""Function to get whether the server is RHEL-6
Args:
- servers(list): List of server hosts to know the RHEL Version
+ servers (str|list): A server|List of servers hosts to know the RHEL Version
Returns:
bool:Returns True, if its RHEL-6 else returns false
"""
+ if isinstance(servers, str):
+ servers = [servers]
results = g.run_parallel(servers, "cat /etc/redhat-release")
rc = True
@@ -500,11 +502,13 @@ def is_rhel7(servers):
"""Function to get whether the server is RHEL-7
Args:
- servers(list): List of server hosts to know the RHEL Version
+ servers (str|list): A server|List of servers hosts to know the RHEL Version
Returns:
bool:Returns True, if its RHEL-7 else returns false
"""
+ if isinstance(servers, str):
+ servers = [servers]
results = g.run_parallel(servers, "cat /etc/redhat-release")
rc = True
@@ -665,7 +669,8 @@ def install_epel(servers):
Module to install epel in rhel/centos/fedora systems.
Args:
- servers (list): servers in which epel to be installed.
+ servers (str|list): A server|List of servers in which epel
+ to be installed.
Returns:
bool: True, if epel is installed successfully, False otherwise
@@ -673,6 +678,8 @@ def install_epel(servers):
Example:
install_epel(["abc.com", "def.com"])
"""
+ if isinstance(servers, str):
+ servers = [servers]
rt = True
results = g.run_parallel(servers, "yum list installed epel-release")
@@ -716,7 +723,8 @@ def inject_msg_in_logs(nodes, log_msg, list_of_dirs=None, list_of_files=None):
"""Injects the message to all log files under all dirs specified on nodes.
Args:
- nodes (list): List of nodes on which message has to be injects to logs
+ nodes (str|list): A server|List of nodes on which message has to be
+ injected to logs
log_msg (str): Message to be injected
list_of_dirs (list): List of dirs to inject message on log files.
list_of_files (list): List of files to inject message.
diff --git a/glustolibs-gluster/glustolibs/gluster/peer_ops.py b/glustolibs-gluster/glustolibs/gluster/peer_ops.py
index 54c2a38..93e4a2c 100644
--- a/glustolibs-gluster/glustolibs/gluster/peer_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/peer_ops.py
@@ -128,7 +128,7 @@ def peer_probe_servers(mnode, servers, validate=True, time_delay=10):
Args:
mnode (str): Node on which command has to be executed.
- servers (list): List of servers to be peer probed.
+ servers (str|list): A server|List of servers to be peer probed.
Kwargs:
validate (bool): True to validate if probed peer is in cluster and
@@ -139,7 +139,7 @@ def peer_probe_servers(mnode, servers, validate=True, time_delay=10):
Returns:
bool: True on success and False on failure.
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
else:
servers = servers[:]
@@ -182,7 +182,7 @@ def peer_detach_servers(mnode, servers, force=False, validate=True,
Args:
mnode (str): Node on which command has to be executed.
- servers (list): List of servers to be peer probed.
+ servers (str|list): A server|List of servers to be peer probed.
Kwargs:
force (bool): option to detach peer.
@@ -195,7 +195,7 @@ def peer_detach_servers(mnode, servers, force=False, validate=True,
Returns:
bool: True on success and False on failure.
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
else:
servers = servers[:]
@@ -361,13 +361,13 @@ def is_peer_connected(mnode, servers):
Args:
mnode (str): Node from which peer probe has to be executed.
- servers (list): List of servers to be validated.
+ servers (str|list): A server|List of servers to be validated.
Returns
bool : True on success (peer in cluster and connected), False on
failure.
"""
- if not isinstance(servers, list):
+ if isinstance(servers, str):
servers = [servers]
else:
servers = servers[:]
diff --git a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py
index 755ca27..7e48a48 100644
--- a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py
+++ b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py
@@ -37,7 +37,8 @@ def add_extra_servers_to_cluster(mnode, extra_servers):
Args:
mnode (str): Node on which cmd has to be executed.
- extra_servers (list) : list of extra servers to be attached to cluster
+ extra_servers (str|list) : A server|list of extra servers to be
+ attached to cluster
Returns:
bool: True, if extra servers are attached to cluster
@@ -47,7 +48,7 @@ def add_extra_servers_to_cluster(mnode, extra_servers):
add_extra_servers_to_cluster("abc.com", ['peer_node1','peer_node2'])
"""
- if not isinstance(extra_servers, list):
+ if isinstance(extra_servers, str):
extra_servers = [extra_servers]
ret = start_glusterd(servers=extra_servers)
@@ -71,8 +72,8 @@ def tier_attach(mnode, volname, num_bricks_to_add, extra_servers,
mnode (str): Node on which cmd has to be executed.
volname (str): volume name
num_bricks_to_add (str): number of bricks to be added as hot tier
- extra_servers (list): from these servers, hot tier will be added
- to volume
+ extra_servers (str|list): from this server|these servers,
+ hot tier will be added to volume
extra_servers_info (dict): dict of server info of each extra servers
Kwargs:
@@ -96,6 +97,8 @@ def tier_attach(mnode, volname, num_bricks_to_add, extra_servers,
tier_attach("abc.com", testvol, '2', ['extra_server1','extra_server2'],
extra_server_info)
"""
+ if isinstance(extra_servers, str):
+ extra_servers = [extra_servers]
replica = int(replica)
repc = ''
diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py
index 5b66835..6687552 100644
--- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py
@@ -1100,14 +1100,15 @@ def enable_and_validate_volume_options(mnode, volname, volume_options_list,
Args:
mnode (str): Node on which commands are executed.
volname (str): Name of the volume.
- volume_options_list (list): List of volume options to be enabled
+ volume_options_list (str|list): A volume option|List of volume options
+ to be enabled
time_delay (int): Time delay between 2 volume set operations
Returns:
bool: True when enabling and validating all volume options is
successful. False otherwise
"""
- if not isinstance(volume_options_list, list):
+ if isinstance(volume_options_list, str):
volume_options_list = [volume_options_list]
for option in volume_options_list:
@@ -1143,7 +1144,7 @@ def expand_volume(mnode, volname, servers, all_servers_info, force=False,
Args:
mnode (str): Node on which commands has to be executed
volname (str): volume name
- servers (list): List of servers in the storage pool.
+ servers (str|list): A server|List of servers in the storage pool.
all_servers_info (dict): Information about all servers.
example :
all_servers_info = {
@@ -1178,6 +1179,9 @@ def expand_volume(mnode, volname, servers, all_servers_info, force=False,
NOTE: adding bricks to hot tier is yet to be added in this function.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
# Check if volume exists
if not volume_exists(mnode, volname):
g.log.error("Volume %s doesn't exists.", volname)
@@ -1553,7 +1557,7 @@ def replace_brick_from_volume(mnode, volname, servers, all_servers_info,
Args:
mnode (str): Node on which commands has to be executed
volname (str): volume name
- servers (list): List of servers in the storage pool.
+ servers (str|list): A server|List of servers in the storage pool.
all_servers_info (dict): Information about all servers.
example :
all_servers_info = {
@@ -1583,6 +1587,9 @@ def replace_brick_from_volume(mnode, volname, servers, all_servers_info,
bool: True if replacing brick from the volume is successful.
False otherwise.
"""
+ if isinstance(servers, str):
+ servers = [servers]
+
# Check if volume exists
if not volume_exists(mnode, volname):
g.log.error("Volume %s doesn't exists.", volname)