Example #1
0
def is_file_bad(filename, mnode):
    """Verifies if scrubber identifies bad file
    Args:
        filename (str): absolute path of the file in mnode
        mnode (str): Node on which cmd has to be executed.
            If None, defaults to servers[0].

    Returns:
        True on success, False otherwise

    Example:
        is_file_bad("/bricks/file1", "abc.xyz.com")
    """
    ret = True
    count = 0
    flag = 0
    while count < SCRUBBER_TIMEOUT:
        attr_info = get_extended_attributes_info([filename], mnode=mnode)
        if attr_info is None:
            ret = False

        if "trusted.bit-rot.bad-file" in attr_info[filename]:
            flag = 1
            break

        time.sleep(10)
        count = count + 10
    if not flag:
        tc.logger.error("Scrubber failed to identify bad file")
        ret = False

    return ret
Example #2
0
def is_file_bad(filename, mnode):
    """Verifies if scrubber identifies bad file
    Args:
        filename (str): absolute path of the file in mnode
        mnode (str): Node on which cmd has to be executed.
            If None, defaults to servers[0].

    Returns:
        True on success, False otherwise

    Example:
        is_file_bad("/bricks/file1", "abc.xyz.com")
    """
    ret = True
    count = 0
    flag = 0
    while (count < SCRUBBER_TIMEOUT):
        attr_info = get_extended_attributes_info([filename], mnode=mnode)
        if attr_info is None:
            ret = False

        if 'trusted.bit-rot.bad-file' in attr_info[filename]:
            flag = 1
            break

        time.sleep(10)
        count = count + 10
    if not flag:
        tc.logger.error("Scrubber failed to identify bad file")
        ret = False

    return ret
Example #3
0
def is_file_signed(filename, mountpoint, expected_file_version=None):
    """Verifies if the given file is signed

    Args:
        filename (str): relative path of filename to be verified
        mountpoint (str): mount point of the file. If mount type is
            nfs or cifs, then mount the volume with gluster mount and
            give the gluster mount path for this parameter.

    Kwargs:
        expected_file_version (str): file version to check with getfattr output
            If this option is set, this function
            will check file versioning as part of signing verification.
            If this option is set to None, function will not check
            for file versioning. Defaults to None.

    Returns:
        True on success, False otherwise

    Example:
        is_file_signed('file1', "/mnt/glusterfs", expected_file_version='2')
    """

    filename_mnt = mountpoint + "/" + filename

    # Getting file path in the rhs node
    file_location = get_pathinfo(filename_mnt)
    if file_location is None:
        tc.logger.error("Failed to get backend file path in is_file_signed()")
        return False

    path_info = file_location[0].split(":")

    expected_file_signature = calculate_checksum([path_info[1]], mnode=path_info[0])[path_info[1]]

    attr_info = get_extended_attributes_info([path_info[1]], mnode=path_info[0])
    if attr_info is None:
        tc.logger.error("Failed to get attribute info in is_file_signed()")
        return False

    file_signature = attr_info[path_info[1]]["trusted.bit-rot.signature"]

    if expected_file_version is not None:
        expected_file_version = ("{0:02d}".format(int(expected_file_version))).ljust(16, "0")
        actual_signature_file_version = re.findall(".{16}", file_signature[4:]).pop(0)

        # Verifying file version after signing
        if actual_signature_file_version != expected_file_version:
            tc.logger.error(
                "File version mismatch in signature.Filename: %s ."
                "Expected file version: %s.Actual file version: %s"
                % (filename, expected_file_version, actual_signature_file_version)
            )
            return False

    actual_file_signature = "".join(re.findall(".{16}", file_signature[4:])[1:])

    # Verifying file signature
    if actual_file_signature != expected_file_signature:
        tc.logger.error(
            "File signature mismatch. File name: %s . Expected "
            "file signature: %s. Actual file signature: %s" % (filename, expected_file_signature, actual_file_signature)
        )
        return False
    return True
Example #4
0
def is_file_signed(filename, mountpoint, expected_file_version=None):
    """Verifies if the given file is signed

    Args:
        filename (str): relative path of filename to be verified
        mountpoint (str): mount point of the file. If mount type is
            nfs or cifs, then mount the volume with gluster mount and
            give the gluster mount path for this parameter.

    Kwargs:
        expected_file_version (str): file version to check with getfattr output
            If this option is set, this function
            will check file versioning as part of signing verification.
            If this option is set to None, function will not check
            for file versioning. Defaults to None.

    Returns:
        True on success, False otherwise

    Example:
        is_file_signed('file1', "/mnt/glusterfs", expected_file_version='2')
    """

    filename_mnt = mountpoint + "/" + filename

    # Getting file path in the rhs node
    file_location = get_pathinfo(filename_mnt)
    if file_location is None:
        tc.logger.error("Failed to get backend file path in is_file_signed()")
        return False

    path_info = file_location[0].split(':')

    expected_file_signature = (calculate_checksum(
        [path_info[1]], mnode=path_info[0])[path_info[1]])

    attr_info = get_extended_attributes_info([path_info[1]],
                                             mnode=path_info[0])
    if attr_info is None:
        tc.logger.error("Failed to get attribute info in is_file_signed()")
        return False

    file_signature = attr_info[path_info[1]]['trusted.bit-rot.signature']

    if expected_file_version is not None:
        expected_file_version = ('{0:02d}'.format(
            int(expected_file_version))).ljust(16, '0')
        actual_signature_file_version = re.findall('.{16}',
                                                   file_signature[4:]).pop(0)

        # Verifying file version after signing
        if actual_signature_file_version != expected_file_version:
            tc.logger.error(
                "File version mismatch in signature.Filename: %s ."
                "Expected file version: %s.Actual file version: %s" %
                (filename, expected_file_version,
                 actual_signature_file_version))
            return False

    actual_file_signature = ''.join(
        re.findall('.{16}', file_signature[4:])[1:])

    # Verifying file signature
    if actual_file_signature != expected_file_signature:
        tc.logger.error(
            "File signature mismatch. File name: %s . Expected "
            "file signature: %s. Actual file signature: %s" %
            (filename, expected_file_signature, actual_file_signature))
        return False
    return True