2020-10-03 15:46:21 -05:00
|
|
|
try:
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import datetime
|
2022-09-29 17:13:46 -05:00
|
|
|
import logging
|
|
|
|
import logging.config
|
2020-10-03 15:46:21 -05:00
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
if sys.version_info.major == 3:
|
|
|
|
from io import StringIO
|
|
|
|
else:
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
2021-02-11 17:00:35 -06:00
|
|
|
from sonic_platform_base.sonic_eeprom import eeprom_base
|
|
|
|
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
from sonic_py_common import device_info
|
|
|
|
|
|
|
|
from sonic_platform.platform_thrift_client import thrift_try
|
|
|
|
from sonic_platform.platform_utils import file_create
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
except ImportError as e:
|
2020-10-03 15:46:21 -05:00
|
|
|
raise ImportError (str(e) + "- required module not found")
|
|
|
|
|
2021-02-11 17:00:35 -06:00
|
|
|
_platform_eeprom_map = {
|
2022-01-16 23:46:20 -06:00
|
|
|
"prod_name" : ("Product Name", "0x21", 12),
|
|
|
|
"odm_pcba_part_num" : ("Part Number", "0x22", 13),
|
|
|
|
"prod_ser_num" : ("Serial Number", "0x23", 12),
|
|
|
|
"ext_mac_addr" : ("Extended MAC Address Base", "0x24", 12),
|
|
|
|
"sys_mfg_date" : ("System Manufacturing Date", "0x25", 4),
|
|
|
|
"prod_ver" : ("Product Version", "0x26", 1),
|
|
|
|
"ext_mac_addr_size" : ("Extende MAC Address Size", "0x2A", 2),
|
|
|
|
"sys_mfger" : ("Manufacturer", "0x2B", 8)
|
2020-10-03 15:46:21 -05:00
|
|
|
}
|
|
|
|
|
2022-01-16 23:46:20 -06:00
|
|
|
_product_dict = {
|
|
|
|
"Montara" : "Wedge100BF-32X-O-AC-F-BF",
|
|
|
|
"Lower MAV" : "Wedge100BF-65X-O-AC-F-BF",
|
|
|
|
"Upper MAV" : "Wedge100BF-65X-O-AC-F-BF"
|
|
|
|
}
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2021-02-11 17:00:35 -06:00
|
|
|
_EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom"
|
|
|
|
_EEPROM_STATUS = "/var/run/platform/eeprom/status"
|
2020-10-03 15:46:21 -05:00
|
|
|
|
|
|
|
class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|
|
|
def __init__(self):
|
[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
|
|
|
file_create(_EEPROM_SYMLINK, '646')
|
|
|
|
file_create(_EEPROM_STATUS, '646')
|
2022-09-29 17:13:46 -05:00
|
|
|
super(Eeprom, self).__init__(_EEPROM_SYMLINK, 0, _EEPROM_STATUS, True)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
self._eeprom_bin = bytearray()
|
|
|
|
self.report_status("initializing..")
|
2020-10-03 15:46:21 -05:00
|
|
|
try:
|
2022-09-29 17:13:46 -05:00
|
|
|
try:
|
|
|
|
if device_info.get_platform() in ["x86_64-accton_as9516_32d-r0",
|
|
|
|
"x86_64-accton_as9516bf_32d-r0"]:
|
|
|
|
def tlv_eeprom_get(client):
|
|
|
|
return client.pltfm_mgr.pltfm_mgr_tlv_eeprom_get()
|
|
|
|
try:
|
|
|
|
self._eeprom_bin = bytearray.fromhex(
|
|
|
|
thrift_try(tlv_eeprom_get, 1).raw_content_hex)
|
|
|
|
except TApplicationException as e:
|
|
|
|
raise RuntimeError("api is not supported")
|
|
|
|
except Exception as e:
|
|
|
|
self._eeprom_bin = bytearray.fromhex(
|
|
|
|
thrift_try(tlv_eeprom_get).raw_content_hex)
|
|
|
|
else:
|
|
|
|
raise RuntimeError("platform is not supported")
|
|
|
|
|
|
|
|
except RuntimeError as e:
|
|
|
|
logging.warning("Tlv eeprom fetching failed: %s, using OpenBMC" % (str(e)))
|
|
|
|
|
|
|
|
def sys_eeprom_get(client):
|
|
|
|
return client.pltfm_mgr.pltfm_mgr_sys_eeprom_get()
|
|
|
|
|
|
|
|
eeprom_params = self.platfrom_eeprom_to_params(thrift_try(sys_eeprom_get))
|
|
|
|
stdout_stream = sys.stdout
|
|
|
|
sys.stdout = open(os.devnull, 'w')
|
|
|
|
self._eeprom_bin = self.set_eeprom(self._eeprom_bin, [eeprom_params])
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout = stdout_stream
|
|
|
|
try:
|
|
|
|
self.write_eeprom(self._eeprom_bin)
|
|
|
|
self.report_status("ok")
|
|
|
|
except IOError as e:
|
|
|
|
logging.error("Failed to write eeprom: %s" % (str(e)))
|
2020-10-05 12:50:03 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
except Exception as e:
|
|
|
|
logging.error("eeprom.py: Initialization failed: %s" % (str(e)))
|
|
|
|
raise RuntimeError("eeprom.py: Initialization failed: %s" % (str(e)))
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
self._system_eeprom_info = dict()
|
|
|
|
visitor = EepromContentVisitor(self._system_eeprom_info)
|
|
|
|
self.visit_eeprom(self._eeprom_bin, visitor)
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
@staticmethod
|
|
|
|
def platfrom_eeprom_to_params(platform_eeprom):
|
2020-10-03 15:46:21 -05:00
|
|
|
eeprom_params = ""
|
2021-02-11 17:00:35 -06:00
|
|
|
for attr, val in platform_eeprom.__dict__.items():
|
2020-10-03 15:46:21 -05:00
|
|
|
if val is None:
|
|
|
|
continue
|
|
|
|
|
2021-02-11 17:00:35 -06:00
|
|
|
elem = _platform_eeprom_map.get(attr)
|
2020-10-03 15:46:21 -05:00
|
|
|
if elem is None:
|
|
|
|
continue
|
|
|
|
|
2021-03-11 21:00:19 -06:00
|
|
|
if isinstance(val, str):
|
2020-10-03 15:46:21 -05:00
|
|
|
value = val.replace('\0', '')
|
|
|
|
else:
|
|
|
|
value = str(val)
|
|
|
|
|
|
|
|
if attr == "sys_mfg_date":
|
|
|
|
value = datetime.datetime.strptime(value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00')
|
|
|
|
|
2021-02-11 17:00:35 -06:00
|
|
|
product = _product_dict.get(value)
|
2020-10-03 15:46:21 -05:00
|
|
|
if product is not None:
|
|
|
|
value = product
|
|
|
|
if len(eeprom_params) > 0:
|
|
|
|
eeprom_params += ","
|
|
|
|
eeprom_params += "{0:s}={1:s}".format(elem[1], value)
|
2022-09-29 17:13:46 -05:00
|
|
|
return eeprom_params
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
def get_data(self):
|
|
|
|
return self._system_eeprom_info
|
2020-10-03 15:46:21 -05:00
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
def get_raw_data(self):
|
|
|
|
return self._eeprom_bin
|
[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
|
|
|
|
2022-09-29 17:13:46 -05:00
|
|
|
def report_status(self, status):
|
|
|
|
status_file = None
|
|
|
|
try:
|
|
|
|
status_file = open(_EEPROM_STATUS, "w")
|
|
|
|
status_file.write(status)
|
|
|
|
except IOError as e:
|
|
|
|
logging.error("Failed to report state: %s" % (str(e)))
|
|
|
|
finally:
|
|
|
|
if status_file is not None:
|
|
|
|
status_file.close()
|
|
|
|
|
|
|
|
class EepromContentVisitor(eeprom_tlvinfo.EepromDefaultVisitor):
|
|
|
|
def __init__(self, content_dict):
|
|
|
|
self.content_dict = content_dict
|
|
|
|
|
|
|
|
def visit_tlv(self, name, code, length, value):
|
|
|
|
if code != Eeprom._TLV_CODE_VENDOR_EXT:
|
|
|
|
self.content_dict["0x{:X}".format(code)] = value.rstrip('\0')
|
|
|
|
else:
|
|
|
|
if value:
|
|
|
|
value = value.rstrip('\0')
|
|
|
|
if value:
|
|
|
|
code = "0x{:X}".format(code)
|
|
|
|
if code not in self.content_dict:
|
|
|
|
self.content_dict[code] = [value]
|
|
|
|
else:
|
|
|
|
self.content_dict[code].append(value)
|
|
|
|
|
|
|
|
def set_error(self, error):
|
|
|
|
logging.error("EepromContentVisitor error: %s" % (str(error)))
|