def setup(self): """ Function to setup ganesha and create volume for testing. """ ret = setup_nfs_ganesha(self.no_of_ganesha_nodes) if ret: tc.logger.info("setup of ganesha for %s node is successfull" % self.no_of_ganesha_nodes) else: tc.logger.error("setup of ganesha for %s node is unsuccessfull" % self.no_of_ganesha_nodes) return False ret = GlusterBaseClass.setup(self) if not ret: return False time.sleep(10) ret = get_volume_status(self.volname) if ret is None: return False ret = get_volume_info(self.volname) if ret is None: return False ret, out, err = tc.run(self.mnode, "showmount -e localhost") if ret != 0: return False ret, out, err = mount_volume(self.volname, self.mount_proto, self.mountpoint, self.vips[0], self.clients[0], self.options) if ret != 0: tc.logger.error("Mounting Volume %s failed on %s:%s" % (self.volname, self.clients[0], self.mountpoint)) return False return True
def vol_set_nfs_disable(volname, option=True, mnode=None): '''Enables/Disables nfs for the volume. Args: volname (str): Volume name. Kwargs: option (Optional[bool]): If True it disables nfs for that volume else enables nfs for that volume. Default value is True. mnode (Optional[str]): Node on which the command has to be executed. Default value is tc.servers[0]. Returns: bool: True if successful, False otherwise. ''' if mnode is None: mnode = tc.servers[0] if option: volinfo = get_volume_info(volname, mnode) nfs_disable = volinfo[volname]['options'].get('nfs.disable') if nfs_disable == "on": tc.logger.info(" nfs is already disabled for the volume %s" % volname) return True ret, _, _ = tc.run(mnode, "gluster volume set %s nfs.disable on " "--mode=script" % volname) if ret != 0: tc.logger.error("failed to set nfs.disable on %s" % volname) return False else: ret, _, _ = tc.run(mnode, "gluster volume set %s nfs.disable off " "--mode=script" % volname) if ret != 0: return False return True
def get_pathinfo(filename, volname, client=None): """This module gets filepath of the given file in gluster server. Example: get_pathinfo("file1", "testvol") Args: filename (str): relative path of file volname (str): volume name Kwargs: client (str): client on which cmd has to be executed. Returns: NoneType: None if command execution fails, parse errors. list: file path for the given file in gluster server """ if client is None: client = tc.clients[0] server = get_volume_info(volname)[volname]['bricks'][0].split(':')[0] mount_point = '/mnt/tmp_fuse' # Performing glusterfs mount because only with glusterfs mount # the file location in gluster server can be identified from client # machine ret, _, _ = mount_volume(volname, mtype='glusterfs', mpoint=mount_point, mserver=server, mclient=client) if ret != 0: tc.logger.error("Failed to do gluster mount on volume %s to fetch" "pathinfo from client %s" % (volname, client)) return None filename = mount_point + '/' + filename attr_name = 'trusted.glusterfs.pathinfo' output = get_extended_attributes_info([filename], attr_name=attr_name, mnode=client) if output is None: tc.logger.error("Failed to get path info for %s" % filename) return None pathinfo = output[filename][attr_name] umount_volume(client, mount_point) return re.findall(".*?POSIX.*?:(\S+)\>", pathinfo)
def form_bricks_path(number_of_bricks, servers, mnode, volname): """Forms complete bricks path for create-volume/add-brick given the num_of_bricks Args: 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 needs to be selected for creating the brick list. mnode (str): The node on which the command has to be run. volname (str): Volume name for which we require brick-list. Returns: str - complete brick path. None - if number_of_bricks is greater than unused bricks. Example: form_bricks_path(6, tc.servers, tc.servers(0), "testvol") """ if not isinstance(servers, list): servers = [servers] dict_index = 0 bricks_path = '' server_bricks_dict = get_servers_unused_bricks_dict(servers, servers[0]) num_of_unused_bricks = 0 for server_brick in server_bricks_dict.values(): num_of_unused_bricks = num_of_unused_bricks + len(server_brick) if num_of_unused_bricks < number_of_bricks: tc.logger.error("Not enough bricks available for creating the bricks") return None brick_index = 0 vol_info_dict = get_volume_info(volname, mnode) if vol_info_dict: brick_index = int(vol_info_dict[volname]['brickCount']) for num in range(brick_index, brick_index + number_of_bricks): if server_bricks_dict.values()[dict_index]: bricks_path = ( "%s %s:%s/%s_brick%s" % (bricks_path, server_bricks_dict.keys()[dict_index], server_bricks_dict.values()[dict_index][0], volname, num)) server_bricks_dict.values()[dict_index].pop(0) if dict_index < len(server_bricks_dict) - 1: dict_index = dict_index + 1 else: dict_index = 0 return bricks_path
def form_bricks_path(number_of_bricks, servers, mnode, volname): """Forms complete bricks path for create-volume/add-brick given the num_of_bricks Args: 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 needs to be selected for creating the brick list. mnode (str): The node on which the command has to be run. volname (str): Volume name for which we require brick-list. Returns: str - complete brick path. None - if number_of_bricks is greater than unused bricks. Example: form_bricks_path(6, tc.servers, tc.servers(0), "testvol") """ if not isinstance(servers, list): servers = [servers] dict_index = 0 bricks_path = '' server_bricks_dict = get_servers_unused_bricks_dict(servers, servers[0]) num_of_unused_bricks = 0 for server_brick in server_bricks_dict.values(): num_of_unused_bricks = num_of_unused_bricks + len(server_brick) if num_of_unused_bricks < number_of_bricks: tc.logger.error("Not enough bricks available for creating the bricks") return None brick_index = 0 vol_info_dict = get_volume_info(volname, mnode) if vol_info_dict: brick_index = int(vol_info_dict[volname]['brickCount']) for num in range(brick_index, brick_index + number_of_bricks): if server_bricks_dict.values()[dict_index]: bricks_path = ("%s %s:%s/%s_brick%s" % (bricks_path, server_bricks_dict.keys()[dict_index], server_bricks_dict.values()[dict_index][0], volname, num)) server_bricks_dict.values()[dict_index].pop(0) if dict_index < len(server_bricks_dict) - 1: dict_index = dict_index + 1 else: dict_index = 0 return bricks_path
def setup(self): """ Function to setup the volume for testing. """ volinfo = get_volume_info(server=self.servers[0]) if volinfo is not None and self.volname in volinfo.keys(): tc.logger.debug("The volume %s is already present in %s", self.volname, self.mnode) if not self.config_data['reuse_setup']: ret = cleanup_volume(self.volname, self.mnode) if not ret: tc.logger.error("Unable to cleanup the setup") return False return self._create_volume() else: return self._create_volume() return True
def vol_set_ganesha(volname, option=True, mnode=None): '''Enables/Disables ganesha for the volume. Args: volname (str): Volume name. Kwargs: option (Optional[bool]): If True it enables ganesha for that volume else disables ganesha for that volume. Default value is True. mnode (Optional[str]): Node on which the command has to be executed. Default value is tc.servers[0]. Returns: bool: True if successful, False otherwise. ''' if mnode is None: mnode = tc.servers[0] if option: ret = vol_set_nfs_disable(volname) if not ret: return False volinfo = get_volume_info(volname, mnode) enable = volinfo[volname]['options'].get('ganesha.enable') if enable == "on": tc.logger.info(" ganesha is already enabled for the volume %s" % volname) return True ret, _, _ = tc.run( mnode, "gluster volume set %s ganesha.enable on " "--mode=script" % volname) if ret != 0: tc.logger.error("failed to set ganesha.enable on %s" % volname) return False else: ret, _, _ = tc.run( mnode, "gluster volume set %s ganesha.enable off " "--mode=script" % volname) if ret != 0: return False return True