Skip to content

Commit

Permalink
Merge pull request #409 from /issues/408
Browse files Browse the repository at this point in the history
fixes #408 - 6.1.7 release
  • Loading branch information
jantman committed May 17, 2019
2 parents e50197f + 00b2d45 commit 029d5c1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

6.1.7 (2019-05-17)
------------------

* `Issue #406 <https://github.com/jantman/awslimitchecker/issues/406>`__ - Fix for unhandled exception when a Trusted Advisor check has a ``null`` timestamp.

6.1.6 (2019-04-19)
------------------

Expand Down
56 changes: 56 additions & 0 deletions awslimitchecker/tests/test_trustedadvisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,31 @@ def test_mode_int(self):
call.info('Refreshing Trusted Advisor check: %s', 'abc123')
]

@freeze_time("2016-12-16 10:40:42", tz_offset=0)
def test_mode_int_check_datetime_None(self):
"""Regression test for Issue #406"""
self.cls.refresh_mode = 120 # 2 minutes
check_dt = None
with patch('%s._get_check_result' % pb, autospec=True) as mock_gcr:
with patch('%s._can_refresh_check' % pb, autospec=True) as mock_crc:
with patch('%s.logger' % pbm, autospec=True) as mock_logger:
with patch('%s._poll_for_refresh' % pb,
autospec=True) as mock_pfr:
mock_gcr.return_value = ({'mock': 'gcr'}, check_dt)
mock_pfr.return_value = {'mock': 'pfr'}
mock_crc.return_value = True
res = self.cls._get_refreshed_check_result('abc123')
assert res == {'mock': 'pfr'}
assert mock_gcr.mock_calls == [call(self.cls, 'abc123')]
assert mock_crc.mock_calls == [call(self.cls, 'abc123')]
assert mock_pfr.mock_calls == [call(self.cls, 'abc123')]
assert mock_logger.mock_calls == [
call.debug('Handling refresh of check: %s', 'abc123'),
call.debug('ta_refresh_mode older; check last refresh: %s; '
'threshold=%d seconds', check_dt, 120),
call.info('Refreshing Trusted Advisor check: %s', 'abc123')
]

@freeze_time("2016-12-16 10:40:42", tz_offset=0)
def test_mode_int_within_threshold(self):
self.cls.refresh_mode = 120 # 2 minutes
Expand Down Expand Up @@ -970,6 +995,37 @@ def test_no_timestamp(self):
]
assert res == (check_result, None)

def test_null_timestamp(self):
"""Regression test for Issue #406"""
tmp = self.mock_conn.describe_trusted_advisor_check_result
check_result = {
'result': {
'timestamp': None,
'flaggedResources': [
{
'status': 'ok',
'resourceId': 'resid1',
'isSuppressed': False,
'region': 'us-west-2',
'metadata': [
'us-west-2',
'AutoScaling',
'Auto Scaling groups',
'20',
'2',
'Green'
]
}
]
}
}
tmp.return_value = check_result
res = self.cls._get_check_result('abc123')
assert tmp.mock_calls == [
call(checkId='abc123', language='en')
]
assert res == (check_result, None)


class TestCanRefreshCheck(object):

Expand Down
14 changes: 10 additions & 4 deletions awslimitchecker/trustedadvisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,12 @@ def _get_refreshed_check_result(self, check_id):
logger.debug('ta_refresh_mode older; check last refresh: %s; '
'threshold=%d seconds', check_datetime,
self.refresh_mode)
if check_datetime >= datetime.now(utc) - timedelta(
seconds=self.refresh_mode):
if (
check_datetime is not None and
check_datetime >= datetime.now(utc) - timedelta(
seconds=self.refresh_mode
)
):
logger.warning('Trusted Advisor check %s last refresh time '
'of %s is newer than refresh threshold of %d '
'seconds.', check_id, check_datetime,
Expand Down Expand Up @@ -382,10 +386,12 @@ def _get_check_result(self, check_id):
check_datetime = parser.parse(checks['result']['timestamp'])
logger.debug("Got TrustedAdvisor data for check %s as of %s",
check_id, check_datetime)
except KeyError:
except (KeyError, TypeError):
check_datetime = None
logger.debug("Got TrustedAdvisor data for check %s but unable to "
"parse timestamp", check_id)
"parse timestamp: %s",
check_id,
checks.get('result', {}).get('timestamp', None))
return checks, check_datetime

def _update_services(self, ta_results):
Expand Down
2 changes: 1 addition & 1 deletion awslimitchecker/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
except ImportError:
logger.error("Unable to import versionfinder", exc_info=True)

_VERSION_TUP = (6, 1, 6)
_VERSION_TUP = (6, 1, 7)
_VERSION = '.'.join([str(x) for x in _VERSION_TUP])
_PROJECT_URL = 'https://github.com/jantman/awslimitchecker'

Expand Down

0 comments on commit 029d5c1

Please sign in to comment.