Skip to content

Commit

Permalink
[DellEMC] Fixing 'show interface status' break in DellEMC platforms (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
santhosh-kt authored Dec 20, 2022
1 parent 7181693 commit e83aa15
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ def __init__(self):

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, component_index = 0):
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):
"""
Expand All @@ -102,6 +102,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ def __init__(self):

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, component_index = 0):
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):
"""
Expand All @@ -101,6 +101,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def __init__(self):

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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, component_index = 0):
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):
"""
Expand All @@ -110,6 +110,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def __init__(self):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, component_index = 0):
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):
"""
Expand All @@ -110,6 +110,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def __init__(self):
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, component_index = 0):
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):
"""
Expand All @@ -135,6 +135,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -107,6 +109,9 @@ def __init__(self):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Chassis(ChassisBase):
'amber': 0x02, 'blinking amber': 0x08
}

_global_port_pres_dict = {}

def __init__(self):

ChassisBase.__init__(self)
Expand Down Expand Up @@ -103,6 +105,13 @@ def __init__(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -27,6 +28,10 @@ def __init__(self, i2c_line=0, iom_eeprom=False):
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ def __init__(self):
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def __init__(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, component_index=0):
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):
Expand Down Expand Up @@ -242,6 +242,8 @@ def get_firmware_version(self):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def __init__(self):
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, component_index=0):
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):
Expand Down Expand Up @@ -208,6 +208,8 @@ def get_firmware_version(self):
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):
Expand Down

0 comments on commit e83aa15

Please sign in to comment.