Skip to content

Commit 9bae794

Browse files
ds952811jleveque
authored andcommitted
[sonic_platform_base] Reallocate empty lists in the constructor of the base class (sonic-net#65)
Signed-off-by: Dante (Kuo-Jung) Su <[email protected]>
1 parent bea68f4 commit 9bae794

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

sonic_platform_base/chassis_base.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,42 @@ class ChassisBase(device_base.DeviceBase):
2828

2929
# List of ComponentBase-derived objects representing all components
3030
# available on the chassis
31-
_component_list = []
31+
_component_list = None
3232

3333
# List of ModuleBase-derived objects representing all modules
3434
# available on the chassis (for use with modular chassis)
35-
_module_list = []
35+
_module_list = None
3636

3737
# List of FanBase-derived objects representing all fans
3838
# available on the chassis
39-
_fan_list = []
39+
_fan_list = None
4040

4141
# List of PsuBase-derived objects representing all power supply units
4242
# available on the chassis
43-
_psu_list = []
43+
_psu_list = None
4444

4545
# List of ThermalBase-derived objects representing all thermals
4646
# available on the chassis
47-
_thermal_list = []
47+
_thermal_list = None
4848

4949
# List of SfpBase-derived objects representing all sfps
5050
# available on the chassis
51-
_sfp_list = []
51+
_sfp_list = None
5252

5353
# Object derived from WatchdogBase for interacting with hardware watchdog
5454
_watchdog = None
5555

5656
# Object derived from eeprom_tlvinfo.TlvInfoDecoder indicating the eeprom on the chassis
5757
_eeprom = None
5858

59+
def __init__(self):
60+
self._component_list = []
61+
self._module_list = []
62+
self._fan_list = []
63+
self._psu_list = []
64+
self._thermal_list = []
65+
self._sfp_list = []
66+
5967
def get_base_mac(self):
6068
"""
6169
Retrieves the base MAC address for the chassis

sonic_platform_base/module_base.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,30 @@ class ModuleBase(device_base.DeviceBase):
1919

2020
# List of ComponentBase-derived objects representing all components
2121
# available on the module
22-
_component_list = []
22+
_component_list = None
2323

2424
# List of FanBase-derived objects representing all fans
2525
# available on the module
26-
_fan_list = []
26+
_fan_list = None
2727

2828
# List of PsuBase-derived objects representing all power supply units
2929
# available on the module
30-
_psu_list = []
30+
_psu_list = None
3131

3232
# List of ThermalBase-derived objects representing all thermals
3333
# available on the module
34-
_thermal_list = []
34+
_thermal_list = None
3535

3636
# List of SfpBase-derived objects representing all sfps
3737
# available on the module
38-
_sfp_list = []
38+
_sfp_list = None
39+
40+
def __init__(self):
41+
self._component_list = []
42+
self._fan_list = []
43+
self._psu_list = []
44+
self._thermal_list = []
45+
self._sfp_list = []
3946

4047
def get_base_mac(self):
4148
"""

sonic_platform_base/psu_base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class PsuBase(device_base.DeviceBase):
2323

2424
# List of FanBase-derived objects representing all fans
2525
# available on the PSU
26-
_fan_list = []
26+
_fan_list = None
27+
28+
def __init__(self):
29+
self._fan_list = []
2730

2831
def get_num_fans(self):
2932
"""

0 commit comments

Comments
 (0)