Fixes tests and some PEP8.

This commit is contained in:
grossmj committed 2016-05-11 15:19:00 -06:00
1 parent 483431438a
commit ef7b4ef020
12 files changed
+39 -40

No files matched your search

+2 -2
View File
@@ -127,7 +127,7 @@ class Controller:
"""
return self._computes
def getCompute(self, compute_id):
def get_compute(self, compute_id):
"""
Return an compute or raise a 404
"""
@@ -162,7 +162,7 @@ class Controller:
except KeyError:
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
def removeProject(self, project):
def remove_project(self, project):
del self._projects[project.id]
@property
+16 -17
View File
@@ -49,7 +49,7 @@ class Compute:
self._password = None
self._connected = False
self._controller = controller
self._setAuth(user, password)
self._set_auth(user, password)
self._session = aiohttp.ClientSession()
self._version = None
@@ -61,7 +61,7 @@ class Compute:
def __del__(self):
self._session.close()
def _setAuth(self, user, password):
def _set_auth(self, user, password):
"""
Set authentication parameters
"""
@@ -120,7 +120,7 @@ class Compute:
@user.setter
def user(self, value):
self._setAuth(value, self._password)
self._set_auth(value, self._password)
@property
def password(self):
@@ -128,7 +128,7 @@ class Compute:
@user.setter
def password(self, value):
self._setAuth(self._user, value)
self._set_auth(self._user, value)
def __json__(self):
return {
@@ -141,7 +141,7 @@ class Compute:
}
@asyncio.coroutine
def streamFile(self, project, path):
def steam_file(self, project, path):
"""
Read file of a project and stream it
@@ -157,12 +157,12 @@ class Compute:
return response.content
@asyncio.coroutine
def httpQuery(self, method, path, data=None):
def http_query(self, method, path, data=None):
if not self._connected:
yield from self._connect()
if not self._connected:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
response = yield from self._runHttpQuery(method, path, data=data)
response = yield from self._run_http_query(method, path, data=data)
return response
@asyncio.coroutine
@@ -171,7 +171,7 @@ class Compute:
Check if remote server is accessible
"""
if not self._connected:
response = yield from self._runHttpQuery("GET", "/version")
response = yield from self._run_http_query("GET", "/version")
if "version" not in response.json:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
@@ -179,12 +179,11 @@ class Compute:
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
self._notifications = asyncio.async(self._connectNotification())
self._notifications = asyncio.async(self._connect_notification())
self._connected = True
@asyncio.coroutine
def _connectNotification(self):
def _connect_notification(self):
"""
Connect to the notification stream
"""
@@ -203,7 +202,7 @@ class Compute:
return "{}://{}:{}/v2/compute{}".format(self._protocol, self._host, self._port, path)
@asyncio.coroutine
def _runHttpQuery(self, method, path, data=None):
def _run_http_query(self, method, path, data=None):
with aiohttp.Timeout(10):
url = self._getUrl(path)
headers = {'content-type': 'application/json'}
@@ -237,7 +236,7 @@ class Compute:
if body and len(body):
try:
response.json = json.loads(body)
except json.JSONDecodeError:
except ValueError:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
if response.json is None:
response.json = {}
@@ -245,18 +244,18 @@ class Compute:
@asyncio.coroutine
def get(self, path):
return (yield from self.httpQuery("GET", path))
return (yield from self.http_query("GET", path))
@asyncio.coroutine
def post(self, path, data={}):
response = yield from self.httpQuery("POST", path, data)
response = yield from self.http_query("POST", path, data)
return response
@asyncio.coroutine
def put(self, path, data={}):
response = yield from self.httpQuery("PUT", path, data)
response = yield from self.http_query("PUT", path, data)
return response
@asyncio.coroutine
def delete(self, path):
return (yield from self.httpQuery("DELETE", path))
return (yield from self.http_query("DELETE", path))
+1 -1
View File
@@ -130,7 +130,7 @@ class Node:
for key, value in response.json.items():
if key == "console":
self._console = value
elif key in ["console_type", "name", "node_id", "project_id", "node_directory", "command_line", "status"]:
elif key in ["console_type", "name", "node_id", "project_id", "vm_directory", "command_line", "status"]:
pass
else:
self._properties[key] = value
+1 -1
View File
@@ -132,4 +132,4 @@ class UDPLink(Link):
"""
if self._capture_node:
compute = self._capture_node["node"].compute
return compute.streamFile(self._project, "tmp/captures/" + self._capture_file_name)
return compute.steam_file(self._project, "tmp/captures/" + self._capture_file_name)