-
Notifications
You must be signed in to change notification settings - Fork 54
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
Parse hostname from /proc/sys/kernel/hostname #704
Conversation
Could you change the title of the PR and your commit message according to our commit style guidelines? |
@@ -149,7 +149,7 @@ def _parse_hostname_string(self, paths: Optional[list[str]] = None) -> Optional[ | |||
paths (list): list of paths | |||
""" | |||
redhat_legacy_path = "/etc/sysconfig/network" | |||
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", redhat_legacy_path] | |||
paths = paths or ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we always want to add the file, or only when a user doesn't specify their own paths? If we always want to include the file you're better off cloning the paths, and merging these four hostname paths together:
If the list order doesn't matter you can combine the two and cast it to a set to make the values unique:
paths = set(paths + ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path])
If the list order does matter, just create a copy and add each unique item to it:
paths = paths.copy() # ensures that we don't modify the existing list in-place
for path in ["/etc/hostname", "/etc/HOSTNAME", "/proc/sys/kernel/hostname", redhat_legacy_path]:
if path not in paths:
paths.append(path)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #704 +/- ##
=======================================
Coverage 77.70% 77.70%
=======================================
Files 326 326
Lines 28481 28481
=======================================
Hits 22131 22131
Misses 6350 6350
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Adds the /proc/sys/kernel/hostname path to the paths mentioned in issue 606