2014-07-12 20:02:31 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Glances - An eye on your system
|
|
|
|
#
|
2022-06-25 16:43:36 +03:00
|
|
|
# SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com>
|
2014-07-12 20:02:31 +04:00
|
|
|
#
|
2022-06-25 16:43:36 +03:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only
|
2014-07-12 20:02:31 +04:00
|
|
|
#
|
|
|
|
|
2015-09-21 20:39:39 +03:00
|
|
|
"""Glances unitary tests suite for the XML-RPC API."""
|
2014-07-12 20:02:31 +04:00
|
|
|
|
2015-09-21 20:39:39 +03:00
|
|
|
import json
|
2014-07-12 20:02:31 +04:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
2015-09-21 20:39:39 +03:00
|
|
|
import time
|
|
|
|
import unittest
|
2022-10-31 10:40:46 +03:00
|
|
|
import os
|
2014-07-12 20:02:31 +04:00
|
|
|
|
2016-03-24 13:33:31 +03:00
|
|
|
from glances import __version__
|
2015-11-14 17:15:15 +03:00
|
|
|
from glances.compat import ServerProxy
|
2015-09-21 20:39:39 +03:00
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
SERVER_PORT = 61234
|
|
|
|
URL = "http://localhost:%s" % SERVER_PORT
|
|
|
|
pid = None
|
|
|
|
|
2015-09-21 20:39:39 +03:00
|
|
|
# Init the XML-RPC client
|
2014-10-03 00:13:48 +04:00
|
|
|
client = ServerProxy(URL)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
# Unitest class
|
|
|
|
# ==============
|
2016-03-24 13:33:31 +03:00
|
|
|
print('XML-RPC API unitary tests for Glances %s' % __version__)
|
2015-01-18 20:21:26 +03:00
|
|
|
|
2015-09-21 20:39:39 +03:00
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
class TestGlances(unittest.TestCase):
|
|
|
|
"""Test Glances class."""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""The function is called *every time* before test_*."""
|
|
|
|
print('\n' + '=' * 78)
|
|
|
|
|
|
|
|
def test_000_start_server(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""Start the Glances Web Server."""
|
2014-07-12 20:02:31 +04:00
|
|
|
global pid
|
2015-01-18 20:21:26 +03:00
|
|
|
|
2015-09-21 20:39:39 +03:00
|
|
|
print('INFO: [TEST_000] Start the Glances Web Server')
|
2022-10-31 10:40:46 +03:00
|
|
|
if os.path.isfile("./venv/bin/python"):
|
|
|
|
cmdline = "./venv/bin/python"
|
|
|
|
else:
|
|
|
|
cmdline = "python"
|
2022-10-31 10:58:16 +03:00
|
|
|
cmdline += " -m glances -B localhost -s -p %s" % SERVER_PORT
|
2014-07-12 20:02:31 +04:00
|
|
|
print("Run the Glances Server on port %s" % SERVER_PORT)
|
|
|
|
args = shlex.split(cmdline)
|
|
|
|
pid = subprocess.Popen(args)
|
|
|
|
print("Please wait...")
|
|
|
|
time.sleep(1)
|
2015-01-18 20:21:26 +03:00
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
self.assertTrue(pid is not None)
|
|
|
|
|
|
|
|
def test_001_all(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""All."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getAll()"
|
|
|
|
print('INFO: [TEST_001] Connection test')
|
2015-09-21 20:39:39 +03:00
|
|
|
print("XML-RPC request: %s" % method)
|
2014-07-12 20:02:31 +04:00
|
|
|
req = json.loads(client.getAll())
|
|
|
|
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_002_pluginslist(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""Plugins list."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getAllPlugins()"
|
|
|
|
print('INFO: [TEST_002] Get plugins list')
|
2015-09-21 20:39:39 +03:00
|
|
|
print("XML-RPC request: %s" % method)
|
2014-07-12 20:02:31 +04:00
|
|
|
req = json.loads(client.getAllPlugins())
|
|
|
|
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_003_system(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""System."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getSystem()"
|
|
|
|
print('INFO: [TEST_003] Method: %s' % method)
|
|
|
|
req = json.loads(client.getSystem())
|
|
|
|
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_004_cpu(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""CPU."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getCpu(), getPerCpu(), getLoad() and getCore()"
|
|
|
|
print('INFO: [TEST_004] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getCpu())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
req = json.loads(client.getPerCpu())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
req = json.loads(client.getLoad())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
req = json.loads(client.getCore())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_005_mem(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""MEM."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getMem() and getMemSwap()"
|
|
|
|
print('INFO: [TEST_005] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getMem())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
req = json.loads(client.getMemSwap())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_006_net(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""NETWORK."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getNetwork()"
|
|
|
|
print('INFO: [TEST_006] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getNetwork())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_007_disk(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""DISK."""
|
2015-11-22 13:02:27 +03:00
|
|
|
method = "getFs(), getFolders() and getDiskIO()"
|
2014-07-12 20:02:31 +04:00
|
|
|
print('INFO: [TEST_007] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getFs())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
2015-11-22 13:02:27 +03:00
|
|
|
req = json.loads(client.getFolders())
|
|
|
|
self.assertIsInstance(req, list)
|
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
req = json.loads(client.getDiskIO())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_008_sensors(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""SENSORS."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getSensors()"
|
|
|
|
print('INFO: [TEST_008] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getSensors())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
def test_009_process(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""PROCESS."""
|
2014-07-12 20:02:31 +04:00
|
|
|
method = "getProcessCount() and getProcessList()"
|
|
|
|
print('INFO: [TEST_009] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getProcessCount())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
|
|
|
req = json.loads(client.getProcessList())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, list)
|
2014-07-12 20:02:31 +04:00
|
|
|
|
2015-01-18 20:21:26 +03:00
|
|
|
def test_010_all_limits(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""All limits."""
|
2015-01-18 20:21:26 +03:00
|
|
|
method = "getAllLimits()"
|
|
|
|
print('INFO: [TEST_010] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getAllLimits())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
|
|
|
self.assertIsInstance(req['cpu'], dict)
|
2015-01-18 20:21:26 +03:00
|
|
|
|
|
|
|
def test_011_all_views(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""All views."""
|
2015-01-18 20:21:26 +03:00
|
|
|
method = "getAllViews()"
|
|
|
|
print('INFO: [TEST_011] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getAllViews())
|
2015-09-21 19:49:49 +03:00
|
|
|
self.assertIsInstance(req, dict)
|
|
|
|
self.assertIsInstance(req['cpu'], dict)
|
2015-01-18 20:21:26 +03:00
|
|
|
|
2016-08-19 20:26:23 +03:00
|
|
|
def test_012_irq(self):
|
2016-08-20 18:49:13 +03:00
|
|
|
"""IRQS"""
|
2016-08-19 20:26:23 +03:00
|
|
|
method = "getIrqs()"
|
|
|
|
print('INFO: [TEST_012] Method: %s' % method)
|
|
|
|
req = json.loads(client.getIrq())
|
|
|
|
self.assertIsInstance(req, list)
|
|
|
|
|
2017-05-14 12:46:23 +03:00
|
|
|
def test_013_plugin_views(self):
|
|
|
|
"""Plugin views."""
|
|
|
|
method = "getViewsCpu()"
|
|
|
|
print('INFO: [TEST_013] Method: %s' % method)
|
|
|
|
|
|
|
|
req = json.loads(client.getViewsCpu())
|
|
|
|
self.assertIsInstance(req, dict)
|
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
def test_999_stop_server(self):
|
2015-09-21 20:39:39 +03:00
|
|
|
"""Stop the Glances Web Server."""
|
2014-07-12 20:02:31 +04:00
|
|
|
print('INFO: [TEST_999] Stop the Glances Server')
|
|
|
|
|
|
|
|
print("Stop the Glances Server")
|
|
|
|
pid.terminate()
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
self.assertTrue(True)
|
|
|
|
|
2017-05-14 12:47:38 +03:00
|
|
|
|
2014-07-12 20:02:31 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|