|
| 1 | +import logging |
| 2 | +import pytest |
| 3 | +import time |
| 4 | +from tests.common.helpers.assertions import pytest_assert |
| 5 | + |
| 6 | +pytestmark = [ |
| 7 | + pytest.mark.disable_loganalyzer, |
| 8 | + pytest.mark.topology('any') |
| 9 | +] |
| 10 | + |
| 11 | +logger = logging.getLogger(__name__) |
| 12 | + |
| 13 | +SLEEP_TIME = 10 |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def pause_orchagent(duthost): |
| 18 | + # find orchagent pid |
| 19 | + pid = duthost.shell( |
| 20 | + r"pgrep orchagent", |
| 21 | + module_ignore_errors=True)['stdout'] |
| 22 | + logger.info('Get orchagent pid: {}'.format(pid)) |
| 23 | + |
| 24 | + # pause orchagent and clear syslog |
| 25 | + duthost.shell(r"sudo kill -STOP {}".format(pid), module_ignore_errors=True) |
| 26 | + duthost.shell(r"sudo truncate -s 0 /var/log/syslog", module_ignore_errors=True) |
| 27 | + |
| 28 | + yield |
| 29 | + |
| 30 | + # resume orchagent and clear syslog |
| 31 | + duthost.shell(r"sudo kill -CONT {}".format(pid), module_ignore_errors=True) |
| 32 | + duthost.shell(r"sudo truncate -s 0 /var/log/syslog", module_ignore_errors=True) |
| 33 | + |
| 34 | + |
| 35 | +def test_orchagent_watchdog(duthosts, enum_rand_one_per_hwsku_hostname, pause_orchagent): |
| 36 | + duthost = duthosts[enum_rand_one_per_hwsku_hostname] |
| 37 | + |
| 38 | + result = duthost.shell( |
| 39 | + r"docker exec -i swss sh -c 'test -f /etc/supervisor/watchdog_processes && echo exist'", |
| 40 | + module_ignore_errors=True)['stdout'] |
| 41 | + logger.info('Check watchdog exist: {}'.format(result)) |
| 42 | + if result != 'exist': |
| 43 | + pytest.skip("Skip orchagent watchdog test.") |
| 44 | + |
| 45 | + # wait watchdog emit alert, orchagent watchdog timeout is 60 seconds |
| 46 | + WATCHDOG_TIMEOUT = 120 |
| 47 | + current_attempt = 0 |
| 48 | + while (True): |
| 49 | + time.sleep(SLEEP_TIME) |
| 50 | + alert = duthost.shell( |
| 51 | + r"sudo cat /var/log/syslog | grep 'is stuck in namespace'", |
| 52 | + module_ignore_errors=True)['stdout'] |
| 53 | + logger.info('Get alert from host: {}'.format(alert)) |
| 54 | + if "orchagent" in str(alert): |
| 55 | + return |
| 56 | + else: |
| 57 | + # orchagent watchdog timeout is 60 seconds |
| 58 | + if current_attempt >= WATCHDOG_TIMEOUT/SLEEP_TIME: |
| 59 | + pytest_assert( |
| 60 | + False, |
| 61 | + "orchagent watchdog did not been trigger after {} seconds".format(WATCHDOG_TIMEOUT)) |
| 62 | + else: |
| 63 | + current_attempt += 1 |
0 commit comments