Skip to content
Merged
Changes from 6 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
26 changes: 26 additions & 0 deletions tests/monit_test/test_monit_service_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Test the running status of Monit service
"""
import logging

import pytest

logger = logging.getLogger(__name__)

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


def test_monit_service_status(duthost):
"""
@summary: Test the running status of Monit service by analyzing the command
output of "sudo systemctl status monit.service | grep Active".
"""
monit_service_status_info = duthost.shell("sudo systemctl status monit.service | grep Active")
Copy link
Contributor

Choose a reason for hiding this comment

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

should just do sudo monit status

and then check the return value, whether it is zero or not.

Copy link
Contributor

@jleveque jleveque Oct 9, 2020

Choose a reason for hiding this comment

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

Yes. Checking the return value of sudo monit status is zero will ensure that not only is Monit running, but that it is configured correctly. I was thinking about added separate tests for testing the config, but this makes for a better one-step liveness/basic health check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! Fixed.


status_line = monit_service_status_info["stdout_lines"][0].strip()
if "active" in status_line:
logger.info("Monit service is running.")
else:
pytest.fail("Monit service is not running: '{}'".format(status_line))