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

[pytest] Test the feature of monitoring critical processes by Supervisord. #2955

Merged
merged 25 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9af1b25
[pytest] Test the feature of monitoring critical process by Supervisord.
yozhao101 Feb 8, 2021
5aeeeb4
[pytest] Fix the syntax error and remove trailing spaces.
yozhao101 Feb 9, 2021
76342c1
[pytest] Skip DUTs which were installed with 201911 image.
yozhao101 Feb 9, 2021
85973df
[pytest] Fix a logic error.
yozhao101 Feb 9, 2021
2737c77
[pytest] Remove the extra imports.
yozhao101 Feb 9, 2021
48179bf
[pytest] Reorganize the comments.
yozhao101 Feb 9, 2021
ae9d1b3
[pytest] Reorganize the comments.
yozhao101 Feb 9, 2021
394ba40
[pytest] Fix the typos in comments.
yozhao101 Feb 10, 2021
7848cb7
[pytest] Fix a typo in the log message.
yozhao101 Feb 10, 2021
6f1a456
[pytest] Fix a typo.
yozhao101 Feb 11, 2021
09e3625
[pytest] Add missing the Macro.
yozhao101 Feb 11, 2021
f266144
[pytest] Use loganalyzer to analyzer the alerting messages from syslog.
yozhao101 Feb 14, 2021
418ebed
[pytest] Made the following changes:
yozhao101 Feb 18, 2021
554b17d
[pytest] Use `pytest_require(...)` instead of `pytest.skip(...)` to skip
yozhao101 Feb 18, 2021
aa6fdbe
[pytest] Import the `pytest_require(...)`.
yozhao101 Feb 18, 2021
f0c549c
[pytest] Import the logging.
yozhao101 Feb 18, 2021
23cd3e3
[pytest] Add a function `get_namespace_ids(...)` into devices.py.
yozhao101 Feb 19, 2021
b0ae37a
[pytest] Remove extra logging statement and fix typos.
yozhao101 Feb 19, 2021
9cfca51
[pytest] Fix a bug.
yozhao101 Feb 19, 2021
f0af91f
[pytest] Reorganize the comments.
yozhao101 Feb 19, 2021
2bf80f0
[pytest] Rename the functions and reorganize their comments.
yozhao101 Feb 24, 2021
37b9f43
[pytest] Add this test case into kvm test.
yozhao101 Feb 26, 2021
8cb60fd
[pytest] Skip the `gbsyncd` container.
yozhao101 Feb 26, 2021
485e176
[pytest] Rename the directory and test file names.
yozhao101 Feb 27, 2021
cbeb62c
[pytest] Update the directory and test file names related to testing
yozhao101 Feb 27, 2021
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
37 changes: 37 additions & 0 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,43 @@ def get_swss_docker_names(self):
swss_docker_names.append("swss{}".format(asic))
return swss_docker_names

def get_namespace_ids(self, container_name):
"""
Gets ids of namespace where the container should reside in.

Returns:
A list contains ids of namespace such as [DEFAULT_ASIC_ID, "0", "1", ...]}
"""
has_global_scope = ""
has_per_asic_scope = ""
namespace_ids = []

num_asics = int(self.facts["num_asic"])
command_config_entry = "sonic-db-cli CONFIG_DB hgetall \"FEATURE|{}\"".format(container_name)
command_output = self.shell(command_config_entry)
exit_code = command_output["rc"]
if exit_code != 0:
return namespace_ids, False

config_info = command_output["stdout_lines"]
for index, item in enumerate(config_info):
if item == "has_global_scope":
has_global_scope = config_info[index + 1]
elif item == "has_per_asic_scope":
has_per_asic_scope = config_info[index + 1]

if num_asics > 1:
if has_global_scope == "True":
namespace_ids.append(DEFAULT_ASIC_ID)
if has_per_asic_scope == "True":
for asic_id in range(0, num_asics):
namespace_ids.append(str(asic_id))
else:
namespace_ids.append(DEFAULT_ASIC_ID)

