Increase test coverage for uptime
This commit is contained in:
parent
52e06b501b
commit
0b55880400
2
AUTHORS
2
AUTHORS
|
@ -1,2 +1,2 @@
|
|||
Kevin Carter <kevin@cloudnull.com>
|
||||
Kevin Carter <kcarter@linux.com>
|
||||
Major Hayden <major@mhtx.net>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CHANGES
|
||||
=======
|
||||
|
||||
* Added KVM Metric plugin
|
||||
* Couple of updates: telegraf line protocol, dynamic imports, metadata
|
||||
* Added KVM Metric plugin (#2)
|
||||
* Couple of updates: telegraf line protocol, dynamic imports, metadata (#1)
|
||||
* Proof of concept
|
||||
* Initial commit
|
||||
|
|
|
@ -26,9 +26,7 @@ from monitorstack.cli import pass_context
|
|||
@pass_context
|
||||
def cli(ctx):
|
||||
"""Get system uptime."""
|
||||
with open('/proc/uptime', 'r') as f:
|
||||
output = f.read()
|
||||
uptime = output.split()[0]
|
||||
uptime = get_uptime()
|
||||
output = {
|
||||
'exit_code': 0,
|
||||
'message': 'uptime is ok',
|
||||
|
@ -37,7 +35,19 @@ def cli(ctx):
|
|||
'platform': platform.platform()
|
||||
},
|
||||
'variables': {
|
||||
'uptime': uptime
|
||||
'uptime': str(uptime)
|
||||
}
|
||||
}
|
||||
return output
|
||||
|
||||
|
||||
def get_uptime():
|
||||
"""Read the uptime from the proc filesystem."""
|
||||
with open('/proc/uptime', 'r') as f:
|
||||
output = f.read()
|
||||
|
||||
# /proc/uptime outputs two numbers: seconds since start (which we want)
|
||||
# and seconds the machine has spent idle (we don't want that)
|
||||
uptime = output.split()[0]
|
||||
|
||||
return float(uptime)
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
"""Tests for the base class."""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from monitorstack.cli import cli
|
||||
from monitorstack.plugins.uptime import get_uptime
|
||||
|
||||
|
||||
class TestUptime(object):
|
||||
|
@ -31,3 +33,9 @@ class TestUptime(object):
|
|||
result_json = json.loads(result.output)
|
||||
assert 'uptime' in result_json['variables']
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_get_uptime(self):
|
||||
"""Ensure the cli() method works."""
|
||||
uptime = get_uptime()
|
||||
assert isinstance(uptime, float)
|
||||
assert uptime > 0
|
||||
|
|
Loading…
Reference in New Issue