diff options
author | Apeksha D Khakharia <akhakhar@redhat.com> | 2016-06-26 14:55:20 +0530 |
---|---|---|
committer | Raghavendra Talur <rtalur@redhat.com> | 2016-06-26 11:10:46 -0700 |
commit | 931c656d6207645d2a7572cacf674f2b77f411f7 (patch) | |
tree | 59d7ccf1ca3d3deb6c07d86f5082aa1f0ec26645 /tests/distaf/distaf_libs | |
parent | 1569b5138e2a482bcd880ca0f5e7b1509a07bea4 (diff) |
distaf: Adding samba_ops library
Change-Id: Icc2b1eefe0f27a67e9f0e50edd41b313bd3cc892
BUG: 1350173
Signed-off-by: Apeksha D Khakharia <akhakhar@redhat.com>
Reviewed-on: http://review.gluster.org/14798
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
Reviewed-by: ShwethaHPanduranga
Tested-by: ShwethaHPanduranga
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'tests/distaf/distaf_libs')
-rw-r--r-- | tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/samba_ops.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/samba_ops.py b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/samba_ops.py new file mode 100644 index 00000000000..63d7aea0b7e --- /dev/null +++ b/tests/distaf/distaf_libs/distaflibs-gluster/distaflibs/gluster/samba_ops.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python +# This file is part of DiSTAF +# Copyright (C) 2015-2016 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 +# the Free Software Foundation; either version 2 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +from distaf.util import tc + + +def setup_samba_service(volname, mnode, username, smbpasswd): + """This module Sets up the servers for samba mount + Takes care of editing the glusterd-volfile and + starting the samba services + Args: + volname(str): Volume name + mnode(str): where the samba setup will be done + username: samba username + smbpasswd: samba password + Returns: + bool: + True: On Success + False: On Failure + Example: + setup_samba_service("testvol", "tc.servers[0]", "Bond", "redhat") + """ + try: + if tc.global_flag['SAMBA_SETUP_DONE'] == True: + tc.logger.error("samba is already setup for the cluster") + return True + except KeyError: + pass + + glusterd_volfile = "/etc/glusterfs/glusterd.vol" + glstrd_edit_cmd = ("grep -F 'option rpc-auth-allow-insecure on' %s > " + "/dev/null || (cp %s %s.orig && " + "sed -i '/^end-volume/d' %s && " + "echo ' option rpc-auth-allow-insecure on' >> %s && " + "echo 'end-volume' >> %s && " + "service glusterd restart)" + % (glusterd_volfile, glusterd_volfile, + glusterd_volfile, glusterd_volfile, + glusterd_volfile, glusterd_volfile)) + + ret, _ = tc.run_servers(glstrd_edit_cmd) + if not ret: + tc.logger.error("Unable to edit glusterd in all servers") + return False + + ret, _, _ = tc.run(mnode, "chkconfig smb on") + + if ret != 0: + tc.logger.error("Unable to set chkconfig smb on") + return False + + tc.logger.info("chkconfig smb on successfull") + + ret, _, _ = tc.run(mnode, "service smb start") + if ret != 0: + tc.logger.error("Unable to start the smb service") + return False + + smbpasswd_cmd = ("(echo \"%s\"; echo \"%s\") | smbpasswd -a %s" % + (smbpasswd, smbpasswd, username)) + + ret, _, _ = tc.run(mnode, smbpasswd_cmd) + if ret != 0: + tc.logger.error("Unable to set the smb password") + return False + + time.sleep(20) + + ret, out, err = tc.run(mnode, "gluster volume set %s " + "server.allow-insecure on" % volname) + if ret != 0: + tc.logger.error("Failed to set the volume option " + "server-allow-insecure") + return False + + ret, out, err = tc.run(mnode, "gluster volume set %s stat-prefetch off" + % volname) + if ret != 0: + tc.logger.error("Failed to set the volume option stat-prefetch off") + return False + + set_volume_cmd = ("gluster volume set %s storage.batch-fsync-delay-usec 0" + % volname) + ret, out, err = tc.run(mnode, set_volume_cmd) + if ret != 0: + tc.logger.error("Failed to set the volume option storage" + "batch-fsync-delay-usec 0") + return False + + smb_cmd = "smbclient -L localhost -U " + username + "%" + smbpasswd + + ret, out, err = tc.run(mnode, smb_cmd + "| grep -i -Fw gluster-%s " + % volname) + if ret != 0: + tc.logger.error("unable to find share entry") + return False + tc.logger.info("Share entry present") + + tc.global_flag['SAMBA_SETUP_DONE'] = True + return True |