From 94a1b5ecad81e5dd7c62ec568ee006c988949daa Mon Sep 17 00:00:00 2001 From: Oleksandr Ivantsiv Date: Tue, 22 Oct 2024 21:46:16 +0300 Subject: [PATCH] [SmartSwitch] Add a new API for the DPU chassis to query dataplane and midplane states --- sonic_platform_base/chassis_base.py | 52 +++++++++++++++++++++++++---- tests/chassis_base_test.py | 11 +++--- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 05a633596..dcb371ff0 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -280,26 +280,64 @@ def get_module_index(self, module_name): # SmartSwitch methods ############################################## - def get_dpu_id(self, name): + def get_dpu_id(self, **kwargs): """ - Retrieves the DPU ID for the given dpu-module name. - Returns None for non-smartswitch chassis. + Retrieves the DPU ID for the specified DPU module on a Smart Switch chassis. + + When run on the Smart Switch chassis, it fetches the ID corresponding to provided DPU module name. + When run on the Smart Switch DPU chassis, returns the ID of the DPU. + This method is relevant only for Smart Switch chassis. + + Args: + name (str, optional): The name of the DPU module (e.g., "DPU0", "DPU1"). Returns: - An integer, indicating the DPU ID Ex: name:DPU0 return value 0, - name:DPU1 return value 1, name:DPUX return value X + int: The DPU ID associated with the given module name. + For example, for name "DPU0", returns 0; for "DPU1", returns 1, and so on. """ raise NotImplementedError def is_smartswitch(self): """ - Retrieves whether the sonic instance is part of smartswitch + Checks whether the current SONiC instance is part of a Smart Switch platform. + + Returns: + bool: True if the instance is part of a Smart Switch, False otherwise. + """ + return False + + def is_dpu(self): + """ + Checks whether the current SONiC instance is running on a DPU. Returns: - Returns:True for SmartSwitch and False for other platforms + bool: True if the instance is running on a DPU, False otherwise. """ return False + def get_dpu_dataplane_state(self): + """ + Retrieves the status of the DPU dataplane. + + This method is applicable only on Smart Switch DPUs. + + Returns: + bool: True if the dataplane is UP, False if it is down. + """ + raise NotImplementedError + + def get_dpu_controlplane_state(self): + """ + Retrieves the status of the DPU control plane. + + This method is applicable only on Smart Switch DPUs. + + Returns: + bool: True if the control plane is UP, False if it is down. + """ + raise NotImplementedError + + ############################################## # Fan methods ############################################## diff --git a/tests/chassis_base_test.py b/tests/chassis_base_test.py index c7dbc512e..68a8db382 100644 --- a/tests/chassis_base_test.py +++ b/tests/chassis_base_test.py @@ -20,17 +20,18 @@ def test_reboot_cause(self): def test_chassis_base(self): chassis = ChassisBase() not_implemented_methods = [ - [chassis.get_uid_led], - [chassis.set_uid_led, "COLOR"], - [chassis.get_dpu_id, "DPU0"], + [chassis.get_uid_led, [], {}], + [chassis.set_uid_led, ["COLOR"], {}], + [chassis.get_dpu_id, [], {"name": "DPU0"}], ] for method in not_implemented_methods: exception_raised = False try: func = method[0] - args = method[1:] - func(*args) + args = method[1] + kwargs = method[2] + func(*args, **kwargs) except NotImplementedError: exception_raised = True