From f09a935d64f25929dd2cac3b74bc335bb7cda058 Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Mon, 11 Mar 2024 10:54:55 -0700 Subject: [PATCH 1/6] modifying snmp psu test to fit format using psu keys instead of index --- tests/snmp/test_snmp_psu.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index ca3f87cfab7..7a8b534409d 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -1,6 +1,8 @@ import pytest from tests.common.helpers.assertions import pytest_assert from tests.common.helpers.snmp_helpers import get_snmp_facts +from natsort import natsorted +import logging PSU_STATUS_OK = 2 PSU_STATUS_FUNCTIONING_FAIL = 7 @@ -10,7 +12,6 @@ pytest.mark.topology('any') ] - @pytest.mark.bsl def test_snmp_numpsu(duthosts, enum_supervisor_dut_hostname, localhost, creds_all_duts): duthost = duthosts[enum_supervisor_dut_hostname] @@ -37,14 +38,15 @@ def test_snmp_psu_status(duthosts, enum_supervisor_dut_hostname, localhost, cred localhost, host=hostip, version="v2c", community=creds_all_duts[duthost.hostname]["snmp_rocommunity"], wait=True)['ansible_facts'] + psu_keys = natsorted(redis_get_keys(duthost, 'STATE_DB', 'PSU_INFO|*')) psus_on = 0 msg = "Unexpected operstatus results {} != {} for PSU {}" - for psu_indx, operstatus in list(snmp_facts['snmp_psu'].items()): + for psu_indx, operstatus in snmp_facts['snmp_psu'].items(): get_presence = duthost.shell( - "redis-cli -n 6 hget 'PSU_INFO|PSU {}' presence".format(psu_indx)) + "redis-cli -n 6 hget '{}' presence".format(psu_keys[int(psu_indx)-1])) get_status = duthost.shell( - "redis-cli -n 6 hget 'PSU_INFO|PSU {}' status".format(psu_indx)) + "redis-cli -n 6 hget '{}' status".format(psu_keys[int(psu_indx)-1])) status = get_status['stdout'] == 'true' presence = get_presence['stdout'] == 'true' @@ -61,3 +63,18 @@ def test_snmp_psu_status(duthosts, enum_supervisor_dut_hostname, localhost, cred pytest_assert( psus_on >= 1, "At least one PSU should be with operstatus OK") + + +def redis_get_keys(duthost, db_id, pattern): + """ + Get all keys for a given pattern in given redis database + :param duthost: DUT host object + :param db_id: ID of redis database + :param pattern: Redis key pattern + :return: A list of key name in string + """ + cmd = 'sonic-db-cli {} KEYS \"{}\"'.format(db_id, pattern) + logging.debug('Getting keys from redis by command: {}'.format(cmd)) + output = duthost.shell(cmd) + content = output['stdout'].strip() + return content.split('\n') if content else None From 276c98b4abfe13a08c971feb51c02fb17b6c1ab0 Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:21:01 -0700 Subject: [PATCH 2/6] addressing precommit blankline check --- tests/snmp/test_snmp_psu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index 7a8b534409d..634052d33fa 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -12,6 +12,7 @@ pytest.mark.topology('any') ] + @pytest.mark.bsl def test_snmp_numpsu(duthosts, enum_supervisor_dut_hostname, localhost, creds_all_duts): duthost = duthosts[enum_supervisor_dut_hostname] From 495dd9614fa4dc86f9f2ff36056a462da93ffec5 Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:49:32 -0700 Subject: [PATCH 3/6] dummy commit --- tests/snmp/test_snmp_psu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index 634052d33fa..6e85fd8c6e2 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -24,7 +24,7 @@ def test_snmp_numpsu(duthosts, enum_supervisor_dut_hostname, localhost, creds_al localhost, host=hostip, version="v2c", community=creds_all_duts[duthost.hostname]["snmp_rocommunity"], wait=True)['ansible_facts'] res = duthost.shell("psuutil numpsus") - assert int(res['rc']) == 0, "Failed to get number of PSUs" + assert int(res['rc']) == 0, "Failed to get number of PSUs " numpsus = int(res['stdout']) assert numpsus == len(snmp_facts['snmp_psu']) From af06c7fe3be67f2be7bdd813c3dbc3b101567e69 Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:49:49 -0700 Subject: [PATCH 4/6] dummy commit revert --- tests/snmp/test_snmp_psu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index 6e85fd8c6e2..634052d33fa 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -24,7 +24,7 @@ def test_snmp_numpsu(duthosts, enum_supervisor_dut_hostname, localhost, creds_al localhost, host=hostip, version="v2c", community=creds_all_duts[duthost.hostname]["snmp_rocommunity"], wait=True)['ansible_facts'] res = duthost.shell("psuutil numpsus") - assert int(res['rc']) == 0, "Failed to get number of PSUs " + assert int(res['rc']) == 0, "Failed to get number of PSUs" numpsus = int(res['stdout']) assert numpsus == len(snmp_facts['snmp_psu']) From 8e6fd7e2cdf7caf468ac8662cfcb3336ebdd842f Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:19:31 -0700 Subject: [PATCH 5/6] removing additional logging module, precommit fail --- tests/snmp/test_snmp_psu.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index fdbe4fee9e7..a52aba6c443 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -3,7 +3,6 @@ from tests.common.helpers.assertions import pytest_assert from tests.common.helpers.snmp_helpers import get_snmp_facts from natsort import natsorted -import logging PSU_STATUS_OK = 2 PSU_STATUS_FUNCTIONING_FAIL = 7 From a5549cbb127cadc65626f962bf304dc0943c0b42 Mon Sep 17 00:00:00 2001 From: Gregory Boudreau <45526465+gregoryboudreau@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:33:16 -0700 Subject: [PATCH 6/6] move psu key call to after kvm testbed check --- tests/snmp/test_snmp_psu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/snmp/test_snmp_psu.py b/tests/snmp/test_snmp_psu.py index a52aba6c443..8518f218021 100644 --- a/tests/snmp/test_snmp_psu.py +++ b/tests/snmp/test_snmp_psu.py @@ -45,7 +45,6 @@ def test_snmp_psu_status(duthosts, enum_supervisor_dut_hostname, localhost, cred localhost, host=hostip, version="v2c", community=creds_all_duts[duthost.hostname]["snmp_rocommunity"], wait=True)['ansible_facts'] - psu_keys = natsorted(redis_get_keys(duthost, 'STATE_DB', 'PSU_INFO|*')) psus_on = 0 msg = "Unexpected operstatus results {} != {} for PSU {}" @@ -54,6 +53,7 @@ def test_snmp_psu_status(duthosts, enum_supervisor_dut_hostname, localhost, cred logging.info("No snmp psu info on kvm testbed.") return + psu_keys = natsorted(redis_get_keys(duthost, 'STATE_DB', 'PSU_INFO|*')) for psu_indx, operstatus in snmp_facts['snmp_psu'].items(): get_presence = duthost.shell( "redis-cli -n 6 hget '{}' presence".format(psu_keys[int(psu_indx)-1]))