def stop_glusterd(servers=''): """ Stops the glusterd in specified machine(s) Returns True if glusterd is stopped in all nodes Returns False on failure """ if servers == '': servers = tc.servers ret, _ = tc.run_servers("service glusterd stop", servers=servers) return ret
def start_glusterd(servers=''): """ Starts glusterd in all servers if they are not running Returns True if glusterd started in all servers Returns False if glusterd failed to start in any server (Will be enhanced to support systemd in future) """ if servers == '': servers = tc.servers ret, _ = tc.run_servers("pgrep glusterd || service glusterd start", \ servers=servers) return ret
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
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