Skip to content

Commit

Permalink
Fix get_monit_services_status logic (sonic-net#16013)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
The current logic simply checks for the keyword "status" in service_info without considering the context. If the keyword appears in 'last output' or another unintended section of the data, the logic misinterprets it.

How did you do it?
Ensuring "status" detection is specific to the intended line. Using a stricter parsing approach to avoid unintended matches.

How did you verify/test it?
Ran the test_pretest.py on kvm-t0 testbed. Captured the get_monit_services_status() output
  • Loading branch information
deepak-singhal0408 authored Dec 11, 2024
1 parent 2cb805c commit 4aa835e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ def get_monit_services_status(self):
return monit_services_status

for index, service_info in enumerate(services_status_result["stdout_lines"]):
if "status" in service_info and "monitoring status" not in service_info:
if service_info.strip().startswith("status"):
service_type_name = services_status_result["stdout_lines"][index - 1]
service_type = service_type_name.split("'")[0].strip()
service_name = service_type_name.split("'")[1].strip()
service_status = service_info[service_info.find("status") + len("status"):].strip()
service_status = service_info.split("status", 1)[1].strip()

monit_services_status[service_name] = {}
monit_services_status[service_name]["service_status"] = service_status
Expand Down

0 comments on commit 4aa835e

Please sign in to comment.