Esempio n. 1
0
def lvm_capacity():
    """
    Return the total LVM capacity in bytes
    """
    lines = execute('vgdisplay', 'lunr-volume', units='b')
    for line in lines.split('\n'):
        # Find the Volume Group Size in the output
        if re.search('VG Size', line):
            # First convert the bytes to GiB, then round down (trunc)
            # Then convert back to bytes. Do this because lunr/cinder
            # stores the size as an integer not a float
            return bytes_to_gibibytes(int(line.split()[2]))
Esempio n. 2
0
def node(helper):
    """
    Report any storage capacity and useage inconsistencies between the
    storage node and the API
    """
    # Get a list of active LVM Volumes
    lvs = [lv for lv in helper.volumes._scan_volumes()
           if lv['origin'] == '']

    # Get our node id
    node_id = request(helper, 'nodes?name=%s' % helper.name)
    # Fetch all information about our node
    node = request(helper, 'nodes/%s' % node_id[0]['id'])

    def msg(_msg):
        return {'node': node['id'], 'msg': _msg}

    # Calculate total space used by volumes
    space_used = 0
    for lv in lvs:
        space_used += bytes_to_gibibytes(lv['size'])

    # API should report the same used and available space
    if node['storage_used'] != space_used:
        return msg("API storage_used is inconsistent with node (%s != %s)"
                   % (node['storage_used'], space_used))

    # Ask the hardware how much capacity it has
    total_capacity = lvm_capacity()
    # Compare total capacity with lunr api capacity numbers
    if total_capacity != node['size']:
        return msg("API 'size' is inconsistent with storage node (%s != %s)"
                   % (node['size'], total_capacity))

    # Available storage should match also
    storage_free = total_capacity - space_used
    if storage_free != node['storage_free']:
        return msg("API 'storage_free' is inconsistent with storage node "
                   " (%s != %s)" % (node['storage_free'], storage_free))