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 --- ansible/library/kolla_toolbox.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'ansible/library') diff --git a/ansible/library/kolla_toolbox.py b/ansible/library/kolla_toolbox.py index d368eb67d..4062fcb6e 100644 --- a/ansible/library/kolla_toolbox.py +++ b/ansible/library/kolla_toolbox.py @@ -13,6 +13,7 @@ # limitations under the License. import json +import re import traceback from ansible.module_utils.basic import AnsibleModule @@ -165,7 +166,22 @@ class KollaToolboxWorker(): def _process_container_output(self, output_raw: bytes) -> dict: """Convert raw bytes output from container.exec_run into dictionary.""" try: - output_json = json.loads(output_raw.decode('utf-8')) + # Extract deprecation warning (if any) + warning_match = re.search(rb'\[DEPRECATION WARNING\].*', + output_raw) + if warning_match: + self.module.warn(warning_match.group(0).decode('utf-8')) + + # Extract JSON block (including curly braces and content) + json_match = re.search(rb'\{.*\}', output_raw, re.DOTALL) + if json_match: + output_json = json.loads(json_match.group(0)) + else: + self.module.fail_json( + msg=('Parsing kolla_toolbox JSON output failed - ' + 'no JSON block in output') + ) + except json.JSONDecodeError as e: self.module.fail_json( msg=f'Parsing kolla_toolbox JSON output failed: {e}' -- cgit v1.2.3