-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay update of artifacts and error fields until final job save (#11832)
* Delay update of artifacts until final job save Save tracebacks from receptor module to callback object Move receptor traceback check up to be more logical Use new mock_me fixture to avoid DB call with me method Update the special runner message to the delay_update pattern * Move special runner message into post-processing of callback fields
- Loading branch information
1 parent
adb2b0d
commit 452744b
Showing
4 changed files
with
100 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from awx.main.tasks.callback import RunnerCallback | ||
from awx.main.constants import ANSIBLE_RUNNER_NEEDS_UPDATE_MESSAGE | ||
|
||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
def test_delay_update(mock_me): | ||
rc = RunnerCallback() | ||
rc.delay_update(foo='bar') | ||
assert rc.extra_update_fields == {'foo': 'bar'} | ||
rc.delay_update(foo='foobar') | ||
assert rc.extra_update_fields == {'foo': 'foobar'} | ||
rc.delay_update(bar='foo') | ||
assert rc.get_delayed_update_fields() == {'foo': 'foobar', 'bar': 'foo', 'emitted_events': 0} | ||
|
||
|
||
def test_delay_update_skip_if_set(mock_me): | ||
rc = RunnerCallback() | ||
rc.delay_update(foo='bar', skip_if_already_set=True) | ||
assert rc.extra_update_fields == {'foo': 'bar'} | ||
rc.delay_update(foo='foobar', skip_if_already_set=True) | ||
assert rc.extra_update_fields == {'foo': 'bar'} | ||
|
||
|
||
def test_delay_update_failure_fields(mock_me): | ||
rc = RunnerCallback() | ||
rc.delay_update(job_explanation='1') | ||
rc.delay_update(job_explanation=_('2')) | ||
assert rc.extra_update_fields == {'job_explanation': '1\n2'} | ||
rc.delay_update(result_traceback='1') | ||
rc.delay_update(result_traceback=_('2')) | ||
rc.delay_update(result_traceback=_('3'), skip_if_already_set=True) | ||
assert rc.extra_update_fields == {'job_explanation': '1\n2', 'result_traceback': '1\n2'} | ||
|
||
|
||
def test_duplicate_updates(mock_me): | ||
rc = RunnerCallback() | ||
rc.delay_update(job_explanation='really long summary...') | ||
rc.delay_update(job_explanation='really long summary...') | ||
rc.delay_update(job_explanation='really long summary...') | ||
assert rc.extra_update_fields == {'job_explanation': 'really long summary...'} | ||
|
||
|
||
def test_special_ansible_runner_message(mock_me): | ||
rc = RunnerCallback() | ||
rc.delay_update(result_traceback='Traceback:\ngot an unexpected keyword argument\nFile: foo.py') | ||
rc.delay_update(result_traceback='Traceback:\ngot an unexpected keyword argument\nFile: bar.py') | ||
assert rc.get_delayed_update_fields().get('result_traceback') == ( | ||
'Traceback:\ngot an unexpected keyword argument\nFile: foo.py\n' | ||
'Traceback:\ngot an unexpected keyword argument\nFile: bar.py\n' | ||
f'{ANSIBLE_RUNNER_NEEDS_UPDATE_MESSAGE}' | ||
) |