From 4652800a3439fa7af10ed918774791b947d0cc28 Mon Sep 17 00:00:00 2001 From: cburroughs Date: Fri, 21 Nov 2014 15:21:12 -0500 Subject: [PATCH] fix handling of boolean config files Config values appear to all be treated as strings regardless of quotes. That mean `"True"` is not `True` and thus '"True" is True` is false. This would result in garbage values being recorded and all of the problems that `force_double` was supposed to address. --- zfs_arc/python_modules/zfs_arc.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zfs_arc/python_modules/zfs_arc.py b/zfs_arc/python_modules/zfs_arc.py index 6b145a78..ff05fb9e 100644 --- a/zfs_arc/python_modules/zfs_arc.py +++ b/zfs_arc/python_modules/zfs_arc.py @@ -179,6 +179,14 @@ 'units': 'bytes/s'}, ] +def sbool(s): + """ convert a string that is probably supposed to be a boolean + value into an actual bool type.""" + if isinstance(s, str): + return s.lower() in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh'] + else: + return bool(s) + ##### Data Access class ArcStats(object): @@ -338,7 +346,7 @@ def metric_init(params): d['name'] = METRIC_PREFIX + d['name'] d['call_back'] = ARC_STATS.get_metric_value descriptors.append(d) - if params['force_double'] is True: + if sbool(params['force_double']) is True: d['value_type'] = 'double' d['format'] = '%f' log.debug('descriptors: %r' % descriptors)