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

[pmon daemon check] refactoring pmon daemon state check code #1537

Merged
merged 4 commits into from
Apr 6, 2020
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
36 changes: 25 additions & 11 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,36 +232,50 @@ def get_crm_resources(self):

return result

def get_pmon_daemon_list(self):
def get_pmon_daemon_states(self):
"""
@summary: get pmon daemon list from the config file (/usr/share/sonic/device/{platform}/{hwsku}/pmon_daemon_control.json)
@summary: get state list of daemons from pmon docker.
Referencing (/usr/share/sonic/device/{platform}/pmon_daemon_control.json)
if some daemon is disabled in the config file, then remove it from the daemon list.

@return: dictionary of { service_name1 : state1, ... ... }
"""
full_daemon_tup = ('xcvrd', 'ledd', 'psud', 'syseepromd')
# some services are meant to have a short life span or not part of the daemons
exemptions = ['lm-sensors', 'start.sh', 'rsyslogd']

daemons = self.shell('docker exec pmon supervisorctl status')['stdout_lines']

daemon_list = [ line.strip().split()[0] for line in daemons if len(line.strip()) > 0 ]

daemon_ctl_key_prefix = 'skip_'
daemon_list = []
daemon_config_file_path = os.path.join('/usr/share/sonic/device', self.facts["platform"], 'pmon_daemon_control.json')
neethajohn marked this conversation as resolved.
Show resolved Hide resolved

try:
output = self.shell('cat %s' % daemon_config_file_path)
json_data = json.loads(output["stdout"])
logging.debug("Original file content is %s" % str(json_data))
for key in full_daemon_tup:
for key in daemon_list:
if (daemon_ctl_key_prefix + key) not in json_data:
daemon_list.append(key)
logging.debug("Daemon %s is enabled" % key)
elif not json_data[daemon_ctl_key_prefix + key]:
daemon_list.append(key)
logging.debug("Daemon %s is enabled" % key)
else:
logging.debug("Daemon %s is disabled" % key)
exemptions.append(key)
except:
# if pmon_daemon_control.json not exist, then it's using default setting,
# all the pmon daemons expected to be running after boot up.
daemon_list = list(full_daemon_tup)
pass

# Collect state of services that are not on the exemption list.
daemon_states = {}
for line in daemons:
words = line.strip().split()
if len(words) >= 2 and words[0] not in exemptions:
daemon_states[words[0]] = words[1]

logging.info("Pmon daemon list for this platform is %s" % str(daemon_list))
return daemon_list
logging.info("Pmon daemon state list for this platform is %s" % str(daemon_states))
return daemon_states

def num_npus(self):
"""
Expand Down Expand Up @@ -321,7 +335,7 @@ def get_image_info(self):
ret = {}
images = []
for line in lines:
words = line.strip().split(' ')
words = line.strip().split()
if len(words) == 2:
if words[0] == 'Current:':
ret['current'] = words[1]
Expand Down
23 changes: 23 additions & 0 deletions tests/common/platform/daemon_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Helper script for checking status of platform daemon status

This script contains re-usable functions for checking status of platform daemon status.
"""
import logging


def check_pmon_daemon_status(dut):
"""
@summary: check daemon running status inside pmon docker.

This function use command "supervisorctl status" inside the container and check the status from the command output.
If the daemon status is "RUNNING" then return True, if daemon not exist or status is not "RUNNING", return false.
"""
daemons = dut.get_pmon_daemon_states()
ret = True
for daemon, state in daemons.items():
logging.debug("Daemon %s status is %s" % (daemon, state))
if state != 'RUNNING':
ret = False

return ret
31 changes: 0 additions & 31 deletions tests/platform/check_daemon_status.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/platform/test_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from common.reboot import *
from common.platform.interface_utils import check_interface_information
from common.platform.transceiver_utils import check_transceiver_basic
from common.platform.daemon_utils import check_pmon_daemon_status

from check_critical_services import check_critical_services
from check_daemon_status import check_pmon_daemon_status

pytestmark = [pytest.mark.disable_loganalyzer]

Expand Down