Avoid logging tracebacks for EAGAIN errors

Occasional socket EAGAIN errors were logged as ERROR messages with a full
traceback.
Cleanup code and improve testing.

Change-Id: I1cf53b637e1350b2d0f8df3c91d339a26cc913c0
Related-Bug: #1558096
This commit is contained in:
Federico Ceratto
2016-03-16 17:05:30 +00:00
parent a4c3fc59f5
commit 6a9d7dfc81
2 changed files with 95 additions and 48 deletions

View File

@@ -18,6 +18,8 @@
"""Unit-test MiniDNS service
"""
import socket
from mock import Mock
from oslotest import base
import dns
@@ -144,7 +146,7 @@ class MdnsNotifyTest(base.BaseTestCase):
zone = RoObject(name='zn')
self.notify._make_dns_message = Mock(return_value='')
self.notify._send_dns_message = Mock(
return_value=dns.exception.Timeout())
side_effect=dns.exception.Timeout)
out = self.notify._make_and_send_dns_message(zone, 'host',
123, 1, 2, 3)
@@ -155,13 +157,40 @@ class MdnsNotifyTest(base.BaseTestCase):
zone = RoObject(name='zn')
self.notify._make_dns_message = Mock(return_value='')
self.notify._send_dns_message = Mock(
return_value=notify.dns_query.BadResponse())
side_effect=notify.dns_query.BadResponse)
out = self.notify._make_and_send_dns_message(zone, 'host',
123, 1, 2, 3)
self.assertEqual((None, 1), out)
def test_make_and_send_dns_message_eagain(self, *mocks):
# bug #1558096
zone = RoObject(name='zn')
self.notify._make_dns_message = Mock(return_value='')
socket_error = socket.error()
socket_error.errno = socket.errno.EAGAIN
self.notify._send_dns_message = Mock(
side_effect=socket_error)
out = self.notify._make_and_send_dns_message(zone, 'host',
123, 1, 2, 3)
self.assertEqual((None, 3), out)
def test_make_and_send_dns_message_econnrefused(self, *mocks):
# bug #1558096
zone = RoObject(name='zn')
self.notify._make_dns_message = Mock(return_value='')
socket_error = socket.error()
socket_error.errno = socket.errno.ECONNREFUSED
# socket errors other than EAGAIN should raise
self.notify._send_dns_message = Mock(
side_effect=socket_error)
self.assertRaises(socket.error, self.notify._make_and_send_dns_message,
zone, 'host', 123, 1, 2, 3)
def test_make_and_send_dns_message_nxdomain(self, *mocks):
zone = RoObject(name='zn')
self.notify._make_dns_message = Mock(return_value='')