Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
ffc684f6
Commit
ffc684f6
authored
Aug 13, 2012
by
Jelte Jansen
Browse files
[2172] only use 'distro' value on linux
parent
be7f08f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/python/isc/sysinfo/sysinfo.py
View file @
ffc684f6
...
...
@@ -36,16 +36,20 @@ class SysInfo:
self
.
_loadavg
=
None
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
'
self
.
_net_stats
=
'Unknown
\n
'
self
.
_net_connections
=
'Unknown
\n
'
# The following are Linux speicific, and should eventually be removed
# from this level; for now we simply default to None (so they won't
# be printed)
self
.
_platform_distro
=
None
self
.
_mem_cached
=
None
self
.
_mem_buffers
=
None
def
get_num_processors
(
self
):
"""Returns the number of processors. This is the number of
hyperthreads when hyper-threading is enabled.
...
...
@@ -77,7 +81,12 @@ class SysInfo:
return
self
.
_platform_is_smp
def
get_platform_distro
(
self
):
"""Returns the name of the OS distribution in use."""
"""Returns the name of the OS distribution in use.
Note: the concept of 'distribution' is Linux specific. This shouldn't
be at this level.
"""
return
self
.
_platform_distro
def
get_uptime
(
self
):
...
...
@@ -276,8 +285,6 @@ class SysInfoBSD(SysInfoPOSIX):
except
(
subprocess
.
CalledProcessError
,
OSError
):
pass
self
.
_platform_distro
=
self
.
_platform_name
+
' '
+
self
.
_platform_version
try
:
s
=
subprocess
.
check_output
([
'ifconfig'
])
self
.
_net_interfaces
=
s
.
decode
(
'utf-8'
)
...
...
src/lib/python/isc/sysinfo/tests/sysinfo_test.py
View file @
ffc684f6
...
...
@@ -261,7 +261,7 @@ class SysInfoTest(unittest.TestCase):
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
(
None
,
s
.
get_platform_distro
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_interfaces
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_routing_table
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_stats
())
...
...
@@ -290,7 +290,7 @@ class SysInfoTest(unittest.TestCase):
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
(
None
,
s
.
get_platform_distro
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_interfaces
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_routing_table
())
self
.
assertEqual
(
'Unknown
\n
'
,
s
.
get_net_stats
())
...
...
@@ -338,6 +338,7 @@ class SysInfoTest(unittest.TestCase):
self
.
assertLess
(
abs
(
76632
-
s
.
get_uptime
()),
4
)
self
.
assertEqual
(
None
,
s
.
get_mem_cached
())
self
.
assertEqual
(
None
,
s
.
get_mem_buffers
())
self
.
assertEqual
(
None
,
s
.
get_platform_distro
())
# These test that the corresponding tools are being called (and
# no further processing is done on this data). Please see the
...
...
@@ -371,13 +372,6 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
566791168
,
s
.
get_mem_swap_total
())
self
.
assertEqual
(
566789120
,
s
.
get_mem_swap_free
())
# Try new regex assertion (which replaced the deprecated
# assertRegexpMatches. If it is not available, use the old one
try
:
self
.
assertRegex
(
s
.
get_platform_distro
(),
'^OpenBSD\s+.*'
)
except
AttributeError
:
self
.
assertRegexpMatches
(
s
.
get_platform_distro
(),
'^OpenBSD\s+.*'
)
def
test_sysinfo_freebsd
(
self
):
"""Tests the FreeBSD implementation of SysInfo. Note that this
tests deep into the implementation, and not just the
...
...
@@ -401,12 +395,6 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
543214321
-
(
343434
*
1024
),
s
.
get_mem_free
())
self
.
assertEqual
(
1037533184
,
s
.
get_mem_swap_total
())
self
.
assertEqual
(
1037533184
,
s
.
get_mem_swap_free
())
# Try new regex assertion (which replaced the deprecated
# assertRegexpMatches. If it is not available, use the old one
try
:
self
.
assertRegex
(
s
.
get_platform_distro
(),
'^FreeBSD\s+.*'
)
except
AttributeError
:
self
.
assertRegexpMatches
(
s
.
get_platform_distro
(),
'^FreeBSD\s+.*'
)
def
test_sysinfo_osx
(
self
):
"""Tests the OS X implementation of SysInfo. Note that this
...
...
@@ -431,12 +419,6 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
((
23456
*
4096
),
s
.
get_mem_free
())
self
.
assertEqual
(
18874368.0
,
s
.
get_mem_swap_total
())
self
.
assertEqual
(
1075988.48
,
s
.
get_mem_swap_free
())
# Try new regex assertion (which replaced the deprecated
# assertRegexpMatches. If it is not available, use the old one
try
:
self
.
assertRegex
(
s
.
get_platform_distro
(),
'^Darwin\s+.*'
)
except
AttributeError
:
self
.
assertRegexpMatches
(
s
.
get_platform_distro
(),
'^Darwin\s+.*'
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment