mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-26 10:42:29 +03:00
unitest-xmlrpc: general cleaning
This commit is contained in:
parent
8ad7af6916
commit
f2cf282ce5
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# Glances - An eye on your system
|
# Glances - An eye on your system
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
|
# Copyright (C) 2015 Nicolargo <nicolas@nicolargo.com>
|
||||||
#
|
#
|
||||||
# Glances is free software; you can redistribute it and/or modify
|
# Glances is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Lesser General Public License as published by
|
# it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -18,47 +18,33 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""Glances unitary tests suite for the XML/RPC API."""
|
"""Glances unitary tests suite for the XML-RPC API."""
|
||||||
|
|
||||||
import sys
|
import json
|
||||||
import time
|
|
||||||
import unittest
|
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import time
|
||||||
|
import unittest
|
||||||
try:
|
try:
|
||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Python 2
|
# Python 2
|
||||||
from xmlrpclib import ServerProxy
|
from xmlrpclib import ServerProxy
|
||||||
|
|
||||||
|
from glances.core.glances_globals import version
|
||||||
|
|
||||||
SERVER_PORT = 61234
|
SERVER_PORT = 61234
|
||||||
URL = "http://localhost:%s" % SERVER_PORT
|
URL = "http://localhost:%s" % SERVER_PORT
|
||||||
pid = None
|
pid = None
|
||||||
|
|
||||||
# Global variables
|
# Init the XML-RPC client
|
||||||
# =================
|
|
||||||
|
|
||||||
# Init Glances core
|
|
||||||
from glances.core.glances_main import GlancesMain
|
|
||||||
core = GlancesMain()
|
|
||||||
if not core.is_standalone():
|
|
||||||
print('ERROR: Glances core should be ran in standalone mode')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Init Glances stats
|
|
||||||
from glances.core.glances_stats import GlancesStats
|
|
||||||
stats = GlancesStats()
|
|
||||||
|
|
||||||
from glances.core.glances_globals import version
|
|
||||||
|
|
||||||
# Init the XML/RCP client
|
|
||||||
client = ServerProxy(URL)
|
client = ServerProxy(URL)
|
||||||
|
|
||||||
# Unitest class
|
# Unitest class
|
||||||
# ==============
|
# ==============
|
||||||
print('XML-RPC API unitary tests for Glances %s' % version)
|
print('XML-RPC API unitary tests for Glances %s' % version)
|
||||||
|
|
||||||
|
|
||||||
class TestGlances(unittest.TestCase):
|
class TestGlances(unittest.TestCase):
|
||||||
|
|
||||||
"""Test Glances class."""
|
"""Test Glances class."""
|
||||||
@ -68,11 +54,10 @@ class TestGlances(unittest.TestCase):
|
|||||||
print('\n' + '=' * 78)
|
print('\n' + '=' * 78)
|
||||||
|
|
||||||
def test_000_start_server(self):
|
def test_000_start_server(self):
|
||||||
"""Start the Glances Web Server"""
|
"""Start the Glances Web Server."""
|
||||||
print('INFO: [TEST_000] Start the Glances Web Server')
|
|
||||||
|
|
||||||
global pid
|
global pid
|
||||||
|
|
||||||
|
print('INFO: [TEST_000] Start the Glances Web Server')
|
||||||
cmdline = "python -m glances -s -p %s" % SERVER_PORT
|
cmdline = "python -m glances -s -p %s" % SERVER_PORT
|
||||||
print("Run the Glances Server on port %s" % SERVER_PORT)
|
print("Run the Glances Server on port %s" % SERVER_PORT)
|
||||||
args = shlex.split(cmdline)
|
args = shlex.split(cmdline)
|
||||||
@ -83,36 +68,33 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertTrue(pid is not None)
|
self.assertTrue(pid is not None)
|
||||||
|
|
||||||
def test_001_all(self):
|
def test_001_all(self):
|
||||||
"""All"""
|
"""All."""
|
||||||
method = "getAll()"
|
method = "getAll()"
|
||||||
print('INFO: [TEST_001] Connection test')
|
print('INFO: [TEST_001] Connection test')
|
||||||
|
print("XML-RPC request: %s" % method)
|
||||||
print("XML/RPC request: %s" % method)
|
|
||||||
req = json.loads(client.getAll())
|
req = json.loads(client.getAll())
|
||||||
|
|
||||||
self.assertIsInstance(req, dict)
|
self.assertIsInstance(req, dict)
|
||||||
|
|
||||||
def test_002_pluginslist(self):
|
def test_002_pluginslist(self):
|
||||||
"""Plugins list"""
|
"""Plugins list."""
|
||||||
method = "getAllPlugins()"
|
method = "getAllPlugins()"
|
||||||
print('INFO: [TEST_002] Get plugins list')
|
print('INFO: [TEST_002] Get plugins list')
|
||||||
|
print("XML-RPC request: %s" % method)
|
||||||
print("XML/RPC request: %s" % method)
|
|
||||||
req = json.loads(client.getAllPlugins())
|
req = json.loads(client.getAllPlugins())
|
||||||
|
|
||||||
self.assertIsInstance(req, list)
|
self.assertIsInstance(req, list)
|
||||||
|
|
||||||
def test_003_system(self):
|
def test_003_system(self):
|
||||||
"""System"""
|
"""System."""
|
||||||
method = "getSystem()"
|
method = "getSystem()"
|
||||||
print('INFO: [TEST_003] Method: %s' % method)
|
print('INFO: [TEST_003] Method: %s' % method)
|
||||||
|
|
||||||
req = json.loads(client.getSystem())
|
req = json.loads(client.getSystem())
|
||||||
|
|
||||||
self.assertIsInstance(req, dict)
|
self.assertIsInstance(req, dict)
|
||||||
|
|
||||||
def test_004_cpu(self):
|
def test_004_cpu(self):
|
||||||
"""CPU"""
|
"""CPU."""
|
||||||
method = "getCpu(), getPerCpu(), getLoad() and getCore()"
|
method = "getCpu(), getPerCpu(), getLoad() and getCore()"
|
||||||
print('INFO: [TEST_004] Method: %s' % method)
|
print('INFO: [TEST_004] Method: %s' % method)
|
||||||
|
|
||||||
@ -129,7 +111,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, dict)
|
self.assertIsInstance(req, dict)
|
||||||
|
|
||||||
def test_005_mem(self):
|
def test_005_mem(self):
|
||||||
"""MEM"""
|
"""MEM."""
|
||||||
method = "getMem() and getMemSwap()"
|
method = "getMem() and getMemSwap()"
|
||||||
print('INFO: [TEST_005] Method: %s' % method)
|
print('INFO: [TEST_005] Method: %s' % method)
|
||||||
|
|
||||||
@ -140,7 +122,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, dict)
|
self.assertIsInstance(req, dict)
|
||||||
|
|
||||||
def test_006_net(self):
|
def test_006_net(self):
|
||||||
"""NETWORK"""
|
"""NETWORK."""
|
||||||
method = "getNetwork()"
|
method = "getNetwork()"
|
||||||
print('INFO: [TEST_006] Method: %s' % method)
|
print('INFO: [TEST_006] Method: %s' % method)
|
||||||
|
|
||||||
@ -148,7 +130,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, list)
|
self.assertIsInstance(req, list)
|
||||||
|
|
||||||
def test_007_disk(self):
|
def test_007_disk(self):
|
||||||
"""DISK"""
|
"""DISK."""
|
||||||
method = "getFs() and getDiskIO()"
|
method = "getFs() and getDiskIO()"
|
||||||
print('INFO: [TEST_007] Method: %s' % method)
|
print('INFO: [TEST_007] Method: %s' % method)
|
||||||
|
|
||||||
@ -159,7 +141,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, list)
|
self.assertIsInstance(req, list)
|
||||||
|
|
||||||
def test_008_sensors(self):
|
def test_008_sensors(self):
|
||||||
"""SENSORS"""
|
"""SENSORS."""
|
||||||
method = "getSensors()"
|
method = "getSensors()"
|
||||||
print('INFO: [TEST_008] Method: %s' % method)
|
print('INFO: [TEST_008] Method: %s' % method)
|
||||||
|
|
||||||
@ -167,7 +149,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, list)
|
self.assertIsInstance(req, list)
|
||||||
|
|
||||||
def test_009_process(self):
|
def test_009_process(self):
|
||||||
"""PROCESS"""
|
"""PROCESS."""
|
||||||
method = "getProcessCount() and getProcessList()"
|
method = "getProcessCount() and getProcessList()"
|
||||||
print('INFO: [TEST_009] Method: %s' % method)
|
print('INFO: [TEST_009] Method: %s' % method)
|
||||||
|
|
||||||
@ -178,7 +160,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req, list)
|
self.assertIsInstance(req, list)
|
||||||
|
|
||||||
def test_010_all_limits(self):
|
def test_010_all_limits(self):
|
||||||
"""All limits"""
|
"""All limits."""
|
||||||
method = "getAllLimits()"
|
method = "getAllLimits()"
|
||||||
print('INFO: [TEST_010] Method: %s' % method)
|
print('INFO: [TEST_010] Method: %s' % method)
|
||||||
|
|
||||||
@ -187,7 +169,7 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req['cpu'], dict)
|
self.assertIsInstance(req['cpu'], dict)
|
||||||
|
|
||||||
def test_011_all_views(self):
|
def test_011_all_views(self):
|
||||||
"""All views"""
|
"""All views."""
|
||||||
method = "getAllViews()"
|
method = "getAllViews()"
|
||||||
print('INFO: [TEST_011] Method: %s' % method)
|
print('INFO: [TEST_011] Method: %s' % method)
|
||||||
|
|
||||||
@ -196,12 +178,11 @@ class TestGlances(unittest.TestCase):
|
|||||||
self.assertIsInstance(req['cpu'], dict)
|
self.assertIsInstance(req['cpu'], dict)
|
||||||
|
|
||||||
def test_999_stop_server(self):
|
def test_999_stop_server(self):
|
||||||
"""Stop the Glances Web Server"""
|
"""Stop the Glances Web Server."""
|
||||||
print('INFO: [TEST_999] Stop the Glances Server')
|
print('INFO: [TEST_999] Stop the Glances Server')
|
||||||
|
|
||||||
print("Stop the Glances Server")
|
print("Stop the Glances Server")
|
||||||
pid.terminate()
|
pid.terminate()
|
||||||
print("Please wait...")
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user