Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BFN] Fix exception when fwutil run without sudo #10335

Merged
merged 9 commits into from
Apr 5, 2022

Conversation

taras-keryk
Copy link
Contributor

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 is 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 is 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.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@lgtm-com
Copy link

lgtm-com bot commented Mar 23, 2022

This pull request introduces 1 alert when merging df354f9 into 8f418bb - view on LGTM.com

new alerts:

  • 1 for Unused import

@taras-keryk taras-keryk force-pushed the tk_fwutil_nosudo4_dmi_ee branch from 39b3966 to 7c03e4a Compare March 24, 2022 06:18
Taras Keryk added 8 commits March 25, 2022 03:58
            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>
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>
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
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>
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
@taras-keryk taras-keryk force-pushed the tk_fwutil_nosudo4_dmi_ee branch from 8749207 to 300d7ef Compare March 25, 2022 11:02
@taras-keryk taras-keryk marked this pull request as ready for review March 25, 2022 12:18
@taras-keryk taras-keryk requested a review from lguohan as a code owner March 25, 2022 12:18
akokhan
akokhan previously approved these changes Mar 25, 2022
@taras-keryk taras-keryk force-pushed the tk_fwutil_nosudo4_dmi_ee branch 3 times, most recently from 65d0965 to 33c68ac Compare March 30, 2022 07:39
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>
@taras-keryk taras-keryk force-pushed the tk_fwutil_nosudo4_dmi_ee branch from 33c68ac to a418aa0 Compare March 31, 2022 07:30
@taras-keryk
Copy link
Contributor Author

taras-keryk commented Apr 1, 2022

@prgeor please review

@taras-keryk
Copy link
Contributor Author

@prgeor, can you please review

@prgeor prgeor merged commit bfe5835 into sonic-net:master Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants