Skip to content

Commit

Permalink
[SmartSwitch] Add a new API for the DPU chassis to query dataplane an…
Browse files Browse the repository at this point in the history
…d midplane states
  • Loading branch information
oleksandrivantsiv committed Oct 23, 2024
1 parent f07a6aa commit 70b3de5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
48 changes: 41 additions & 7 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,60 @@ 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:
Returns:True for SmartSwitch and False for other platforms
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:
bool: True if the instance is running on a DPU, False otherwise.
"""
return False

def get_dataplane_state(self):
"""
Retrieves the status of the dataplane.
Returns:
bool: True if the dataplane is UP, False if it is down.
"""
raise NotImplementedError

def get_controlplane_state(self):
"""
Retrieves the status of the DPU control plane.
Returns:
bool: True if the control plane is UP, False if it is down.
"""
raise NotImplementedError


##############################################
# Fan methods
##############################################
Expand Down
14 changes: 9 additions & 5 deletions tests/chassis_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ 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"}],
[chassis.get_dataplane_state, [], {}],
[chassis.get_controlplane_state, [], {}],
]

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

Expand All @@ -39,6 +42,7 @@ def test_chassis_base(self):
def test_smartswitch(self):
chassis = ChassisBase()
assert(chassis.is_smartswitch() == False)
assert(chassis.is_dpu() == False)

def test_sensors(self):
chassis = ChassisBase()
Expand Down

0 comments on commit 70b3de5

Please sign in to comment.