From 9bae7944f23cd4fad3fbb0cfb04425e2c06a1ef0 Mon Sep 17 00:00:00 2001 From: "Dante (Kuo-Jung) Su" Date: Wed, 13 Nov 2019 08:57:56 +0800 Subject: [PATCH] [sonic_platform_base] Reallocate empty lists in the constructor of the base class (#65) Signed-off-by: Dante (Kuo-Jung) Su --- sonic_platform_base/chassis_base.py | 20 ++++++++++++++------ sonic_platform_base/module_base.py | 17 ++++++++++++----- sonic_platform_base/psu_base.py | 5 ++++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 4e1762699e9a..eb1e089b564d 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -28,27 +28,27 @@ class ChassisBase(device_base.DeviceBase): # List of ComponentBase-derived objects representing all components # available on the chassis - _component_list = [] + _component_list = None # List of ModuleBase-derived objects representing all modules # available on the chassis (for use with modular chassis) - _module_list = [] + _module_list = None # List of FanBase-derived objects representing all fans # available on the chassis - _fan_list = [] + _fan_list = None # List of PsuBase-derived objects representing all power supply units # available on the chassis - _psu_list = [] + _psu_list = None # List of ThermalBase-derived objects representing all thermals # available on the chassis - _thermal_list = [] + _thermal_list = None # List of SfpBase-derived objects representing all sfps # available on the chassis - _sfp_list = [] + _sfp_list = None # Object derived from WatchdogBase for interacting with hardware watchdog _watchdog = None @@ -56,6 +56,14 @@ class ChassisBase(device_base.DeviceBase): # Object derived from eeprom_tlvinfo.TlvInfoDecoder indicating the eeprom on the chassis _eeprom = None + def __init__(self): + self._component_list = [] + self._module_list = [] + self._fan_list = [] + self._psu_list = [] + self._thermal_list = [] + self._sfp_list = [] + def get_base_mac(self): """ Retrieves the base MAC address for the chassis diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index b4f8ac4514f1..6a7d2a7d567a 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -19,23 +19,30 @@ class ModuleBase(device_base.DeviceBase): # List of ComponentBase-derived objects representing all components # available on the module - _component_list = [] + _component_list = None # List of FanBase-derived objects representing all fans # available on the module - _fan_list = [] + _fan_list = None # List of PsuBase-derived objects representing all power supply units # available on the module - _psu_list = [] + _psu_list = None # List of ThermalBase-derived objects representing all thermals # available on the module - _thermal_list = [] + _thermal_list = None # List of SfpBase-derived objects representing all sfps # available on the module - _sfp_list = [] + _sfp_list = None + + def __init__(self): + self._component_list = [] + self._fan_list = [] + self._psu_list = [] + self._thermal_list = [] + self._sfp_list = [] def get_base_mac(self): """ diff --git a/sonic_platform_base/psu_base.py b/sonic_platform_base/psu_base.py index adb1a6051db0..0341a50e0e44 100644 --- a/sonic_platform_base/psu_base.py +++ b/sonic_platform_base/psu_base.py @@ -23,7 +23,10 @@ class PsuBase(device_base.DeviceBase): # List of FanBase-derived objects representing all fans # available on the PSU - _fan_list = [] + _fan_list = None + + def __init__(self): + self._fan_list = [] def get_num_fans(self): """