mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
status.cpuinfo: unbreak on OpenBSD and add NetBSD support
the field separator on OpenBSD and NetBSD is '=', not ':'. verified on OpenBSD, assuming this now works on NetBSD based on upstream documentation for sysctl(8)
This commit is contained in:
parent
54cf591078
commit
fe7f0b5fcc
@ -593,6 +593,9 @@ def cpuinfo():
|
||||
.. versionchanged:: 2016.11.4
|
||||
Added support for AIX
|
||||
|
||||
.. versionchanged:: Oxygen
|
||||
Added support for NetBSD and OpenBSD
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
@ -623,14 +626,19 @@ def cpuinfo():
|
||||
|
||||
def bsd_cpuinfo():
|
||||
'''
|
||||
freebsd specific cpuinfo implementation
|
||||
bsd specific cpuinfo implementation
|
||||
'''
|
||||
freebsd_cmd = 'sysctl hw.model hw.ncpu'
|
||||
bsd_cmd = 'sysctl hw.model hw.ncpu'
|
||||
ret = {}
|
||||
for line in __salt__['cmd.run'](freebsd_cmd).splitlines():
|
||||
if __grains__['kernel'].lower() in ['netbsd', 'openbsd']:
|
||||
sep = '='
|
||||
else:
|
||||
sep = ':'
|
||||
|
||||
for line in __salt__['cmd.run'](bsd_cmd).splitlines():
|
||||
if not line:
|
||||
continue
|
||||
comps = line.split(':')
|
||||
comps = line.split(sep)
|
||||
comps[0] = comps[0].strip()
|
||||
ret[comps[0]] = comps[1].strip()
|
||||
return ret
|
||||
@ -775,6 +783,7 @@ def cpuinfo():
|
||||
get_version = {
|
||||
'Linux': linux_cpuinfo,
|
||||
'FreeBSD': bsd_cpuinfo,
|
||||
'NetBSD': bsd_cpuinfo,
|
||||
'OpenBSD': bsd_cpuinfo,
|
||||
'SunOS': sunos_cpuinfo,
|
||||
'AIX': aix_cpuinfo,
|
||||
|
@ -202,3 +202,36 @@ class StatusTestCase(TestCase, LoaderModuleMockMixin):
|
||||
patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value=systat)}):
|
||||
ret = status.cpustats()
|
||||
self.assertDictEqual(ret, m.ret)
|
||||
|
||||
def _set_up_test_cpuinfo_bsd(self):
|
||||
class MockData(object):
|
||||
'''
|
||||
Store mock data
|
||||
'''
|
||||
|
||||
m = MockData()
|
||||
m.ret = {
|
||||
'hw.model': 'Intel(R) Core(TM) i5-7287U CPU @ 3.30GHz',
|
||||
'hw.ncpu': '4',
|
||||
}
|
||||
|
||||
return m
|
||||
|
||||
def test_cpuinfo_freebsd(self):
|
||||
m = self._set_up_test_cpuinfo_bsd()
|
||||
sysctl = 'hw.model:Intel(R) Core(TM) i5-7287U CPU @ 3.30GHz\nhw.ncpu:4'
|
||||
|
||||
with patch.dict(status.__grains__, {'kernel': 'FreeBSD'}):
|
||||
with patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value=sysctl)}):
|
||||
ret = status.cpuinfo()
|
||||
self.assertDictEqual(ret, m.ret)
|
||||
|
||||
def test_cpuinfo_openbsd(self):
|
||||
m = self._set_up_test_cpuinfo_bsd()
|
||||
sysctl = 'hw.model=Intel(R) Core(TM) i5-7287U CPU @ 3.30GHz\nhw.ncpu=4'
|
||||
|
||||
for bsd in ['NetBSD', 'OpenBSD']:
|
||||
with patch.dict(status.__grains__, {'kernel': bsd}):
|
||||
with patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value=sysctl)}):
|
||||
ret = status.cpuinfo()
|
||||
self.assertDictEqual(ret, m.ret)
|
||||
|
Loading…
Reference in New Issue
Block a user