2020-10-03 15:46:21 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
try:
|
[BFN] Fix exception when fwutil run without sudo (#10335)
* [BFN] Fix for run fwutil without sudo
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
```
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
```
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk tarasx.keryk@intel.com
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* rewrite a call of dmidecode, when run without sudo
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
The previous implementaion of eeprom.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/logging/config.py", line 564, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib/python3.9/logging/config.py", line 745, in configure_handler
result = factory(**kwargs)
File "/usr/lib/python3.9/logging/handlers.py", line 153, in init
BaseRotatingHandler.init(self, filename, mode, encoding=encoding,
File "/usr/lib/python3.9/logging/handlers.py", line 58, in init
logging.FileHandler.init(self, filename, mode=mode,
File "/usr/lib/python3.9/logging/init.py", line 1142, in init
StreamHandler.init(self, self._open())
File "/usr/lib/python3.9/logging/init.py", line 1171, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding,
PermissionError: [Errno 13] Permission denied: '/var/log/platform.log'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/init.py", line 3, in
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 41, in
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 162, in init
self.chassis_component_map = self.__get_chassis_component_map()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 168, in __get_chassis_component_map
chassis_name = self.__chassis.get_name()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 146, in get_name
return self._eeprom.modelstr()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 54, in _eeprom
self.__eeprom = Eeprom()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/eeprom.py", line 50, in init
logging.config.dictConfig(config_dict)
File "/usr/lib/python3.9/logging/config.py", line 809, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.9/logging/config.py", line 571, in configure
raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'file'
How I did it
Modification call of dmidecode command.
Added modification of log files access attributes before file open operations.
How to verify it
Run manually 'fwutil' (without sudo)
New command output have no exception.
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added file_check for checking access to log files for eeprom.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Removed unused import
* Added logfile_create to eeprom.py and chassis.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Created platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added interpreter string to platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
2022-04-05 13:33:51 -05:00
|
|
|
import os
|
2022-01-16 23:46:20 -06:00
|
|
|
import time
|
|
|
|
import syslog
|
[BFN] Fix exception when fwutil run without sudo (#10335)
* [BFN] Fix for run fwutil without sudo
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
```
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
```
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk tarasx.keryk@intel.com
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* rewrite a call of dmidecode, when run without sudo
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
The previous implementaion of eeprom.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/logging/config.py", line 564, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib/python3.9/logging/config.py", line 745, in configure_handler
result = factory(**kwargs)
File "/usr/lib/python3.9/logging/handlers.py", line 153, in init
BaseRotatingHandler.init(self, filename, mode, encoding=encoding,
File "/usr/lib/python3.9/logging/handlers.py", line 58, in init
logging.FileHandler.init(self, filename, mode=mode,
File "/usr/lib/python3.9/logging/init.py", line 1142, in init
StreamHandler.init(self, self._open())
File "/usr/lib/python3.9/logging/init.py", line 1171, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding,
PermissionError: [Errno 13] Permission denied: '/var/log/platform.log'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/init.py", line 3, in
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 41, in
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 162, in init
self.chassis_component_map = self.__get_chassis_component_map()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 168, in __get_chassis_component_map
chassis_name = self.__chassis.get_name()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 146, in get_name
return self._eeprom.modelstr()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 54, in _eeprom
self.__eeprom = Eeprom()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/eeprom.py", line 50, in init
logging.config.dictConfig(config_dict)
File "/usr/lib/python3.9/logging/config.py", line 809, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.9/logging/config.py", line 571, in configure
raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'file'
How I did it
Modification call of dmidecode command.
Added modification of log files access attributes before file open operations.
How to verify it
Run manually 'fwutil' (without sudo)
New command output have no exception.
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added file_check for checking access to log files for eeprom.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Removed unused import
* Added logfile_create to eeprom.py and chassis.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Created platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added interpreter string to platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
2022-04-05 13:33:51 -05:00
|
|
|
import logging
|
|
|
|
import logging.config
|
|
|
|
import yaml
|
2022-01-16 23:46:20 -06:00
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
from sonic_platform_base.chassis_base import ChassisBase
|
2022-01-16 23:46:20 -06:00
|
|
|
from sonic_platform.sfp import Sfp
|
2021-06-04 11:48:57 -05:00
|
|
|
from sonic_platform.psu import psu_list_get
|
2021-03-12 12:52:48 -06:00
|
|
|
from sonic_platform.fan_drawer import fan_drawer_list_get
|
2022-10-10 20:12:28 -05:00
|
|
|
from sonic_platform.thermal import chassis_thermals_list_get
|
2022-09-29 17:13:46 -05:00
|
|
|
from sonic_platform.platform_utils import file_create
|
|
|
|
from sonic_platform.eeprom import Eeprom
|
2022-12-08 07:56:40 -06:00
|
|
|
from sonic_platform.watchdog import Watchdog
|
2022-01-16 23:46:20 -06:00
|
|
|
|
|
|
|
from sonic_platform.platform_thrift_client import pltfm_mgr_ready
|
|
|
|
from sonic_platform.platform_thrift_client import thrift_try
|
|
|
|
|
|
|
|
from sonic_py_common import device_info
|
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
[BFN] Implementation API for platform component (#10180)
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
get chassis name from json
* [BFN] Implementation API for platform component
Updated platform and platrom_components json
* [BFN] Implementation API for platform component
Fixed spaces in component.py
* [BFN] Implementation API for platform component
Fixed exception in component.py
* Update chassis.py
* [BFN] Implementation API for platform component
Fixed spaces in component.py, chassis.py
* [BFN] Implementation API for platform component: Fixed spaces in component.py, chassis.py
* Fixed exception in get_bios_version
2022-03-10 04:55:06 -06:00
|
|
|
NUM_COMPONENT = 2
|
2020-10-03 15:46:21 -05:00
|
|
|
class Chassis(ChassisBase):
|
|
|
|
"""
|
|
|
|
Platform-specific Chassis class
|
|
|
|
"""
|
2022-01-16 23:46:20 -06:00
|
|
|
|
|
|
|
PORT_START = 1
|
|
|
|
PORT_END = 0
|
|
|
|
PORTS_IN_BLOCK = 0
|
|
|
|
QSFP_PORT_START = 1
|
|
|
|
QSFP_PORT_END = 0
|
|
|
|
QSFP_CHECK_INTERVAL = 4
|
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
def __init__(self):
|
|
|
|
ChassisBase.__init__(self)
|
|
|
|
|
2022-10-10 20:12:28 -05:00
|
|
|
self.__eeprom = None
|
|
|
|
self.__tlv_bin_eeprom = None
|
|
|
|
self.__tlv_dict_eeprom = None
|
2022-09-29 17:13:46 -05:00
|
|
|
|
2021-03-26 12:18:54 -05:00
|
|
|
self.__fan_drawers = None
|
2022-01-16 23:46:20 -06:00
|
|
|
self.__fan_list = None
|
2021-03-26 12:18:54 -05:00
|
|
|
self.__thermals = None
|
2021-06-04 11:48:57 -05:00
|
|
|
self.__psu_list = None
|
|
|
|
self.__sfp_list = None
|
2022-12-08 07:56:40 -06:00
|
|
|
self.__watchdog = None
|
2022-01-16 23:46:20 -06:00
|
|
|
|
|
|
|
self.ready = False
|
|
|
|
self.phy_port_cur_state = {}
|
|
|
|
self.qsfp_interval = self.QSFP_CHECK_INTERVAL
|
[BFN] Implementation API for platform component (#10180)
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
get chassis name from json
* [BFN] Implementation API for platform component
Updated platform and platrom_components json
* [BFN] Implementation API for platform component
Fixed spaces in component.py
* [BFN] Implementation API for platform component
Fixed exception in component.py
* Update chassis.py
* [BFN] Implementation API for platform component
Fixed spaces in component.py, chassis.py
* [BFN] Implementation API for platform component: Fixed spaces in component.py, chassis.py
* Fixed exception in get_bios_version
2022-03-10 04:55:06 -06:00
|
|
|
self.__initialize_components()
|
2021-06-04 11:48:57 -05:00
|
|
|
|
[BFN] Fix exception when fwutil run without sudo (#10335)
* [BFN] Fix for run fwutil without sudo
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
```
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
```
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
How I did it
Modification of dmidecode command
How to verify it
Run manually 'fwutil' (without sudo)
Previous command output had exception
New command output:
Root privileges are required
Signed-off-by: Taras Keryk tarasx.keryk@intel.com
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* rewrite a call of dmidecode, when run without sudo
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Why I did it
The previous implementaion of component.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in <module>
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/__init__.py", line 3, in <module>
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 40, in <module>
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 159, in __init__
self.__platform = Platform()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/platform.py", line 21, in __init__
self._chassis = Chassis()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 48, in __init__
self.__initialize_components()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 136, in __initialize_components
component = Components(index)
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 184, in __init__
self.version = get_bios_version()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/component.py", line 19, in get_bios_version
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dmidecode'
The previous implementaion of eeprom.py expect fwutil run with sudo.
When fwutil run without sudo, there are an exception:
Traceback (most recent call last):
File "/usr/lib/python3.9/logging/config.py", line 564, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib/python3.9/logging/config.py", line 745, in configure_handler
result = factory(**kwargs)
File "/usr/lib/python3.9/logging/handlers.py", line 153, in init
BaseRotatingHandler.init(self, filename, mode, encoding=encoding,
File "/usr/lib/python3.9/logging/handlers.py", line 58, in init
logging.FileHandler.init(self, filename, mode=mode,
File "/usr/lib/python3.9/logging/init.py", line 1142, in init
StreamHandler.init(self, self._open())
File "/usr/lib/python3.9/logging/init.py", line 1171, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding,
PermissionError: [Errno 13] Permission denied: '/var/log/platform.log'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/fwutil", line 5, in
from fwutil.main import cli
File "/usr/local/lib/python3.9/dist-packages/fwutil/init.py", line 3, in
from . import main
File "/usr/local/lib/python3.9/dist-packages/fwutil/main.py", line 41, in
pdp = PlatformDataProvider()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 162, in init
self.chassis_component_map = self.__get_chassis_component_map()
File "/usr/local/lib/python3.9/dist-packages/fwutil/lib.py", line 168, in __get_chassis_component_map
chassis_name = self.__chassis.get_name()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 146, in get_name
return self._eeprom.modelstr()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/chassis.py", line 54, in _eeprom
self.__eeprom = Eeprom()
File "/usr/local/lib/python3.9/dist-packages/sonic_platform/eeprom.py", line 50, in init
logging.config.dictConfig(config_dict)
File "/usr/lib/python3.9/logging/config.py", line 809, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.9/logging/config.py", line 571, in configure
raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'file'
How I did it
Modification call of dmidecode command.
Added modification of log files access attributes before file open operations.
How to verify it
Run manually 'fwutil' (without sudo)
New command output have no exception.
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added file_check for checking access to log files for eeprom.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Removed unused import
* Added logfile_create to eeprom.py and chassis.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Created platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* Added interpreter string to platform_utils.py
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
2022-04-05 13:33:51 -05:00
|
|
|
with open(os.path.dirname(__file__) + "/logging.conf", 'r') as f:
|
|
|
|
config_dict = yaml.load(f, yaml.SafeLoader)
|
|
|
|
file_create(config_dict['handlers']['file']['filename'], '646')
|
|
|
|
logging.config.dictConfig(config_dict)
|
|
|
|
|
2022-10-10 20:12:28 -05:00
|
|
|
@property
|
|
|
|
def _eeprom(self):
|
|
|
|
if self.__eeprom is None:
|
|
|
|
self.__eeprom = Eeprom()
|
|
|
|
return self.__eeprom
|
|
|
|
|
|
|
|
@_eeprom.setter
|
|
|
|
def _eeprom(self, value):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _tlv_bin_eeprom(self):
|
|
|
|
if self.__tlv_bin_eeprom is None:
|
|
|
|
self.__tlv_bin_eeprom = self._eeprom.get_raw_data()
|
|
|
|
return self.__tlv_bin_eeprom
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _tlv_dict_eeprom(self):
|
|
|
|
if self.__tlv_dict_eeprom is None:
|
|
|
|
self.__tlv_dict_eeprom = self._eeprom.get_data()
|
|
|
|
return self.__tlv_dict_eeprom
|
|
|
|
|
2022-12-08 07:56:40 -06:00
|
|
|
@property
|
|
|
|
def _watchdog(self):
|
|
|
|
if self.__watchdog is None:
|
|
|
|
self.__watchdog = Watchdog()
|
|
|
|
return self.__watchdog
|
|
|
|
|
|
|
|
@_watchdog.setter
|
|
|
|
def _watchdog(self, value):
|
|
|
|
pass
|
|
|
|
|
2021-03-26 12:18:54 -05:00
|
|
|
@property
|
|
|
|
def _fan_drawer_list(self):
|
|
|
|
if self.__fan_drawers is None:
|
|
|
|
self.__fan_drawers = fan_drawer_list_get()
|
|
|
|
return self.__fan_drawers
|
|
|
|
|
|
|
|
@_fan_drawer_list.setter
|
|
|
|
def _fan_drawer_list(self, value):
|
|
|
|
pass
|
|
|
|
|
2022-01-16 23:46:20 -06:00
|
|
|
@property
|
|
|
|
def _fan_list(self):
|
|
|
|
if self.__fan_list is None:
|
|
|
|
self.__fan_list = []
|
|
|
|
for fan_drawer in self._fan_drawer_list:
|
|
|
|
self.__fan_list.extend(fan_drawer._fan_list)
|
|
|
|
return self.__fan_list
|
|
|
|
|
|
|
|
@_fan_list.setter
|
|
|
|
def _fan_list(self, value):
|
|
|
|
pass
|
|
|
|
|
2021-03-26 12:18:54 -05:00
|
|
|
@property
|
|
|
|
def _thermal_list(self):
|
|
|
|
if self.__thermals is None:
|
2022-10-10 20:12:28 -05:00
|
|
|
self.__thermals = chassis_thermals_list_get()
|
2021-03-26 12:18:54 -05:00
|
|
|
return self.__thermals
|
|
|
|
|
|
|
|
@_thermal_list.setter
|
|
|
|
def _thermal_list(self, value):
|
|
|
|
pass
|
2021-03-12 12:52:48 -06:00
|
|
|
|
2021-06-04 11:48:57 -05:00
|
|
|
@property
|
|
|
|
def _psu_list(self):
|
|
|
|
if self.__psu_list is None:
|
|
|
|
self.__psu_list = psu_list_get()
|
|
|
|
return self.__psu_list
|
|
|
|
|
|
|
|
@_psu_list.setter
|
|
|
|
def _psu_list(self, value):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _sfp_list(self):
|
|
|
|
if self.__sfp_list is None:
|
2022-01-16 23:46:20 -06:00
|
|
|
self.__update_port_info()
|
|
|
|
self.__sfp_list = []
|
|
|
|
for index in range(self.PORT_START, self.PORT_END + 1):
|
|
|
|
sfp_node = Sfp(index)
|
|
|
|
self.__sfp_list.append(sfp_node)
|
2021-06-04 11:48:57 -05:00
|
|
|
return self.__sfp_list
|
|
|
|
|
|
|
|
@_sfp_list.setter
|
|
|
|
def _sfp_list(self, value):
|
|
|
|
pass
|
|
|
|
|
2022-01-16 23:46:20 -06:00
|
|
|
def __update_port_info(self):
|
|
|
|
def qsfp_max_port_get(client):
|
|
|
|
return client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port()
|
|
|
|
|
|
|
|
if self.QSFP_PORT_END == 0:
|
|
|
|
platform = device_info.get_platform()
|
|
|
|
self.QSFP_PORT_END = thrift_try(qsfp_max_port_get)
|
|
|
|
exclude_cpu_port = [
|
|
|
|
"x86_64-accton_as9516_32d-r0",
|
|
|
|
"x86_64-accton_as9516bf_32d-r0",
|
|
|
|
"x86_64-accton_wedge100bf_32x-r0"
|
|
|
|
]
|
|
|
|
if platform in exclude_cpu_port:
|
|
|
|
self.QSFP_PORT_END -= 1
|
|
|
|
self.PORT_END = self.QSFP_PORT_END
|
|
|
|
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
|
|
|
|
|
[BFN] Implementation API for platform component (#10180)
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
SONiC has a concept of "platform components"
this may include - CPLD, FPGA, BIOS, BMC, etc.
These changes are needed to read the version of the BIOS and BMC component.
What I did
Create components.py module
Add funcion for reading componet version to thrift interface
How I did it
The previous implementaion didn't have platform components API, so fwutil return an empty list.
After implementation of the platform component API, we have actual list of platform components and firmware versions
How to verify it
Run manually 'fwutil show status' or run unit tests
Previous command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
New command output
Chassis Module Component Version Description
------------------------ -------- ----------- --------- -------------
Chassis1 N/A BIOS 1.2.3 Chassis BIOS
BMC 5.1 Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
* [BFN] Implementation API for platform component
get chassis name from json
* [BFN] Implementation API for platform component
Updated platform and platrom_components json
* [BFN] Implementation API for platform component
Fixed spaces in component.py
* [BFN] Implementation API for platform component
Fixed exception in component.py
* Update chassis.py
* [BFN] Implementation API for platform component
Fixed spaces in component.py, chassis.py
* [BFN] Implementation API for platform component: Fixed spaces in component.py, chassis.py
* Fixed exception in get_bios_version
2022-03-10 04:55:06 -06:00
|
|
|
def __initialize_components(self):
|
|
|
|
from sonic_platform.component import Components
|
|
|
|
for index in range(0, NUM_COMPONENT):
|
|
|
|
component = Components(index)
|
|
|
|
self._component_list.append(component)
|
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
def get_name(self):
|
|
|
|
"""
|
|
|
|
Retrieves the name of the chassis
|
|
|
|
Returns:
|
|
|
|
string: The name of the chassis
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._eeprom.modelstr(self._tlv_bin_eeprom)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
|
|
|
def get_presence(self):
|
|
|
|
"""
|
|
|
|
Retrieves the presence of the chassis
|
|
|
|
Returns:
|
|
|
|
bool: True if chassis is present, False if not
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_model(self):
|
|
|
|
"""
|
|
|
|
Retrieves the model number (or part number) of the chassis
|
|
|
|
Returns:
|
|
|
|
string: Model/part number of chassis
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._eeprom.part_number_str(self._tlv_bin_eeprom)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
|
|
|
def get_serial(self):
|
|
|
|
"""
|
|
|
|
Retrieves the serial number of the chassis (Service tag)
|
|
|
|
Returns:
|
|
|
|
string: Serial number of chassis
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._eeprom.serial_number_str(self._tlv_bin_eeprom)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-01-16 23:46:20 -06:00
|
|
|
def get_revision(self):
|
|
|
|
"""
|
|
|
|
Retrieves the revision number of the chassis (Service tag)
|
|
|
|
Returns:
|
|
|
|
string: Revision number of chassis
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._tlv_dict_eeprom.get(
|
2022-09-29 17:13:46 -05:00
|
|
|
"0x{:X}".format(Eeprom._TLV_CODE_LABEL_REVISION), 'N/A')
|
2022-01-16 23:46:20 -06:00
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
def get_sfp(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves sfp represented by (1-based) index <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
|
|
|
The index should be the sequence of a physical port in a chassis,
|
|
|
|
starting from 1.
|
|
|
|
For example, 0 for Ethernet0, 1 for Ethernet4 and so on.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object dervied from SfpBase representing the specified sfp
|
|
|
|
"""
|
|
|
|
sfp = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
sfp = self._sfp_list[index-1]
|
|
|
|
except IndexError:
|
2022-01-16 23:46:20 -06:00
|
|
|
syslog.syslog(syslog.LOG_ERR, "SFP index {} out of range (1-{})\n".format(
|
2020-10-03 15:46:21 -05:00
|
|
|
index, len(self._sfp_list)-1))
|
|
|
|
return sfp
|
|
|
|
|
|
|
|
def get_status(self):
|
|
|
|
"""
|
|
|
|
Retrieves the operational status of the chassis
|
|
|
|
Returns:
|
|
|
|
bool: A boolean value, True if chassis is operating properly
|
|
|
|
False if not
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_base_mac(self):
|
|
|
|
"""
|
|
|
|
Retrieves the base MAC address for the chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string containing the MAC address in the format
|
|
|
|
'XX:XX:XX:XX:XX:XX'
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._eeprom.base_mac_addr(self._tlv_bin_eeprom)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
|
|
|
def get_system_eeprom_info(self):
|
|
|
|
"""
|
|
|
|
Retrieves the full content of system EEPROM information for the chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A dictionary where keys are the type code defined in
|
|
|
|
OCP ONIE TlvInfo EEPROM format and values are their corresponding
|
|
|
|
values.
|
|
|
|
"""
|
2022-10-10 20:12:28 -05:00
|
|
|
return self._tlv_dict_eeprom
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-01-16 23:46:20 -06:00
|
|
|
def __get_transceiver_change_event(self, timeout=0):
|
|
|
|
forever = False
|
|
|
|
if timeout == 0:
|
|
|
|
forever = True
|
|
|
|
elif timeout > 0:
|
|
|
|
timeout = timeout / float(1000) # Convert to secs
|
|
|
|
else:
|
|
|
|
syslog.syslog(syslog.LOG_ERR, "Invalid timeout value {}".format(timeout))
|
|
|
|
return False, {}
|
|
|
|
|
|
|
|
phy_port_dict = {} if self.ready else {'-1': 'system_not_ready'}
|
|
|
|
|
|
|
|
while forever or timeout > 0:
|
|
|
|
if not self.ready:
|
|
|
|
if pltfm_mgr_ready():
|
|
|
|
self.ready = True
|
|
|
|
phy_port_dict = {}
|
|
|
|
|
|
|
|
if self.ready and self.qsfp_interval == 0:
|
|
|
|
self.qsfp_interval = self.QSFP_CHECK_INTERVAL
|
|
|
|
|
|
|
|
# Get presence of each SFP
|
|
|
|
for port in range(self.PORT_START, self.PORT_END + 1):
|
|
|
|
try:
|
|
|
|
sfp_resent = self.get_sfp(port).get_presence()
|
|
|
|
except Exception:
|
|
|
|
sfp_resent = False
|
|
|
|
sfp_state = '1' if sfp_resent else '0'
|
|
|
|
|
|
|
|
if port in self.phy_port_cur_state:
|
|
|
|
if self.phy_port_cur_state[port] != sfp_state:
|
|
|
|
phy_port_dict[port] = sfp_state
|
|
|
|
else:
|
|
|
|
phy_port_dict[port] = sfp_state
|
|
|
|
|
|
|
|
# Update port current state
|
|
|
|
self.phy_port_cur_state[port] = sfp_state
|
|
|
|
|
|
|
|
# Break if tranceiver state has changed
|
|
|
|
if phy_port_dict:
|
|
|
|
break
|
|
|
|
|
|
|
|
if timeout:
|
|
|
|
timeout -= 1
|
|
|
|
|
|
|
|
if self.qsfp_interval:
|
|
|
|
self.qsfp_interval -= 1
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
return self.ready, phy_port_dict
|
|
|
|
|
2020-10-03 15:46:21 -05:00
|
|
|
def get_change_event(self, timeout=0):
|
2022-01-16 23:46:20 -06:00
|
|
|
ready, event_sfp = self.__get_transceiver_change_event(timeout)
|
2020-10-03 15:46:21 -05:00
|
|
|
return ready, { 'sfp': event_sfp } if ready else {}
|
2021-06-11 15:30:03 -05:00
|
|
|
|
|
|
|
def get_reboot_cause(self):
|
|
|
|
"""
|
|
|
|
Retrieves the cause of the previous reboot
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A tuple (string, string) where the first element is a string
|
|
|
|
containing the cause of the previous reboot. This string must be
|
|
|
|
one of the predefined strings in this class. If the first string
|
|
|
|
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
|
|
|
|
to pass a description of the reboot cause.
|
|
|
|
"""
|
|
|
|
return self.REBOOT_CAUSE_NON_HARDWARE, ''
|
2022-01-16 23:46:20 -06:00
|
|
|
|
|
|
|
def get_position_in_parent(self):
|
|
|
|
"""
|
|
|
|
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
|
|
|
|
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
|
|
|
|
Returns:
|
|
|
|
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
|
|
|
|
"""
|
|
|
|
return -1
|
|
|
|
|
|
|
|
def is_replaceable(self):
|
|
|
|
"""
|
|
|
|
Indicate whether this device is replaceable.
|
|
|
|
Returns:
|
|
|
|
bool: True if it is replaceable.
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def initizalize_system_led(self):
|
|
|
|
self.system_led = ""
|
|
|
|
return True
|
|
|
|
|
|
|
|
def set_status_led(self, color):
|
|
|
|
"""
|
|
|
|
Sets the state of the system LED
|
|
|
|
|
|
|
|
Args:
|
|
|
|
color: A string representing the color with which to set the
|
|
|
|
system LED
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if system LED state is set successfully, False if not
|
|
|
|
"""
|
|
|
|
self.system_led = color
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_status_led(self):
|
|
|
|
"""
|
|
|
|
Gets the state of the system LED
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string, one of the valid LED color strings which could be vendor
|
|
|
|
specified.
|
|
|
|
"""
|
|
|
|
return self.system_led
|