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

[2018.3] removing use of comments from incron modules #52345

Merged
Show file tree
Hide file tree
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
36 changes: 15 additions & 21 deletions salt/modules/incron.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def _render_tab(lst):
for pre in lst['pre']:
ret.append('{0}\n'.format(pre))
for cron in lst['crons']:
ret.append('{0} {1} {2} {3}\n'.format(cron['path'],
cron['mask'],
cron['cmd'],
TAG
)
ret.append('{0} {1} {2}\n'.format(cron['path'],
cron['mask'],
cron['cmd'],
)
)
return ret

Expand Down Expand Up @@ -191,23 +190,18 @@ def list_tab(user):
'pre': []
}
flag = False
comment = None
tag = '# Line managed by Salt, do not edit'
for line in data.splitlines():
if line.endswith(tag):
if len(line.split()) > 3:
# Appears to be a standard incron line
comps = line.split()
path = comps[0]
mask = comps[1]
(cmd, comment) = ' '.join(comps[2:]).split(' # ')

dat = {'path': path,
'mask': mask,
'cmd': cmd,
'comment': comment}
ret['crons'].append(dat)
comment = None
if len(line.split()) > 3:
# Appears to be a standard incron line
comps = line.split()
path = comps[0]
mask = comps[1]
cmd = ' '.join(comps[2:])

dat = {'path': path,
'mask': mask,
'cmd': cmd}
ret['crons'].append(dat)
else:
ret['pre'].append(line)
return ret
Expand Down
5 changes: 5 additions & 0 deletions salt/states/incron.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals

import logging
log = logging.getLogger(__name__)


def _check_cron(user,
path,
Expand All @@ -56,6 +59,8 @@ def _check_cron(user,
arg_mask.sort()

lst = __salt__['incron.list_tab'](user)
if cmd.endswith('\n'):
cmd = cmd[:-1]
for cron in lst['crons']:
if path == cron['path'] and cron['cmd'] == cmd:
cron_mask = cron['mask'].split(',')
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/test_incron.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_set_job(self):

val = {'pre': [], 'crons': [{'path': '/home/cybage',
'mask': 'IN_MODIFY',
'cmd': 'echo "SALT"', 'comment': ''}]}
'cmd': 'echo "SALT"'}]}
with patch.object(incron, 'list_tab',
MagicMock(return_value=val)):
self.assertEqual(incron.set_job('cybage', '/home/cybage',
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_set_job(self):

val = {'pre': [], 'crons': [{'path': '/home/cybage',
'mask': 'IN_MODIFY,IN_DELETE',
'cmd': 'echo "SALT"', 'comment': ''}]}
'cmd': 'echo "SALT"'}]}
with patch.object(incron, 'list_tab',
MagicMock(return_value=val)):
mock = MagicMock(return_value='incrontab')
Expand Down