[Mellanox] Fix issue: failed to decode Json while there is no hwsku.json (#11436)
- Why I did it Fix bug: pmon report error on start up because some SKUs do not have hwsku.json - How I did it If hwsku.json, do not extract RJ45 port information - How to verify it Manual test. Unit test.
This commit is contained in:
parent
fae1ab6761
commit
2863945f7c
@ -111,7 +111,8 @@ class Chassis(ChassisBase):
|
|||||||
self.reboot_cause_initialized = False
|
self.reboot_cause_initialized = False
|
||||||
|
|
||||||
# Build the RJ45 port list from platform.json and hwsku.json
|
# Build the RJ45 port list from platform.json and hwsku.json
|
||||||
self.RJ45_port_list = extract_RJ45_ports_index()
|
self._RJ45_port_inited = False
|
||||||
|
self._RJ45_port_list = None
|
||||||
|
|
||||||
logger.log_info("Chassis loaded successfully")
|
logger.log_info("Chassis loaded successfully")
|
||||||
|
|
||||||
@ -124,6 +125,13 @@ class Chassis(ChassisBase):
|
|||||||
if SFP.shared_sdk_handle:
|
if SFP.shared_sdk_handle:
|
||||||
deinitialize_sdk_handle(SFP.shared_sdk_handle)
|
deinitialize_sdk_handle(SFP.shared_sdk_handle)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def RJ45_port_list(self):
|
||||||
|
if not self._RJ45_port_inited:
|
||||||
|
self._RJ45_port_list = extract_RJ45_ports_index()
|
||||||
|
self._RJ45_port_inited = True
|
||||||
|
return self._RJ45_port_list
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# PSU methods
|
# PSU methods
|
||||||
##############################################
|
##############################################
|
||||||
|
@ -177,12 +177,12 @@ def is_host():
|
|||||||
"""
|
"""
|
||||||
Test whether current process is running on the host or an docker
|
Test whether current process is running on the host or an docker
|
||||||
return True for host and False for docker
|
return True for host and False for docker
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen("docker --version 2>/dev/null",
|
proc = subprocess.Popen("docker --version 2>/dev/null",
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
shell=True,
|
shell=True,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
stdout = proc.communicate()[0]
|
stdout = proc.communicate()[0]
|
||||||
proc.wait()
|
proc.wait()
|
||||||
@ -239,9 +239,13 @@ def load_json_file(filename, log_func=logger.log_error):
|
|||||||
def extract_RJ45_ports_index():
|
def extract_RJ45_ports_index():
|
||||||
# Cross check 'platform.json' and 'hwsku.json' to extract the RJ45 port index if exists.
|
# Cross check 'platform.json' and 'hwsku.json' to extract the RJ45 port index if exists.
|
||||||
hwsku_path = device_info.get_path_to_hwsku_dir()
|
hwsku_path = device_info.get_path_to_hwsku_dir()
|
||||||
|
hwsku_file = os.path.join(hwsku_path, HWSKU_JSON)
|
||||||
|
if not os.path.exists(hwsku_file):
|
||||||
|
# Platforms having no hwsku.json do not have RJ45 port
|
||||||
|
return None
|
||||||
|
|
||||||
platform_file = device_info.get_path_to_port_config_file()
|
platform_file = device_info.get_path_to_port_config_file()
|
||||||
platform_dict = load_json_file(platform_file)['interfaces']
|
platform_dict = load_json_file(platform_file)['interfaces']
|
||||||
hwsku_file = os.path.join(hwsku_path, HWSKU_JSON)
|
|
||||||
hwsku_dict = load_json_file(hwsku_file)['interfaces']
|
hwsku_dict = load_json_file(hwsku_file)['interfaces']
|
||||||
port_name_to_index_map_dict = {}
|
port_name_to_index_map_dict = {}
|
||||||
RJ45_port_index_list = []
|
RJ45_port_index_list = []
|
||||||
|
@ -113,10 +113,15 @@ class TestUtils:
|
|||||||
@utils.default_return(100, log_func=mock_log)
|
@utils.default_return(100, log_func=mock_log)
|
||||||
def func():
|
def func():
|
||||||
raise RuntimeError('')
|
raise RuntimeError('')
|
||||||
|
|
||||||
assert func() == 100
|
assert func() == 100
|
||||||
assert mock_log.call_count == 1
|
assert mock_log.call_count == 1
|
||||||
|
|
||||||
def test_run_command(self):
|
def test_run_command(self):
|
||||||
output = utils.run_command('ls')
|
output = utils.run_command('ls')
|
||||||
assert output
|
assert output
|
||||||
|
|
||||||
|
@mock.patch('sonic_py_common.device_info.get_path_to_hwsku_dir', mock.MagicMock(return_value='/tmp'))
|
||||||
|
def test_extract_RJ45_ports_index(self):
|
||||||
|
rj45_list = utils.extract_RJ45_ports_index()
|
||||||
|
assert rj45_list is None
|
||||||
|
Reference in New Issue
Block a user