Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[output] catch requests timeout exceptions #627

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stream_alert/alert_processor/outputs/output_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import tempfile
import requests
from requests.exceptions import Timeout as ReqTimeout
import urllib3

import backoff
Expand Down Expand Up @@ -266,7 +267,7 @@ def _log_status(cls, success):
@classmethod
def _catch_exceptions(cls):
"""Classmethod that returns a tuple of the exceptions to catch"""
default_exceptions = (OutputRequestFailure,)
default_exceptions = (OutputRequestFailure, ReqTimeout)
exceptions = cls._get_exceptions_to_catch()
if not exceptions:
return default_exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# pylint: disable=abstract-class-instantiated,protected-access,attribute-defined-outside-init
import os

from requests.exceptions import Timeout as ReqTimeout

from mock import Mock, patch
from moto import mock_kms, mock_s3
from nose.tools import (
Expand Down Expand Up @@ -214,19 +216,19 @@ def test_catch_exceptions_non_default(self):
"""OutputDispatcher - Catch Non Default Exceptions"""
exceptions = self._dispatcher._catch_exceptions()

assert_equal(exceptions, (OutputRequestFailure, ValueError))
assert_equal(exceptions, (OutputRequestFailure, ReqTimeout, ValueError))

@patch.object(OutputDispatcher,
'_get_exceptions_to_catch', Mock(return_value=(ValueError, TypeError)))
def test_catch_exceptions_non_default_tuple(self):
"""OutputDispatcher - Catch Non Default Exceptions Tuple"""
exceptions = self._dispatcher._catch_exceptions()

assert_equal(exceptions, (OutputRequestFailure, ValueError, TypeError))
assert_equal(exceptions, (OutputRequestFailure, ReqTimeout, ValueError, TypeError))

@patch.object(OutputDispatcher, '_get_exceptions_to_catch', Mock(return_value=()))
def test_catch_exceptions_default(self):
"""OutputDispatcher - Catch Default Exceptions"""
exceptions = self._dispatcher._catch_exceptions()

assert_equal(exceptions, (OutputRequestFailure,))
assert_equal(exceptions, (OutputRequestFailure, ReqTimeout))