Skip to content

Commit 91a7bed

Browse files
vboykoxCarl Keene
authored andcommitted
[barefoot][platform] Refactor chassis.py (sonic-net#7704)
#### Why I did it On our platforms syncd must be up while using the sonic_platform. The issue is warm-reboot script first disables syncd then instantiate Chassis, which tries to connect syncd in __init__. #### How I did it Refactor Chassis to lazy initialize components. Signed-off-by: Volodymyr Boyko <[email protected]>
1 parent 8b80acd commit 91a7bed

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/chassis.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
try:
44
import sys
55
from sonic_platform_base.chassis_base import ChassisBase
6-
from sonic_platform.sfp import Sfp
7-
from sonic_platform.psu import Psu
6+
from sonic_platform.sfp import Sfp, sfp_list_get
7+
from sonic_platform.psu import psu_list_get
88
from sonic_platform.fan_drawer import fan_drawer_list_get
99
from sonic_platform.thermal import thermal_list_get
1010
from eeprom import Eeprom
@@ -18,18 +18,21 @@ class Chassis(ChassisBase):
1818
def __init__(self):
1919
ChassisBase.__init__(self)
2020

21-
self._eeprom = Eeprom()
22-
23-
for index in range(Sfp.port_start(), Sfp.port_end() + 1):
24-
sfp_node = Sfp(index)
25-
self._sfp_list.append(sfp_node)
26-
27-
for i in range(1, Psu.get_num_psus() + 1):
28-
psu = Psu(i)
29-
self._psu_list.append(psu)
30-
21+
self.__eeprom = None
3122
self.__fan_drawers = None
3223
self.__thermals = None
24+
self.__psu_list = None
25+
self.__sfp_list = None
26+
27+
@property
28+
def _eeprom(self):
29+
if self.__eeprom is None:
30+
self.__eeprom = Eeprom()
31+
return self.__eeprom
32+
33+
@_eeprom.setter
34+
def _eeprom(self, value):
35+
pass
3336

3437
@property
3538
def _fan_drawer_list(self):
@@ -51,6 +54,26 @@ def _thermal_list(self):
5154
def _thermal_list(self, value):
5255
pass
5356

57+
@property
58+
def _psu_list(self):
59+
if self.__psu_list is None:
60+
self.__psu_list = psu_list_get()
61+
return self.__psu_list
62+
63+
@_psu_list.setter
64+
def _psu_list(self, value):
65+
pass
66+
67+
@property
68+
def _sfp_list(self):
69+
if self.__sfp_list is None:
70+
self.__sfp_list = sfp_list_get()
71+
return self.__sfp_list
72+
73+
@_sfp_list.setter
74+
def _sfp_list(self, value):
75+
pass
76+
5477
def get_name(self):
5578
"""
5679
Retrieves the name of the chassis

platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/psu.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ def get_model(self):
104104

105105
def is_replaceable(self):
106106
return True
107+
108+
def psu_list_get():
109+
psu_list = []
110+
for i in range(1, Psu.get_num_psus() + 1):
111+
psu = Psu(i)
112+
psu_list.append(psu)
113+
return psu_list

platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/sfp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,10 @@ def get_transceiver_threshold_info(self):
269269

270270
def get_change_event(self, timeout=0):
271271
return Sfp.get_transceiver_change_event(timeout)
272+
273+
def sfp_list_get():
274+
sfp_list = []
275+
for index in range(Sfp.port_start(), Sfp.port_end() + 1):
276+
sfp_node = Sfp(index)
277+
sfp_list.append(sfp_node)
278+
return sfp_list

0 commit comments

Comments
 (0)