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

Fix multiple failures in KillProcess test on KVM. #16303

Merged
merged 13 commits into from
Jan 24, 2025
Merged
10 changes: 9 additions & 1 deletion tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,15 @@ def is_host_service_running(self, service):
@param service: Service name
@return: True if specified service is running, else False
"""
service_status = self.shell("sudo systemctl status {} | grep 'Active'".format(service))
try:
service_status = self.shell("sudo systemctl status {} | grep 'Active'".format(service))
hdwhdw marked this conversation as resolved.
Show resolved Hide resolved
except RunAnsibleModuleFail as e:
# If the services does not exist, systemd will output
# "Unit <service> could not be found." with a nonzero return code
# We want to catch the error here.
if 'could not be found' in e.results['stderr']:
return False
raise
return "active (running)" in service_status['stdout']

def critical_services_status(self):
Expand Down
12 changes: 9 additions & 3 deletions tests/common/plugins/conditional_mark/tests_mark_conditions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,17 @@ gnmi/test_gnmi_configdb.py:
- "'t2' in topo_name"
- "is_multi_asic==True"

gnmi/test_gnoi_killprocess.py:
gnmi/test_gnoi_killprocess.py::test_gnoi_killprocess_then_restart[pmon-True-]:
skip:
reason: "There is some issues running on kvm testbeds."
reason: "Not supported on KVM due to missing system EEPROM."
conditions:
- "asic_type in ['vs'] and https://github.com/sonic-net/sonic-mgmt/issues/16238"
- "asic_type in ['vs'] and https://github.com/sonic-net/sonic-mgmt/issues/16615"

gnmi/test_gnoi_killprocess.py::test_gnoi_killprocess_then_restart[snmp-True-]:
skip:
reason: "Not supported on KVM due to missing system EEPROM."
conditions:
- "asic_type in ['vs'] and https://github.com/sonic-net/sonic-mgmt/issues/16615"

#######################################
##### hash #####
Expand Down
14 changes: 7 additions & 7 deletions tests/gnmi/test_gnoi_killprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .helper import gnoi_request
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.dut_utils import is_container_running

from tests.common.platform.processes_utils import wait_critical_processes

pytestmark = [
pytest.mark.topology('any')
Expand All @@ -24,14 +24,13 @@
("swss", True, ""),
hdwhdw marked this conversation as resolved.
Show resolved Hide resolved
("pmon", True, ""),
("rsyslog", True, ""),
("telemetry", True, "")
("telemetry", True, ""),
])
def test_gnoi_killprocess_then_restart(duthosts, rand_one_dut_hostname, localhost, process, is_valid, expected_msg):
duthost = duthosts[rand_one_dut_hostname]

if process and process != "nonexistent":
pytest_assert(duthost.is_host_service_running(process),
"{} should be running before KillProcess test attempts to kill this process".format(process))
if process and not duthost.is_host_service_running(process):
pytest.skip("{} is not running".format(process))

request_kill_json_data = '{{"name": "{}", "signal": 1}}'.format(process)
ret, msg = gnoi_request(duthost, localhost, "KillProcess", request_kill_json_data)
Expand All @@ -49,7 +48,7 @@ def test_gnoi_killprocess_then_restart(duthosts, rand_one_dut_hostname, localhos
else:
pytest_assert(ret != 0, "KillProcess API unexpectedly succeeded with invalid request parameters")
pytest_assert(expected_msg in msg, "Unexpected error message in response to invalid gNOI request")

wait_critical_processes(duthost)
pytest_assert(duthost.critical_services_fully_started, "System unhealthy after gNOI API request")


Expand All @@ -70,15 +69,16 @@ def test_gnoi_killprocess_restart(duthosts, rand_one_dut_hostname, localhost, re
else:
pytest_assert(ret != 0, "KillProcess API unexpectedly succeeded with invalid request parameters")
pytest_assert("panic" in msg, "Unexpected error message in response to invalid gNOI request")
wait_critical_processes(duthost)
pytest_assert(duthost.critical_services_fully_started, "System unhealthy after gNOI API request")


def test_invalid_signal(duthosts, rand_one_dut_hostname, localhost):
duthost = duthosts[rand_one_dut_hostname]
request_json_data = '{"name": "snmp", "restart": true, "signal": 2}'
ret, msg = gnoi_request(duthost, localhost, "KillProcess", request_json_data)

pytest_assert(ret != 0, "KillProcess API unexpectedly succeeded with invalid request parameters")
pytest_assert("KillProcess only supports SIGNAL_TERM (option 1)" in msg,
"Unexpected error message in response to invalid gNOI request")
wait_critical_processes(duthost)
pytest_assert(duthost.critical_services_fully_started, "System unhealthy after gNOI API request")
Loading