From 20cc87f0598e14fde3218d012c7234f5049d2899 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Wed, 12 Jan 2022 15:36:51 -0500 Subject: [PATCH] Expect upper case message 'levels' for galaxy publish results (#63530) --- changelogs/fragments/galaxy-import-level-fix.yml | 2 ++ lib/ansible/galaxy/api.py | 4 ++-- test/units/galaxy/test_api.py | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/galaxy-import-level-fix.yml diff --git a/changelogs/fragments/galaxy-import-level-fix.yml b/changelogs/fragments/galaxy-import-level-fix.yml new file mode 100644 index 00000000000..edf8c4249e2 --- /dev/null +++ b/changelogs/fragments/galaxy-import-level-fix.yml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-galaxy publish - Fix warning and error detection in import messages to properly display them in Ansible diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 3178d47b0d1..166847c850b 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -715,9 +715,9 @@ class GalaxyAPI: for message in data.get('messages', []): level = message['level'] - if level == 'error': + if level.lower() == 'error': display.error("Galaxy import error message: %s" % message['message']) - elif level == 'warning': + elif level.lower() == 'warning': display.warning("Galaxy import warning message: %s" % message['message']) else: display.vvv("Galaxy import message: %s - %s" % (level, message['message'])) diff --git a/test/units/galaxy/test_api.py b/test/units/galaxy/test_api.py index 8081c7924f0..2fb0879aa2b 100644 --- a/test/units/galaxy/test_api.py +++ b/test/units/galaxy/test_api.py @@ -509,15 +509,15 @@ def test_wait_import_task_with_failure(server_url, api_version, token_type, toke }, 'messages': [ { - 'level': 'error', + 'level': 'ERrOR', 'message': u'Somé error', }, { - 'level': 'warning', + 'level': 'WARNiNG', 'message': u'Some wärning', }, { - 'level': 'info', + 'level': 'INFO', 'message': u'Somé info', }, ], @@ -549,7 +549,7 @@ def test_wait_import_task_with_failure(server_url, api_version, token_type, toke assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri assert mock_vvv.call_count == 1 - assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: info - Somé info' + assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: INFO - Somé info' assert mock_warn.call_count == 1 assert mock_warn.mock_calls[0][1][0] == u'Galaxy import warning message: Some wärning' @@ -582,15 +582,15 @@ def test_wait_import_task_with_failure_no_error(server_url, api_version, token_t 'error': {}, 'messages': [ { - 'level': 'error', + 'level': 'ERROR', 'message': u'Somé error', }, { - 'level': 'warning', + 'level': 'WARNING', 'message': u'Some wärning', }, { - 'level': 'info', + 'level': 'INFO', 'message': u'Somé info', }, ], @@ -622,7 +622,7 @@ def test_wait_import_task_with_failure_no_error(server_url, api_version, token_t assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri assert mock_vvv.call_count == 1 - assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: info - Somé info' + assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: INFO - Somé info' assert mock_warn.call_count == 1 assert mock_warn.mock_calls[0][1][0] == u'Galaxy import warning message: Some wärning'