From 45728d739cb7f6f252b7ff502cf07f93292c7c19 Mon Sep 17 00:00:00 2001 From: Simon Zimmermann Date: Sat, 18 Jan 2014 10:50:24 +0100 Subject: [PATCH 1/2] Correctly compare values as returned from 'sysctl -e -n' --- system/sysctl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/system/sysctl b/system/sysctl index 59b92eb6f48..0039928809a 100644 --- a/system/sysctl +++ b/system/sysctl @@ -148,7 +148,7 @@ class SysctlModule(object): if self.args['sysctl_set']: if self.proc_value is None: self.changed = True - elif self.proc_value != self.args['value']: + elif self._compare_values(self.proc_value, self.args['value']): self.changed = True self.set_proc = True @@ -161,6 +161,21 @@ class SysctlModule(object): if self.set_proc: self.set_token_value(self.args['name'], self.args['value']) + def _compare_values(self, a, b): + """Expects two string values. It will split the string by whitespace + and compare each value. It will return True if both lists are the same, + contain the same elements and the same order.""" + if a is None or b is None: + return False + + a = a.split() + b = b.split() + + if len(a) != len(b): + return False + + return len([i for i, j in zip(a, b) if i == j]) != len(a) + # ============================================================== # SYSCTL COMMAND MANAGEMENT # ============================================================== From be69ca4eaddb9b19828fb7b6cd053f2c4c6116b8 Mon Sep 17 00:00:00 2001 From: Simon Zimmermann Date: Sat, 18 Jan 2014 11:04:15 +0100 Subject: [PATCH 2/2] correctly compare the values, better func name --- system/sysctl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/sysctl b/system/sysctl index 0039928809a..85fe4151d37 100644 --- a/system/sysctl +++ b/system/sysctl @@ -148,7 +148,7 @@ class SysctlModule(object): if self.args['sysctl_set']: if self.proc_value is None: self.changed = True - elif self._compare_values(self.proc_value, self.args['value']): + elif not self._values_is_equal(self.proc_value, self.args['value']): self.changed = True self.set_proc = True @@ -161,7 +161,7 @@ class SysctlModule(object): if self.set_proc: self.set_token_value(self.args['name'], self.args['value']) - def _compare_values(self, a, b): + def _values_is_equal(self, a, b): """Expects two string values. It will split the string by whitespace and compare each value. It will return True if both lists are the same, contain the same elements and the same order.""" @@ -174,7 +174,7 @@ class SysctlModule(object): if len(a) != len(b): return False - return len([i for i, j in zip(a, b) if i == j]) != len(a) + return len([i for i, j in zip(a, b) if i == j]) == len(a) # ============================================================== # SYSCTL COMMAND MANAGEMENT