mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Cleaning up some stuff related to the connection info/become/executable change
This commit is contained in:
parent
1c185b68be
commit
3d77723e3d
3 changed files with 10 additions and 12 deletions
|
@ -325,7 +325,6 @@ class ConnectionInformation:
|
|||
prompt = None
|
||||
success_key = None
|
||||
|
||||
print("in make_become_cmd, executable is: %s" % executable)
|
||||
if executable is None:
|
||||
executable = C.DEFAULT_EXECUTABLE
|
||||
|
||||
|
@ -381,7 +380,7 @@ class ConnectionInformation:
|
|||
self.success_key = success_key
|
||||
return ('%s -c ' % executable) + pipes.quote(becomecmd)
|
||||
|
||||
return ('%s -c ' % executable) + pipes.quote(cmd)
|
||||
return cmd
|
||||
|
||||
def _get_fields(self):
|
||||
return [i for i in self.__dict__.keys() if i[:1] != '_']
|
||||
|
|
|
@ -429,7 +429,6 @@ class ActionBase:
|
|||
debug("no command, exiting _low_level_execute_command()")
|
||||
return dict(stdout='', stderr='')
|
||||
|
||||
print("in _low_level_execute_command, executable is: %s" % executable)
|
||||
if sudoable:
|
||||
cmd = self._connection_info.make_become_cmd(cmd, executable=executable)
|
||||
|
||||
|
|
|
@ -129,27 +129,27 @@ class TestConnectionInformation(unittest.TestCase):
|
|||
pfexec_exe = 'pfexec'
|
||||
pfexec_flags = ''
|
||||
|
||||
(cmd, prompt, key) = conn_info.make_become_cmd(cmd=default_cmd, executable=default_exe)
|
||||
cmd = conn_info.make_become_cmd(cmd=default_cmd, executable=default_exe)
|
||||
self.assertEqual(cmd, default_cmd)
|
||||
|
||||
conn_info.become = True
|
||||
conn_info.become_user = 'foo'
|
||||
|
||||
conn_info.become_method = 'sudo'
|
||||
(cmd, prompt, key) = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s -k && %s %s -S -p "%s" -u %s %s -c '"'"'echo %s; %s'"'"''""" % (default_exe, sudo_exe, sudo_exe, sudo_flags, prompt, conn_info.become_user, default_exe, key, default_cmd))
|
||||
cmd = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s -k && %s %s -S -p "%s" -u %s %s -c '"'"'echo %s; %s'"'"''""" % (default_exe, sudo_exe, sudo_exe, sudo_flags, conn_info.prompt, conn_info.become_user, default_exe, conn_info.success_key, default_cmd))
|
||||
|
||||
conn_info.become_method = 'su'
|
||||
(cmd, prompt, key) = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s %s -c "%s -c '"'"'echo %s; %s'"'"'"'""" % (default_exe, su_exe, conn_info.become_user, default_exe, key, default_cmd))
|
||||
cmd = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s %s -c "%s -c '"'"'echo %s; %s'"'"'"'""" % (default_exe, su_exe, conn_info.become_user, default_exe, conn_info.success_key, default_cmd))
|
||||
|
||||
conn_info.become_method = 'pbrun'
|
||||
(cmd, prompt, key) = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s -b %s -u %s '"'"'echo %s; %s'"'"''""" % (default_exe, pbrun_exe, pbrun_flags, conn_info.become_user, key, default_cmd))
|
||||
cmd = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s -b %s -u %s '"'"'echo %s; %s'"'"''""" % (default_exe, pbrun_exe, pbrun_flags, conn_info.become_user, conn_info.success_key, default_cmd))
|
||||
|
||||
conn_info.become_method = 'pfexec'
|
||||
(cmd, prompt, key) = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s %s "'"'"'echo %s; %s'"'"'"'""" % (default_exe, pfexec_exe, pfexec_flags, key, default_cmd))
|
||||
cmd = conn_info.make_become_cmd(cmd=default_cmd, executable="/bin/bash")
|
||||
self.assertEqual(cmd, """%s -c '%s %s "'"'"'echo %s; %s'"'"'"'""" % (default_exe, pfexec_exe, pfexec_flags, conn_info.success_key, default_cmd))
|
||||
|
||||
conn_info.become_method = 'bad'
|
||||
self.assertRaises(AnsibleError, conn_info.make_become_cmd, cmd=default_cmd, executable="/bin/bash")
|
||||
|
|
Loading…
Reference in a new issue