Send compute usage via in the compute.updated notification

Ref https://github.com/GNS3/gns3-gui/issues/1261
This commit is contained in:
Julien Duponchelle committed 2016-06-30 09:55:59 +02:00
1 parent 66959ee4e9
commit 543b423e03
5 files changed
+77 -5

No files matched your search

+39
View File
@@ -194,6 +194,43 @@ def test_connectNotification(compute, async_run):
assert compute._connected is False
def test_connectNotificationPing(compute, async_run):
"""
When we receive a ping from a compute we update
the compute memory and CPU usage
"""
ws_mock = AsyncioMagicMock()
call = 0
@asyncio.coroutine
def receive():
nonlocal call
call += 1
if call == 1:
response = MagicMock()
response.data = '{"action": "ping", "event": {"cpu_usage_percent": 35.7, "memory_usage_percent": 80.7}}'
response.tp = aiohttp.MsgType.text
return response
else:
response = MagicMock()
response.tp = aiohttp.MsgType.closed
return response
compute._controller._notification = MagicMock()
compute._session = AsyncioMagicMock(return_value=ws_mock)
compute._session.ws_connect = AsyncioMagicMock(return_value=ws_mock)
ws_mock.receive = receive
async_run(compute._connect_notification())
assert not compute._controller.notification.dispatch.called
assert compute.cpu_usage_percent == 35.7
assert compute.memory_usage_percent == 80.7
args, _ = compute._controller.notification.emit.call_args
assert args[0] == "compute.updated"
assert args[1]["memory_usage_percent"] == 80.7
def test_json(compute):
compute.user = "test"
assert compute.__json__() == {
@@ -203,6 +240,8 @@ def test_json(compute):
"host": "example.com",
"port": 84,
"user": "test",
"cpu_usage_percent": None,
"memory_usage_percent": None,
"connected": True
}
assert compute.__json__(topology_dump=True) == {
+3 -1
View File
@@ -67,7 +67,9 @@ def test_load(controller, controller_config_path, async_run):
"port": 8000,
"protocol": "http",
"user": "admin",
"name": "http://admin@localhost:8000"
"name": "http://admin@localhost:8000",
"cpu_usage_percent": None,
"memory_usage_percent": None
}