From: Paulo E. Castro Date: Tue, 22 Apr 2025 23:07:01 +0000 (+0100) Subject: python-common/cryptotools: Always encode, Err via stderr and signal the exit. X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=56d508f9dc1b5503a465cb2b25838a1e81182a49;p=ceph.git python-common/cryptotools: Always encode, Err via stderr and signal the exit. Signed-off-by: Paulo E. Castro --- diff --git a/src/pybind/mgr/tests/test_tls.py b/src/pybind/mgr/tests/test_tls.py index 39ba5ae0a0333..7cba929fe438f 100644 --- a/src/pybind/mgr/tests/test_tls.py +++ b/src/pybind/mgr/tests/test_tls.py @@ -41,7 +41,6 @@ class TLSchecks(unittest.TestCase): new_key = crypto.PKey() new_key.generate_key(crypto.TYPE_RSA, 2048) new_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, new_key).decode('utf-8') - self.assertRaises(ServerConfigException, verify_tls, crt, new_key) def test_get_cert_issuer_info(self): diff --git a/src/python-common/ceph/cryptotools/cryptotools.py b/src/python-common/ceph/cryptotools/cryptotools.py index dd9f5367b6a17..e021cf82ad6b7 100644 --- a/src/python-common/ceph/cryptotools/cryptotools.py +++ b/src/python-common/ceph/cryptotools/cryptotools.py @@ -129,7 +129,8 @@ def get_cert_issuer_info(args: Namespace) -> None: def _fail_message(msg: str) -> None: - json.dump({'error': msg}, sys.stdout) + json.dump({'error': msg}, sys.stderr) + sys.exit(1) def verify_tls(args: Namespace) -> None: diff --git a/src/python-common/ceph/cryptotools/remote.py b/src/python-common/ceph/cryptotools/remote.py index 1ad410814454a..a83399828e1ff 100644 --- a/src/python-common/ceph/cryptotools/remote.py +++ b/src/python-common/ceph/cryptotools/remote.py @@ -55,16 +55,14 @@ class CryptoCaller: def _run( self, args: List[str], - input_data: Union[str, bytes, None] = None, + input_data: Union[str, None] = None, capture_output: bool = False, check: bool = False, ) -> subprocess.CompletedProcess: if input_data is None: _input = None - elif isinstance(input_data, str): - _input = input_data.encode('utf-8') else: - _input = input_data + _input = input_data.encode('utf-8') cmd = ['python3', '-m', _ctmodule] + list(args) logger.warning('CryptoCaller will run: %r', cmd) try: