Skip to content

Commit

Permalink
Better EC2 duplicate SG error.
Browse files Browse the repository at this point in the history
  • Loading branch information
spulec committed Mar 16, 2017
1 parent 5f3fbff commit 8a803cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions moto/ec2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def __init__(self):
"The specified rule does not exist in this security group")


class InvalidPermissionDuplicateError(EC2ClientError):

def __init__(self):
super(InvalidPermissionDuplicateError, self).__init__(
"InvalidPermission.Duplicate",
"The specified rule already exists")


class InvalidRouteTableIdError(EC2ClientError):

def __init__(self, route_table_id):
Expand Down
3 changes: 2 additions & 1 deletion moto/ec2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
InvalidSecurityGroupDuplicateError,
InvalidSecurityGroupNotFoundError,
InvalidPermissionNotFoundError,
InvalidPermissionDuplicateError,
InvalidRouteTableIdError,
InvalidRouteError,
InvalidInstanceIdError,
Expand Down Expand Up @@ -1311,7 +1312,7 @@ def get_cfn_attribute(self, attribute_name):

def add_ingress_rule(self, rule):
if rule in self.ingress_rules:
raise InvalidParameterValueError('security_group')
raise InvalidPermissionDuplicateError()
else:
self.ingress_rules.append(rule)

Expand Down

0 comments on commit 8a803cd

Please sign in to comment.