Merge branch 'daemon-log-sync-errors' into 'master'

catch and log all sync exceptions in daemon

See merge request !3
master
Justin Riley 2017-04-14 14:18:34 -04:00
commit 5805c65dc4
2 changed files with 19 additions and 3 deletions

View File

@ -94,12 +94,13 @@ class OneDNS(resolver.DynamicResolver):
test = kwargs.pop('test', False)
test_vms = kwargs.pop('test_vms', None)
sync_interval = kwargs.pop('sync_interval', 5 * 60)
self.sync(vms=test_vms)
if self._udp_server is None or not self._udp_server.isAlive():
self.start(*args, **kwargs)
time.sleep(sync_interval)
while self._udp_server.isAlive():
self.sync(vms=test_vms)
try:
self.sync(vms=test_vms)
except Exception:
log.exception('onedns sync failed:')
time.sleep(sync_interval)
if test:
break

View File

@ -1,5 +1,9 @@
import mock
import pytest
from testfixtures import LogCapture
from onedns import exception
from onedns.tests import vcr
from onedns.tests import utils
@ -76,3 +80,14 @@ def test_onedns_remove_vm_by_id(oneclient, one_dns):
_add_and_verify(one_dns, vm)
one_dns.remove_vm_by_id(vm.id)
utils.verify_vm_dns_absent(dns_entries)
def test_onedns_daemon_no_crash(one_dns):
def sync_fail(*args, **kwargs):
raise Exception('this should be logged')
with LogCapture() as log_capture:
with mock.patch.object(one_dns, 'sync', sync_fail):
one_dns.daemon(test=True, sync_interval=1)
log_capture.check(
('onedns', 'ERROR', 'onedns sync failed:')
)