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

Pulls/52 #58

Merged
merged 3 commits into from
Aug 12, 2015
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
21 changes: 17 additions & 4 deletions awslimitchecker/services/elasticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import abc # noqa
from boto.elasticache.layer1 import ElastiCacheConnection
from boto.exception import BotoServerError
import logging

from .base import _AwsService
Expand Down Expand Up @@ -121,10 +122,22 @@ def _find_usage_parameter_groups(self):

def _find_usage_security_groups(self):
"""find usage for elasticache security groups"""
groups = self.conn.describe_cache_security_groups()[
'DescribeCacheSecurityGroupsResponse'][
'DescribeCacheSecurityGroupsResult'][
'CacheSecurityGroups']
try:
# If EC2-Classic isn't available (e.g., a new account)
# this method will fail with:
# Code: "InvalidParameterValue"
# Message: "Use of cache security groups is not permitted in
# this API version for your account."
# Type: "Sender"
groups = self.conn.describe_cache_security_groups()[
'DescribeCacheSecurityGroupsResponse'][
'DescribeCacheSecurityGroupsResult'][
'CacheSecurityGroups']
except BotoServerError:
logger.debug("caught BotoServerError checking ElastiCache security "
"groups (account without EC2-Classic?)")
groups = []

self.limits['Security Groups']._add_current_usage(
len(groups),
aws_type='WS::ElastiCache::SecurityGroup'
Expand Down
21 changes: 20 additions & 1 deletion awslimitchecker/tests/services/test_elasticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"""

import sys
# TODO confirm this is the correct import
from boto.elasticache.layer1 import ElastiCacheConnection
from boto.exception import BotoServerError
from awslimitchecker.services.elasticache import _ElastiCacheService

# https://code.google.com/p/mock/issues/detail?id=249
Expand Down Expand Up @@ -469,6 +469,25 @@ def test_find_usage_security_groups(self):
assert len(usage) == 1
assert usage[0].get_value() == 2

def test_find_usage_security_groups_exception(self):
"""test find usage for security groups"""
def se_exc():
raise BotoServerError(None, None, None)

mock_conn = Mock(spec_set=ElastiCacheConnection)
mock_conn.describe_cache_security_groups.side_effect = se_exc
cls = _ElastiCacheService(21, 43)
cls.conn = mock_conn
cls._find_usage_security_groups()

assert mock_conn.mock_calls == [
call.describe_cache_security_groups(),
]

usage = cls.limits['Security Groups'].get_current_usage()
assert len(usage) == 1
assert usage[0].get_value() == 0

def test_required_iam_permissions(self):
cls = _ElastiCacheService(21, 43)
assert cls.required_iam_permissions() == [
Expand Down