-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release_2.1] Keep worker --private-data-dir when --delete not given (#…
…887) (#919) [release_2.1] Keep worker --private-data-dir when --delete not given (#887) Backport of #887 for Ansible Runner 2.1. Reviewed-by: David Shrewsbury <None> Reviewed-by: None <None> Reviewed-by: Alan Rominger <arominge@redhat.com> Reviewed-by: Bianca Henderson <beeankha@gmail.com>
- Loading branch information
Showing
5 changed files
with
106 additions
and
24 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
Empty file.
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,45 @@ | ||
import ansible_runner.__main__ as ansible_runner__main__ | ||
import pytest | ||
|
||
|
||
def test_worker_delete(mocker): | ||
mock_output = mocker.patch.object(ansible_runner__main__, 'output') | ||
mock_output.configure.side_effect = AttributeError('Raised intentionally') | ||
|
||
mock_register_for_cleanup = mocker.patch.object(ansible_runner__main__, 'register_for_cleanup') | ||
mock_rmtree = mocker.patch.object(ansible_runner__main__.shutil, 'rmtree') | ||
mock_mkdtemp = mocker.patch.object(ansible_runner__main__.tempfile, 'mkdtemp', return_value='some_tmp_dir') | ||
|
||
sys_args = [ | ||
'worker', | ||
'--delete', | ||
] | ||
|
||
with pytest.raises(AttributeError, match='Raised intentionally'): | ||
ansible_runner__main__.main(sys_args) | ||
|
||
mock_rmtree.assert_not_called() | ||
mock_register_for_cleanup.assert_called_once_with('some_tmp_dir') | ||
mock_mkdtemp.assert_called_once() | ||
|
||
|
||
def test_worker_delete_private_data_dir(mocker, tmp_path): | ||
mock_output = mocker.patch.object(ansible_runner__main__, 'output') | ||
mock_output.configure.side_effect = AttributeError('Raised intentionally') | ||
|
||
mock_register_for_cleanup = mocker.patch.object(ansible_runner__main__, 'register_for_cleanup') | ||
mock_rmtree = mocker.patch.object(ansible_runner__main__.shutil, 'rmtree') | ||
mock_mkdtemp = mocker.patch.object(ansible_runner__main__.tempfile, 'mkdtemp', return_value='some_tmp_dir') | ||
|
||
sys_args = [ | ||
'worker', | ||
'--private-data-dir', str(tmp_path), | ||
'--delete', | ||
] | ||
|
||
with pytest.raises(AttributeError, match='Raised intentionally'): | ||
ansible_runner__main__.main(sys_args) | ||
|
||
mock_rmtree.assert_called_once_with(str(tmp_path), ignore_errors=True) | ||
mock_register_for_cleanup.assert_called_once_with(str(tmp_path)) | ||
mock_mkdtemp.assert_not_called() |