Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def get_pathinfo(filename, volname, mnode=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:
        mnode (str): Node on which cmd has to be executed. Defaults
            to tc.servers[0].

    Returns:
        NoneType: None if command execution fails, parse errors.
        list: file path for the given file in gluster server
    """

    if mnode is None:
        mnode = tc.servers[0]

    mount_point = tempfile.mkdtemp()

    # Performing glusterfs mount because only with glusterfs mount
    # the file location in gluster server can be identified
    ret, _, _ = mount_volume(volname,
                             mtype='glusterfs',
                             mpoint=mount_point,
                             mserver=mnode,
                             mclient=mnode)
    if ret != 0:
        tc.logger.error("Failed to do gluster mount on volume %s to fetch"
                        "pathinfo from server %s" % (volname, mnode))
        return None

    filename = mount_point + '/' + filename
    attr_name = 'trusted.glusterfs.pathinfo'
    output = get_extended_attributes_info([filename],
                                          attr_name=attr_name,
                                          mnode=mnode)
    if output is None:
        tc.logger.error("Failed to get path info for %s" % filename)
        return None

    pathinfo = output[filename][attr_name]

    umount_volume(mnode, mount_point)
    tc.run(mnode, "rm -rf " + mount_point)

    return re.findall(".*?POSIX.*?:(\S+)\>", pathinfo)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def get_pathinfo(filename, volname, mnode=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:
        mnode (str): Node on which cmd has to be executed. Defaults
            to tc.servers[0].

    Returns:
        NoneType: None if command execution fails, parse errors.
        list: file path for the given file in gluster server
    """

    if mnode is None:
        mnode = tc.servers[0]

    mount_point = tempfile.mkdtemp()

    # Performing glusterfs mount because only with glusterfs mount
    # the file location in gluster server can be identified
    ret, _, _ = mount_volume(volname, mtype='glusterfs',
                             mpoint=mount_point,
                             mserver=mnode,
                             mclient=mnode)
    if ret != 0:
        tc.logger.error("Failed to do gluster mount on volume %s to fetch"
                        "pathinfo from server %s"
                        % (volname, mnode))
        return None

    filename = mount_point + '/' + filename
    attr_name = 'trusted.glusterfs.pathinfo'
    output = get_extended_attributes_info([filename],
                                          attr_name=attr_name,
                                          mnode=mnode)
    if output is None:
        tc.logger.error("Failed to get path info for %s" % filename)
        return None

    pathinfo = output[filename][attr_name]

    umount_volume(mnode, mount_point)
    tc.run(mnode, "rm -rf " + mount_point)

    return re.findall(".*?POSIX.*?:(\S+)\>", pathinfo)
 def run(self):
     _rc = True
     client = self.clients[0]
     tc.run(self.mnode, "gluster volume status %s" % self.volname)
     ret, _, _ = mount_volume(self.volname, self.mount_proto,
                              self.mountpoint, mclient=client)
     if ret != 0:
         tc.logger.error("Unable to mount the volume %s in %s"
                         "Please check the logs" % (self.volname, client))
         return False
     ret, _, _ = tc.run(client, "cp -r /etc %s" % self.mountpoint)
     if ret != 0:
         tc.logger.error("cp failed in %s. Please check the logs" % client)
         _rc = False
     tc.run(client, "rm -rf %s/etc" % self.mountpoint)
     umount_volume(client, self.mountpoint)
     return _rc
 def run(self):
     _rc = True
     client = self.clients[0]
     tc.run(self.mnode, "gluster volume status %s" % self.volname)
     ret, _, _ = mount_volume(self.volname,
                              self.mount_proto,
                              self.mountpoint,
                              mclient=client)
     if ret != 0:
         tc.logger.error("Unable to mount the volume %s in %s"
                         "Please check the logs" % (self.volname, client))
         return False
     ret, _, _ = tc.run(client, "cp -r /etc %s" % self.mountpoint)
     if ret != 0:
         tc.logger.error("cp failed in %s. Please check the logs" % client)
         _rc = False
     tc.run(client, "rm -rf %s/etc" % self.mountpoint)
     umount_volume(client, self.mountpoint)
     return _rc
 def teardown(self, teardown_ganesha_setup=False):
     """
         The function to cleanup the test setup
         Kwargs:
             teardown_ganesha_setup (bool): If True teardowns ganesha setup,
                 else leaves the ganesha setup as it is.
                 Default value is False
     """
     umount_volume(tc.clients[0], self.mountpoint)
     ret, out, err = tc.run(tc.clients[0], "rm -rf %s/*" % self.mountpoint)
     time.sleep(5)
     if ret != 0:
         tc.logger.error("rm -rf command failed on the mountpoint %s"
                         % self.mountpoint)
         return False
     if teardown_ganesha_setup:
         ret = teardown_nfs_ganesha_setup()
         return ret
     return True