Merge pull request #8325 from cachedout/#7860

Add a dir_mode to file.managed
This commit is contained in:
Colton Myers 2013-11-07 09:35:54 -08:00
commit 78662d270b
3 changed files with 33 additions and 3 deletions

View File

@ -2135,7 +2135,8 @@ def manage_file(name,
backup,
template=None,
show_diff=True,
contents=None):
contents=None,
dir_mode=None):
'''
Checks the destination against what was retrieved with get_managed and
makes the appropriate modifications (if necessary).
@ -2282,7 +2283,7 @@ def manage_file(name,
if not os.path.isdir(os.path.dirname(name)):
if makedirs:
makedirs(name, user=user, group=group, mode=mode)
makedirs(name, user=user, group=group, mode=dir_mode or mode)
else:
__clean_tmp(sfn)
return _error(ret, 'Parent directory not present')

View File

@ -933,6 +933,7 @@ def managed(name,
mode=None,
template=None,
makedirs=False,
dir_mode=None,
context=None,
replace=True,
defaults=None,
@ -999,6 +1000,11 @@ def managed(name,
directories will be created to facilitate the creation of the named
file.
dir_mode
If directories are to be created, passing this option specifies the
permissions for those directories. If this is not set, directories
will be assigned permissions from the 'mode' argument.
replace
If this file should be replaced. If false, this command will
not overwrite file contents but will enforce permissions if the file
@ -1163,7 +1169,8 @@ def managed(name,
backup,
template,
show_diff,
contents)
contents,
dir_mode)
def directory(name,

View File

@ -15,6 +15,9 @@ ensure_in_syspath('../../')
import integration
import salt.utils
# Import Python libs
import stat
class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
'''
@ -109,6 +112,25 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
self.assertEqual(master_data, minion_data)
self.assertSaltTrueReturn(ret)
def test_managed_dir_mode(self):
'''
Tests to ensure that file.managed creates directories with the permissions
requested with the dir_mode argument
'''
desired_mode=511 # 0777 in octal
name = os.path.join(integration.TMP, 'a', 'managed_dir_mode_test_file')
ret = self.run_state(
'file.managed',
name=name,
source='salt://grail/scene33',
mode=600,
makedirs=True,
dir_mode=oct(desired_mode) # 0777
)
resulting_mode = stat.S_IMODE(os.stat(os.path.join(integration.TMP, 'a')).st_mode)
self.assertEqual(oct(desired_mode), oct(resulting_mode))
self.assertSaltTrueReturn(ret)
def test_test_managed(self):
'''
file.managed test interface