Backport changes from #45308

This commit is contained in:
twangboy 2018-01-10 11:16:59 -07:00
parent 541e59fa75
commit 419be8a9b5
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB
4 changed files with 23 additions and 16 deletions

View file

@ -2332,9 +2332,17 @@ def managed(name,
)
if salt.utils.is_windows():
ret = __salt__['file.check_perms'](
name, ret, win_owner, win_perms, win_deny_perms,
win_inheritance)
try:
ret = __salt__['file.check_perms'](
path=name,
ret=ret,
owner=win_owner,
grant_perms=win_perms,
deny_perms=win_deny_perms,
inheritance=win_inheritance)
except CommandExecutionError as exc:
if exc.strerror.startswith('Path not found'):
ret['pchanges'] = '{0} will be created'.format(name)
if isinstance(ret['pchanges'], tuple):
ret['result'], ret['comment'] = ret['pchanges']

View file

@ -7,7 +7,7 @@
# | | |
# B --------+ | |
# | |
# D-------------+  |
# D-------------+ |
# |
# E-----------------+

View file

@ -1,4 +1,4 @@
test_file:
file.managed:
- name: /tmp/nonbase_env
- name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('nonbase_env') }}
- source: salt://nonbase_env

View file

@ -205,12 +205,7 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
''')
if not salt.utils.is_windows():
contents += os.linesep
contents += textwrap.dedent('''\
# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
@ -971,7 +966,8 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
self.assertIn('Gromit', data)
self.assertIn('Comte', data)
finally:
os.unlink(tgt)
if os.path.islink(tgt):
os.unlink(tgt)
# onchanges tests
@ -1273,17 +1269,20 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
test state.sls with saltenv using a nonbase environment
with a salt source
'''
file_name = os.path.join(TMP, 'nonbase_env')
state_run = self.run_function(
'state.sls',
mods='non-base-env',
saltenv='prod'
)
state_id = 'file_|-test_file_|-/tmp/nonbase_env_|-managed'
self.assertEqual(state_run[state_id]['comment'], 'File /tmp/nonbase_env updated')
self.assertTrue(state_run['file_|-test_file_|-/tmp/nonbase_env_|-managed']['result'])
self.assertTrue(os.path.isfile('/tmp/nonbase_env'))
state_id = 'file_|-test_file_|-{0}_|-managed'.format(file_name)
self.assertEqual(state_run[state_id]['comment'],
'File {0} updated'.format(file_name))
self.assertTrue(
state_run['file_|-test_file_|-{0}_|-managed'.format(file_name)]['result'])
self.assertTrue(os.path.isfile(file_name))
def tearDown(self):
nonbase_file = '/tmp/nonbase_env'
nonbase_file = os.path.join(TMP, 'nonbase_env')
if os.path.isfile(nonbase_file):
os.remove(nonbase_file)