Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] Extend Nvidia Bluefield DPU chassis implementation #20620

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"skip_ledd": true,
"skip_psud": true,
"skip_fancontrol": true,
"skip_chassisd": true,
"skip_chassisd": false,
"skip_ycabled": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import os
from functools import reduce
from time import sleep
import psutil
import ipaddress
import socket

from . import utils
from .device_data import DeviceDataManager
Expand Down Expand Up @@ -53,8 +56,25 @@ def __init__(self):
self.sfp_event = None
self._eeprom = Eeprom()
self._watchdog = Watchdog()

logger.log_info("Chassis loaded successfully")

def _get_dpu_id(self):
ip = None
midplane_inft = psutil.net_if_addrs().get('eth0-midplane', [])

for address in midplane_inft:
if address.family == socket.AF_INET:
ip = ipaddress.IPv4Address(address.address)
break

if not ip:
raise RuntimeError("Midplane interface IP address is not available")

last_byte = int(str(ip).split('.')[-1])

return last_byte - 1

def _initialize_sfp(self):
self._sfp_list = []

Expand Down Expand Up @@ -272,3 +292,36 @@ def get_reboot_cause(self):
to pass a description of the reboot cause.
"""
return "N/A", "N/A"

##############################################
# SmartSwitch methods
##############################################

def get_dpu_id(self, **kwargs):
"""
For the smart switch DPU retrieves the ID of the DPU.
Returns None for non-smartswitch chassis.

Returns:
An integer, indicating the DPU ID Ex: name:DPU0 return value 0,
name:DPU1 return value 1, name:DPUX return value X
"""
return self._get_dpu_id()

def is_smartswitch(self):
"""
Retrieves whether the sonic instance is part of smartswitch

Returns:
Returns:True for SmartSwitch and False for other platforms
"""
return True

def is_dpu(self):
"""
Retrieves whether the SONiC instance runs on the DPU

Returns:
True if the SONiC instance runs on the DPU else False
"""
return True
10 changes: 10 additions & 0 deletions platform/nvidia-bluefield/platform-api/tests/test_chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import os
import sys
import socket
from collections import namedtuple

from unittest.mock import patch
from unittest.mock import mock_open
Expand Down Expand Up @@ -83,3 +85,11 @@ def test_sfp(self, *args):
assert len(sfp_list) == 2
assert id(sfp1) == id(sfp_list[0])
assert id(sfp2) == id(sfp_list[1])


@patch('psutil.net_if_addrs', return_value={
'eth0-midplane': [namedtuple('snicaddr', ['family', 'address'])(family=socket.AF_INET, address='169.254.200.1')]})
def test_get_dpu_id(self, *args):
chassis = Chassis()

assert chassis.get_dpu_id() == 0
Loading