module_utils: don't add newline to the data

When executing a command via the run_command method and passing some
data with stdin then the default behavior is to add append a newline.
This breaks the value of password used by our modules.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
(cherry picked from commit 6616908577)
pull/6210/head
Dimitri Savineau 2021-01-13 21:11:39 -05:00 committed by Dimitri Savineau
parent fdda54eeb4
commit c4f11809c4
2 changed files with 18 additions and 1 deletions

View File

@ -179,7 +179,10 @@ def exec_commands(module, cmd, stdin=None):
Execute command(s)
'''
rc, out, err = module.run_command(cmd, data=stdin)
binary_data = False
if stdin:
binary_data = True
rc, out, err = module.run_command(cmd, data=stdin, binary_data=binary_data)
return rc, cmd, out, err

View File

@ -241,3 +241,17 @@ class TestCephDashboardUserModule(object):
]
assert ceph_dashboard_user.remove_user(self.fake_module) == expected_cmd
@pytest.mark.parametrize('stdin', [None, 'foo'])
def test_exec_command(self, stdin):
fake_module = MagicMock()
rc = 0
stderr = ''
stdout = 'ceph version 1.2.3'
fake_module.run_command.return_value = 0, stdout, stderr
expected_cmd = [self.fake_binary, '--version']
_rc, _cmd, _out, _err = ceph_dashboard_user.exec_commands(fake_module, expected_cmd, stdin=stdin)
assert _rc == rc
assert _cmd == expected_cmd
assert _err == stderr
assert _out == stdout