Merge pull request #48375 from Ch3LL/file_copy

Add user and group to makedirs cmd in file.copy
This commit is contained in:
Nicole Thomas 2018-07-10 08:35:10 -04:00 committed by GitHub
commit 16d3daab3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -5669,7 +5669,7 @@ def copy(
if not os.path.isdir(dname):
if makedirs:
try:
_makedirs(name=name)
_makedirs(name=name, user=user, group=group, dir_mode=mode)
except CommandExecutionError as exc:
return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
else:

View file

@ -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)
@ -2529,6 +2534,27 @@ 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'
mode = '0644'
self.run_function('user.add', [user])
ret = self.run_state('file.copy', name=dest, source=source, user=user,
makedirs=True, mode=mode)
file_checks = [dest, os.path.join(TMP, 'dir1'), os.path.join(TMP, 'dir1', 'dir2')]
for check in file_checks:
user_check = self.run_function('file.get_user', [check])
mode_check = self.run_function('file.get_mode', [check])
assert user_check == user
assert salt.utils.normalize_mode(mode_check) == mode
def test_contents_pillar_with_pillar_list(self):
'''
This tests for any regressions for this issue: