Fix logging issues with the controller

This commit is contained in:
Julien Duponchelle 2016-03-04 16:55:59 +01:00
parent 4d77b2918e
commit 0532b4de8a
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
5 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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):
"""

View File

@ -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

View File

@ -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
}