mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add user and group to makedirs cmd in file.copy
This commit is contained in:
parent
14db0aa35d
commit
2cbcb4fd26
2 changed files with 23 additions and 1 deletions
|
@ -5663,7 +5663,7 @@ def copy(
|
|||
if not os.path.isdir(dname):
|
||||
if makedirs:
|
||||
try:
|
||||
_makedirs(name=name)
|
||||
_makedirs(name=name, user=user, group=group)
|
||||
except CommandExecutionError as exc:
|
||||
return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
|
||||
else:
|
||||
|
|
|
@ -25,6 +25,7 @@ from tests.support.case import ModuleCase
|
|||
from tests.support.unit import skipIf
|
||||
from tests.support.paths import FILES, TMP, TMP_STATE_TREE
|
||||
from tests.support.helpers import (
|
||||
destructiveTest,
|
||||
skip_if_not_root,
|
||||
with_system_user_and_group,
|
||||
with_tempfile,
|
||||
|
@ -137,6 +138,10 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
'''
|
||||
remove files created in previous tests
|
||||
'''
|
||||
user = 'salt'
|
||||
if user in str(self.run_function('user.list_users', [user])):
|
||||
self.run_function('user.delete', [user])
|
||||
|
||||
for path in (FILEPILLAR, FILEPILLARDEF, FILEPILLARGIT):
|
||||
try:
|
||||
os.remove(path)
|
||||
|
@ -2478,6 +2483,23 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
os.remove(source)
|
||||
os.remove(dest)
|
||||
|
||||
@destructiveTest
|
||||
@with_tempfile
|
||||
def test_file_copy_make_dirs(self, source):
|
||||
'''
|
||||
ensure make_dirs creates correct user perms
|
||||
'''
|
||||
shutil.copyfile(os.path.join(FILES, 'hosts'), source)
|
||||
dest = os.path.join(TMP, 'dir1', 'dir2', 'copied_file.txt')
|
||||
|
||||
user = 'salt'
|
||||
self.run_function('user.add', [user])
|
||||
ret = self.run_state('file.copy', name=dest, source=source, user=user, makedirs=True)
|
||||
file_checks = [dest, os.path.join(TMP, 'dir1'), os.path.join(TMP, 'dir1', 'dir2')]
|
||||
for check in file_checks:
|
||||
ret = self.run_function('file.get_user', [check])
|
||||
assert ret == user
|
||||
|
||||
def test_contents_pillar_with_pillar_list(self):
|
||||
'''
|
||||
This tests for any regressions for this issue:
|
||||
|
|
Loading…
Add table
Reference in a new issue