From effd154e04a56203296a46fcce0b1919ddd029fb Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Thu, 8 Jan 2026 14:56:36 +0100 Subject: kolla_toolbox: Add support for deprecation warnings ansible-core 2.20 introduced some deprecation warnings in internal module functions and not all modules have adapted to new functionality, therefore kolla_toolbox invocations contain both deprecation warnings (or other warnings) and JSON blocks. This patch adds support for separating these and printing deprecation warnings using warn() function in AnsibleModule Closes-Bug: #2138234 Change-Id: I2008d9d8c85b2216036f5155e29f7e5db43832f0 Signed-off-by: Michal Nasiadka --- tests/test_kolla_toolbox.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/test_kolla_toolbox.py b/tests/test_kolla_toolbox.py index 9dca821cc..e170964db 100644 --- a/tests/test_kolla_toolbox.py +++ b/tests/test_kolla_toolbox.py @@ -263,6 +263,53 @@ class TestKollaToolboxMethods(TestKollaToolboxModule): self.assertIn('Ansible JSON output has unexpected format', error.result['msg']) + def test_process_container_output_deprecation(self): + container_output_deprecation = "[DEPRECATION WARNING] Some deprecation" + container_output_json = { + 'custom_stats': {}, + 'global_custom_stats': {}, + 'plays': [ + { + 'tasks': [ + { + 'hosts': { + 'localhost': { + '_ansible_no_log': False, + 'action': 'ping', + 'changed': False, + 'invocation': { + 'module_args': { + 'data': 'pong' + } + }, + 'ping': 'pong' + } + }, + } + ] + } + ], + } + container_encoded_json = json.dumps(container_output_json) + container_output = (str(container_output_deprecation) + + str(container_encoded_json)).encode('utf-8') + + expected_output = { + 'action': 'ping', + 'changed': False, + 'invocation': { + 'module_args': { + 'data': 'pong' + } + }, + 'ping': 'pong' + } + generated_module_output = self.fake_ktbw._process_container_output( + container_output) + + self.assertNotIn('_ansible_no_log', generated_module_output) + self.assertEqual(expected_output, generated_module_output) + def test_process_container_output_success(self): container_output_json = { 'custom_stats': {}, -- cgit v1.2.3