Merge "kolla_toolbox: Add support for deprecation warnings"
This commit is contained in:
commit
c3d03c0b4f
2 files changed
+64
-1
No files matched your search
@@ -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}'
|
||||
|
||||
@@ -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': {},
|
||||
|
||||
Reference in new issue
Block a user