From b918a0f025d24c5ff63e8459a8d9be88398155af Mon Sep 17 00:00:00 2001 From: agadia-cisco Date: Thu, 14 Nov 2024 14:16:26 -0800 Subject: [PATCH] added multi-asic handling in sonic-cfggen --- tests/gnmi/test_gnmi_configdb.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/gnmi/test_gnmi_configdb.py b/tests/gnmi/test_gnmi_configdb.py index 53e3b47ee0..5e63717821 100644 --- a/tests/gnmi/test_gnmi_configdb.py +++ b/tests/gnmi/test_gnmi_configdb.py @@ -51,6 +51,18 @@ def get_interface_status(duthost, field, interface='Ethernet0'): return output["stdout"] +def get_sonic_cfggen_output(duthost, namespace=None): + ''' + Fetch and return the sonic-cfggen output + ''' + cmd = "sonic-cfggen -d --print-data" + if namespace: + cmd = f"sonic-cfggen -n {namespace} -d --print-data" + output = duthost.shell(cmd) + assert (not output['rc']), "No output" + return (json.loads(output["stdout"])) + + def test_gnmi_configdb_incremental_01(duthosts, rand_one_dut_hostname, ptfhost): ''' Verify GNMI native write, incremental config for configDB @@ -224,12 +236,19 @@ def test_gnmi_configdb_full_01(duthosts, rand_one_dut_hostname, ptfhost): Toggle interface admin status ''' duthost = duthosts[rand_one_dut_hostname] - output = duthost.shell("sonic-cfggen -d --print-data") - assert (not output['rc']), "No output" - dic = json.loads(output["stdout"]) - assert "PORT" in dic, "Failed to read running config" interface = get_first_interface(duthost) assert interface is not None, "Invalid interface" + + # Get ASIC namespace and check interface + if duthost.sonichost.is_multi_asic: + for asic in duthost.frontend_asics: + dic = get_sonic_cfggen_output(duthost, asic.namespace) + if interface in dic["PORT"]: + break + else: + dic = get_sonic_cfggen_output(duthost) + + assert "PORT" in dic, "Failed to read running config" assert interface in dic["PORT"], "Failed to get interface %s" % interface assert "admin_status" in dic["PORT"][interface], "Failed to get interface %s" % interface