From a6d54cd993744c3bc4de2feb76cd3a6a9834eed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu> Date: Wed, 23 Aug 2017 09:56:00 +0200 Subject: [PATCH] Check available disk space and not free space (refs #22279). --- tests/test_partitions.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/test_partitions.py b/tests/test_partitions.py index 5bb9fc30..ba81f825 100755 --- a/tests/test_partitions.py +++ b/tests/test_partitions.py @@ -29,13 +29,13 @@ paths = [ 'mount_point': '/', 'recommended_types': ('ext4',), 'min_size_gbytes': 14, - 'min_free_size_gbytes': 5, + 'min_available_gbytes': 5, }, { 'mount_point': '/home/msuser/msinstance', 'recommended_types': ('ext4', 'nfsv4'), 'min_size_gbytes': 400, - 'min_free_size_gbytes': 15, + 'min_available_gbytes': 15, }, { 'type': 'swap', @@ -59,12 +59,12 @@ def get_swap_gbytes(): def get_path(path): # Filesystem Type 1B-blocks Used Available Use% Mounted on # /dev/loop2 ext4 52710469632 38253940736 11755397120 77% / - status, output = subprocess.getstatusoutput('df --output="source,fstype,size,used" -B 1 %s | tail -n 1' % path) + status, output = subprocess.getstatusoutput('df --output="source,fstype,size,avail" -B 1 %s | tail -n 1' % path) if status == 0: - dev, fstype, size, used = output.split() + dev, fstype, size, available = output.split() else: - dev = fstype = size = used = None - return dev, fstype, to_gbytes(int(size)), to_gbytes(int(used)) + dev = fstype = size = available = None + return dev, fstype, to_gbytes(int(size)), to_gbytes(int(available)) def check_allocation(dev): @@ -105,19 +105,18 @@ def check_path(p): if os.path.exists(mount_point): mount_point = os.path.realpath(mount_point) name = mount_point - dev, fstype, psize, used = get_path(mount_point) + dev, fstype, psize, available = get_path(mount_point) if fstype not in p.get('recommended_types'): print('Warning, partition of %s fs type not recommended %s(current: %s, recommended: %s)%s' % (name, YELLOW, fstype, p['recommended_types'], DEF)) warning = True if 'nfs' not in dev: warning = not check_allocation(dev) - free_gb = psize - used - min_free_size_gbytes = p.get('min_free_size_gbytes') - if min_free_size_gbytes and free_gb < min_free_size_gbytes: - print('Partition of %s has less than %s GB free (%s GB free)' % (mount_point, min_free_size_gbytes, free_gb)) + min_available_gbytes = p.get('min_available_gbytes') + if min_available_gbytes and available < min_available_gbytes: + print('Partition of %s has less than %s GB available (%s GB available)' % (mount_point, min_available_gbytes, available)) error = True else: - print('Partition of %s is OK' % name) + print('Partition of %s is OK (%s GB available)' % (name, available)) else: print('%s not found, cannot check' % mount_point) elif p.get('type') == 'swap': -- GitLab