Skip to content

Commit

Permalink
Fix a issue with multi-value sysctls
Browse files Browse the repository at this point in the history
Following state file to reproduce:

    net.ipv4.tcp_rmem:
      sysctl:
        - present
        - value: 4096 87380 16777216

    net.ipv4.tcp_wmem:
      sysctl:
        - present
        - value: 4096 87380 16777216

Without this patch, these two sysctls will be constantly
set over and over again each time state.highstate is called
  • Loading branch information
SEJeff committed Mar 20, 2012
1 parent 7d657ef commit 545dca0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions salt/modules/linux_sysctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

__outputter__ = {
'assign': 'txt',
'get': 'txt',
}


Expand Down Expand Up @@ -106,9 +107,21 @@ def persist(name, value, config='/etc/sysctl.conf'):
if '=' not in line:
nlines.append(line)
continue
comps = line.split('=')
comps[0] = comps[0].strip()
comps[1] = comps[1].strip()

# Strip trailing whitespace and split the k,v
comps = [i.strip() for i in line.split('=', 1)]

# On Linux procfs, files such as /proc/sys/net/ipv4/tcp_rmem or any
# other sysctl with whitespace in it consistently uses 1 tab. Lets
# allow our users to put a space or tab between multi-value sysctls
# and have salt not try to set it every single time.
if isinstance(comps[1], basestring) and ' ' in comps[1]:
comps[1] = re.sub('\s+', '\t', comps[1])

# Do the same thing for the value 'just in case'
if isinstance(value, basestring) and ' ' in value:
value = re.sub('\s+', '\t', value)

if len(comps) < 2:
nlines.append(line)
continue
Expand Down

0 comments on commit 545dca0

Please sign in to comment.