Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly compare values returned by 'sysctl -e -n' #5676

Merged
merged 2 commits into from
Jan 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion library/system/sysctl
Original file line number Diff line number Diff line change
Expand Up @@ -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 not self._values_is_equal(self.proc_value, self.args['value']):
self.changed = True
self.set_proc = True

Expand All @@ -161,6 +161,21 @@ class SysctlModule(object):
if self.set_proc:
self.set_token_value(self.args['name'], self.args['value'])

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."""
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
# ==============================================================
Expand Down