From e83aa15f30da2c559d22d7f5905a59e3333ec712 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar T <53558409+santhosh-kt@users.noreply.github.com> Date: Wed, 21 Dec 2022 02:08:09 +0530 Subject: [PATCH] [DellEMC] Fixing 'show interface status' break in DellEMC platforms (#13021) When a non-root user tries to run 'show interface status' command, the command got break as 2.0 API throws permission denied error. --- .../s5212f/sonic_platform/chassis.py | 6 +----- .../s5212f/sonic_platform/component.py | 4 +++- .../s5224f/sonic_platform/chassis.py | 6 +----- .../s5224f/sonic_platform/component.py | 4 +++- .../s5232f/sonic_platform/chassis.py | 3 +-- .../s5232f/sonic_platform/component.py | 4 +++- .../s5248f/sonic_platform/chassis.py | 3 +-- .../s5248f/sonic_platform/component.py | 4 +++- .../s5296f/sonic_platform/chassis.py | 3 +++ .../s5296f/sonic_platform/component.py | 4 +++- .../s6000/sonic_platform/chassis.py | 5 +++++ .../s6100/sonic_platform/chassis.py | 9 +++++++++ .../s6100/sonic_platform/eeprom.py | 5 +++++ .../z9264f/sonic_platform/chassis.py | 7 ++----- .../z9332f/sonic_platform/chassis.py | 3 +-- .../z9332f/sonic_platform/component.py | 4 +++- .../z9432f/sonic_platform/chassis.py | 3 +-- .../z9432f/sonic_platform/component.py | 4 +++- 18 files changed, 51 insertions(+), 30 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/chassis.py index eb99821ae8..47bf5584e6 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/chassis.py @@ -123,11 +123,7 @@ class Chassis(ChassisBase): for port_num in range(self.PORT_START, (self.PORT_END + 1)): # sfp get uses zero-indexing, but port numbers start from 1 - presence = self.get_sfp(port_num-1).get_presence() - if presence: - self._global_port_pres_dict[port_num] = '1' - else: - self._global_port_pres_dict[port_num] = '0' + self._global_port_pres_dict[port_num] = '0' self.LOCATOR_LED_ON = self.STATUS_LED_COLOR_BLUE_BLINK self.LOCATOR_LED_OFF = self.STATUS_LED_COLOR_OFF diff --git a/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/component.py index fba5128356..d7a93cf5f4 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5212f/sonic_platform/component.py @@ -78,7 +78,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None def get_name(self): """ @@ -102,6 +102,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def get_presence(self): diff --git a/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/chassis.py index 02ebfbc3b7..1d14e2c0f3 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/chassis.py @@ -125,11 +125,7 @@ class Chassis(ChassisBase): for port_num in range(self.PORT_START, (self.PORT_END + 1)): # sfp get uses zero-indexing, but port numbers start from 1 - presence = self.get_sfp(port_num-1).get_presence() - if presence: - self._global_port_pres_dict[port_num] = '1' - else: - self._global_port_pres_dict[port_num] = '0' + self._global_port_pres_dict[port_num] = '0' self.LOCATOR_LED_ON = self.STATUS_LED_COLOR_BLUE_BLINK self.LOCATOR_LED_OFF = self.STATUS_LED_COLOR_OFF diff --git a/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/component.py index b0dabc1398..25f1f3b67f 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5224f/sonic_platform/component.py @@ -77,7 +77,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None def get_name(self): """ @@ -101,6 +101,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def install_firmware(self, image_path): diff --git a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/chassis.py index 41f985a173..f0c67d4e92 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/chassis.py @@ -92,8 +92,7 @@ class Chassis(ChassisBase): for port_num in range(self.PORT_START, self.PORTS_IN_BLOCK): # sfp get uses zero-indexing, but port numbers start from 1 - presence = self.get_sfp(port_num).get_presence() - self._global_port_pres_dict[port_num] = '1' if presence else '0' + self._global_port_pres_dict[port_num] = '0' def __del__(self): if self.oir_fd != -1: diff --git a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/component.py index 52f2bacd70..2a81be140d 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/component.py @@ -86,7 +86,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None def get_name(self): """ @@ -110,6 +110,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def install_firmware(self, image_path): diff --git a/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/chassis.py index b047ec0c96..fc0768368e 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/chassis.py @@ -151,8 +151,7 @@ class Chassis(ChassisBase): self._component_list = [Component(i) for i in range(MAX_S5248F_COMPONENT)] for port_num in range(self.PORT_START, self.PORTS_IN_BLOCK): # sfp get uses zero-indexing, but port numbers start from 1 - presence = self.get_sfp(port_num-1).get_presence() - self._global_port_pres_dict[port_num] = '1' if presence else '0' + self._global_port_pres_dict[port_num] = '0' #self.LOCATOR_LED_ON = self.STATUS_LED_COLOR_BLUE_BLINK #self.LOCATOR_LED_OFF = self.STATUS_LED_COLOR_OFF diff --git a/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/component.py index fdca4614c2..f55099cdec 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5248f/sonic_platform/component.py @@ -86,7 +86,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None def get_name(self): """ @@ -110,6 +110,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def install_firmware(self, image_path): diff --git a/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/chassis.py index c981e4bc7a..d382876549 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/chassis.py @@ -126,6 +126,9 @@ class Chassis(ChassisBase): self._num_fans = MAX_S5296F_FANTRAY * MAX_S5296F_FAN self._watchdog = Watchdog() + for port_num in range(self.PORT_START, self.PORTS_IN_BLOCK): + # sfp get uses zero-indexing, but port numbers start from 1 + self._global_port_pres_dict[port_num] = '0' def __del__(self): if self.oir_fd != -1: diff --git a/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/component.py index 43c43e0a4e..592cd4e8c4 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5296f/sonic_platform/component.py @@ -111,7 +111,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None def get_name(self): """ @@ -135,6 +135,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def get_presence(self): diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py index 6ae79ffadb..5ff498fe8d 100755 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/chassis.py @@ -56,6 +56,8 @@ class Chassis(ChassisBase): _is_fan_control_enabled = False _fan_control_initialised = False + _global_port_pres_dict = {} + def __init__(self): ChassisBase.__init__(self) self.status_led_reg = "system_led" @@ -107,6 +109,9 @@ class Chassis(ChassisBase): component = Component(i) self._component_list.append(component) + for port_num in range(self.PORT_START, (self.PORT_END + 1)): + self._global_port_pres_dict[port_num] = '0' + def _get_cpld_register(self, reg_name): rv = 'ERR' mb_reg_file = self.CPLD_DIR+'/'+reg_name diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py index b3d258f32e..6af22720f1 100755 --- a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/chassis.py @@ -65,6 +65,8 @@ class Chassis(ChassisBase): 'amber': 0x02, 'blinking amber': 0x08 } + _global_port_pres_dict = {} + def __init__(self): ChassisBase.__init__(self) @@ -103,6 +105,13 @@ class Chassis(ChassisBase): component = Component(i) self._component_list.append(component) + for i in self._sfp_list: + presence = i.get_presence() + if presence: + self._global_port_pres_dict[i.index] = '1' + else: + self._global_port_pres_dict[i.index] = '0' + bios_ver = self.get_component(0).get_firmware_version() bios_minor_ver = bios_ver.split("-")[-1] if bios_minor_ver.isdigit() and (int(bios_minor_ver) >= 9): diff --git a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/eeprom.py index ab3bb174e6..cab1998be3 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6100/sonic_platform/eeprom.py @@ -11,6 +11,7 @@ try: from sonic_eeprom import eeprom_tlvinfo + import os except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -27,6 +28,10 @@ class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): super(Eeprom, self).__init__(self.eeprom_path, 0, '', True) self.eeprom_tlv_dict = dict() + if os.geteuid() != 0: + self.eeprom_data = "N/A" + return + try: if self.is_module: self.write_eeprom(b"\x00\x00") diff --git a/platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/chassis.py index 9430f918f9..d1b2766b95 100644 --- a/platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/chassis.py @@ -83,11 +83,8 @@ class Chassis(ChassisBase): self._thermal_list.append(thermal) for port_num in range(self.PORT_START, (self.PORT_END + 1)): - presence = self.get_sfp(port_num).get_presence() - if presence: - self._global_port_pres_dict[port_num] = '1' - else: - self._global_port_pres_dict[port_num] = '0' + #presence = self.get_sfp(port_num).get_presence() + self._global_port_pres_dict[port_num] = '0' def __del__(self): if self.oir_fd != -1: diff --git a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/chassis.py index d59deb8b0a..c22466c6c1 100755 --- a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/chassis.py @@ -147,8 +147,7 @@ class Chassis(ChassisBase): self._component_list = [Component(i) for i in range(MAX_Z9332F_COMPONENT)] for port_num in range(self.PORT_START, self.PORTS_IN_BLOCK): # sfp get uses zero-indexing, but port numbers start from 1 - presence = self.get_sfp(port_num).get_presence() - self._global_port_pres_dict[port_num] = '1' if presence else '0' + self._global_port_pres_dict[port_num] = '0' self._watchdog = Watchdog() def __del__(self): diff --git a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py index 7e413e041a..6abe435ca6 100644 --- a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py @@ -153,7 +153,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None @staticmethod def _get_available_firmware_version(image_path): @@ -242,6 +242,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def get_presence(self): diff --git a/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/chassis.py index bb2446445f..e8a878d773 100644 --- a/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/chassis.py @@ -130,8 +130,7 @@ class Chassis(ChassisBase): self._thermal_list = [Thermal(i) for i in range(MAX_Z9432F_THERMAL)] self._component_list = [Component(i) for i in range(MAX_Z9432F_COMPONENT)] for port_num in range(PORT_START, PORTS_IN_BLOCK): - presence = self.get_sfp(port_num).get_presence() - self._global_port_pres_dict[port_num] = '1' if presence else '0' + self._global_port_pres_dict[port_num] = '0' self._watchdog = Watchdog() #self.LOCATOR_LED_ON = self.STATUS_LED_COLOR_BLUE_BLINK diff --git a/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/component.py index 763db39f5e..42d8d50d09 100644 --- a/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9432f/sonic_platform/component.py @@ -127,7 +127,7 @@ class Component(ComponentBase): self.index = component_index self.name = self.CHASSIS_COMPONENTS[self.index][0] self.description = self.CHASSIS_COMPONENTS[self.index][1] - self.version = self.CHASSIS_COMPONENTS[self.index][2]() + self.version = None @staticmethod def _get_available_firmware_version(image_path): @@ -208,6 +208,8 @@ class Component(ComponentBase): Returns: A string containing the firmware version of the component """ + if self.version == None: + self.version = self.CHASSIS_COMPONENTS[self.index][2]() return self.version def get_presence(self):