1
0
Fork 0

plugin_sysctl: consolidated whitespaces in values from profile configuration

Also introduced function remove_ws in utils which returns string
with consolidated whitespaces. Consolidated means with stripped
leading and trailing whitespaces and with multiple whitespaces
turned into one space.

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2015-05-19 17:41:47 +02:00
parent 6c51fc8725
commit 8cdf443cd0
2 changed files with 5 additions and 2 deletions

View file

@ -51,7 +51,7 @@ class SysctlPlugin(base.Plugin):
ret = True
for option, value in instance._sysctl.iteritems():
curr_val = self._read_sysctl(option)
if self._verify_value(option, value, curr_val) == False:
if self._verify_value(option, self._cmd.remove_ws(value), curr_val) == False:
ret = False
return ret
@ -67,7 +67,7 @@ class SysctlPlugin(base.Plugin):
def _read_sysctl(self, option):
retcode, stdout = self._execute_sysctl(["-e", option])
if retcode == 0:
parts = map(lambda value: re.sub('\s+', ' ', value).strip(), stdout.split("=", 1))
parts = map(lambda value: self._cmd.remove_ws(value), stdout.split("=", 1))
if len(parts) == 2:
option, value = parts
return value

View file

@ -26,6 +26,9 @@ class commands:
v = str(value).upper().strip()
return {"Y":"1", "YES":"1", "T":"1", "TRUE":"1", "N":"0", "NO":"0", "F":"0", "FALSE":"0"}.get(v, value)
def remove_ws(self, s):
return re.sub('\s+', ' ', s).strip()
def write_to_file(self, f, data):
self._debug("Writing to file: %s < %s" % (f, data))
try: