Skip to content

Commit

Permalink
Add support for request intervals in health checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdeboard committed Feb 19, 2014
1 parent bbb9f1e commit c0fadbb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
19 changes: 18 additions & 1 deletion boto/route53/healthcheck.py
Expand Up @@ -56,14 +56,19 @@ class HealthCheck(object):
<ResourcePath>%(resource_path)s</ResourcePath>
%(fqdn_part)s
%(string_match_part)s
%(request_interval)s
</HealthCheckConfig>
"""

XMLFQDNPart = """<FullyQualifiedDomainName>%(fqdn)s</FullyQualifiedDomainName>"""

XMLStringMatchPart = """<SearchString>%(string_match)s</SearchString>"""

def __init__(self, ip_addr, port, hc_type, resource_path, fqdn=None, string_match=None):
XMLRequestIntervalPart = """<RequestInterval>%(request_interval)d</RequestInterval>"""

valid_request_intervals = (10, 30)

def __init__(self, ip_addr, port, hc_type, resource_path, fqdn=None, string_match=None, request_interval=30):
"""
HealthCheck object
Expand All @@ -85,6 +90,9 @@ def __init__(self, ip_addr, port, hc_type, resource_path, fqdn=None, string_matc
:type string_match: str
:param string_match: if hc_type is HTTP_STR_MATCH or HTTPS_STR_MATCH, the string to search for in the response body from the specified resource
:type request_interval: int
:param request_interval: The number of seconds between the time that Amazon Route 53 gets a response from your endpoint and the time that it sends the next health-check request.
"""
self.ip_addr = ip_addr
self.port = port
Expand All @@ -93,6 +101,13 @@ def __init__(self, ip_addr, port, hc_type, resource_path, fqdn=None, string_matc
self.fqdn = fqdn
self.string_match = string_match

if request_interval in self.valid_request_intervals:
self.request_interval = request_interval
else:
raise AttributeError(
"Valid values for request_interval are: %s" %
",".join(str(i) for i in self.valid_request_intervals))

def to_xml(self):
params = {
'ip_addr': self.ip_addr,
Expand All @@ -101,6 +116,8 @@ def to_xml(self):
'resource_path': self.resource_path,
'fqdn_part': "",
'string_match_part': "",
'request_interval': (self.XMLRequestIntervalPart %
{'request_interval': self.request_interval}),
}
if self.fqdn is not None:
params['fqdn_part'] = self.XMLFQDNPart % {'fqdn': self.fqdn}
Expand Down
28 changes: 27 additions & 1 deletion tests/integration/route53/test_health_check.py
Expand Up @@ -99,7 +99,6 @@ def test_create_health_check_https_string_match(self):
self.assertEquals(result[u'CreateHealthCheckResponse'][u'HealthCheck'][u'HealthCheckConfig'][u'SearchString'], 'test')
self.conn.delete_health_check(result['CreateHealthCheckResponse']['HealthCheck']['Id'])


def test_create_resource_record_set(self):
hc = HealthCheck(ip_addr="54.217.7.118", port=80, hc_type="HTTP", resource_path="/testing")
result = self.conn.create_health_check(hc)
Expand All @@ -115,3 +114,30 @@ def test_create_resource_record_set(self):
weight=1, health_check=result['CreateHealthCheckResponse']['HealthCheck']['Id'])
deleted.add_value('54.217.7.118')
records.commit()

def test_create_health_check_invalid_request_interval(self):
"""Test that health checks cannot be created with an invalid
'request_interval'.
"""
with self.assertRaises(AttributeError):
HealthCheck(**self.health_check_params(request_interval=5))

def test_create_health_check_request_interval(self):
hc_params = self.health_check_params(request_interval=10)
hc = HealthCheck(**hc_params)
result = self.conn.create_health_check(hc)
hc_config = (result[u'CreateHealthCheckResponse']
[u'HealthCheck'][u'HealthCheckConfig'])
self.assertEquals(hc_config[u'RequestInterval'],
unicode(hc_params['request_interval']))

def health_check_params(self, **kwargs):
params = {
'ip_addr': "54.217.7.118",
'port': 80,
'hc_type': 'HTTP',
'resource_path': '/testing',
}
params.update(kwargs)
return params

0 comments on commit c0fadbb

Please sign in to comment.