Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | from subprocess import Popen, PIPE |
| 2 | |
| 3 | from oeqa.runtime.case import OERuntimeTestCase |
| 4 | from oeqa.core.decorator.oeid import OETestID |
| 5 | from oeqa.core.decorator.oetimeout import OETimeout |
| 6 | |
| 7 | class PingTest(OERuntimeTestCase): |
| 8 | |
| 9 | @OETimeout(30) |
| 10 | @OETestID(964) |
| 11 | def test_ping(self): |
| 12 | output = '' |
| 13 | count = 0 |
| 14 | while count < 5: |
| 15 | cmd = 'ping -c 1 %s' % self.target.ip |
| 16 | proc = Popen(cmd, shell=True, stdout=PIPE) |
| 17 | output += proc.communicate()[0].decode('utf-8') |
| 18 | if proc.poll() == 0: |
| 19 | count += 1 |
| 20 | else: |
| 21 | count = 0 |
| 22 | msg = ('Expected 5 consecutive, got %d.\n' |
| 23 | 'ping output is:\n%s' % (count,output)) |
| 24 | self.assertEqual(count, 5, msg = msg) |