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

ipset: fix the comment containing blank #34233

Merged
merged 1 commit into from
Jun 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions salt/states/ipset.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ def present(name, entry=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}
test_flag = False

if not entry:
ret['result'] = False
Expand All @@ -198,25 +197,24 @@ def present(name, entry=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)
if 'timeout' in kwargs:
if 'comment' in _entry:
_entry = '{0} timeout {1} {2} {3}'.format(entry.split()[0], kwargs['timeout'], entry.split()[1], entry.split()[2])
else:
_entry = '{0} timeout {1}'.format(entry.split()[0], kwargs['timeout'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

if __salt__['ipset.check'](kwargs['set_name'],
_entry,
family) is True:
if test_flag is False:
ret['result'] = True
ret['comment'] += 'entry for {0} already in set ({1}) for {2}\n'.format(
entry,
kwargs['set_name'],
family)
else:
if __opts__['test']:
test_flag = True
ret['result'] = None
ret['comment'] += 'entry {0} needs to be added to set {1} for family {2}\n'.format(
entry,
Expand All @@ -226,7 +224,6 @@ def present(name, entry=None, family='ipv4', **kwargs):
command = __salt__['ipset.add'](kwargs['set_name'], entry, family, **kwargs)
if 'Error' not in command:
ret['changes'] = {'locale': name}
ret['result'] = True
ret['comment'] += 'entry {0} added to set {1} for family {2}\n'.format(
_entry,
kwargs['set_name'],
Expand Down Expand Up @@ -255,7 +252,7 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}

if not entry:
Expand All @@ -270,23 +267,26 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)

if 'comment' in kwargs:
_entry = '{0} comment "{1}"'.format(entry, kwargs['comment'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

log.debug('_entry {0}'.format(_entry))
if not __salt__['ipset.check'](kwargs['set_name'],
_entry,
family) is True:
ret['result'] = True
ret['comment'] += 'ipset entry for {0} not present in set ({1}) for {2}\n'.format(
_entry,
kwargs['set_name'],
family)
else:

if __opts__['test']:
ret['result'] = None
ret['comment'] += 'ipset entry {0} needs to removed from set {1} for family {2}\n'.format(
entry,
kwargs['set_name'],
Expand All @@ -295,7 +295,6 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
command = __salt__['ipset.delete'](kwargs['set_name'], entry, family, **kwargs)
if 'Error' not in command:
ret['changes'] = {'locale': name}
ret['result'] = True
ret['comment'] += 'ipset entry {1} for set {0} removed for family {2}\n'.format(
kwargs['set_name'],
_entry,
Expand Down