-
Notifications
You must be signed in to change notification settings - Fork 837
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
replace usage of dmidecode with kenv on FreeBSD #621
replace usage of dmidecode with kenv on FreeBSD #621
Conversation
You can also drop dmidecode from the dependency list in tools/build-on-freebsd. |
this is far from done… |
1dd9a74
to
40e58d0
Compare
5f552de
to
66f7751
Compare
faee463
to
963690e
Compare
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.
Fix the hard coded path and the exception. Humor me and think about the DMIDECODE map rework.
e8dddce
to
37ca15c
Compare
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.
looks good. some comments inline.
one thought... I think we could use functools.lru_cache on is_container. In real life, the result is never going to change... we don't go from being inside a container to not inside a container in the same python process (at least cloud-init doesn't). And that will save us several calls to subprocess.
I did a quick test, and adding lru_cache didn't seem to break any unit tests. Probably because we don't actually have unit tests for the is_container function.
cloudinit/util.py
Outdated
_is_container_systemd, | ||
_is_container_upstart, | ||
_is_container_old_lxc, | ||
_is_container_freebsd) |
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.
i just threw this together, with no test at all. i'm surprised that it apparently passes tests.
I think it is probably sane to put _is_container_freebsd
before upstart or old_lxc... as i think its probably more likely for this new thing in cloud-init to run on freebsd than a 2014 era linux.
cloudinit/util.py
Outdated
return False | ||
try: | ||
subp.subp(cmd) | ||
return True |
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.
i dont know on convention, but it seems maybe move 'return True' to outside the try. as it is probably more than a little bit unlikely for 'return True' to raise a subprocesserror. (and yes, i'm fully aware that I wrote that).
cloudinit/dmi.py
Outdated
@@ -111,6 +140,9 @@ def read_dmi_data(key): | |||
if syspath_value is not None: | |||
return syspath_value | |||
|
|||
if is_FreeBSD(): | |||
return _read_kenv(key) | |||
|
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.
seems like you might as well bump this up above the '_read_dmi_syspath' call.
theres no point in looking in /sys on freebsd, right? So that would always be a wasted stat (inside _read_dmi_syspath) on freebsd. And on linux we'd just pay the '@lru_cache' call is_FreeBSD.
I'm not sure if that is clear...
short summary: just move this up above the call to _read_dmi_syspath.
tools/ds-identify
Outdated
warn "No kenv program. Cannot read $sys_field." | ||
return 1 | ||
} | ||
case "$1" in |
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.
you shoudl use $sys_field
rather than $1
.
return 1;; | ||
esac | ||
val=$(kenv -q $kenv_field 2>/dev/null) || return 1 | ||
_RET="$val" |
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.
i think this looks good,. thanks.
I suggest shortening kenv_field and sys_field to ename and sname.
tools/ds-identify
Outdated
*) error "Unknown field $sys_field. Cannot call kenv." | ||
return 1;; | ||
esac | ||
val=$(kenv -q $kenv_field 2>/dev/null) || return 1 |
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.
you should quote $kenv_field
here just to be pedantic.
yeah… i noticed that, but didn't wanna go there yet… my brave suggestion is to add |
dmi_decode() { | ||
local sys_field="$1" dmi_field="" val="" | ||
command -v dmidecode >/dev/null 2>&1 || { | ||
warn "No dmidecode program. Cannot read $sys_field." | ||
return 1 | ||
} | ||
case "$1" in | ||
case "$sys_field" in |
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.
thank you for fixing that.
cc5fb80
to
432e709
Compare
FreeBSD lets us read out kernel parameters with kenv(1), a user-space utility that's shipped in "base" We can use it in place of dmidecode(8), thus removing the dependency on sysutils/dmidecode, and the restrictions to i386 and x86_64 architectures that this utility imposes on FreeBSD. Co-authored-by: Scott Moser <smoser@brickies.net>
432e709
to
c557eb0
Compare
Proposed Commit Message
FreeBSD lets us read out kernel parameters with
kenv(1)
, a user-space utility that's shipped in "base"We can use it in place of
dmidecode(8)
, thus removing the dependency on sysutils/dmidecode, and the restrictions to i386 and x86_64 architectures that this utility imposes on FreeBSD.Additional Context
I added this code, and while it opened the doors for more BSD stuff to be added, I'd like to remedy this restriction.
I'd also like to remind that @goneri already pointed this path out a year ago: #42 (comment)
Test Steps
run
kenv | grep smbios
on your favourite FreeBSD machine, and notice that unlikedmidecode
you can just run it without being root!Checklist: