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

issue 538 - Update usage calculation for Rules per network ACL #543

Merged
merged 2 commits into from
Jul 9, 2021
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
15 changes: 14 additions & 1 deletion awslimitchecker/services/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,21 @@ def _find_usage_ACLs(self):
)['NetworkAcls']:
acls[acl['VpcId']] += 1
# Rules per network ACL
egress_ipv4 = sum(map(
lambda x: x["Egress"] and "CidrBlock" in x, acl['Entries']
))
ingress_ipv4 = sum(map(
lambda x: not x["Egress"] and "CidrBlock" in x, acl['Entries']
))
egress_ipv6 = sum(map(
lambda x: x["Egress"] and "Ipv6CidrBlock" in x, acl['Entries']
))
ingress_ipv6 = sum(map(
lambda x: not x["Egress"] and "Ipv6CidrBlock" in x,
acl['Entries']
))
self.limits['Rules per network ACL']._add_current_usage(
len(acl['Entries']),
max(egress_ipv4, ingress_ipv4, egress_ipv6, ingress_ipv6),
aws_type='AWS::EC2::NetworkAcl',
resource_id=acl['NetworkAclId']
)
Expand Down
64 changes: 62 additions & 2 deletions awslimitchecker/tests/services/result_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,72 @@ class VPC(object):
{
'NetworkAclId': 'acl-2',
'VpcId': 'vpc-1',
'Entries': [1],
'Entries': [
{
'Egress': True,
'CidrBlock': 'string'
},
{
'Egress': True,
'Ipv6CidrBlock': 'string'
},
{
'Egress': False,
'CidrBlock': 'string'
},
],
},
{
'NetworkAclId': 'acl-3',
'VpcId': 'vpc-2',
'Entries': [1, 2, 3, 4, 5],
'Entries': [
{
'Egress': True,
'Ipv6CidrBlock': 'string'
},
{
'Egress': False,
'CidrBlock': 'string'
},
{
'Egress': True,
'Ipv6CidrBlock': 'string'
},
{
'Egress': True,
'Ipv6CidrBlock': 'string'
},
{
'Egress': True,
'Ipv6CidrBlock': 'string'
}
],
},
{
'NetworkAclId': 'acl-4',
'VpcId': 'vpc-1',
'Entries': [
{
'Egress': False,
'Ipv6CidrBlock': 'string'
},
{
'Egress': False,
'CidrBlock': 'string'
},
{
'Egress': False,
'Ipv6CidrBlock': 'string'
},
{
'Egress': True,
'Ipv6CidrBlock': 'string'
},
{
'Egress': False,
'Ipv6CidrBlock': 'string'
}
],
},
]
}
Expand Down
12 changes: 7 additions & 5 deletions awslimitchecker/tests/services/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,19 @@ def test_find_usage_acls(self):
assert len(usage) == 2
assert usage[0].get_value() == 1
assert usage[0].resource_id == 'vpc-2'
assert usage[1].get_value() == 2
assert usage[1].get_value() == 3
assert usage[1].resource_id == 'vpc-1'
entries = sorted(cls.limits['Rules per network '
'ACL'].get_current_usage())
assert len(entries) == 3
assert len(entries) == 4
assert entries[0].resource_id == 'acl-2'
assert entries[0].get_value() == 1
assert entries[1].resource_id == 'acl-1'
assert entries[1].get_value() == 3
assert entries[2].resource_id == 'acl-3'
assert entries[2].get_value() == 5
assert entries[1].get_value() == 2
assert entries[2].resource_id == 'acl-4'
assert entries[2].get_value() == 3
assert entries[3].resource_id == 'acl-3'
assert entries[3].get_value() == 4
assert mock_conn.mock_calls == [
call.describe_network_acls(Filters=[{
'Name': 'owner-id', 'Values': ['0123456789']
Expand Down