Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for request intervals in health checks.

  • Loading branch information...
commit c0fadbb608d967171d6df1dd3d3fb03938e8685b 1 parent bbb9f1e
@mattdeboard mattdeboard authored
View
19 boto/route53/healthcheck.py
@@ -56,6 +56,7 @@ class HealthCheck(object):
<ResourcePath>%(resource_path)s</ResourcePath>
%(fqdn_part)s
%(string_match_part)s
+ %(request_interval)s
</HealthCheckConfig>
"""
@@ -63,7 +64,11 @@ class HealthCheck(object):
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
@@ -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
@@ -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,
@@ -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}
View
28 tests/integration/route53/test_health_check.py
@@ -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)
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.