ELBv2 - enable Tags for create_target_group (#5045)
This commit is contained in:
parent
8da9666a90
commit
61a5d5ca3b
@ -115,6 +115,9 @@ class FakeTargetGroup(CloudFormationModel):
|
|||||||
self.attributes = {
|
self.attributes = {
|
||||||
"deregistration_delay.timeout_seconds": 300,
|
"deregistration_delay.timeout_seconds": 300,
|
||||||
"stickiness.enabled": "false",
|
"stickiness.enabled": "false",
|
||||||
|
"load_balancing.algorithm.type": "round_robin",
|
||||||
|
"slow_start.duration_seconds": 0,
|
||||||
|
"waf.fail_open.enabled": "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
self.targets = OrderedDict()
|
self.targets = OrderedDict()
|
||||||
@ -1009,8 +1012,11 @@ Member must satisfy regular expression pattern: {}".format(
|
|||||||
arn = make_arn_for_target_group(
|
arn = make_arn_for_target_group(
|
||||||
account_id=ACCOUNT_ID, name=name, region_name=self.region_name
|
account_id=ACCOUNT_ID, name=name, region_name=self.region_name
|
||||||
)
|
)
|
||||||
|
tags = kwargs.pop("tags", None)
|
||||||
target_group = FakeTargetGroup(name, arn, **kwargs)
|
target_group = FakeTargetGroup(name, arn, **kwargs)
|
||||||
self.target_groups[target_group.arn] = target_group
|
self.target_groups[target_group.arn] = target_group
|
||||||
|
if tags:
|
||||||
|
self.add_tags(resource_arns=[target_group.arn], tags=tags)
|
||||||
return target_group
|
return target_group
|
||||||
|
|
||||||
def modify_target_group_attributes(self, target_group_arn, attributes):
|
def modify_target_group_attributes(self, target_group_arn, attributes):
|
||||||
|
@ -177,11 +177,12 @@ class ELBV2Response(BaseResponse):
|
|||||||
|
|
||||||
@amzn_request_id
|
@amzn_request_id
|
||||||
def create_target_group(self):
|
def create_target_group(self):
|
||||||
name = self._get_param("Name")
|
params = self._get_params()
|
||||||
vpc_id = self._get_param("VpcId")
|
name = params.get("Name")
|
||||||
protocol = self._get_param("Protocol")
|
vpc_id = params.get("VpcId")
|
||||||
protocol_version = self._get_param("ProtocolVersion", "HTTP1")
|
protocol = params.get("Protocol")
|
||||||
port = self._get_param("Port")
|
protocol_version = params.get("ProtocolVersion", "HTTP1")
|
||||||
|
port = params.get("Port")
|
||||||
healthcheck_protocol = self._get_param("HealthCheckProtocol")
|
healthcheck_protocol = self._get_param("HealthCheckProtocol")
|
||||||
healthcheck_port = self._get_param("HealthCheckPort")
|
healthcheck_port = self._get_param("HealthCheckPort")
|
||||||
healthcheck_path = self._get_param("HealthCheckPath")
|
healthcheck_path = self._get_param("HealthCheckPath")
|
||||||
@ -190,8 +191,9 @@ class ELBV2Response(BaseResponse):
|
|||||||
healthcheck_enabled = self._get_param("HealthCheckEnabled")
|
healthcheck_enabled = self._get_param("HealthCheckEnabled")
|
||||||
healthy_threshold_count = self._get_param("HealthyThresholdCount")
|
healthy_threshold_count = self._get_param("HealthyThresholdCount")
|
||||||
unhealthy_threshold_count = self._get_param("UnhealthyThresholdCount")
|
unhealthy_threshold_count = self._get_param("UnhealthyThresholdCount")
|
||||||
matcher = self._get_params().get("Matcher")
|
matcher = params.get("Matcher")
|
||||||
target_type = self._get_param("TargetType")
|
target_type = params.get("TargetType")
|
||||||
|
tags = params.get("Tags")
|
||||||
|
|
||||||
target_group = self.elbv2_backend.create_target_group(
|
target_group = self.elbv2_backend.create_target_group(
|
||||||
name,
|
name,
|
||||||
@ -209,6 +211,7 @@ class ELBV2Response(BaseResponse):
|
|||||||
unhealthy_threshold_count=unhealthy_threshold_count,
|
unhealthy_threshold_count=unhealthy_threshold_count,
|
||||||
matcher=matcher,
|
matcher=matcher,
|
||||||
target_type=target_type,
|
target_type=target_type,
|
||||||
|
tags=tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
template = self.response_template(CREATE_TARGET_GROUP_TEMPLATE)
|
template = self.response_template(CREATE_TARGET_GROUP_TEMPLATE)
|
||||||
|
@ -10,7 +10,7 @@ relative_files = True
|
|||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore = W503,W605,E128,E501,E203,E266,E501,E231
|
ignore = W503,W605,E128,E501,E203,E266,E501,E231
|
||||||
exclude = moto/packages,dist
|
exclude = moto/packages,dist,tests/terraformtests
|
||||||
|
|
||||||
[pylint.MASTER]
|
[pylint.MASTER]
|
||||||
ignore-paths=moto/packages
|
ignore-paths=moto/packages
|
||||||
|
@ -6,7 +6,6 @@ TestAccAPIGatewayV2Authorizer
|
|||||||
TestAccAPIGatewayV2Route
|
TestAccAPIGatewayV2Route
|
||||||
TestAccAppsyncApiKey
|
TestAccAppsyncApiKey
|
||||||
TestAccAppsyncGraphqlApi
|
TestAccAppsyncGraphqlApi
|
||||||
TestAccAutoscalingAttachment
|
|
||||||
TestAccAutoscalingPolicy
|
TestAccAutoscalingPolicy
|
||||||
TestAccBatchJobQueue
|
TestAccBatchJobQueue
|
||||||
TestAccCloudTrail
|
TestAccCloudTrail
|
||||||
@ -48,8 +47,6 @@ TestAccIAMRole
|
|||||||
TestAccIotThing
|
TestAccIotThing
|
||||||
TestAccIPRanges
|
TestAccIPRanges
|
||||||
TestAccKinesisStream
|
TestAccKinesisStream
|
||||||
TestAccLbListenerCertificate
|
|
||||||
TestAccLBTargetGroupAttachment
|
|
||||||
TestAccELBPolicy
|
TestAccELBPolicy
|
||||||
TestAccLambdaAlias
|
TestAccLambdaAlias
|
||||||
TestAccLambdaLayerVersion
|
TestAccLambdaLayerVersion
|
||||||
|
@ -9,6 +9,7 @@ apigatewayv2:
|
|||||||
- TestAccAPIGatewayV2VPCLink
|
- TestAccAPIGatewayV2VPCLink
|
||||||
autoscaling:
|
autoscaling:
|
||||||
- TestAccAutoScalingGroupDataSource
|
- TestAccAutoScalingGroupDataSource
|
||||||
|
- TestAccAutoScalingAttachment
|
||||||
batch:
|
batch:
|
||||||
- TestAccBatchJobDefinition
|
- TestAccBatchJobDefinition
|
||||||
cloudtrail:
|
cloudtrail:
|
||||||
@ -50,6 +51,10 @@ elb:
|
|||||||
- TestAccELBListenerPolicy
|
- TestAccELBListenerPolicy
|
||||||
- TestAccELBServiceAccountDataSource
|
- TestAccELBServiceAccountDataSource
|
||||||
- TestAccELBSSLNegotiationPolicy
|
- TestAccELBSSLNegotiationPolicy
|
||||||
|
elbv2:
|
||||||
|
- TestAccELBV2ListenerCertificate
|
||||||
|
- TestAccELBV2TargetGroupAttachment
|
||||||
|
- TestAccELBV2TargetGroupDataSource
|
||||||
events:
|
events:
|
||||||
- TestAccEventsAPIDestination
|
- TestAccEventsAPIDestination
|
||||||
- TestAccEventsArchive
|
- TestAccEventsArchive
|
||||||
|
@ -54,6 +54,7 @@ def test_create_target_group_with_tags():
|
|||||||
HealthyThresholdCount=5,
|
HealthyThresholdCount=5,
|
||||||
UnhealthyThresholdCount=2,
|
UnhealthyThresholdCount=2,
|
||||||
Matcher={"HttpCode": "200"},
|
Matcher={"HttpCode": "200"},
|
||||||
|
Tags=[{"Key": "key1", "Value": "val1"}],
|
||||||
)
|
)
|
||||||
target_group = response.get("TargetGroups")[0]
|
target_group = response.get("TargetGroups")[0]
|
||||||
target_group_arn = target_group["TargetGroupArn"]
|
target_group_arn = target_group["TargetGroupArn"]
|
||||||
@ -61,7 +62,7 @@ def test_create_target_group_with_tags():
|
|||||||
# Add tags to the target group
|
# Add tags to the target group
|
||||||
conn.add_tags(
|
conn.add_tags(
|
||||||
ResourceArns=[target_group_arn],
|
ResourceArns=[target_group_arn],
|
||||||
Tags=[{"Key": "key1", "Value": "val1"}, {"Key": "key2", "Value": "val2"}],
|
Tags=[{"Key": "key2", "Value": "val2"}],
|
||||||
)
|
)
|
||||||
conn.describe_tags(ResourceArns=[target_group_arn])["TagDescriptions"][0][
|
conn.describe_tags(ResourceArns=[target_group_arn])["TagDescriptions"][0][
|
||||||
"Tags"
|
"Tags"
|
||||||
@ -384,10 +385,11 @@ def test_target_group_attributes():
|
|||||||
|
|
||||||
# The attributes should start with the two defaults
|
# The attributes should start with the two defaults
|
||||||
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
|
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
|
||||||
response["Attributes"].should.have.length_of(2)
|
response["Attributes"].should.have.length_of(5)
|
||||||
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
|
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
|
||||||
attributes["deregistration_delay.timeout_seconds"].should.equal("300")
|
attributes["deregistration_delay.timeout_seconds"].should.equal("300")
|
||||||
attributes["stickiness.enabled"].should.equal("false")
|
attributes["stickiness.enabled"].should.equal("false")
|
||||||
|
attributes["waf.fail_open.enabled"].should.equal("false")
|
||||||
|
|
||||||
# Add cookie stickiness
|
# Add cookie stickiness
|
||||||
response = conn.modify_target_group_attributes(
|
response = conn.modify_target_group_attributes(
|
||||||
@ -406,7 +408,7 @@ def test_target_group_attributes():
|
|||||||
|
|
||||||
# These new values should be in the full attribute list
|
# These new values should be in the full attribute list
|
||||||
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
|
response = conn.describe_target_group_attributes(TargetGroupArn=target_group_arn)
|
||||||
response["Attributes"].should.have.length_of(3)
|
response["Attributes"].should.have.length_of(6)
|
||||||
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
|
attributes = {attr["Key"]: attr["Value"] for attr in response["Attributes"]}
|
||||||
attributes["stickiness.type"].should.equal("lb_cookie")
|
attributes["stickiness.type"].should.equal("lb_cookie")
|
||||||
attributes["stickiness.enabled"].should.equal("true")
|
attributes["stickiness.enabled"].should.equal("true")
|
||||||
|
Loading…
Reference in New Issue
Block a user