From c61d10bec78bfcbb96c49c062c3fd9a70fc3c9f9 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sat, 25 May 2024 09:42:02 +0200 Subject: [PATCH] Unittest OK --- glances/server.py | 30 ++++-------------------------- glances/stats.py | 8 +++++++- unittest-xmlrpc.py | 4 ++-- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/glances/server.py b/glances/server.py index 21c8ee63..ce33c5a0 100644 --- a/glances/server.py +++ b/glances/server.py @@ -156,35 +156,13 @@ class GlancesInstance: return json.dumps(self.stats.getAllViewsAsDict()) def getPlugin(self, plugin): - # Update and return the system stats + # Update and return the plugin stat self.__update__() return json.dumps(self.stats.get_plugin(plugin).get_raw()) - # ['alert', 'ports', 'diskio', 'containers', 'processcount', 'gpu', - # 'percpu', 'system', 'network', 'cpu', 'amps', 'processlist', - # 'load', 'sensors', 'uptime', 'now', 'fs', 'wifi', 'ip', 'help', - # 'version', 'psutilversion', 'core', 'mem', 'folders', 'quicklook', 'memswap', 'raid'] - - # It works... - # def getSystem(self): - # return self._get_plugin('system') - - # Do not work... - # def __getattr__(self, item): - # """Overwrite the getattr method in case of attribute is not found. - # The goal is to dynamically generate the API get'Stats'() methods. - # """ - # header = 'get' - # # Check if the attribute starts with 'get' - # if item.startswith(header): - # try: - # return self._get_plugin(item[len(header):]) - # except Exception: - # # The method is not found for the plugin - # raise AttributeError(item) - # else: - # # Default behavior - # raise AttributeError(item) + def getPluginView(self, plugin): + # Update and return the plugin view + return json.dumps(self.stats.get_plugin(plugin).get_views()) class GlancesServer: diff --git a/glances/stats.py b/glances/stats.py index ca098dd2..d56983a9 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -358,11 +358,17 @@ class GlancesStats: return self._plugins def get_plugin(self, plugin_name): - """Return the plugin name.""" + """Return the plugin stats.""" if plugin_name in self._plugins: return self._plugins[plugin_name] return None + def get_plugin_view(self, plugin_name): + """Return the plugin views.""" + if plugin_name in self._plugins: + return self._plugins[plugin_name].get_views() + return None + def end(self): """End of the Glances stats.""" # Close export modules diff --git a/unittest-xmlrpc.py b/unittest-xmlrpc.py index e71582ae..0e438df8 100755 --- a/unittest-xmlrpc.py +++ b/unittest-xmlrpc.py @@ -185,7 +185,7 @@ class TestGlances(unittest.TestCase): """IRQS""" method = "getIrqs()" print(f'INFO: [TEST_012] Method: {method}') - req = json.loads(client.getIrq()) + req = json.loads(client.getPlugin('irq')) self.assertIsInstance(req, list) def test_013_plugin_views(self): @@ -193,7 +193,7 @@ class TestGlances(unittest.TestCase): method = "getViewsCpu()" print(f'INFO: [TEST_013] Method: {method}') - req = json.loads(client.getViewsCpu()) + req = json.loads(client.getPluginView('cpu')) self.assertIsInstance(req, dict) def test_999_stop_server(self):