Skip to content

Commit

Permalink
Backport changes from saltstack#45308
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy authored and rallytime committed Jan 11, 2018
1 parent f7da716 commit 0356b3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
14 changes: 11 additions & 3 deletions salt/states/file.py
Expand Up @@ -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']
Expand Down
Expand Up @@ -7,7 +7,7 @@
# | | |
# B --------+ | |
# | |
# D-------------+  |
# D-------------+ |
# |
# E-----------------+

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/files/file/prod/non-base-env.sls
@@ -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
21 changes: 10 additions & 11 deletions tests/integration/modules/test_state.py
Expand Up @@ -206,12 +206,7 @@ def test_issue_1896_file_append_source(self):
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
Expand Down Expand Up @@ -956,7 +951,8 @@ def test_get_file_from_env_in_top_match(self):
self.assertIn('Gromit', data)
self.assertIn('Comte', data)
finally:
os.unlink(tgt)
if os.path.islink(tgt):
os.unlink(tgt)

# onchanges tests

Expand Down Expand Up @@ -1258,17 +1254,20 @@ def test_state_nonbase_environment(self):
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)

0 comments on commit 0356b3d

Please sign in to comment.