Fix test_ping

When pinging to an invalid network ping command
could report a connection error instead of exiting.

Change-Id: I6ce849869f6ea9644fbab57cfcb435cd169a7826
This commit is contained in:
Federico Ressi 2020-10-30 08:24:16 +01:00
parent 0146c96046
commit 8d7ee27a8a
3 changed files with 13 additions and 1 deletions

View File

@ -35,6 +35,10 @@ class SendToPingError(PingError):
"""Raised when sendto error happens"""
class ConnectPingError(PingError):
"""Raised when sendto error happens"""
class UnknowHostError(PingError):
"""Raised when unable to resolve host name"""

View File

@ -313,6 +313,13 @@ def handle_ping_local_error(text):
raise _exception.LocalPingError(details=details)
def handle_ping_connect_error(text):
prefix = 'connect: '
if text.startswith(prefix):
details = text[len(prefix):].strip()
raise _exception.ConnectPingError(details=details)
def handle_ping_send_to_error(text):
prefix = 'sendto: '
if text.startswith(prefix):

View File

@ -85,7 +85,8 @@ class PingTest(testtools.TestCase):
self.assertEqual('unreceived', ex.message_type)
def test_ping_until_unreceived_unrecheable(self):
result = ping.ping_until_unreceived('1.2.3.4', count=3)
result = ping.ping_until_unreceived('1.2.3.4', count=3,
check=False)
self.assertIsNone(result.source)
self.assertEqual(netaddr.IPAddress('1.2.3.4'), result.destination)
result.assert_transmitted()