return namespace_ids, True


def get_up_time(self):
up_time_text = self.command("uptime -s")["stdout"]
return datetime.strptime(up_time_text, "%Y-%m-%d %H:%M:%S")
Expand Down
72 changes: 72 additions & 0 deletions tests/common/helpers/dut_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging

from tests.common.utilities import get_host_visible_vars

logger = logging.getLogger(__name__)

def is_supervisor_node(inv_files, hostname):
"""Check if the current node is a supervisor node in case of multi-DUT.
Expand Down Expand Up @@ -27,3 +30,72 @@ def is_frontend_node(inv_files, hostname):
node. If we add more types of nodes, then we need to exclude them from this method as well.
"""
return not is_supervisor_node(inv_files, hostname)


def get_group_program_info(duthost, container_name, group_name):
"""Gets program names, running status and their pids by analyzing the command
output of "docker exec <container_name> supervisorctl status". Program name
at here represents a program which is part of group <group_name>

Args:
duthost: Hostname of DUT.
container_name: A string shows container name.
program_name: A string shows process name.

Returns:
A dictionary where keys are the program names and values are their running
status and pids.
"""
group_program_info = defaultdict(list)
program_name = None
program_status = None
program_pid = None

program_list = duthost.shell("docker exec {} supervisorctl status".format(container_name), module_ignore_errors=True)
for program_info in program_list["stdout_lines"]:
if program_info.find(group_name) != -1:
program_name = program_info.split()[0].split(':')[1].strip()
program_status = program_info.split()[1].strip()
if program_status in ["EXITED", "STOPPED", "STARTING"]:
program_pid = -1
else:
program_pid = int(program_info.split()[3].strip(','))

group_program_info[program_name].append(program_status)
group_program_info[program_name].append(program_pid)

if program_pid != -1:
logger.info("Found program '{}' in the '{}' state with pid {}"
.format(program_name, program_status, program_pid))

return group_program_info


def get_program_info(duthost, container_name, program_name):
"""Gets program running status and its pid by analyzing the command
output of "docker exec <container_name> supervisorctl status"

Args:
duthost: Hostname of DUT.
container_name: A string shows container name.
program_name: A string shows process name.

Return:
Program running status and its pid.
"""
program_status = None
program_pid = -1

program_list = duthost.shell("docker exec {} supervisorctl status".format(container_name), module_ignore_errors=True)
for program_info in program_list["stdout_lines"]:
if program_info.find(program_name) != -1:
program_status = program_info.split()[1].strip()
if program_status == "RUNNING":
program_pid = int(program_info.split()[3].strip(','))
break

if program_pid != -1:
logger.info("Found program '{}' in the '{}' state with pid {}"
.format(program_name, program_status, program_pid))

return program_status, program_pid
6 changes: 4 additions & 2 deletions tests/kvmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ test_t0() {
test_procdockerstatsd.py \
iface_namingmode/test_iface_namingmode.py \
platform_tests/test_cpu_memory_usage.py \
bgp/test_bgpmon.py"
bgp/test_bgpmon.py \
process_monitoring/test_critical_process_monitoring.py"

pushd $SONIC_MGMT_DIR/tests
./run_tests.sh $RUNTEST_CLI_COMMON_OPTS -c "$tests" -p logs/$tgname
Expand Down Expand Up @@ -154,7 +155,8 @@ test_t1_lag() {
lldp/test_lldp.py \
route/test_default_route.py \
platform_tests/test_cpu_memory_usage.py \
bgp/test_bgpmon.py"
bgp/test_bgpmon.py \
process_monitoring/test_critical_process_monitoring.py"

pushd $SONIC_MGMT_DIR/tests
./run_tests.sh $RUNTEST_CLI_COMMON_OPTS -c "$tests" -p logs/$tgname
Expand Down
Loading