1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix stacktrace when exiting with Ctrl + C

Fix #547
This commit is contained in:
Julien Duponchelle 2016-06-02 13:44:12 +02:00
parent f47eb326c7
commit 4afa5994e8
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
5 changed files with 31 additions and 1 deletions

View File

@ -125,10 +125,17 @@ class Controller:
:param compute_id: Compute server identifier
"""
compute = self.get_compute(compute_id)
yield from compute.close()
del self._computes[compute_id]
self.save()
self.notification.emit("compute.deleted", compute.__json__())
@asyncio.coroutine
def close(self):
log.info("Close controller")
for compute in self._computes.values():
yield from compute.close()
@property
def notification(self):
"""

View File

@ -93,6 +93,11 @@ class Compute:
self._connected = False
self._controller.notification.emit("compute.updated", self.__json__())
@asyncio.coroutine
def close(self):
self._connected = False
self._session.close()
@property
def version(self):
"""

View File

@ -91,6 +91,9 @@ class WebServer:
yield from self._handler.finish_connections()
self._handler = None
if Config.instance().get_section_config("Server").getboolean("controller"):
yield from Controller.instance().close()
for module in MODULES:
log.debug("Unloading module {}".format(module.__name__))
m = module.instance()
@ -182,6 +185,7 @@ class WebServer:
# Add a periodic callback to give a chance to process signals on Windows
# because asyncio.add_signal_handler() is not supported yet on that platform
# otherwise the loop runs outside of signal module's ability to trap signals.
def wakeup():
loop.call_later(0.5, wakeup)
loop.call_later(0.5, wakeup)
@ -189,7 +193,6 @@ class WebServer:
server_config = Config.instance().get_section_config("Server")
ssl_context = None
if server_config.getboolean("ssl"):
if sys.platform.startswith("win"):

View File

@ -205,6 +205,12 @@ def test_streamFile(project, async_run, compute):
mock.assert_called_with("GET", "https://example.com:84/v2/compute/projects/{}/stream/test/titi".format(project.id), auth=None)
def test_close(compute, async_run):
assert compute.connected is True
async_run(compute.close())
assert compute.connected is False
def test_update(compute, controller, async_run):
compute._controller._notification = MagicMock()
compute.name = "Test"

View File

@ -91,12 +91,14 @@ def test_deleteCompute(controller, controller_config_path, async_run):
c = async_run(controller.add_compute(compute_id="test1"))
assert len(controller.computes) == 1
controller._notification = MagicMock()
c._connected = True
async_run(controller.delete_compute("test1"))
assert len(controller.computes) == 0
controller._notification.emit.assert_called_with("compute.deleted", c.__json__())
with open(controller_config_path) as f:
data = json.load(f)
assert len(data["computes"]) == 0
assert c.connected is False
def test_addComputeConfigFile(controller, controller_config_path, async_run):
@ -174,3 +176,10 @@ def test_getProject(controller, async_run):
assert controller.get_project(uuid1) == project
with pytest.raises(aiohttp.web.HTTPNotFound):
assert controller.get_project("dsdssd")
def test_close(controller, async_run):
c = async_run(controller.add_compute(compute_id="test1"))
c._connected = True
async_run(controller.close())
assert c.connected is False