Skip to content

Commit

Permalink
Merge pull request #360 from /issues/358
Browse files Browse the repository at this point in the history
Issues/358
  • Loading branch information
jantman committed Sep 23, 2018
2 parents 3e40d46 + 55fc189 commit d09b1a1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ dev/terraform.tfstate.backup
results/
.release_position.json
dev/terraform.tfstate
man/
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ matrix:
env: TOXENV=py35
- python: "3.6"
env: TOXENV=py36
- python: "3.7-dev"
- python: "3.7"
env: TOXENV=py37
dist: xenial
sudo: true
- python: "2.7"
env: TOXENV=docs
- python: "2.7"
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
Unreleased Changes
------------------

* Add support for t3 EC2 instance types.
* `Issue #358 <https://github.com/jantman/awslimitchecker/issues/358>`_ - Update EFS with new default limit for number of File systems: 70 in us-east-1 and 125 in other regions.
* `PR #359 <https://github.com/jantman/awslimitchecker/pull/359>`_ - Add support for ``t3`` EC2 instance types (thanks to `chafouin <https://github.com/chafouin>`_).
* Switch ``py37`` TravisCI tests from py37-dev to py37 (release).

5.0.0 (2018-07-30)
------------------
Expand Down
23 changes: 22 additions & 1 deletion awslimitchecker/services/efs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def get_limits(self):
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
**Note:** we can't make connections to AWS in this method. So, the
:py:meth:`~._update_limits_from_api` method fixes this limit if we're
in us-east-1, which has a lower default limit.
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict
"""
Expand All @@ -101,14 +105,31 @@ def get_limits(self):
limits['File systems'] = AwsLimit(
'File systems',
self,
10,
125,
self.warning_threshold,
self.critical_threshold,
limit_type='AWS::EFS::FileSystem',
)
self.limits = limits
return limits

def _update_limits_from_api(self):
"""
Call :py:meth:`~.connect` and then check what region we're running in;
adjust default limits as required for regions that differ (us-east-1).
"""
region_limits = {
'us-east-1': 70
}
self.connect()
rname = self.conn._client_config.region_name
if rname in region_limits:
self.limits['File systems'].default_limit = region_limits[rname]
logger.debug(
'Running in region %s; setting EFS "File systems" default '
'limit value to: %d', rname, region_limits[rname]
)

def required_iam_permissions(self):
"""
Return a list of IAM Actions required for this Service to function
Expand Down
48 changes: 47 additions & 1 deletion awslimitchecker/tests/services/test_efs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,53 @@ def test_get_limits(self):
assert res['File systems'].service == cls
assert res['File systems'].def_warning_threshold == 21
assert res['File systems'].def_critical_threshold == 43
assert res['File systems'].default_limit == 10
assert res['File systems'].default_limit == 125

def test_update_limits_from_api(self):
mock_conn = Mock()
mock_conf = Mock()
type(mock_conf).region_name = 'us-west-2'
mock_conn._client_config = mock_conf
with patch('%s.connect' % pb, create=True) as mock_connect:
cls = _EfsService(21, 43)
cls.conn = mock_conn
cls.limits = {
'File systems': AwsLimit(
'File systems',
cls,
125,
cls.warning_threshold,
cls.critical_threshold,
limit_type='AWS::EFS::FileSystem',
)
}
cls._update_limits_from_api()
assert mock_connect.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert cls.limits['File systems'].default_limit == 125

def test_update_limits_from_api_us_east_1(self):
mock_conn = Mock()
mock_conf = Mock()
type(mock_conf).region_name = 'us-east-1'
mock_conn._client_config = mock_conf
with patch('%s.connect' % pb, create=True) as mock_connect:
cls = _EfsService(21, 43)
cls.conn = mock_conn
cls.limits = {
'File systems': AwsLimit(
'File systems',
cls,
125,
cls.warning_threshold,
cls.critical_threshold,
limit_type='AWS::EFS::FileSystem',
)
}
cls._update_limits_from_api()
assert mock_connect.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert cls.limits['File systems'].default_limit == 70

def test_get_limits_again(self):
"""test that existing limits dict is returned on subsequent calls"""
Expand Down

0 comments on commit d09b1a1

Please sign in to comment.