summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/volume_libs.py
diff options
context:
space:
mode:
authorShwetha Panduranga <spandura@redhat.com>2017-02-08 18:52:37 +0530
committerNigel Babu <nigelb@redhat.com>2017-02-27 04:45:08 -0500
commitdaca62f4b7f876bf675e5b29b643e3d472903597 (patch)
tree2d036166d6e5fe51e43edea5e97d1befac178352 /glustolibs-gluster/glustolibs/gluster/volume_libs.py
parentbc30c6a7eebc20416e6c7fe5c7b080f4e96b5f57 (diff)
Adding a new test to VVT:
1) glusterbaseclass: - Making changes in glusterbaseclass to not necessarily have volume_type and mount_type. 2) volume_libs: - setup_volume don't have to export the volume. It just creates starts and setup's any operation on the volume. - Moved the sharing/exporting the volume to BaseClass 3) Renaming samba_ops to samba_libs to have better naming practice. 4) Adding nfs_ganesha_libs for any nfs related helper functions 5) Adding a new vvt case which creates, deteles, creates the volume. Change-Id: I238c349df7165d669d3bc7234d97845dba2f51a6 Signed-off-by: Shwetha Panduranga <spandura@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/volume_libs.py')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/volume_libs.py182
1 files changed, 99 insertions, 83 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py
index 94a817d..6a3f80a 100644
--- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py
+++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
# Copyright (C) 2015-2016 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -26,14 +25,14 @@ from glustolibs.gluster.lib_utils import form_bricks_list
from glustolibs.gluster.volume_ops import (volume_create, volume_start,
set_volume_options, get_volume_info,
volume_stop, volume_delete,
- volume_info, volume_status)
+ volume_info, volume_status,
+ get_volume_options)
from glustolibs.gluster.tiering_ops import (add_extra_servers_to_cluster,
tier_attach,
is_tier_process_running)
from glustolibs.gluster.quota_ops import (enable_quota, set_quota_limit_usage,
is_quota_enabled)
from glustolibs.gluster.uss_ops import enable_uss, is_uss_enabled
-from glustolibs.gluster.samba_ops import share_volume_over_smb
from glustolibs.gluster.snap_ops import snap_delete_by_volumename
from glustolibs.gluster.brick_libs import are_bricks_online, get_all_bricks
from glustolibs.gluster.heal_libs import are_all_self_heal_daemons_are_online
@@ -210,14 +209,14 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False):
bricks_list=bricks_list, force=force,
**kwargs)
if ret != 0:
- g.log.error("Unable to create volume %s" % volname)
+ g.log.error("Unable to create volume %s", volname)
return False
# Start Volume
time.sleep(2)
ret = volume_start(mnode, volname)
if not ret:
- g.log.error("volume start %s failed" % volname)
+ g.log.error("volume start %s failed", volname)
return False
# Create Tier volume
@@ -273,13 +272,13 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False):
time.sleep(30)
# Check if tier is running
- rc = True
+ _rc = True
for server in extra_servers:
ret = is_tier_process_running(server, volname)
if not ret:
g.log.error("Tier process not running on %s", server)
- rc = False
- if not rc:
+ _rc = False
+ if not _rc:
return False
# Enable Quota
@@ -291,13 +290,13 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False):
return False
# Check if 'limit_usage' is defined
- if ('limit_usage' in volume_config['quota']):
- if ('path' in volume_config['quota']['limit_usage']):
+ if 'limit_usage' in volume_config['quota']:
+ if 'path' in volume_config['quota']['limit_usage']:
path = volume_config['quota']['limit_usage']['path']
else:
path = "/"
- if ('size' in volume_config['quota']['limit_usage']):
+ if 'size' in volume_config['quota']['limit_usage']:
size = volume_config['quota']['limit_usage']['size']
else:
size = "100GB"
@@ -331,34 +330,6 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False):
g.log.error("USS is not enabled on the volume %s", volname)
return False
- # Enable Ganesha
-# if ('nfs_ganesha' in volume_config and
-# 'enable' in volume_config['nfs_ganesha'] and
-# volume_config['nfs_ganesha']['enable']):
-# from glustolibs.gluster.ganesha import vol_set_ganesha
-# ret = vol_set_ganesha(mnode=mnode, volname=volname, option=True)
-# if not ret:
-# g.log.error("failed to set the ganesha option for %s" % volname)
-# return False
-
- # Enable Samba
- if ('smb' in volume_config and 'enable' in volume_config['smb'] and
- volume_config['smb']['enable']):
- smb_users_info = {}
- if ('users_info' in volume_config['smb'] and
- volume_config['smb']['users_info']):
- smb_users_info = volume_config['smb']['users_info']
- else:
- g.log.error("SMB Users info not available in the volume config."
- "Unable to export volume %s as SMB Share" % volname)
- return False
- ret = share_volume_over_smb(mnode=mnode, volname=volname,
- servers=servers,
- smb_users_info=smb_users_info)
- if not ret:
- g.log.error("Failed to export volume %s as SMB Share" % volname)
- return False
-
# Set all the volume options:
if 'options' in volume_config:
volume_options = volume_config['options']
@@ -388,23 +359,22 @@ def cleanup_volume(mnode, volname):
"""
volinfo = get_volume_info(mnode, volname)
if volinfo is None or volname not in volinfo:
- g.log.info("Volume %s does not exist in %s" % (volname, mnode))
+ g.log.info("Volume %s does not exist in %s", volname, mnode)
return True
ret, _, _ = snap_delete_by_volumename(mnode, volname)
if ret != 0:
- g.log.error("Failed to delete the snapshots in "
- "volume %s" % volname)
+ g.log.error("Failed to delete the snapshots in volume %s", volname)
return False
ret, _, _ = volume_stop(mnode, volname, force=True)
if ret != 0:
- g.log.error("Failed to stop volume %s" % volname)
+ g.log.error("Failed to stop volume %s", volname)
return False
ret = volume_delete(mnode, volname)
if not ret:
- g.log.error("Unable to cleanup the volume %s" % volname)
+ g.log.error("Unable to cleanup the volume %s", volname)
return False
return True
@@ -431,7 +401,7 @@ def is_volume_exported(mnode, volname, share_type):
else:
return True
- if 'cifs' in share_type:
+ if 'cifs' in share_type or 'smb' in share_type:
cmd = "smbclient -L localhost"
_, _, _ = g.run(mnode, cmd)
@@ -525,18 +495,19 @@ def get_subvols(mnode, volname):
['hotBricks']['hotBrickType'])
tmp = volinfo[volname]["bricks"]['hotBricks']["brick"]
hot_tier_bricks = [x["name"] for x in tmp if "name" in x]
- if (hot_tier_type == 'Distribute'):
+ if hot_tier_type == 'Distribute':
for brick in hot_tier_bricks:
subvols['hot_tier_subvols'].append([brick])
elif (hot_tier_type == 'Replicate' or
hot_tier_type == 'Distributed-Replicate'):
- rep_count = int((volinfo[volname]["bricks"]['hotBricks']
- ['numberOfBricks']).split("=", 1)[0].
- split("x")[1].strip())
- subvol_list = ([hot_tier_bricks[i:i + rep_count]
- for i in range(0, len(hot_tier_bricks),
- rep_count)])
+ rep_count = int(
+ (volinfo[volname]["bricks"]['hotBricks']
+ ['numberOfBricks']).split("=", 1)[0].split("x")[1].strip()
+ )
+ subvol_list = (
+ [hot_tier_bricks[i:i + rep_count]
+ for i in range(0, len(hot_tier_bricks), rep_count)])
subvols['hot_tier_subvols'] = subvol_list
# Get cold tier subvols
@@ -546,29 +517,31 @@ def get_subvols(mnode, volname):
cold_tier_bricks = [x["name"] for x in tmp if "name" in x]
# Distribute volume
- if (cold_tier_type == 'Distribute'):
+ if cold_tier_type == 'Distribute':
for brick in cold_tier_bricks:
subvols['cold_tier_subvols'].append([brick])
# Replicate or Distribute-Replicate volume
elif (cold_tier_type == 'Replicate' or
cold_tier_type == 'Distributed-Replicate'):
- rep_count = int((volinfo[volname]["bricks"]['coldBricks']
- ['numberOfBricks']).split("=", 1)[0].
- split("x")[1].strip())
- subvol_list = ([cold_tier_bricks[i:i + rep_count]
- for i in range(0, len(cold_tier_bricks),
- rep_count)])
+ rep_count = int(
+ (volinfo[volname]["bricks"]['coldBricks']
+ ['numberOfBricks']).split("=", 1)[0].split("x")[1].strip()
+ )
+ subvol_list = (
+ [cold_tier_bricks[i:i + rep_count]
+ for i in range(0, len(cold_tier_bricks), rep_count)])
subvols['cold_tier_subvols'] = subvol_list
# Disperse or Distribute-Disperse volume
elif (cold_tier_type == 'Disperse' or
cold_tier_type == 'Distributed-Disperse'):
- disp_count = sum([int(nums) for nums in
- ((volinfo[volname]["bricks"]['coldBricks']
- ['numberOfBricks']).split("x", 1)[1].
- strip().split("=")[0].strip().strip("()").
- split()) if nums.isdigit()])
+ disp_count = sum(
+ [int(nums) for nums in (
+ (volinfo[volname]["bricks"]['coldBricks']
+ ['numberOfBricks']).split("x", 1)[1].
+ strip().split("=")[0].strip().strip("()").
+ split()) if nums.isdigit()])
subvol_list = [cold_tier_bricks[i:i + disp_count]
for i in range(0, len(cold_tier_bricks),
disp_count)]
@@ -587,11 +560,10 @@ def get_subvols(mnode, volname):
for brick in bricks:
subvols['volume_subvols'].append([brick])
- elif (voltype == 'Disperse' or voltype == 'Distributed-Disperse'):
+ elif voltype == 'Disperse' or voltype == 'Distributed-Disperse':
disp_count = int(volinfo[volname]['disperseCount'])
- subvol_list = [bricks[i:i + disp_count]for i in range(0,
- len(bricks),
- disp_count)]
+ subvol_list = ([bricks[i:i + disp_count]
+ for i in range(0, len(bricks), disp_count)])
subvols['volume_subvols'] = subvol_list
return subvols
@@ -609,7 +581,7 @@ def is_tiered_volume(mnode, volname):
"""
volinfo = get_volume_info(mnode, volname)
if volinfo is None:
- g.log.error("Unable to get the volume info for volume %s" % volname)
+ g.log.error("Unable to get the volume info for volume %s", volname)
return None
voltype = volinfo[volname]['typeStr']
@@ -632,7 +604,7 @@ def is_distribute_volume(mnode, volname):
"""
volume_type_info = get_volume_type_info(mnode, volname)
if volume_type_info is None:
- g.log.error("Unable to check if the volume %s is distribute" % volname)
+ g.log.error("Unable to check if the volume %s is distribute", volname)
return False
if volume_type_info['is_tier']:
@@ -640,7 +612,7 @@ def is_distribute_volume(mnode, volname):
['hotBrickType'])
cold_tier_type = (volume_type_info['cold_tier_type_info']
['coldBrickType'])
- if (hot_tier_type == 'Distribute' and cold_tier_type == 'Distribute'):
+ if hot_tier_type == 'Distribute' and cold_tier_type == 'Distribute':
return True
else:
return False
@@ -693,7 +665,7 @@ def get_volume_type_info(mnode, volname):
"""
volinfo = get_volume_info(mnode, volname)
if volinfo is None:
- g.log.error("Unable to get the volume info for volume %s" % volname)
+ g.log.error("Unable to get the volume info for volume %s", volname)
return None
volume_type_info = {
@@ -726,7 +698,7 @@ def get_volume_type_info(mnode, volname):
non_tiered_volume_type_info[key] = volinfo[volname][key]
else:
g.log.error("Unable to find key '%s' in the volume info for "
- "the volume %s" % (key, volname))
+ "the volume %s", key, volname)
non_tiered_volume_type_info[key] = None
volume_type_info['volume_type_info'] = non_tiered_volume_type_info
@@ -754,11 +726,11 @@ def get_cold_tier_type_info(mnode, volname):
"""
volinfo = get_volume_info(mnode, volname)
if volinfo is None:
- g.log.error("Unable to get the volume info for volume %s" % volname)
+ g.log.error("Unable to get the volume info for volume %s", volname)
return None
if not is_tiered_volume(mnode, volname):
- g.log.error("Volume %s is not a tiered volume" % volname)
+ g.log.error("Volume %s is not a tiered volume", volname)
return None
cold_tier_type_info = {
@@ -773,7 +745,7 @@ def get_cold_tier_type_info(mnode, volname):
['coldBricks'][key])
else:
g.log.error("Unable to find key '%s' in the volume info for the "
- "volume %s" % (key, volname))
+ "volume %s", key, volname)
return None
if 'Disperse' in cold_tier_type_info['coldBrickType']:
@@ -804,11 +776,11 @@ def get_hot_tier_type_info(mnode, volname):
"""
volinfo = get_volume_info(mnode, volname)
if volinfo is None:
- g.log.error("Unable to get the volume info for volume %s" % volname)
+ g.log.error("Unable to get the volume info for volume %s", volname)
return None
if not is_tiered_volume(mnode, volname):
- g.log.error("Volume %s is not a tiered volume" % volname)
+ g.log.error("Volume %s is not a tiered volume", volname)
return None
hot_tier_type_info = {
@@ -821,7 +793,7 @@ def get_hot_tier_type_info(mnode, volname):
[key])
else:
g.log.error("Unable to find key '%s' in the volume info for the "
- "volume %s" % (key, volname))
+ "volume %s", key, volname)
return None
return hot_tier_type_info
@@ -889,7 +861,7 @@ def get_cold_tier_num_of_bricks_per_subvol(mnode, volname):
NoneType: None if volume doesnot exist or not a tiered volume.
"""
if not is_tiered_volume(mnode, volname):
- g.log.error("Volume %s is not a tiered volume" % volname)
+ g.log.error("Volume %s is not a tiered volume", volname)
return None
subvols_dict = get_subvols(mnode, volname)
if subvols_dict['cold_tier_subvols']:
@@ -910,7 +882,7 @@ def get_hot_tier_num_of_bricks_per_subvol(mnode, volname):
NoneType: None if volume doesnot exist or not a tiered volume.
"""
if not is_tiered_volume(mnode, volname):
- g.log.error("Volume %s is not a tiered volume" % volname)
+ g.log.error("Volume %s is not a tiered volume", volname)
return None
subvols_dict = get_subvols(mnode, volname)
if subvols_dict['hot_tier_subvols']:
@@ -945,7 +917,7 @@ def get_replica_count(mnode, volname):
"""
vol_type_info = get_volume_type_info(mnode, volname)
if vol_type_info is None:
- g.log.error("Unable to get the replica count info for the volume %s" %
+ g.log.error("Unable to get the replica count info for the volume %s",
volname)
return None
@@ -1036,7 +1008,7 @@ def get_disperse_count(mnode, volname):
"""
vol_type_info = get_volume_type_info(mnode, volname)
if vol_type_info is None:
- g.log.error("Unable to get the disperse count info for the volume %s" %
+ g.log.error("Unable to get the disperse count info for the volume %s",
volname)
return None
@@ -1077,3 +1049,47 @@ def get_cold_tier_disperse_count(mnode, volname):
cold_tier_disperse_count = (volinfo[volname]["bricks"]['coldBricks']
['colddisperseCount'])
return cold_tier_disperse_count
+
+
+def enable_and_validate_volume_options(mnode, volname, volume_options_list,
+ time_delay=5):
+ """Enable the volume option and validate whether the option has be
+ successfully enabled or not
+
+ 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
+ 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):
+ volume_options_list = [volume_options_list]
+
+ for option in volume_options_list:
+ # Set volume option to 'enable'
+ g.log.info("Setting the volume option : %s", option)
+ ret = set_volume_options(mnode, volname, {option: "enable"})
+ if not ret:
+ return False
+
+ # Validate whether the option is set on the volume
+ g.log.info("Validating the volume option : %s to be set to 'enable'",
+ option)
+ option_dict = get_volume_options(mnode, volname, option)
+ g.log.info("Options Dict: %s", option_dict)
+ if option_dict is None:
+ g.log.error("%s is not enabled on the volume %s", option, volname)
+ return False
+
+ if option not in option_dict or "enable" not in option_dict[option]:
+ g.log.error("%s is not enabled on the volume %s", option, volname)
+ return False
+
+ g.log.info("%s is enabled on the volume %s", option, volname)
+ time.sleep(time_delay)
+
+ return True