fixed tf tests: TestAccRoute53HealthCheck (#5241)
This commit is contained in:
parent
836a2e6538
commit
48186924ae
@ -64,9 +64,22 @@ class HealthCheck(CloudFormationModel):
|
||||
self.measure_latency = health_check_args.get("measure_latency") or False
|
||||
self.inverted = health_check_args.get("inverted") or False
|
||||
self.disabled = health_check_args.get("disabled") or False
|
||||
self.enable_sni = health_check_args.get("enable_sni") or False
|
||||
self.children = health_check_args.get("children") or None
|
||||
self.enable_sni = health_check_args.get("enable_sni") or True
|
||||
self.caller_reference = caller_reference
|
||||
self.children = None
|
||||
self.regions = None
|
||||
|
||||
def set_children(self, children):
|
||||
if children and isinstance(children, list):
|
||||
self.children = children
|
||||
elif children and isinstance(children, str):
|
||||
self.children = [children]
|
||||
|
||||
def set_regions(self, regions):
|
||||
if regions and isinstance(regions, list):
|
||||
self.regions = regions
|
||||
elif regions and isinstance(regions, str):
|
||||
self.regions = [regions]
|
||||
|
||||
@property
|
||||
def physical_resource_id(self):
|
||||
@ -135,10 +148,17 @@ class HealthCheck(CloudFormationModel):
|
||||
{% if health_check.children %}
|
||||
<ChildHealthChecks>
|
||||
{% for child in health_check.children %}
|
||||
<member>{{ child }}</member>
|
||||
<ChildHealthCheck>{{ child }}</ChildHealthCheck>
|
||||
{% endfor %}
|
||||
</ChildHealthChecks>
|
||||
{% endif %}
|
||||
{% if health_check.regions %}
|
||||
<Regions>
|
||||
{% for region in health_check.regions %}
|
||||
<Region>{{ region }}</Region>
|
||||
{% endfor %}
|
||||
</Regions>
|
||||
{% endif %}
|
||||
</HealthCheckConfig>
|
||||
<HealthCheckVersion>1</HealthCheckVersion>
|
||||
</HealthCheck>"""
|
||||
@ -617,9 +637,45 @@ class Route53Backend(BaseBackend):
|
||||
def create_health_check(self, caller_reference, health_check_args):
|
||||
health_check_id = str(uuid.uuid4())
|
||||
health_check = HealthCheck(health_check_id, caller_reference, health_check_args)
|
||||
health_check.set_children(health_check_args.get("children"))
|
||||
health_check.set_regions(health_check_args.get("regions"))
|
||||
self.health_checks[health_check_id] = health_check
|
||||
return health_check
|
||||
|
||||
def update_health_check(self, health_check_id, health_check_args):
|
||||
health_check = self.health_checks.get(health_check_id)
|
||||
if not health_check:
|
||||
raise NoSuchHealthCheck()
|
||||
|
||||
if health_check_args.get("ip_address"):
|
||||
health_check.ip_address = health_check_args.get("ip_address")
|
||||
if health_check_args.get("port"):
|
||||
health_check.port = health_check_args.get("port")
|
||||
if health_check_args.get("resource_path"):
|
||||
health_check.resource_path = health_check_args.get("resource_path")
|
||||
if health_check_args.get("fqdn"):
|
||||
health_check.fqdn = health_check_args.get("fqdn")
|
||||
if health_check_args.get("search_string"):
|
||||
health_check.search_string = health_check_args.get("search_string")
|
||||
if health_check_args.get("request_interval"):
|
||||
health_check.request_interval = health_check_args.get("request_interval")
|
||||
if health_check_args.get("failure_threshold"):
|
||||
health_check.failure_threshold = health_check_args.get("failure_threshold")
|
||||
if health_check_args.get("health_threshold"):
|
||||
health_check.health_threshold = health_check_args.get("health_threshold")
|
||||
if health_check_args.get("inverted"):
|
||||
health_check.inverted = health_check_args.get("inverted")
|
||||
if health_check_args.get("disabled"):
|
||||
health_check.disabled = health_check_args.get("disabled")
|
||||
if health_check_args.get("enable_sni"):
|
||||
health_check.enable_sni = health_check_args.get("enable_sni")
|
||||
if health_check_args.get("children"):
|
||||
health_check.set_children(health_check_args.get("children"))
|
||||
if health_check_args.get("regions"):
|
||||
health_check.set_regions(health_check_args.get("regions"))
|
||||
|
||||
return health_check
|
||||
|
||||
def list_health_checks(self):
|
||||
return self.health_checks.values()
|
||||
|
||||
|
@ -248,7 +248,7 @@ class Route53(BaseResponse):
|
||||
)
|
||||
return 200, headers, template
|
||||
|
||||
def health_check_response(self, request, full_url, headers):
|
||||
def health_check_response1(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
|
||||
parsed_url = urlparse(full_url)
|
||||
@ -273,6 +273,7 @@ class Route53(BaseResponse):
|
||||
"disabled": config.get("Disabled"),
|
||||
"enable_sni": config.get("EnableSNI"),
|
||||
"children": config.get("ChildHealthChecks", {}).get("ChildHealthCheck"),
|
||||
"regions": config.get("Regions", {}).get("Region"),
|
||||
}
|
||||
health_check = route53_backend.create_health_check(
|
||||
caller_reference, health_check_args
|
||||
@ -293,22 +294,42 @@ class Route53(BaseResponse):
|
||||
template.render(health_checks=health_checks, xmlns=XMLNS),
|
||||
)
|
||||
|
||||
def get_or_delete_health_check_response(self, request, full_url, headers):
|
||||
def health_check_response2(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
|
||||
parsed_url = urlparse(full_url)
|
||||
method = request.method
|
||||
health_check_id = parsed_url.path.split("/")[-1]
|
||||
|
||||
if method == "GET":
|
||||
health_check_id = parsed_url.path.split("/")[-1]
|
||||
health_check = route53_backend.get_health_check(health_check_id)
|
||||
template = Template(GET_HEALTH_CHECK_RESPONSE)
|
||||
return 200, headers, template.render(health_check=health_check)
|
||||
elif method == "DELETE":
|
||||
health_check_id = parsed_url.path.split("/")[-1]
|
||||
route53_backend.delete_health_check(health_check_id)
|
||||
template = Template(DELETE_HEALTH_CHECK_RESPONSE)
|
||||
return 200, headers, template.render(xmlns=XMLNS)
|
||||
elif method == "POST":
|
||||
config = xmltodict.parse(self.body)["UpdateHealthCheckRequest"]
|
||||
health_check_args = {
|
||||
"ip_address": config.get("IPAddress"),
|
||||
"port": config.get("Port"),
|
||||
"resource_path": config.get("ResourcePath"),
|
||||
"fqdn": config.get("FullyQualifiedDomainName"),
|
||||
"search_string": config.get("SearchString"),
|
||||
"failure_threshold": config.get("FailureThreshold"),
|
||||
"health_threshold": config.get("HealthThreshold"),
|
||||
"inverted": config.get("Inverted"),
|
||||
"disabled": config.get("Disabled"),
|
||||
"enable_sni": config.get("EnableSNI"),
|
||||
"children": config.get("ChildHealthChecks", {}).get("ChildHealthCheck"),
|
||||
"regions": config.get("Regions", {}).get("Region"),
|
||||
}
|
||||
health_check = route53_backend.update_health_check(
|
||||
health_check_id, health_check_args
|
||||
)
|
||||
template = Template(UPDATE_HEALTH_CHECK_RESPONSE)
|
||||
return 200, headers, template.render(health_check=health_check)
|
||||
|
||||
def not_implemented_response(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
@ -697,6 +718,12 @@ CREATE_HEALTH_CHECK_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
{{ health_check.to_xml() }}
|
||||
</CreateHealthCheckResponse>"""
|
||||
|
||||
UPDATE_HEALTH_CHECK_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<UpdateHealthCheckResponse>
|
||||
{{ health_check.to_xml() }}
|
||||
</UpdateHealthCheckResponse>
|
||||
"""
|
||||
|
||||
LIST_HEALTH_CHECKS_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ListHealthChecksResponse xmlns="{{ xmlns }}">
|
||||
<HealthChecks>
|
||||
|
@ -22,8 +22,8 @@ url_paths = {
|
||||
r"{0}/(?P<api_version>[\d_-]+)/hostedzonesbyname": Route53().list_hosted_zones_by_name_response,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/hostedzonesbyvpc": Route53().list_hosted_zones_by_vpc_response,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/hostedzonecount": Route53().get_hosted_zone_count_response,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/healthcheck$": Route53().health_check_response,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/healthcheck/(?P<health_check_id>[^/]+)$": Route53().get_or_delete_health_check_response,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/healthcheck$": Route53().health_check_response1,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/healthcheck/(?P<health_check_id>[^/]+)$": Route53().health_check_response2,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/tags/healthcheck/(?P<zone_id>[^/]+)$": tag_response1,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/tags/hostedzone/(?P<zone_id>[^/]+)$": tag_response2,
|
||||
r"{0}/(?P<api_version>[\d_-]+)/trafficpolicyinstances/*": Route53().not_implemented_response,
|
||||
|
@ -179,6 +179,16 @@ route53:
|
||||
- TestAccRoute53ZoneDataSource_name
|
||||
- TestAccRoute53ZoneDataSource_tags
|
||||
- TestAccRoute53ZoneDataSource_vpc
|
||||
- TestAccRoute53HealthCheck_basic
|
||||
- TestAccRoute53HealthCheck_tags
|
||||
- TestAccRoute53HealthCheck_withSearchString
|
||||
- TestAccRoute53HealthCheck_withChildHealthChecks
|
||||
- TestAccRoute53HealthCheck_withHealthCheckRegions
|
||||
- TestAccRoute53HealthCheck_ip
|
||||
- TestAccRoute53HealthCheck_ipv6
|
||||
- TestAccRoute53HealthCheck_withSNI
|
||||
- TestAccRoute53HealthCheck_disabled
|
||||
- TestAccRoute53HealthCheck_disappears
|
||||
s3:
|
||||
- TestAccS3BucketPolicy
|
||||
- TestAccS3BucketPublicAccessBlock
|
||||
|
Loading…
x
Reference in New Issue
Block a user