Increase test coverage for uptime
This commit is contained in:
2
AUTHORS
2
AUTHORS
@@ -1,2 +1,2 @@
|
|||||||
Kevin Carter <kevin@cloudnull.com>
|
Kevin Carter <kcarter@linux.com>
|
||||||
Major Hayden <major@mhtx.net>
|
Major Hayden <major@mhtx.net>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
CHANGES
|
CHANGES
|
||||||
=======
|
=======
|
||||||
|
|
||||||
* Added KVM Metric plugin
|
* Added KVM Metric plugin (#2)
|
||||||
* Couple of updates: telegraf line protocol, dynamic imports, metadata
|
* Couple of updates: telegraf line protocol, dynamic imports, metadata (#1)
|
||||||
* Proof of concept
|
* Proof of concept
|
||||||
* Initial commit
|
* Initial commit
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ from monitorstack.cli import pass_context
|
|||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx):
|
def cli(ctx):
|
||||||
"""Get system uptime."""
|
"""Get system uptime."""
|
||||||
with open('/proc/uptime', 'r') as f:
|
uptime = get_uptime()
|
||||||
output = f.read()
|
|
||||||
uptime = output.split()[0]
|
|
||||||
output = {
|
output = {
|
||||||
'exit_code': 0,
|
'exit_code': 0,
|
||||||
'message': 'uptime is ok',
|
'message': 'uptime is ok',
|
||||||
@@ -37,7 +35,19 @@ def cli(ctx):
|
|||||||
'platform': platform.platform()
|
'platform': platform.platform()
|
||||||
},
|
},
|
||||||
'variables': {
|
'variables': {
|
||||||
'uptime': uptime
|
'uptime': str(uptime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output
|
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."""
|
"""Tests for the base class."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
|
||||||
from monitorstack.cli import cli
|
from monitorstack.cli import cli
|
||||||
|
from monitorstack.plugins.uptime import get_uptime
|
||||||
|
|
||||||
|
|
||||||
class TestUptime(object):
|
class TestUptime(object):
|
||||||
@@ -31,3 +33,9 @@ class TestUptime(object):
|
|||||||
result_json = json.loads(result.output)
|
result_json = json.loads(result.output)
|
||||||
assert 'uptime' in result_json['variables']
|
assert 'uptime' in result_json['variables']
|
||||||
assert result.exit_code == 0
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user