def test_mountpoints_in_group(mplist, patterns_include, patterns_exclude, expected): """Returns list of mountpoints without duplicates.""" result = df.mountpoints_in_group(mplist, patterns_include, patterns_exclude) assert isinstance(result, list) assert result == expected
def df_check_filesystem_list_coroutine( item, params, fslist_blocks, fslist_inodes=None, this_time=None, ): """Wrapper for `df_check_filesystem_single` supporting groups""" def group_sum(metric_name, info, mountpoints_group): """Calculate sum of named values for matching mount points""" return sum(block_info[metric_name] # for (mp, block_info) in info.items() # if mp in mountpoints_group) # Translate lists of tuples into convienient dicts blocks_info = { mountp: { "size_mb": size_mb, "avail_mb": avail_mb, "reserved_mb": reserved_mb, } for (mountp, size_mb, avail_mb, reserved_mb) in (fslist_blocks or []) } inodes_info = { mountp: { "inodes_total": inodes_total, "inodes_avail": inodes_avail, } for (mountp, inodes_total, inodes_avail) in (fslist_inodes or []) } if "patterns" not in params: # No patterns provided - return result for mountpoint defined in @item if item not in blocks_info: return data, inodes_data = blocks_info.get(item), inodes_info.get(item, {}) assert data is not None yield from df_check_filesystem_single_coroutine( item, data["size_mb"], data["avail_mb"], data["reserved_mb"], inodes_data.get("inodes_total"), inodes_data.get("inodes_avail"), params, this_time, ) return matching_mountpoints = mountpoints_in_group(blocks_info, *params["patterns"]) if not matching_mountpoints: yield 3, "No filesystem matching the patterns", [] return total_size_mb = group_sum("size_mb", blocks_info, matching_mountpoints) total_avail_mb = group_sum("avail_mb", blocks_info, matching_mountpoints) total_reserved_mb = group_sum("reserved_mb", blocks_info, matching_mountpoints) total_inodes = group_sum("inodes_total", inodes_info, matching_mountpoints) total_inodes_avail = group_sum("inodes_avail", inodes_info, matching_mountpoints) yield from df_check_filesystem_single_coroutine( item, total_size_mb, total_avail_mb, total_reserved_mb, total_inodes, total_inodes_avail, params, this_time, ) yield 0, "%d filesystems" % len(matching_mountpoints), []