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

eliminate dmidecode in component.py because it requires root privileges #17509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justindthomas
Copy link
Contributor

Why I did it

As described in #16878, every show command on the N3248TE-ON results in an error about dmidecode not being found. This is because that command is called in the get_bios_version function of component.py, which is used in a lot of places (many which should not require privileged access).

The error message prior to this change:

jdt@sonic:~$ show system-health
failed to import plugin show.plugins.cisco-8000: [Errno 2] No such file or directory: 'dmidecode'
Usage: show system-health [OPTIONS] COMMAND [ARGS]...

  Show system-health information

Work item tracking
  • Microsoft ADO (number only):

How I did it

On this platform, at least, the BIOS version can be obtained from /sys/class/dmi/id/bios_versionwithout requiring root privileges. I adjusted component.py to use that instead of dmidecode.

How to verify it

With that change in place, you can see that commands no longer complain about dmidecode:

jdt@sonic:~$ show system-health
Usage: show system-health [OPTIONS] COMMAND [ARGS]...

  Show system-health information

Options:
  -?, -h, --help  Show this message and exit.

Commands:
  detail           Show system-health detail information
  monitor-list     Show system-health monitored services and devices name...
  summary          Show system-health summary information
  sysready-status  Show system-health system ready status
  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

master

Description for the changelog

Removed call to dmidecode for every component command on the N3248TE-ON platform.

@justindthomas
Copy link
Contributor Author

@jeff-yin flagging this one too for review by someone at Dell.

@jeff-yin
Copy link
Collaborator

@justindthomas please assign @arunlk-dell and @vpsubramaniam as reviewers too, thanks!

@@ -16,7 +16,7 @@
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
def get_bios_version():
return subprocess.check_output(['dmidecode', '-s', 'system-version']).strip().decode()
return subprocess.check_output(['cat', '/sys/class/dmi/id/bios_version']).strip().decode()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vpsubramaniam can you check this change and see whether it is Kosher to get the bios version this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, here's what those commands look like on my N3248TE-ON.

Last login: Thu Dec 14 23:39:12 2023 from 10.20.37.104
jdt@sonic:~$ sudo dmidecode -s system-version
3.45.0.9-4
jdt@sonic:~$ cat /sys/class/dmi/id/bios_version
3.45.0.9-4
jdt@sonic:~$ show ver

SONiC Software Version: SONiC.jdt.0-865e34c64
SONiC OS Version: 12
Distribution: Debian 12.4
Kernel: 6.1.0-11-2-amd64
Build commit: 865e34c64
Build date: Mon Dec 11 10:57:26 UTC 2023
Built by: justin@sonic-build

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vpsubramaniam can you check this change and see whether it is Kosher to get the bios version this way?

Yes Jeff, for getting the BIOS version we can use this file as well.

@justindthomas
Copy link
Contributor Author

Is there a meeting I need to attend or something to get things like this merged? This seems like a pretty trivial change, but has a significantly positive usability impact (i.e., operations that shouldn't require privileges no longer error out).

I have 4 PRs that have been sitting for months with some reviews, but apparently not enough. How do I move these forward?

@jeff-yin

@jeff-yin
Copy link
Collaborator

@zhangyanzhao @lguohan -- these changes have been approved by Dell staff. Can someone merge?

@zhangyanzhao
Copy link
Collaborator

@yxieca can you please help to check this PR to see if we can merge it? Thanks.

@yxieca yxieca requested a review from prgeor April 10, 2024 15:22
@yxieca
Copy link
Contributor

yxieca commented Apr 10, 2024

@yxieca can you please help to check this PR to see if we can merge it? Thanks.

I think it is okay, @prgeor can you take a quick look?

@yxieca
Copy link
Contributor

yxieca commented Apr 10, 2024

/Semgrep

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.

None yet

6 participants