mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixing the output when there are changes for the ACL state so the permissions are shown and not the octal number.
This commit is contained in:
parent
f8c0266569
commit
4b99afa819
2 changed files with 20 additions and 11 deletions
|
@ -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,11 @@ def present(name, acl_type, acl_name='', perms='', recurse=False):
|
|||
'comment': ''}
|
||||
|
||||
_octal = {'r': 4, 'w': 2, 'x': 1, '-': 0}
|
||||
_octal_lookup = {'1': 'x',
|
||||
'2': 'w',
|
||||
'4': 'r',
|
||||
'5': 'rx',
|
||||
'7': 'rwx'}
|
||||
|
||||
if not os.path.exists(name):
|
||||
ret['comment'] = '{0} does not exist'.format(name)
|
||||
|
@ -111,18 +119,19 @@ def present(name, acl_type, acl_name='', perms='', recurse=False):
|
|||
if not need_refresh:
|
||||
ret['comment'] = 'Permissions are in the desired state'
|
||||
else:
|
||||
new_perms = _octal_lookup[six.text_type(user[_search_name]['octal'])]
|
||||
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}: rx -> {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': 'rx'}},
|
||||
'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': 'rx'}},
|
||||
'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…
Add table
Reference in a new issue