mirror of
https://github.com/ansible/awx.git
synced 2026-03-16 00:17:29 -02:30
fix: ensure temp files are cleaned up after failed HCC (#6952)
This commit is contained in:
committed by
GitHub
parent
5cf3a09163
commit
bb6bf33b9e
@@ -322,10 +322,10 @@ def gather(dest=None, module=None, subset=None, since=None, until=None, collecti
|
|||||||
settings.AUTOMATION_ANALYTICS_LAST_ENTRIES = json.dumps(last_entries, cls=DjangoJSONEncoder)
|
settings.AUTOMATION_ANALYTICS_LAST_ENTRIES = json.dumps(last_entries, cls=DjangoJSONEncoder)
|
||||||
|
|
||||||
if collection_type != 'dry-run':
|
if collection_type != 'dry-run':
|
||||||
if succeeded:
|
for fpath in tarfiles:
|
||||||
for fpath in tarfiles:
|
if os.path.exists(fpath):
|
||||||
if os.path.exists(fpath):
|
os.remove(fpath)
|
||||||
os.remove(fpath)
|
|
||||||
with disable_activity_stream():
|
with disable_activity_stream():
|
||||||
if not settings.AUTOMATION_ANALYTICS_LAST_GATHER or until > settings.AUTOMATION_ANALYTICS_LAST_GATHER:
|
if not settings.AUTOMATION_ANALYTICS_LAST_GATHER or until > settings.AUTOMATION_ANALYTICS_LAST_GATHER:
|
||||||
# `AUTOMATION_ANALYTICS_LAST_GATHER` is set whether collection succeeds or fails;
|
# `AUTOMATION_ANALYTICS_LAST_GATHER` is set whether collection succeeds or fails;
|
||||||
|
|||||||
@@ -150,3 +150,24 @@ def test_ship_credential(setting_map, expected_result, expected_auth, temp_analy
|
|||||||
assert mock_analytic_post.call_args[1]['auth'] == expected_auth
|
assert mock_analytic_post.call_args[1]['auth'] == expected_auth
|
||||||
else:
|
else:
|
||||||
mock_analytic_post.assert_not_called()
|
mock_analytic_post.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_gather_cleanup_on_auth_failure(mock_valid_license, temp_analytic_tar):
|
||||||
|
settings.INSIGHTS_TRACKING_STATE = True
|
||||||
|
settings.AUTOMATION_ANALYTICS_URL = 'https://example.com/api'
|
||||||
|
settings.REDHAT_USERNAME = 'test_user'
|
||||||
|
settings.REDHAT_PASSWORD = 'test_password'
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False, suffix='.tar.gz') as temp_file:
|
||||||
|
temp_file_path = temp_file.name
|
||||||
|
|
||||||
|
try:
|
||||||
|
with mock.patch('awx.main.analytics.core.ship', return_value=False):
|
||||||
|
with mock.patch('awx.main.analytics.core.package', return_value=temp_file_path):
|
||||||
|
gather(module=importlib.import_module(__name__), collection_type='scheduled')
|
||||||
|
|
||||||
|
assert not os.path.exists(temp_file_path), "Temp file was not cleaned up after ship failure"
|
||||||
|
finally:
|
||||||
|
if os.path.exists(temp_file_path):
|
||||||
|
os.remove(temp_file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user