mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #48814 from isbm/isbm-2018.3-smbios-bugfix
dmidecode race conditions check
This commit is contained in:
commit
9fda70b3d0
@ -29,18 +29,13 @@ from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-bui
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
DMIDECODER = salt.utils.path.which_bin(['dmidecode', 'smbios'])
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only work when dmidecode is installed.
|
||||
'''
|
||||
if DMIDECODER is None:
|
||||
log.debug('SMBIOS: neither dmidecode nor smbios found!')
|
||||
return (False, 'The smbios execution module failed to load: neither dmidecode nor smbios in the path.')
|
||||
else:
|
||||
return True
|
||||
return (bool(salt.utils.path.which_bin(['dmidecode', 'smbios'])),
|
||||
'The smbios execution module failed to load: neither dmidecode nor smbios in the path.')
|
||||
|
||||
|
||||
def get(string, clean=True):
|
||||
@ -86,16 +81,12 @@ def get(string, clean=True):
|
||||
|
||||
val = _dmidecoder('-s {0}'.format(string)).strip()
|
||||
|
||||
# Sometimes dmidecode delivers comments in strings.
|
||||
# Don't.
|
||||
# Cleanup possible comments in strings.
|
||||
val = '\n'.join([v for v in val.split('\n') if not v.startswith('#')])
|
||||
if val.startswith('/dev/mem') or clean and not _dmi_isclean(string, val):
|
||||
val = None
|
||||
|
||||
# handle missing /dev/mem
|
||||
if val.startswith('/dev/mem'):
|
||||
return None
|
||||
|
||||
if not clean or _dmi_isclean(string, val):
|
||||
return val
|
||||
return val
|
||||
|
||||
|
||||
def records(rec_type=None, fields=None, clean=True):
|
||||
@ -327,7 +318,11 @@ def _dmidecoder(args=None):
|
||||
'''
|
||||
Call DMIdecode
|
||||
'''
|
||||
if args is None:
|
||||
return salt.modules.cmdmod._run_quiet(DMIDECODER)
|
||||
dmidecoder = salt.utils.path.which_bin(['dmidecode', 'smbios'])
|
||||
|
||||
if not args:
|
||||
out = salt.modules.cmdmod._run_quiet(dmidecoder)
|
||||
else:
|
||||
return salt.modules.cmdmod._run_quiet('{0} {1}'.format(DMIDECODER, args))
|
||||
out = salt.modules.cmdmod._run_quiet('{0} {1}'.format(dmidecoder, args))
|
||||
|
||||
return out
|
||||
|
Loading…
Reference in New Issue
Block a user