From dc05ac27ff5848af65c263fec9e21f20ba2136ae Mon Sep 17 00:00:00 2001 From: gupurush Date: Thu, 2 Jan 2025 11:01:14 -0800 Subject: [PATCH] feature: add functionality to retrieve console information (#16249) Summary: Added functionality to retrieve console information from testbed devices in spytest framework. This enables access to console details (IP, port, protocol) for test cases and debugging purposes. Approach What is the motivation for this PR? To provide easy access to device console information within spytest framework, which helps in debugging and monitoring test cases that require console access. How did you do it? Added new method get_console() in framework.py to access testbed console info Implemented get_console_info() in infra.py as a utility function Added get_console() in testbed.py to retrieve console IP, port, and protocol from device info How did you verify/test it? By running spytest with a testbed configuration that includes console information and verifying the returned console details match the configuration. --- spytest/spytest/framework.py | 3 +++ spytest/spytest/infra.py | 4 ++++ spytest/spytest/testbed.py | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/spytest/spytest/framework.py b/spytest/spytest/framework.py index df9290128b2..7f7cb859a11 100644 --- a/spytest/spytest/framework.py +++ b/spytest/spytest/framework.py @@ -3932,6 +3932,9 @@ def get_config_profile(self): profile = profile or self.cfg.config_profile profile = profile or "na" return profile.lower() + + def get_console(self, dut): + return self._context._tb.get_console(dut) def get_device_type(self, dut): return self._context._tb.get_device_type(dut) diff --git a/spytest/spytest/infra.py b/spytest/spytest/infra.py index 2da20a260b2..943f6bd547b 100644 --- a/spytest/spytest/infra.py +++ b/spytest/spytest/infra.py @@ -405,6 +405,10 @@ def get_mgmt_ip(dut): return getwa().get_mgmt_ip(dut) +def get_console_info(dut): + return getwa().get_console(dut) + + def get_datastore(dut, name, scope="default"): return getwa().get_datastore(dut, name, scope) diff --git a/spytest/spytest/testbed.py b/spytest/spytest/testbed.py index 12e38b3fdd0..0f60d44f5dd 100644 --- a/spytest/spytest/testbed.py +++ b/spytest/spytest/testbed.py @@ -1396,6 +1396,17 @@ def get_ts(self, dut): return rv["ts"] return None + def get_console(self, dut, default=""): + dinfo = self.get_device_info(dut) + rv = SpyTestDict() + if not dinfo: + return default + if dinfo["console"]: + rv.ip = dinfo["console"].ip + rv.port = dinfo["console"].port + rv.protocol = dinfo["console"].protocol + return rv + def get_rps(self, dut): """ Returns RPS details read from testbed file for given DUT