Issue with set asset on Centos7
Just recently moved from centos6 to centos7 and ran into an issue with setting an asset tag on my server. I have a fix but wanted to see if this is just something specific to my setup vs an actual issue with the library.
Version Info:
[root@localhost ~]# python3 --version
Python 3.4.8
[root@localhost ~]# uname -a
Linux localhost 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 13:12:24 CST 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# rpm -qa | grep smb
libsmbios-2.4.1-1.el7.centos.x86_64
smbios-utils-2.4.1-1.el7.centos.x86_64
python3-smbios-2.4.1-1.el7.centos.x86_64
smbios-utils-bin-2.4.1-1.el7.centos.x86_64
smbios-utils-python-2.4.1-1.el7.centos.x86_64
After all of the above is installed on the server I get the following when trying to set the asset tag.
[root@localhost ~]# smbios-sys-info --asset-tag --set=M0000003
Current tag value:
Asset Tag: M
Setting new tag value: M0000003
Traceback (most recent call last):
File "/usr/sbin/smbios-sys-info", line 132, in <module>
sys.exit( main() )
File "/usr/sbin/smbios-sys-info", line 120, in main
fn(options.set, options.password_ascii, options.password_scancode)
File "/usr/lib64/python3.4/site-packages/libsmbios_c/trace_decorator.py", line 103, in trace
result = func(*args, **kw)
File "/usr/lib64/python3.4/site-packages/libsmbios_c/system_info.py", line 88, in set_asset_tag
return DLL.sysinfo_set_asset_tag(newtag, pass_ascii, pass_scancode)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
The function that this is failing in look like this.
DLL.sysinfo_set_asset_tag.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
DLL.sysinfo_set_asset_tag.restype = ctypes.c_int
DLL.sysinfo_set_asset_tag.errcheck=errorOnNegativeFN(lambda r,f,a: _strerror())
@traceLog()
def set_asset_tag(newtag, pass_ascii=None, pass_scancode=None):
return DLL.sysinfo_set_asset_tag(newtag, pass_ascii, pass_scancode)
__all__.append("set_asset_tag")
Digging around I found that ctypes.c_char_p is expecting to be passed in bytes and not just a string which I verified was happening via a print statement. Changing the return line above to below fixes the issue and sets the asset tag properly.
return DLL.sysinfo_set_asset_tag(newtag.encode(), pass_ascii, pass_scancode)
Other Notes:
Initially the rpm packages were a tad hard to install because I couldn't actually find any python3 packages for centos7 all I found was python34 and python36. This is more an issue with centos7 or just me being unable to find the proper packages but seems to be a common issue all around in centos from a few google searches. I ended up forcing the install with a rpm --nodeps since python3 is satisfied by python34 although rpm isn't smart enough to figure that out.
That looks like a valid fix, can you please send a PR? It was probably just missed as part of the python3 conversion.
Regarding the missing python3 packages, see if https://github.com/dell/libsmbios/commit/01b56546172fe568419af50a01edf19dc011d751 helps you.
Unfortunately my commit https://github.com/dell/libsmbios/commit/01b56546172fe568419af50a01edf19dc011d751 doesn't work on on the version of rpm in centos 7, so I'll have to revert it. http://rpm.org/user_doc/boolean_dependencies.html
Please send a PR for your other change.
Will do, sorry I am easily distracted :) i'll do my best to publish that tonight and also do a bit more digging into the python issue.