From 0532b4de8a39937c92dc371e9b1b159c5e689ad6 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 4 Mar 2016 16:55:59 +0100 Subject: [PATCH] Fix logging issues with the controller --- gns3server/controller/controller_error.py | 3 +-- gns3server/controller/server.py | 6 ++++-- gns3server/web/response.py | 7 ++++--- requirements.txt | 2 +- tests/controller/test_server.py | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gns3server/controller/controller_error.py b/gns3server/controller/controller_error.py index 8f93dd1b..072d1a6d 100644 --- a/gns3server/controller/controller_error.py +++ b/gns3server/controller/controller_error.py @@ -17,6 +17,7 @@ class ControllerError(Exception): + def __init__(self, message): super().__init__(message) self._message = message @@ -26,5 +27,3 @@ class ControllerError(Exception): def __str__(self): return self._message - - diff --git a/gns3server/controller/server.py b/gns3server/controller/server.py index 047cf236..f9d99d62 100644 --- a/gns3server/controller/server.py +++ b/gns3server/controller/server.py @@ -19,6 +19,9 @@ from ..controller.controller_error import ControllerError from ..config import Config +import logging +log = logging.getLogger(__name__) + class ServerError(ControllerError): pass @@ -30,6 +33,7 @@ class Server: """ def __init__(self, server_id, protocol="http", host="localhost", port=8000, user=None, password=None): + log.info("Create server %s", server_id) self._id = server_id self._protocol = protocol self._host = host @@ -69,5 +73,3 @@ class Server: "connected": self._connected, "version": self._version } - - diff --git a/gns3server/web/response.py b/gns3server/web/response.py index 492d615a..fc87e809 100644 --- a/gns3server/web/response.py +++ b/gns3server/web/response.py @@ -17,6 +17,7 @@ import json import jsonschema +import asyncio import aiohttp.web import logging import sys @@ -32,7 +33,6 @@ renderer = jinja2.Environment(loader=jinja2.FileSystemLoader(get_resource('templ class Response(aiohttp.web.Response): def __init__(self, request=None, route=None, output_schema=None, headers={}, **kwargs): - self._route = route self._output_schema = output_schema self._request = request @@ -41,7 +41,8 @@ class Response(aiohttp.web.Response): headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__) super().__init__(headers=headers, **kwargs) - def start(self, request): + @asyncio.coroutine + def prepare(self, request): if log.getEffectiveLevel() == logging.DEBUG: log.info("%s %s", request.method, request.path_qs) log.debug("%s", dict(request.headers)) @@ -51,7 +52,7 @@ class Response(aiohttp.web.Response): log.debug(dict(self.headers)) if hasattr(self, 'body') and self.body is not None and self.headers["CONTENT-TYPE"] == "application/json": log.debug(json.loads(self.body.decode('utf-8'))) - return super().start(request) + return (yield from super().prepare(request)) def html(self, answer): """ diff --git a/requirements.txt b/requirements.txt index 083172b3..81c0f1c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ jsonschema>=2.4.0 -aiohttp==0.19.0 +aiohttp==0.21.2 Jinja2>=2.7.3 raven>=5.2.0 psutil>=3.0.0 diff --git a/tests/controller/test_server.py b/tests/controller/test_server.py index dd619644..2f04a2c9 100644 --- a/tests/controller/test_server.py +++ b/tests/controller/test_server.py @@ -44,6 +44,7 @@ def test_server_local(server): with patch("gns3server.config.Config.get_section_config", return_value={"local": True}): s = Server("test") + def test_json(server): assert server.__json__() == { "server_id": "my_server_id", @@ -54,4 +55,3 @@ def test_json(server): "connected": False, "version": None } -