raise error when name is more than 32 when creating target group

This commit is contained in:
Toshiya Kawasaki 2017-08-18 23:54:28 +09:00
parent a579280b7a
commit d4c6111c40
3 changed files with 29 additions and 1 deletions

View File

@ -166,3 +166,11 @@ class DuplicatePriorityError(ELBClientError):
super(DuplicatePriorityError, self).__init__(
"ValidationError",
"Priority '%s' was provided multiple times" % invalid_value)
class InvalidTargetGroupNameError(ELBClientError):
def __init__(self, invalid_name):
super(InvalidTargetGroupNameError, self).__init__(
"ValidationError",
"Target group name '%s' cannot be longer than '32' characters" % invalid_name)

View File

@ -21,7 +21,8 @@ from .exceptions import (
ActionTargetGroupNotFoundError,
InvalidDescribeRulesRequest,
RuleNotFoundError,
DuplicatePriorityError
DuplicatePriorityError,
InvalidTargetGroupNameError
)
@ -264,6 +265,8 @@ class ELBv2Backend(BaseBackend):
return [rule]
def create_target_group(self, name, **kwargs):
if len(name) > 32:
raise InvalidTargetGroupNameError(name)
for target_group in self.target_groups.values():
if target_group.name == name:
raise DuplicateTargetGroupName()

View File

@ -327,6 +327,23 @@ def test_create_target_group_and_listeners():
response = conn.describe_target_groups()
response.get('TargetGroups').should.have.length_of(0)
# Fail to create target group with name which length is 33
long_name = 'A' * 33
with assert_raises(ClientError):
conn.create_target_group(
Name=long_name,
Protocol='HTTP',
Port=8080,
VpcId=vpc.id,
HealthCheckProtocol='HTTP',
HealthCheckPort='8080',
HealthCheckPath='/',
HealthCheckIntervalSeconds=5,
HealthCheckTimeoutSeconds=5,
HealthyThresholdCount=5,
UnhealthyThresholdCount=2,
Matcher={'HttpCode': '200'})
@mock_elbv2
@mock_ec2