mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Add TCP health check support to Record
This commit is contained in:
@@ -137,7 +137,7 @@ class Record(EqualityTupleMixin):
|
||||
reasons.append('missing ttl')
|
||||
try:
|
||||
if data['octodns']['healthcheck']['protocol'] \
|
||||
not in ('HTTP', 'HTTPS'):
|
||||
not in ('HTTP', 'HTTPS', 'TCP'):
|
||||
reasons.append('invalid healthcheck protocol')
|
||||
except KeyError:
|
||||
pass
|
||||
@@ -181,15 +181,21 @@ class Record(EqualityTupleMixin):
|
||||
|
||||
@property
|
||||
def healthcheck_host(self):
|
||||
healthcheck = self._octodns.get('healthcheck', {})
|
||||
if healthcheck.get('protocol', None) == 'TCP':
|
||||
return None
|
||||
try:
|
||||
return self._octodns['healthcheck']['host']
|
||||
return healthcheck['host']
|
||||
except KeyError:
|
||||
return self.fqdn[:-1]
|
||||
|
||||
@property
|
||||
def healthcheck_path(self):
|
||||
healthcheck = self._octodns.get('healthcheck', {})
|
||||
if healthcheck.get('protocol', None) == 'TCP':
|
||||
return None
|
||||
try:
|
||||
return self._octodns['healthcheck']['path']
|
||||
return healthcheck['path']
|
||||
except KeyError:
|
||||
return '/_dns'
|
||||
|
||||
|
||||
@@ -886,6 +886,40 @@ class TestRecord(TestCase):
|
||||
self.assertEquals('HTTPS', new.healthcheck_protocol)
|
||||
self.assertEquals(443, new.healthcheck_port)
|
||||
|
||||
def test_healthcheck_tcp(self):
|
||||
new = Record.new(self.zone, 'a', {
|
||||
'ttl': 44,
|
||||
'type': 'A',
|
||||
'value': '1.2.3.4',
|
||||
'octodns': {
|
||||
'healthcheck': {
|
||||
'path': '/ignored',
|
||||
'host': 'completely.ignored',
|
||||
'protocol': 'TCP',
|
||||
'port': 8080,
|
||||
}
|
||||
}
|
||||
})
|
||||
self.assertIsNone(new.healthcheck_path)
|
||||
self.assertIsNone(new.healthcheck_host)
|
||||
self.assertEquals('TCP', new.healthcheck_protocol)
|
||||
self.assertEquals(8080, new.healthcheck_port)
|
||||
|
||||
new = Record.new(self.zone, 'a', {
|
||||
'ttl': 44,
|
||||
'type': 'A',
|
||||
'value': '1.2.3.4',
|
||||
'octodns': {
|
||||
'healthcheck': {
|
||||
'protocol': 'TCP',
|
||||
}
|
||||
}
|
||||
})
|
||||
self.assertIsNone(new.healthcheck_path)
|
||||
self.assertIsNone(new.healthcheck_host)
|
||||
self.assertEquals('TCP', new.healthcheck_protocol)
|
||||
self.assertEquals(443, new.healthcheck_port)
|
||||
|
||||
def test_inored(self):
|
||||
new = Record.new(self.zone, 'txt', {
|
||||
'ttl': 44,
|
||||
|
||||
Reference in New Issue
Block a user