Skip to content

Commit

Permalink
chroot: fix bug in safe_kwargs iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
aplanas committed Sep 12, 2019
1 parent 19967cf commit b87c46c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion salt/modules/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def call(root, function, *args, **kwargs):
.. code-block:: bash
salt myminion chroot.call /chroot test.ping
salt myminion chroot.call /chroot ssh.set_auth_key user key=mykey
'''

Expand Down Expand Up @@ -147,7 +148,7 @@ def call(root, function, *args, **kwargs):
'-l', 'quiet',
'--',
function
] + list(args) + ['{}={}'.format(k, v) for (k, v) in safe_kwargs]
] + list(args) + ['{}={}'.format(k, v) for (k, v) in safe_kwargs.items()]
ret = __salt__['cmd.run_chroot'](root, [str(x) for x in salt_argv])
if ret['retcode'] != EX_OK:
raise CommandExecutionError(ret['stderr'])
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/modules/test_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import sys

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
Expand Down Expand Up @@ -182,3 +183,41 @@ def test_call_success(self, mkdtemp, exist):
salt_mock['archive.tar'].assert_called_once()
salt_mock['cmd.run_chroot'].assert_called_once()
utils_mock['files.rm_rf'].assert_called_once()

@patch('salt.modules.chroot.exist')
@patch('tempfile.mkdtemp')
def test_call_success_parameters(self, mkdtemp, exist):
'''
Test execution of Salt functions in chroot with parameters.
'''
# Success test
exist.return_value = True
mkdtemp.return_value = '/chroot/tmp01'
utils_mock = {
'thin.gen_thin': MagicMock(return_value='/salt-thin.tgz'),
'files.rm_rf': MagicMock(),
'json.find_json': MagicMock(return_value={'return': 'result'})
}
salt_mock = {
'archive.tar': MagicMock(return_value=''),
'config.option': MagicMock(),
'cmd.run_chroot': MagicMock(return_value={
'retcode': 0,
'stdout': '',
}),
}
with patch.dict(chroot.__utils__, utils_mock), \
patch.dict(chroot.__salt__, salt_mock):
self.assertEqual(chroot.call('/chroot', 'ssh.set_auth_key',
user='user', key='key'), 'result')
utils_mock['thin.gen_thin'].assert_called_once()
salt_mock['config.option'].assert_called()
salt_mock['archive.tar'].assert_called_once()
salt_mock['cmd.run_chroot'].assert_called_with(
'/chroot',
['python{}'.format(sys.version_info[0]), '/tmp01/salt-call',
'--metadata', '--local',
'--log-file', '/tmp01/log', '--cachedir', '/tmp01/cache',
'--out', 'json', '-l', 'quiet',
'--', 'ssh.set_auth_key', 'user=user', 'key=key'])
utils_mock['files.rm_rf'].assert_called_once()

0 comments on commit b87c46c

Please sign in to comment.