mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Avoid too much ressources usage during tests
This commit is contained in:
3 files changed
+24
-18
No files matched your search
@@ -208,13 +208,14 @@ class Controller:
|
||||
return Config.instance().get_section_config("Server").getboolean("controller")
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_compute(self, compute_id=None, name=None, force=False, **kwargs):
|
||||
def add_compute(self, compute_id=None, name=None, force=False, connect=True, **kwargs):
|
||||
"""
|
||||
Add a server to the dictionary of compute servers controlled by this controller
|
||||
|
||||
:param compute_id: Compute server identifier
|
||||
:param name: Compute name
|
||||
:param force: True skip security check
|
||||
:param connect: True connect to the compute immediately
|
||||
:param kwargs: See the documentation of Compute
|
||||
"""
|
||||
if compute_id not in self._computes:
|
||||
@@ -230,11 +231,13 @@ class Controller:
|
||||
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
||||
self._computes[compute.id] = compute
|
||||
self.save()
|
||||
yield from compute.connect()
|
||||
if connect:
|
||||
yield from compute.connect()
|
||||
self.notification.emit("compute.created", compute.__json__())
|
||||
return compute
|
||||
else:
|
||||
yield from self._computes[compute_id].connect()
|
||||
if connect:
|
||||
yield from self._computes[compute_id].connect()
|
||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||
return self._computes[compute_id]
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import asyncio
|
||||
import socket
|
||||
import json
|
||||
import uuid
|
||||
import sys
|
||||
import os
|
||||
import io
|
||||
|
||||
@@ -348,8 +349,9 @@ class Compute:
|
||||
try:
|
||||
response = yield from self._run_http_query("GET", "/capabilities")
|
||||
except (aiohttp.errors.ClientOSError, aiohttp.errors.ClientRequestError, aiohttp.ClientResponseError):
|
||||
# Try to reconnect after 2 seconds if server unavailable
|
||||
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self.connect()))
|
||||
# Try to reconnect after 2 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
||||
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
||||
asyncio.get_event_loop().call_later(2, lambda: asyncio.async(self.connect()))
|
||||
return
|
||||
|
||||
if "version" not in response.json:
|
||||
@@ -392,8 +394,9 @@ class Compute:
|
||||
if self._ws:
|
||||
yield from self._ws.close()
|
||||
|
||||
# Try to reconnect after 1 seconds if server unavailable
|
||||
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
|
||||
# Try to reconnect after 1 seconds if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
||||
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
||||
asyncio.get_event_loop().call_later(1, lambda: asyncio.async(self.connect()))
|
||||
self._ws = None
|
||||
self._cpu_usage_percent = None
|
||||
self._memory_usage_percent = None
|
||||
|
||||
Reference in new issue
Block a user