Skip to content

Commit c61d10b

Browse files
committed
Unittest OK
1 parent 60d6be1 commit c61d10b

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

glances/server.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -156,35 +156,13 @@ def getAllViews(self):
156156
return json.dumps(self.stats.getAllViewsAsDict())
157157

158158
def getPlugin(self, plugin):
159-
# Update and return the system stats
159+
# Update and return the plugin stat
160160
self.__update__()
161161
return json.dumps(self.stats.get_plugin(plugin).get_raw())
162162

163-
# ['alert', 'ports', 'diskio', 'containers', 'processcount', 'gpu',
164-
# 'percpu', 'system', 'network', 'cpu', 'amps', 'processlist',
165-
# 'load', 'sensors', 'uptime', 'now', 'fs', 'wifi', 'ip', 'help',
166-
# 'version', 'psutilversion', 'core', 'mem', 'folders', 'quicklook', 'memswap', 'raid']
167-
168-
# It works...
169-
# def getSystem(self):
170-
# return self._get_plugin('system')
171-
172-
# Do not work...
173-
# def __getattr__(self, item):
174-
# """Overwrite the getattr method in case of attribute is not found.
175-
# The goal is to dynamically generate the API get'Stats'() methods.
176-
# """
177-
# header = 'get'
178-
# # Check if the attribute starts with 'get'
179-
# if item.startswith(header):
180-
# try:
181-
# return self._get_plugin(item[len(header):])
182-
# except Exception:
183-
# # The method is not found for the plugin
184-
# raise AttributeError(item)
185-
# else:
186-
# # Default behavior
187-
# raise AttributeError(item)
163+
def getPluginView(self, plugin):
164+
# Update and return the plugin view
165+
return json.dumps(self.stats.get_plugin(plugin).get_views())
188166

189167

190168
class GlancesServer:

glances/stats.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,17 @@ def get_plugin_list(self):
358358
return self._plugins
359359

360360
def get_plugin(self, plugin_name):
361-
"""Return the plugin name."""
361+
"""Return the plugin stats."""
362362
if plugin_name in self._plugins:
363363
return self._plugins[plugin_name]
364364
return None
365365

366+
def get_plugin_view(self, plugin_name):
367+
"""Return the plugin views."""
368+
if plugin_name in self._plugins:
369+
return self._plugins[plugin_name].get_views()
370+
return None
371+
366372
def end(self):
367373
"""End of the Glances stats."""
368374
# Close export modules

unittest-xmlrpc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ def test_012_irq(self):
185185
"""IRQS"""
186186
method = "getIrqs()"
187187
print(f'INFO: [TEST_012] Method: {method}')
188-
req = json.loads(client.getIrq())
188+
req = json.loads(client.getPlugin('irq'))
189189
self.assertIsInstance(req, list)
190190

191191
def test_013_plugin_views(self):
192192
"""Plugin views."""
193193
method = "getViewsCpu()"
194194
print(f'INFO: [TEST_013] Method: {method}')
195195

196-
req = json.loads(client.getViewsCpu())
196+
req = json.loads(client.getPluginView('cpu'))
197197
self.assertIsInstance(req, dict)
198198

199199
def test_999_stop_server(self):

0 commit comments

Comments
 (0)