From c4f11809c461f7ff10cd249875f1113489e17ac7 Mon Sep 17 00:00:00 2001 From: Dimitri Savineau Date: Wed, 13 Jan 2021 21:11:39 -0500 Subject: [PATCH] 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 (cherry picked from commit 661690857726de9a63abc3c9503f6bcae52cb975) --- library/ceph_dashboard_user.py | 5 ++++- tests/library/test_ceph_dashboard_user.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/library/ceph_dashboard_user.py b/library/ceph_dashboard_user.py index 39d806062..6565a776d 100644 --- a/library/ceph_dashboard_user.py +++ b/library/ceph_dashboard_user.py @@ -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 diff --git a/tests/library/test_ceph_dashboard_user.py b/tests/library/test_ceph_dashboard_user.py index aa6118bbe..b3f4e4303 100644 --- a/tests/library/test_ceph_dashboard_user.py +++ b/tests/library/test_ceph_dashboard_user.py @@ -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 -- 2.39.5