mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #52172 from garethgreenaway/51959_fix_acl_present_output
[2018.3] Changes to linux_acl state.
This commit is contained in:
commit
7040643a82
@ -29,6 +29,7 @@ Ensure a Linux ACL does not exist
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
# Import salt libs
|
||||
@ -36,6 +37,8 @@ from salt.ext import six
|
||||
from salt.exceptions import CommandExecutionError
|
||||
import salt.utils.path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__virtualname__ = 'acl'
|
||||
|
||||
|
||||
@ -60,6 +63,7 @@ def present(name, acl_type, acl_name='', perms='', recurse=False):
|
||||
'comment': ''}
|
||||
|
||||
_octal = {'r': 4, 'w': 2, 'x': 1, '-': 0}
|
||||
_octal_lookup = {0: '-', 1: 'r', 2: 'w', 4: 'x'}
|
||||
|
||||
if not os.path.exists(name):
|
||||
ret['comment'] = '{0} does not exist'.format(name)
|
||||
@ -111,18 +115,22 @@ def present(name, acl_type, acl_name='', perms='', recurse=False):
|
||||
if not need_refresh:
|
||||
ret['comment'] = 'Permissions are in the desired state'
|
||||
else:
|
||||
_num = user[_search_name]['octal']
|
||||
new_perms = '{}{}{}'.format(_octal_lookup[_num & 1],
|
||||
_octal_lookup[_num & 2],
|
||||
_octal_lookup[_num & 4])
|
||||
changes = {'new': {'acl_name': acl_name,
|
||||
'acl_type': acl_type,
|
||||
'perms': perms},
|
||||
'old': {'acl_name': acl_name,
|
||||
'acl_type': acl_type,
|
||||
'perms': six.text_type(user[_search_name]['octal'])}}
|
||||
'perms': new_perms}}
|
||||
|
||||
if __opts__['test']:
|
||||
ret.update({'comment': 'Updated permissions will be applied for '
|
||||
'{0}: {1} -> {2}'.format(
|
||||
acl_name,
|
||||
six.text_type(user[_search_name]['octal']),
|
||||
new_perms,
|
||||
perms),
|
||||
'result': None, 'pchanges': changes})
|
||||
return ret
|
||||
|
@ -43,17 +43,17 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
perms = 'rwx'
|
||||
|
||||
mock = MagicMock(side_effect=[{name: {acl_type: [{acl_name:
|
||||
{'octal': 'A'}}]}},
|
||||
{'octal': 5}}]}},
|
||||
{name: {acl_type: [{acl_name:
|
||||
{'octal': 'A'}}]}},
|
||||
{'octal': 5}}]}},
|
||||
{name: {acl_type: [{acl_name:
|
||||
{'octal': 'A'}}]}},
|
||||
{'octal': 5}}]}},
|
||||
{name: {acl_type: [{}]}},
|
||||
{name: {acl_type: [{}]}},
|
||||
{name: {acl_type: [{}]}},
|
||||
{
|
||||
name: {acl_type: [{acl_name: {'octal': 7}}]},
|
||||
name+"/foo": {acl_type: [{acl_name: {'octal': 'A'}}]}
|
||||
name+"/foo": {acl_type: [{acl_name: {'octal': 5}}]}
|
||||
},
|
||||
{
|
||||
name: {acl_type: [{acl_name: {'octal': 7}}]},
|
||||
@ -65,7 +65,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(linux_acl.__salt__, {'acl.getfacl': mock}):
|
||||
# Update - test=True
|
||||
with patch.dict(linux_acl.__opts__, {'test': True}):
|
||||
comt = ('Updated permissions will be applied for {0}: A -> {1}'
|
||||
comt = ('Updated permissions will be applied for {0}: r-x -> {1}'
|
||||
''.format(acl_name, perms))
|
||||
ret = {'name': name,
|
||||
'comment': comt,
|
||||
@ -75,7 +75,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'perms': perms},
|
||||
'old': {'acl_name': acl_name,
|
||||
'acl_type': acl_type,
|
||||
'perms': 'A'}},
|
||||
'perms': 'r-x'}},
|
||||
'result': None}
|
||||
|
||||
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
|
||||
@ -91,7 +91,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'perms': perms},
|
||||
'old': {'acl_name': acl_name,
|
||||
'acl_type': acl_type,
|
||||
'perms': 'A'}},
|
||||
'perms': 'r-x'}},
|
||||
'pchanges': {},
|
||||
'result': True}
|
||||
self.assertDictEqual(linux_acl.present(name, acl_type,
|
||||
@ -159,7 +159,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(linux_acl.__salt__, {'acl.getfacl': mock}):
|
||||
# Update - test=True
|
||||
with patch.dict(linux_acl.__opts__, {'test': True}):
|
||||
comt = ('Updated permissions will be applied for {0}: 7 -> {1}'
|
||||
comt = ('Updated permissions will be applied for {0}: rwx -> {1}'
|
||||
''.format(acl_name, perms))
|
||||
ret = {'name': name,
|
||||
'comment': comt,
|
||||
@ -169,7 +169,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'perms': perms},
|
||||
'old': {'acl_name': acl_name,
|
||||
'acl_type': acl_type,
|
||||
'perms': '7'}},
|
||||
'perms': 'rwx'}},
|
||||
'result': None}
|
||||
|
||||
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
|
||||
|
Loading…
Reference in New Issue
Block a user