From 263ba7146abdbd99862f10b2827688b8f7fdcb68 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:46:08 +0200 Subject: [PATCH] Follow links for msinstance dir (refs #22279). --- tests/test_partitions.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/test_partitions.py b/tests/test_partitions.py index fa656197..5bb9fc30 100755 --- a/tests/test_partitions.py +++ b/tests/test_partitions.py @@ -10,6 +10,10 @@ import sys import os BS = 512 +YELLOW = '\033[93m' +GREEN = '\033[92m' +RED = '\033[91m' +DEF = '\033[0m' def to_gbytes(size_bytes): @@ -31,7 +35,7 @@ paths = [ 'mount_point': '/home/msuser/msinstance', 'recommended_types': ('ext4', 'nfsv4'), 'min_size_gbytes': 400, - 'min_free_size_gbytes': 10, + 'min_free_size_gbytes': 15, }, { 'type': 'swap', @@ -98,19 +102,22 @@ def check_path(p): psize = None mount_point = p.get('mount_point') if mount_point: - if os.path.isdir(mount_point): + if os.path.exists(mount_point): + mount_point = os.path.realpath(mount_point) name = mount_point - dev, fstype, psize, used = get_path(p['mount_point']) + dev, fstype, psize, used = get_path(mount_point) if fstype not in p.get('recommended_types'): - print('Warning, fs type %s not recommended (recommended: %s)' % (fstype, p['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('%s has less than %s GB free (%s GB free)' % (mount_point, min_free_size_gbytes, free_gb)) + print('Partition of %s has less than %s GB free (%s GB free)' % (mount_point, min_free_size_gbytes, free_gb)) error = True + else: + print('Partition of %s is OK' % name) else: print('%s not found, cannot check' % mount_point) elif p.get('type') == 'swap': @@ -118,25 +125,20 @@ def check_path(p): psize = get_swap_gbytes() if psize and psize < p['min_size_gbytes']: - print('%s is smaller than the minimum required size (%s GB < %s GB)' % (name, psize, p['min_size_gbytes'])) + print('%s is smaller than the minimum required size %s(%s GB < %s GB)%s' % (name, RED, psize, p['min_size_gbytes'], DEF)) error = True for p in paths: check_path(p) -OK = 0 -ERROR = 1 -WARNING = 3 -UNTESTABLE = 2 - if error: print('Errors found') - code = ERROR + code = 1 elif warning: print('Some warnings were found') - code = WARNING + code = 2 else: - print('All ok') - code = OK + print(GREEN + 'All ok' + DEF) + code = 0 sys.exit(code) -- GitLab