Commit 05cff66f authored by Jelte Jansen's avatar Jelte Jansen

[2172] use None instead of -1 for unknown values

and update calling tool to not show anything for some values where it is None (i.e. where they have no relevance on the system)
parent 1f3ce585
......@@ -57,8 +57,8 @@ def main():
s = SysInfoFromFactory()
f.write('BIND 10 ShowTech tool\n')
f.write('=====================\n')
f.write('ISC Sysinfo tool\n')
f.write('================\n')
f.write('\nCPU\n');
f.write(' + Number of processors: %d\n' % (s.get_num_processors()))
......@@ -69,12 +69,13 @@ def main():
f.write(' + Distribution: %s\n' % (s.get_platform_distro()))
f.write(' + Kernel version: %s\n' % (s.get_platform_version()))
f.write(' + SMP kernel: ')
if s.get_platform_is_smp():
f.write('yes')
else:
f.write('no')
f.write('\n')
if s.get_platform_is_smp() is not None:
f.write(' + SMP kernel: ')
if s.get_platform_is_smp():
f.write('yes')
else:
f.write('no')
f.write('\n')
f.write(' + Machine name: %s\n' % (s.get_platform_machine()))
f.write(' + Hostname: %s\n' % (s.get_platform_hostname()))
......@@ -86,8 +87,10 @@ def main():
f.write('\nMemory\n');
f.write(' + Total: %d bytes\n' % (s.get_mem_total()))
f.write(' + Free: %d bytes\n' % (s.get_mem_free()))
f.write(' + Cached: %d bytes\n' % (s.get_mem_cached()))
f.write(' + Buffers: %d bytes\n' % (s.get_mem_buffers()))
if s.get_mem_cached() is not None:
f.write(' + Cached: %d bytes\n' % (s.get_mem_cached()))
if s.get_mem_buffers() is not None:
f.write(' + Buffers: %d bytes\n' % (s.get_mem_buffers()))
f.write(' + Swap total: %d bytes\n' % (s.get_mem_swap_total()))
f.write(' + Swap free: %d bytes\n' % (s.get_mem_swap_free()))
......
......@@ -25,21 +25,21 @@ import time
class SysInfo:
def __init__(self):
self._num_processors = -1
self._num_processors = None
self._endianness = 'Unknown'
self._hostname = ''
self._platform_name = 'Unknown'
self._platform_version = 'Unknown'
self._platform_machine = 'Unknown'
self._platform_is_smp = False
self._uptime = -1
self._uptime = None
self._loadavg = [-1.0, -1.0, -1.0]
self._mem_total = -1
self._mem_free = -1
self._mem_cached = -1
self._mem_buffers = -1
self._mem_swap_total = -1
self._mem_swap_free = -1
self._mem_total = None
self._mem_free = None
self._mem_cached = None
self._mem_buffers = None
self._mem_swap_total = None
self._mem_swap_free = None
self._platform_distro = 'Unknown'
self._net_interfaces = 'Unknown\n'
self._net_routing_table = 'Unknown\n'
......@@ -303,11 +303,6 @@ class SysInfoOpenBSD(SysInfoBSD):
def __init__(self):
super().__init__()
# Don't know how to gather these
self._platform_is_smp = False
self._mem_cached = -1
self._mem_buffers = -1
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.boottime'])
t = s.decode('utf-8').strip()
......@@ -356,10 +351,6 @@ class SysInfoFreeBSDOSX(SysInfoBSD):
def __init__(self):
super().__init__()
# Don't know how to gather these
self._mem_cached = -1
self._mem_buffers = -1
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.boottime'])
t = s.decode('utf-8').strip()
......
......@@ -246,21 +246,21 @@ class SysInfoTest(unittest.TestCase):
"""Test that the various methods on SysInfo exist and return data."""
s = SysInfo()
self.assertEqual(-1, s.get_num_processors())
self.assertEqual(None, s.get_num_processors())
self.assertEqual('Unknown', s.get_endianness())
self.assertEqual('', s.get_platform_hostname())
self.assertEqual('Unknown', s.get_platform_name())
self.assertEqual('Unknown', s.get_platform_version())
self.assertEqual('Unknown', s.get_platform_machine())
self.assertFalse(s.get_platform_is_smp())
self.assertEqual(-1, s.get_uptime())
self.assertEqual(None, s.get_uptime())
self.assertEqual([-1.0, -1.0, -1.0], s.get_loadavg())
self.assertEqual(-1, s.get_mem_total())
self.assertEqual(-1, s.get_mem_free())
self.assertEqual(-1, s.get_mem_cached())
self.assertEqual(-1, s.get_mem_buffers())
self.assertEqual(-1, s.get_mem_swap_total())
self.assertEqual(-1, s.get_mem_swap_free())
self.assertEqual(None, s.get_mem_total())
self.assertEqual(None, s.get_mem_free())
self.assertEqual(None, s.get_mem_cached())
self.assertEqual(None, s.get_mem_buffers())
self.assertEqual(None, s.get_mem_swap_total())
self.assertEqual(None, s.get_mem_swap_free())
self.assertEqual('Unknown', s.get_platform_distro())
self.assertEqual('Unknown\n', s.get_net_interfaces())
self.assertEqual('Unknown\n', s.get_net_routing_table())
......@@ -275,7 +275,7 @@ class SysInfoTest(unittest.TestCase):
platform.system = _my_testcase_platform_system
s = SysInfoFromFactory()
self.assertEqual(-1, s.get_num_processors())
self.assertEqual(None, s.get_num_processors())
self.assertEqual('bigrastafarian', s.get_endianness())
self.assertEqual('', s.get_platform_hostname())
self.assertEqual('b10test', s.get_platform_name())
......@@ -284,12 +284,12 @@ class SysInfoTest(unittest.TestCase):
self.assertFalse(s.get_platform_is_smp())
self.assertEqual(131072, s.get_uptime())
self.assertEqual([-1.0, -1.0, -1.0], s.get_loadavg())
self.assertEqual(-1, s.get_mem_total())
self.assertEqual(-1, s.get_mem_free())
self.assertEqual(-1, s.get_mem_cached())
self.assertEqual(-1, s.get_mem_buffers())
self.assertEqual(-1, s.get_mem_swap_total())
self.assertEqual(-1, s.get_mem_swap_free())
self.assertEqual(None, s.get_mem_total())
self.assertEqual(None, s.get_mem_free())
self.assertEqual(None, s.get_mem_cached())
self.assertEqual(None, s.get_mem_buffers())
self.assertEqual(None, s.get_mem_swap_total())
self.assertEqual(None, s.get_mem_swap_free())
self.assertEqual('Unknown', s.get_platform_distro())
self.assertEqual('Unknown\n', s.get_net_interfaces())
self.assertEqual('Unknown\n', s.get_net_routing_table())
......@@ -336,8 +336,8 @@ class SysInfoTest(unittest.TestCase):
# check values shared by all bsd implementations
self.assertEqual('test.example.com', s.get_platform_hostname())
self.assertLess(abs(76632 - s.get_uptime()), 4)
self.assertEqual(-1, s.get_mem_cached())
self.assertEqual(-1, s.get_mem_buffers())
self.assertEqual(None, s.get_mem_cached())
self.assertEqual(None, s.get_mem_buffers())
# These test that the corresponding tools are being called (and
# no further processing is done on this data). Please see the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment