mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
When test=True and there are permissions changes, report it.
This commit is contained in:
parent
1abffb20b9
commit
53ba0689a8
@ -2514,10 +2514,19 @@ def managed(name,
|
||||
inheritance=win_inheritance,
|
||||
reset=win_perms_reset)
|
||||
else:
|
||||
ret, _ = __salt__['file.check_perms'](
|
||||
ret, perms = __salt__['file.check_perms'](
|
||||
name, ret, user, group, mode, attrs, follow_symlinks)
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'File {0} not updated'.format(name)
|
||||
if isinstance(perms, dict) and \
|
||||
'lmode' in perms and \
|
||||
mode != perms['lmode']:
|
||||
ret['comment'] = ('File {0} will be updated with permissions '
|
||||
'{1} from its current '
|
||||
'state of {2}'.format(name,
|
||||
mode,
|
||||
perms['lmode']))
|
||||
else:
|
||||
ret['comment'] = 'File {0} not updated'.format(name)
|
||||
elif not ret['changes'] and ret['result']:
|
||||
ret['comment'] = ('File {0} exists with proper permissions. '
|
||||
'No changes made.'.format(name))
|
||||
|
@ -758,6 +758,28 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
|
||||
(name, user=user, group=group),
|
||||
ret)
|
||||
|
||||
if salt.utils.platform.is_windows():
|
||||
mock_ret = MagicMock(return_value=ret)
|
||||
comt = ('File {0} not updated'.format(name))
|
||||
else:
|
||||
perms = {'luser': user,
|
||||
'lmode': '0644',
|
||||
'lgroup': group}
|
||||
mock_ret = MagicMock(return_value=(ret, perms))
|
||||
comt = ('File {0} will be updated with '
|
||||
'permissions 0400 from its current '
|
||||
'state of 0644'.format(name))
|
||||
|
||||
with patch.dict(filestate.__salt__,
|
||||
{'file.check_perms': mock_ret}):
|
||||
with patch.object(os.path, 'exists', mock_t):
|
||||
with patch.dict(filestate.__opts__, {'test': True}):
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(filestate.managed
|
||||
(name, user=user,
|
||||
group=group,
|
||||
mode=400), ret)
|
||||
|
||||
# 'directory' function tests: 1
|
||||
|
||||
def test_directory(self):
|
||||
|
Loading…
Reference in New Issue
Block a user