Skip to content

Commit

Permalink
Merge pull request #52172 from garethgreenaway/51959_fix_acl_present_…
Browse files Browse the repository at this point in the history
…output

[2018.3] Changes to linux_acl state.
  • Loading branch information
dwoz authored Mar 27, 2019
2 parents 45d6cad + 8c53890 commit 7040643
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 10 additions & 2 deletions salt/states/linux_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@

# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import logging
import os

# Import salt libs
from salt.ext import six
from salt.exceptions import CommandExecutionError
import salt.utils.path

log = logging.getLogger(__name__)

__virtualname__ = 'acl'


Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/states/test_linux_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ def test_present(self):
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}}]},
Expand All @@ -65,7 +65,7 @@ def test_present(self):
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,
Expand All @@ -75,7 +75,7 @@ def test_present(self):
'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,
Expand All @@ -91,7 +91,7 @@ def test_present(self):
'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,
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_present(self):
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,
Expand All @@ -169,7 +169,7 @@ def test_present(self):
'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,
Expand Down

0 comments on commit 7040643

Please sign in to comment.