Commit 300d2fd3 authored by Furkan Mustafa's avatar Furkan Mustafa

Merge branch 'upgrade-tornado' into 'dev-0.0.9'

Upgrade tornado

See merge request !52
parents 49714799 8e851d2f
......@@ -26,7 +26,7 @@ from typing import Callable, Any
from tornado import httputil
from tornado import web
from tornado.web import MissingArgumentError, HTTPError
from tornado.web import HTTPError
LOGGER = logging.getLogger('beiran.cmd_req_handler')
......@@ -117,7 +117,6 @@ class RPCEndpoint(BaseRPCEndpoint, JSONEndpoint):
to appropriate methods.
"""
# pylint: disable=arguments-differ
@web.asynchronous
async def post(self) -> None:
"""
Requires `cmd` arguments and checks if it is in available public method list.
......@@ -127,17 +126,17 @@ class RPCEndpoint(BaseRPCEndpoint, JSONEndpoint):
HTTPError: if `cmd` is not in allowed methods.
"""
# If 'default' parameter of get_argument function is not provided,
# the argument is considered to be required.
# If it is missing, 'MissingArgumentError' will be raised.
# pylint: disable=no-value-for-parameter
command = self.get_argument('cmd')
if not command:
raise MissingArgumentError('cmd')
if command not in self.public_methods:
if command not in self.public_methods: # type: ignore
raise HTTPError(
400,
"This endpoint does not implement `{}`. `cmd may be one of those {}".format(
command, ', '.join(self.public_methods))
command, ', '.join(self.public_methods)) # type: ignore
)
LOGGER.debug("Node endpoint is invoked with command `%s`", command)
......
......@@ -19,6 +19,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""HTTP and WS API implementation of beiran daemon"""
from typing import Union
from tornado import websocket, web
from tornado.options import define
from tornado.web import HTTPError
......@@ -30,7 +32,6 @@ from beiran.cmd_req_handler import RPCEndpoint, rpc
from beiran.daemon.common import Services
from beiran.daemon.lib import get_listen_address
define('listen_address',
group='webserver',
default=get_listen_address(),
......@@ -62,10 +63,13 @@ class EchoWebSocket(websocket.WebSocketHandler):
"""
Services.get_logger().info("WebSocket opened")
def on_message(self, message: str):
def on_message(self, message: Union[str, bytes]):
""" Received message from websocket
"""
self.write_message(u"You said: " + message)
if isinstance(message, bytes):
message = message.decode("utf-8") # type: ignore
self.write_message(u"You said: " + message) # type: ignore
def on_close(self):
""" Monitor if websocket is closed
......@@ -79,7 +83,8 @@ class ApiRootHandler(web.RequestHandler):
def data_received(self, chunk):
pass
def get(self, *args, **kwargs):
def get(self):
"""Get the local node's version"""
self.set_header("Content-Type", "application/json")
self.write('{"version":"' + Services.daemon.nodes.local_node.version + '"}')
self.finish()
......@@ -91,8 +96,6 @@ class NodeInfo(web.RequestHandler):
def data_received(self, chunk):
pass
# pylint: disable=arguments-differ
@web.asynchronous
async def get(self, uuid: str = None):
"""Retrieve info of the node by `uuid` or the local node"""
......@@ -208,6 +211,7 @@ class StatusHandler(web.RequestHandler):
# pylint: disable=arguments-differ
def get(self):
"""Get status of plugins"""
status_response = {
"status": "ok",
"sync_state_version": Services.daemon.sync_state_version,
......@@ -237,6 +241,7 @@ class PluginStatusHandler(web.RequestHandler):
# pylint: disable=arguments-differ
def get(self, plugin_id: str):
"""Get the status of a plugin"""
if not plugin_id in Services.plugins:
raise HTTPError(status_code=404, log_message="Plugin Not Found")
......
tornado>=5.0.1,<6.0.0
tornado>=6.0.0,<6.1.0
peewee==3.10.0
click==6.7
tabulate==0.8.2
......
......@@ -52,7 +52,7 @@ class UnixResolver(Resolver):
self.close()
@gen.coroutine
def resolve(self, host: str, port: int, family: int = socket.AF_UNSPEC, callback=None):
def resolve(self, host: str, port: int, family: int = socket.AF_UNSPEC):
"""
Unix Socket resolve
Args:
......@@ -63,7 +63,7 @@ class UnixResolver(Resolver):
"""
if host == 'unixsocket':
raise gen.Return([(socket.AF_UNIX, self.socket_path)])
result = yield self.resolve(host, port, family, callback)
result = yield self.resolve(host, port, family)
raise gen.Return(result)
......
......@@ -339,7 +339,7 @@ class ImageList(RPCEndpoint):
self.finish() # type: ignore
@staticmethod
async def pull_routine_distributed(tag_or_digest: str, rpc_call: "RPCEndpoint" = None, # pylint: disable=too-many-locals,too-many-branches, too-many-statements
async def pull_routine_distributed(tag_or_digest: str, rpc_call: "ImageList" = None, # pylint: disable=too-many-locals,too-many-branches, too-many-statements
wait: bool = False, show_progress: bool = False) -> None:
"""Coroutine to pull image (download distributed layers)
"""
......@@ -499,7 +499,7 @@ class ImageList(RPCEndpoint):
@staticmethod
async def pull_routine(image_identifier: str, node_identifier: str = None, # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements, too-many-return-statements
rpc_call: "RPCEndpoint" = None, wait: bool = False,
rpc_call: "ImageList" = None, wait: bool = False,
show_progress: bool = False, force: bool = False) -> str:
"""Coroutine to pull image in cluster
"""
......
......@@ -7,4 +7,4 @@ click==6.7
tabulate==0.8.3
pyee==6.0.0
peewee==3.10.0
tornado>=5.0.1,<6.0.0
tornado>=6.0.0,<6.1.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment