mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #51992 from garethgreenaway/51932_show_diff_when_test_True
[2019.2] Swapping pchanges for changes in file state.
This commit is contained in:
commit
3173673dcc
2 changed files with 24 additions and 7 deletions
|
@ -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,
|
||||
|
@ -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)
|
||||
|
|
|
@ -459,6 +459,21 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
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):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue