1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Rework get_health_check_id, just take value to check

This commit is contained in:
Ross McFarland
2019-04-01 07:40:23 -07:00
parent d610a0c920
commit b8be28c1dc
2 changed files with 19 additions and 20 deletions

View File

@@ -179,8 +179,9 @@ class _Route53GeoRecord(_Route53Record):
super(_Route53GeoRecord, self).__init__(provider, record, creating)
self.geo = geo
self.health_check_id = provider.get_health_check_id(record, ident,
geo, creating)
value = geo.values[0]
self.health_check_id = provider.get_health_check_id(record, value,
creating)
def mod(self, action):
geo = self.geo
@@ -574,25 +575,22 @@ class Route53Provider(BaseProvider):
.get('measure_latency', True)
def _health_check_equivilent(self, host, path, protocol, port,
measure_latency, health_check,
first_value=None):
measure_latency, health_check, value=None):
config = health_check['HealthCheckConfig']
return host == config['FullyQualifiedDomainName'] and \
path == config['ResourcePath'] and protocol == config['Type'] \
and port == config['Port'] and \
measure_latency == config['MeasureLatency'] and \
(first_value is None or first_value == config['IPAddress'])
(value is None or value == config['IPAddress'])
def get_health_check_id(self, record, ident, geo, create):
def get_health_check_id(self, record, value, create):
# fqdn & the first value are special, we use them to match up health
# checks to their records. Route53 health checks check a single ip and
# we're going to assume that ips are interchangeable to avoid
# health-checking each one independently
fqdn = record.fqdn
first_value = geo.values[0]
self.log.debug('get_health_check_id: fqdn=%s, type=%s, geo=%s, '
'first_value=%s', fqdn, record._type, ident,
first_value)
self.log.debug('get_health_check_id: fqdn=%s, type=%s, value=%s',
fqdn, record._type, value)
healthcheck_host = record.healthcheck_host
healthcheck_path = record.healthcheck_path
@@ -614,7 +612,7 @@ class Route53Provider(BaseProvider):
healthcheck_port,
healthcheck_latency,
health_check,
first_value=first_value):
value=value):
# this is the health check we're looking for
self.log.debug('get_health_check_id: found match id=%s', id)
return id
@@ -629,7 +627,7 @@ class Route53Provider(BaseProvider):
'EnableSNI': healthcheck_protocol == 'HTTPS',
'FailureThreshold': 6,
'FullyQualifiedDomainName': healthcheck_host,
'IPAddress': first_value,
'IPAddress': value,
'MeasureLatency': healthcheck_latency,
'Port': healthcheck_port,
'RequestInterval': 10,
@@ -647,10 +645,9 @@ class Route53Provider(BaseProvider):
self._health_checks[id] = health_check
self.log.info('get_health_check_id: created id=%s, host=%s, '
'path=%s, protocol=%s, port=%d, measure_latency=%r, '
'first_value=%s',
id, healthcheck_host, healthcheck_path,
'value=%s', id, healthcheck_host, healthcheck_path,
healthcheck_protocol, healthcheck_port,
healthcheck_latency, first_value)
healthcheck_latency, value)
return id
def _gc_health_checks(self, record, new):

View File

@@ -773,7 +773,8 @@ class TestRoute53Provider(TestCase):
'AF': ['4.2.3.4'],
}
})
id = provider.get_health_check_id(record, 'AF', record.geo['AF'], True)
value = record.geo['AF'].values[0]
id = provider.get_health_check_id(record, value, True)
self.assertEquals('42', id)
def test_health_check_create(self):
@@ -859,12 +860,12 @@ class TestRoute53Provider(TestCase):
})
# if not allowed to create returns none
id = provider.get_health_check_id(record, 'AF', record.geo['AF'],
False)
value = record.geo['AF'].values[0]
id = provider.get_health_check_id(record, value, False)
self.assertFalse(id)
# when allowed to create we do
id = provider.get_health_check_id(record, 'AF', record.geo['AF'], True)
id = provider.get_health_check_id(record, value, True)
self.assertEquals('42', id)
stubber.assert_no_pending_responses()
@@ -965,7 +966,8 @@ class TestRoute53Provider(TestCase):
}
})
id = provider.get_health_check_id(record, 'AF', record.geo['AF'], True)
value = record.geo['AF'].values[0]
id = provider.get_health_check_id(record, value, True)
ml = provider.health_checks[id]['HealthCheckConfig']['MeasureLatency']
self.assertEqual(False, ml)