Skip to content

Commit

Permalink
[system_health] Add support for check_system_health_info both old and…
Browse files Browse the repository at this point in the history
… new format (#7681)

What is the motivation for this PR?
Test failed introduced by this PR sonic-net/sonic-buildimage#13497 has been fixed by this PR #7649. But in DUT with old image, it will failed.

How did you do it?
Add support for check_system_health_info to support both two formats

How did you verify/test it?
Run test

Signed-off-by: Yaqiang Zhu <yaqiangzhu@microsoft.com>
  • Loading branch information
yaqiangz authored Mar 8, 2023
1 parent 198265a commit 446721a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/system_health/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ def test_service_checker_with_process_exit(duthosts, enum_rand_one_per_hwsku_hos
# use wait_until to check if SYSTEM_HEALTH_INFO has expected content
# avoid waiting for too long or DEFAULT_INTERVAL is not long enough to refresh db
category = '{}:{}'.format(container, critical_process)
expected_value = "Process '{}' in container '{}' is not running".format(critical_process, container)
result = wait_until(WAIT_TIMEOUT, 10, 2, check_system_health_info, duthost, category, expected_value)
expected_values = ["Process '{}' in container '{}' is not running".format(critical_process, container),
"'{}' is not running".format(critical_process)]
result = wait_until(WAIT_TIMEOUT, 10, 2, check_system_health_info_any_of, duthost, category,
expected_values)

assert result == True, '{} is not recorded'.format(critical_process)
summary = redis_get_field_value(duthost, STATE_DB, HEALTH_TABLE_NAME, 'summary')
assert summary == SUMMARY_NOT_OK, 'Expect summary {}, got {}'.format(SUMMARY_NOT_OK, summary)
Expand Down Expand Up @@ -365,6 +368,14 @@ def redis_get_system_health_info(duthost, db_id, key):
output = duthost.shell(cmd)['stdout'].strip()
return output

def check_system_health_info_any_of(duthost, category, expected_values):
value = redis_get_field_value(duthost, STATE_DB, HEALTH_TABLE_NAME, category)
for expected_value in expected_values:
if value == expected_value:
return True

return False

def check_system_health_info(duthost, category, expected_value):
value = redis_get_field_value(duthost, STATE_DB, HEALTH_TABLE_NAME, category)
return value == expected_value
Expand Down

0 comments on commit 446721a

Please sign in to comment.