Skip to content

Commit

Permalink
Merge pull request saltstack#51992 from garethgreenaway/51932_show_di…
Browse files Browse the repository at this point in the history
…ff_when_test_True

[2019.2] Swapping pchanges for changes in file state.
  • Loading branch information
garethgreenaway authored Apr 9, 2019
2 parents bd3ad7b + 7c4abd6 commit 3173673
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
16 changes: 9 additions & 7 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2736,7 +2736,7 @@ def managed(name,
try:
if __opts__['test']:
if 'file.check_managed_changes' in __salt__:
ret['pchanges'] = __salt__['file.check_managed_changes'](
ret['changes'] = __salt__['file.check_managed_changes'](
name,
source,
source_hash,
Expand Down Expand Up @@ -2767,15 +2767,17 @@ def managed(name,
reset=win_perms_reset)
except CommandExecutionError as exc:
if exc.strerror.startswith('Path not found'):
ret['pchanges'] = '{0} will be created'.format(name)
ret['changes'] = {name: 'will be created'}

if isinstance(ret['pchanges'], tuple):
ret['result'], ret['comment'] = ret['pchanges']
elif ret['pchanges']:
if isinstance(ret['changes'], tuple):
ret['result'], ret['comment'] = ret['changes']
elif ret['changes']:
ret['result'] = None
ret['comment'] = 'The file {0} is set to be changed'.format(name)
if 'diff' in ret['pchanges'] and not show_changes:
ret['pchanges']['diff'] = '<show_changes=False>'
ret['comment'] += ('\nNote: No changes made, actual changes may\n'
'be different due to other states.')
if 'diff' in ret['changes'] and not show_changes:
ret['changes']['diff'] = '<show_changes=False>'
else:
ret['result'] = True
ret['comment'] = 'The file {0} is in the correct state'.format(name)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,21 @@ def test_managed_show_changes_false(self):
changes = next(six.itervalues(ret))['changes']
self.assertEqual('<show_changes=False>', changes['diff'])

def test_managed_show_changes_true(self):
'''
file.managed test interface
'''
name = os.path.join(TMP, 'grail_not_scene33')
with salt.utils.files.fopen(name, 'wb') as fp_:
fp_.write(b'test_managed_show_changes_false\n')

ret = self.run_state(
'file.managed', name=name, source='salt://grail/scene33',
)

changes = next(six.itervalues(ret))['changes']
self.assertIn('diff', changes)

@skipIf(IS_WINDOWS, 'Don\'t know how to fix for Windows')
def test_managed_escaped_file_path(self):
'''
Expand Down

0 comments on commit 3173673

Please sign in to comment.