Skip to content

Commit

Permalink
Merge pull request #481 from /issues/464
Browse files Browse the repository at this point in the history
Fixes #464 - handle ConnectTimeoutError from SES in regions where it is not enabled
  • Loading branch information
jantman committed Sep 18, 2020
2 parents 033a85e + 0f53c4a commit 32417b9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog

* `PR #468 <https://github.com/jantman/awslimitchecker/pull/468>`_ - Fix transposed headings in CLI Usage documentation. Thanks to `@owenmann <https://github.com/owenmann>`__.
* `PR #470 <https://github.com/jantman/awslimitchecker/pull/470>`_ - Fix new EBS "Active snapshots" limit (bumped from 10,000 to 100,000) and Quotas Service name. Thanks to `@rashidamiri <https://github.com/rashidamiri>`__.
* `Issue #464 <https://github.com/jantman/awslimitchecker/issues/464>`_ - Fix bug where SES was causing ``ConnectTimeoutError`` in some regions. This has been added to the list of SES exceptions that we catch and silently ignore. This is a new exception thrown by regions that do not have SES support.
* Internal testing changes:

* Stop testing under Python 2.7 and Python 3.4.
Expand Down
11 changes: 9 additions & 2 deletions awslimitchecker/services/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@

from .base import _AwsService
from ..limit import AwsLimit
from botocore.exceptions import EndpointConnectionError
from botocore.exceptions import ClientError
from botocore.exceptions import (
EndpointConnectionError, ClientError, ConnectTimeoutError
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,6 +74,9 @@ def find_usage(self):
logger.warning('Skipping SES: %s', ex)
return
raise
except ConnectTimeoutError as ex:
logger.warning('Skipping SES: %s', str(ex))
return
self.limits['Daily sending quota']._add_current_usage(
resp['SentLast24Hours']
)
Expand Down Expand Up @@ -117,6 +121,9 @@ def _update_limits_from_api(self):
logger.warning('Skipping SES: %s', ex)
return
raise
except ConnectTimeoutError as ex:
logger.warning('Skipping SES: %s', str(ex))
return
self.limits['Daily sending quota']._set_api_limit(resp['Max24HourSend'])

def required_iam_permissions(self):
Expand Down
24 changes: 0 additions & 24 deletions awslimitchecker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@
################################################################################
"""

import sys
import os
import re

from _pytest.terminal import TerminalReporter
import pytest
from awslimitchecker.services import _services
from awslimitchecker.tests.test_integration import REGION

Expand Down Expand Up @@ -108,27 +105,6 @@ def fullwidth(self):
return self._tw.fullwidth


class WholeNodeIDTerminalReporter(TerminalReporter):

def _outrep_summary(self, rep):
sanitizer = OutputSanitizer(self._tw)
rep.toterminal(sanitizer)
for secname, content in rep.sections:
self._tw.sep("-", secname)
if content[-1:] == "\n":
content = content[:-1]
sanitizer.line(content)


@pytest.mark.trylast
def pytest_configure(config):
# Get the standard terminal reporter plugin and replace it with our
standard_reporter = config.pluginmanager.getplugin('terminalreporter')
wholenodeid_reporter = WholeNodeIDTerminalReporter(config, sys.stdout)
config.pluginmanager.unregister(standard_reporter)
config.pluginmanager.register(wholenodeid_reporter, 'terminalreporter')


def pytest_generate_tests(metafunc):
if (
metafunc.cls.__name__ == 'Test_AwsServiceSubclasses' and
Expand Down
49 changes: 48 additions & 1 deletion awslimitchecker/tests/services/test_ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import sys
import pytest
from awslimitchecker.services.ses import _SesService
from botocore.exceptions import ClientError, EndpointConnectionError
from botocore.exceptions import (
ClientError, EndpointConnectionError, ConnectTimeoutError
)

# https://code.google.com/p/mock/issues/detail?id=249
# py>=3.4 should use unittest.mock not the mock package on pypi
Expand Down Expand Up @@ -172,6 +174,30 @@ def se_get():
assert mock_conn.mock_calls == [call.get_send_quota()]
assert len(cls.limits['Daily sending quota'].get_current_usage()) == 0

def test_find_usage_invalid_region_connect_timeout(self):
ce = ConnectTimeoutError(endpoint_url='http://example.com')

def se_get():
raise ce

mock_conn = Mock()
mock_conn.get_send_quota.side_effect = se_get

with patch('%s.connect' % pb) as mock_connect:
with patch('%s.logger' % pbm) as mock_logger:
cls = _SesService(21, 43, {}, None)
cls.conn = mock_conn
assert cls._have_usage is False
cls.find_usage()
assert mock_connect.mock_calls == [call()]
assert cls._have_usage is False
assert mock_logger.mock_calls == [
call.debug('Checking usage for service %s', 'SES'),
call.warning('Skipping SES: %s', str(ce))
]
assert mock_conn.mock_calls == [call.get_send_quota()]
assert len(cls.limits['Daily sending quota'].get_current_usage()) == 0

def test_find_usage_invalid_region_503(self):
resp = {
'ResponseMetadata': {
Expand Down Expand Up @@ -313,6 +339,27 @@ def se_get():
]
assert cls.limits['Daily sending quota'].api_limit is None

def test_update_limits_from_api_invalid_region_connect_timeout(self):
ce = ConnectTimeoutError(endpoint_url='http://example.com')

def se_get():
raise ce

mock_conn = Mock()
mock_conn.get_send_quota.side_effect = se_get

with patch('%s.connect' % pb) as mock_connect:
with patch('%s.logger' % pbm) as mock_logger:
cls = _SesService(21, 43, {}, None)
cls.conn = mock_conn
cls._update_limits_from_api()
assert mock_connect.mock_calls == [call()]
assert mock_conn.mock_calls == [call.get_send_quota()]
assert mock_logger.mock_calls == [
call.warning('Skipping SES: %s', str(ce))
]
assert cls.limits['Daily sending quota'].api_limit is None

def test_update_limits_from_api_invalid_region_503(self):
resp = {
'ResponseMetadata': {
Expand Down

0 comments on commit 32417b9

Please sign in to comment.