Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UT for orchagent watchdog #8306

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ t0:
- test_interfaces.py
- test_procdockerstatsd.py
- database/test_db_scripts.py
- system_health/test_watchdog.py

t0-2vlans:
- dhcp_relay/test_dhcp_relay.py
Expand Down
63 changes: 63 additions & 0 deletions tests/system_health/test_watchdog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging
import pytest
import time
from tests.common.helpers.assertions import pytest_assert

pytestmark = [
pytest.mark.disable_loganalyzer,
pytest.mark.topology('any')
]

logger = logging.getLogger(__name__)

SLEEP_TIME = 10


@pytest.fixture
def pause_orchagent(duthost):
# find orchagent pid
pid = duthost.shell(
r"pgrep orchagent",
module_ignore_errors=True)['stdout']
logger.info('Get orchagent pid: {}'.format(pid))

# pause orchagent and clear syslog
duthost.shell(r"sudo kill -STOP {}".format(pid), module_ignore_errors=True)
duthost.shell(r"sudo truncate -s 0 /var/log/syslog", module_ignore_errors=True)

yield

# resume orchagent and clear syslog
duthost.shell(r"sudo kill -CONT {}".format(pid), module_ignore_errors=True)
duthost.shell(r"sudo truncate -s 0 /var/log/syslog", module_ignore_errors=True)


def test_orchagent_watchdog(duthosts, enum_rand_one_per_hwsku_hostname, pause_orchagent):
duthost = duthosts[enum_rand_one_per_hwsku_hostname]

result = duthost.shell(
r"docker exec -i swss sh -c 'test -f /etc/supervisor/watchdog_processes && echo exist'",
module_ignore_errors=True)['stdout']
logger.info('Check watchdog exist: {}'.format(result))
if result != 'exist':
pytest.skip("Skip orchagent watchdog test.")

# wait watchdog emit alert, orchagent watchdog timeout is 60 seconds
WATCHDOG_TIMEOUT = 120
Copy link
Contributor

@qiluo-msft qiluo-msft Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

120

Magic number. How do you get the value? Is it too long or possible too short if anyone change code accidently? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watchdog will send alert after 60 seconds, so I wait for 60*2 here.

current_attempt = 0
while (True):
time.sleep(SLEEP_TIME)
alert = duthost.shell(
r"sudo cat /var/log/syslog | grep 'is stuck in namespace'",
module_ignore_errors=True)['stdout']
logger.info('Get alert from host: {}'.format(alert))
if "orchagent" in str(alert):
return
else:
# orchagent watchdog timeout is 60 seconds
if current_attempt >= WATCHDOG_TIMEOUT/SLEEP_TIME:
pytest_assert(
False,
"orchagent watchdog did not been trigger after {} seconds".format(WATCHDOG_TIMEOUT))
else:
current_attempt += 1