From 0a4cdc909d4f5cb60b5dba5f2ca360db8e74796f Mon Sep 17 00:00:00 2001 From: ShwethaHP Date: Fri, 4 Aug 2017 16:43:43 +0530 Subject: Providing configs to set volume options, group options when exporting volume as 'smb share', 'nfs-ganesha export' in the config yml. Reading the configs in the gluster_base_class and setting those configs when exporting the volumes as 'smb share' or 'nfs-ganesha export'. recommended options when exporting volume as 'smb share': group: "metadata-cache" cache-samba-metadata: "on" Change-Id: I86a118c7015eaedd849a0f6e8b613605df5b6c32 Signed-off-by: ShwethaHP --- .../glustolibs/gluster/gluster_base_class.py | 45 +++++++++++++++++++++- .../glustolibs/gluster/samba_libs.py | 8 ++-- .../glustolibs/gluster/volume_ops.py | 14 +++++++ 3 files changed, 62 insertions(+), 5 deletions(-) (limited to 'glustolibs-gluster/glustolibs/gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py index 3dd8f976f..3f94fbff7 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py @@ -28,7 +28,7 @@ import datetime from glusto.core import Glusto as g from glustolibs.gluster.exceptions import ExecutionError, ConfigError from glustolibs.gluster.peer_ops import is_peer_connected, peer_status -from glustolibs.gluster.volume_ops import volume_info +from glustolibs.gluster.volume_ops import volume_info, set_volume_options from glustolibs.gluster.volume_libs import (setup_volume, cleanup_volume, log_volume_info_and_status) from glustolibs.gluster.samba_libs import share_volume_over_smb @@ -210,6 +210,22 @@ class GlusterBaseClass(unittest.TestCase): g.config['gluster'].get('volume_options')): cls.volume_options = g.config['gluster']['volume_options'] + # If the volume is exported as SMB Share, then set the following + # volume options on the share. + cls.smb_share_options = {} + if (g.config.get('gluster') and + g.config['gluster'].get('smb_share_options')): + cls.smb_share_options = ( + g.config['gluster']['smb_share_options']) + + # If the volume is exported as NFS-Ganesha export, + # then set the following volume options on the export. + cls.nfs_ganesha_export_options = {} + if (g.config.get('gluster') and + g.config['gluster'].get('nfs_ganesha_export_options')): + cls.nfs_ganesha_export_options = ( + g.config['gluster']['nfs_ganesha_export_options']) + # Get the volume configuration. cls.volume = {} if cls.volume_type: @@ -425,6 +441,20 @@ class GlusterVolumeBaseClass(GlusterBaseClass): raise ExecutionError("Failed to export volume %s " "as NFS export", cls.volname) + # Set NFS-Ganesha specific volume options + if cls.enable_nfs_ganesha and cls.nfs_ganesha_export_options: + g.log.info("Setting NFS-Ganesha export specific " + "volume options") + ret = set_volume_options( + mnode=cls.mnode, volname=cls.volname, + options=cls.nfs_ganesha_export_options) + if not ret: + raise ExecutionError("Failed to set NFS-Ganesha " + "export specific options on " + "volume %s", cls.volname) + g.log.info("Successful in setting NFS-Ganesha export " + "specific volume options") + if "smb" in cls.mount_type or "cifs" in cls.mount_type: ret = share_volume_over_smb(mnode=cls.mnode, volname=cls.volname, @@ -433,6 +463,19 @@ class GlusterVolumeBaseClass(GlusterBaseClass): raise ExecutionError("Failed to export volume %s " "as SMB Share", cls.volname) + # Set SMB share specific volume options + if cls.smb_share_options: + g.log.info("Setting SMB share specific volume options") + ret = set_volume_options(mnode=cls.mnode, + volname=cls.volname, + options=cls.smb_share_options) + if not ret: + raise ExecutionError("Failed to set SMB share " + "specific options " + "on volume %s", cls.volname) + g.log.info("Successful in setting SMB share specific " + "volume options") + # Log Volume Info and Status ret = log_volume_info_and_status(cls.mnode, cls.volname) if not ret: diff --git a/glustolibs-gluster/glustolibs/gluster/samba_libs.py b/glustolibs-gluster/glustolibs/gluster/samba_libs.py index a12e48855..8c70b6774 100644 --- a/glustolibs-gluster/glustolibs/gluster/samba_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/samba_libs.py @@ -244,13 +244,13 @@ def share_volume_over_smb(mnode, volname, smb_users_info): """ g.log.info("Start sharing the volume over SMB") - # Set volume option 'stat-prefetch' to 'off'. - cmd = "gluster volume set %s stat-prefetch off" % volname + # Set volume option 'stat-prefetch' to 'on'. + cmd = "gluster volume set %s stat-prefetch on" % volname ret, _, _ = g.run(mnode, cmd) if ret != 0: - g.log.error("Failed to set the volume option stat-prefetch off") + g.log.error("Failed to set the volume option stat-prefetch on") return False - g.log.info("Successfully set 'stat-prefetch' to 'off' on %s", volname) + g.log.info("Successfully set 'stat-prefetch' to 'on' on %s", volname) # Set volume option 'server.allow-insecure' to 'on'. cmd = "gluster volume set %s server.allow-insecure on" % volname diff --git a/glustolibs-gluster/glustolibs/gluster/volume_ops.py b/glustolibs-gluster/glustolibs/gluster/volume_ops.py index 6770b1d3e..503f2c2f1 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_ops.py @@ -539,6 +539,20 @@ def set_volume_options(mnode, volname, options): set_volume_option("abc.com", "testvol", options) """ _rc = True + + # Check if group options are specified. + if 'group' in options: + group_options = options.pop('group') + if isinstance(group_options, str): + group_options = [group_options] + for group_option in group_options: + cmd = ("gluster volume set %s group %s --mode=script" % + (volname, group_option)) + ret, _, _ = g.run(mnode, cmd) + if ret != 0: + g.log.error("Unable to set group option: %s", group_option) + _rc = False + for option in options: cmd = ("gluster volume set %s %s %s --mode=script" % (volname, option, options[option])) -- cgit