diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/ping.py')
| -rw-r--r-- | meta/lib/oeqa/runtime/cases/ping.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/meta/lib/oeqa/runtime/cases/ping.py b/meta/lib/oeqa/runtime/cases/ping.py index f6603f75ec..efb91d4cc9 100644 --- a/meta/lib/oeqa/runtime/cases/ping.py +++ b/meta/lib/oeqa/runtime/cases/ping.py | |||
| @@ -1,11 +1,15 @@ | |||
| 1 | # | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 2 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
| 3 | # | 5 | # |
| 4 | 6 | ||
| 5 | from subprocess import Popen, PIPE | 7 | from subprocess import Popen, PIPE |
| 8 | from time import sleep | ||
| 6 | 9 | ||
| 7 | from oeqa.runtime.case import OERuntimeTestCase | 10 | from oeqa.runtime.case import OERuntimeTestCase, run_network_serialdebug |
| 8 | from oeqa.core.decorator.oetimeout import OETimeout | 11 | from oeqa.core.decorator.oetimeout import OETimeout |
| 12 | from oeqa.core.exception import OEQATimeoutError | ||
| 9 | 13 | ||
| 10 | class PingTest(OERuntimeTestCase): | 14 | class PingTest(OERuntimeTestCase): |
| 11 | 15 | ||
| @@ -13,14 +17,27 @@ class PingTest(OERuntimeTestCase): | |||
| 13 | def test_ping(self): | 17 | def test_ping(self): |
| 14 | output = '' | 18 | output = '' |
| 15 | count = 0 | 19 | count = 0 |
| 16 | while count < 5: | 20 | self.assertNotEqual(len(self.target.ip), 0, msg="No target IP address set") |
| 17 | cmd = 'ping -c 1 %s' % self.target.ip | 21 | |
| 18 | proc = Popen(cmd, shell=True, stdout=PIPE) | 22 | # If the target IP is localhost (because user-space networking is being used), |
| 19 | output += proc.communicate()[0].decode('utf-8') | 23 | # then there's no point in pinging it. |
| 20 | if proc.poll() == 0: | 24 | if self.target.ip.startswith("127.0.0.") or self.target.ip in ("localhost", "::1"): |
| 21 | count += 1 | 25 | print("runtime/ping: localhost detected, not pinging") |
| 22 | else: | 26 | return |
| 23 | count = 0 | 27 | |
| 28 | try: | ||
| 29 | while count < 5: | ||
| 30 | cmd = 'ping -c 1 %s' % self.target.ip | ||
| 31 | proc = Popen(cmd, shell=True, stdout=PIPE) | ||
| 32 | output += proc.communicate()[0].decode('utf-8') | ||
| 33 | if proc.poll() == 0: | ||
| 34 | count += 1 | ||
| 35 | else: | ||
| 36 | count = 0 | ||
| 37 | sleep(1) | ||
| 38 | except OEQATimeoutError: | ||
| 39 | run_network_serialdebug(self.target.runner) | ||
| 40 | self.fail("Ping timeout error for address %s, count %s, output: %s" % (self.target.ip, count, output)) | ||
| 24 | msg = ('Expected 5 consecutive, got %d.\n' | 41 | msg = ('Expected 5 consecutive, got %d.\n' |
| 25 | 'ping output is:\n%s' % (count,output)) | 42 | 'ping output is:\n%s' % (count,output)) |
| 26 | self.assertEqual(count, 5, msg = msg) | 43 | self.assertEqual(count, 5, msg = msg) |
