mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix up pre-commit and lint
This commit is contained in:
parent
680301504f
commit
ade9da2703
8 changed files with 16 additions and 29 deletions
|
@ -1364,6 +1364,7 @@ repos:
|
||||||
- msgpack==1.0.3
|
- msgpack==1.0.3
|
||||||
- packaging
|
- packaging
|
||||||
- looseversion
|
- looseversion
|
||||||
|
- tornado
|
||||||
|
|
||||||
- repo: https://github.com/saltstack/invoke-pre-commit
|
- repo: https://github.com/saltstack/invoke-pre-commit
|
||||||
rev: v1.9.0
|
rev: v1.9.0
|
||||||
|
@ -1387,6 +1388,7 @@ repos:
|
||||||
- msgpack==1.0.3
|
- msgpack==1.0.3
|
||||||
- packaging
|
- packaging
|
||||||
- looseversion
|
- looseversion
|
||||||
|
- tornado
|
||||||
|
|
||||||
- repo: https://github.com/saltstack/invoke-pre-commit
|
- repo: https://github.com/saltstack/invoke-pre-commit
|
||||||
rev: v1.9.0
|
rev: v1.9.0
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ class SAuth(AsyncAuth):
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
return self._crypticle
|
return self._crypticle
|
||||||
|
|
||||||
def authenticate(self, _=None): # TODO: remove unused var
|
def authenticate(self): # TODO: remove unused var
|
||||||
"""
|
"""
|
||||||
Authenticate with the master, this method breaks the functional
|
Authenticate with the master, this method breaks the functional
|
||||||
paradigm, it will update the master information from a fresh sign
|
paradigm, it will update the master information from a fresh sign
|
||||||
|
|
|
@ -39,8 +39,6 @@ def get_application(opts):
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
log.error("ImportError! %s", err)
|
log.error("ImportError! %s", err)
|
||||||
return None
|
return None
|
||||||
log = logging.getLogger()
|
|
||||||
log.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
mod_opts = opts.get(__virtualname__, {})
|
mod_opts = opts.get(__virtualname__, {})
|
||||||
|
|
||||||
|
@ -58,7 +56,6 @@ def get_application(opts):
|
||||||
|
|
||||||
# if you have enabled websockets, add them!
|
# if you have enabled websockets, add them!
|
||||||
if mod_opts.get("websockets", False):
|
if mod_opts.get("websockets", False):
|
||||||
log.error("ENABEL WEBSOC")
|
|
||||||
from . import saltnado_websockets
|
from . import saltnado_websockets
|
||||||
|
|
||||||
token_pattern = r"([0-9A-Fa-f]{{{0}}})".format(
|
token_pattern = r"([0-9A-Fa-f]{{{0}}})".format(
|
||||||
|
@ -76,11 +73,8 @@ def get_application(opts):
|
||||||
(all_events_pattern, saltnado_websockets.AllEventsHandler),
|
(all_events_pattern, saltnado_websockets.AllEventsHandler),
|
||||||
(formatted_events_pattern, saltnado_websockets.FormattedEventsHandler),
|
(formatted_events_pattern, saltnado_websockets.FormattedEventsHandler),
|
||||||
]
|
]
|
||||||
log.error("ENABEL WEBSOC - DONE")
|
|
||||||
|
|
||||||
application = salt.ext.tornado.web.Application(
|
application = salt.ext.tornado.web.Application(paths, mod_opts.get("debug", False))
|
||||||
paths, debug=True
|
|
||||||
)
|
|
||||||
|
|
||||||
application.opts = opts
|
application.opts = opts
|
||||||
application.mod_opts = mod_opts
|
application.mod_opts = mod_opts
|
||||||
|
|
|
@ -506,11 +506,6 @@ class BaseSaltAPIHandler(salt.ext.tornado.web.RequestHandler): # pylint: disabl
|
||||||
# TODO: set a header or something??? so we know it was a timeout
|
# TODO: set a header or something??? so we know it was a timeout
|
||||||
self.application.event_listener.clean_by_request(self)
|
self.application.event_listener.clean_by_request(self)
|
||||||
|
|
||||||
def finish(self):
|
|
||||||
import traceback
|
|
||||||
log.error("FINISH CALLED: %s", "\n".join(traceback.format_stack()))
|
|
||||||
super().finish()
|
|
||||||
|
|
||||||
def on_finish(self):
|
def on_finish(self):
|
||||||
"""
|
"""
|
||||||
When the job has been done, lets cleanup
|
When the job has been done, lets cleanup
|
||||||
|
@ -924,7 +919,6 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
||||||
"""
|
"""
|
||||||
Disbatch all lowstates to the appropriate clients
|
Disbatch all lowstates to the appropriate clients
|
||||||
"""
|
"""
|
||||||
log.error("BEGIN DISBATCH")
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
# check clients before going, we want to throw 400 if one is bad
|
# check clients before going, we want to throw 400 if one is bad
|
||||||
|
@ -961,9 +955,7 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
||||||
self.write(self.serialize({"return": ret}))
|
self.write(self.serialize({"return": ret}))
|
||||||
self.finish()
|
self.finish()
|
||||||
except RuntimeError as exc:
|
except RuntimeError as exc:
|
||||||
log.exception("DISBATCH RUNTIME ERROR")
|
log.exception("Encountered Runtime Error")
|
||||||
pass # Do we need any logging here?
|
|
||||||
log.error("END DISBATCH")
|
|
||||||
|
|
||||||
@salt.ext.tornado.gen.coroutine
|
@salt.ext.tornado.gen.coroutine
|
||||||
def get_minion_returns(
|
def get_minion_returns(
|
||||||
|
@ -1431,17 +1423,14 @@ class JobsSaltAPIHandler(SaltAPIHandler): # pylint: disable=W0223
|
||||||
"""
|
"""
|
||||||
# if you aren't authenticated, redirect to login
|
# if you aren't authenticated, redirect to login
|
||||||
if not self._verify_auth():
|
if not self._verify_auth():
|
||||||
log.error("AUTH ERROR")
|
|
||||||
self.redirect("/login")
|
self.redirect("/login")
|
||||||
return
|
return
|
||||||
|
|
||||||
log.error("LOWSTATE")
|
|
||||||
if jid:
|
if jid:
|
||||||
self.lowstate = [{"fun": "jobs.list_job", "jid": jid, "client": "runner"}]
|
self.lowstate = [{"fun": "jobs.list_job", "jid": jid, "client": "runner"}]
|
||||||
else:
|
else:
|
||||||
self.lowstate = [{"fun": "jobs.list_jobs", "client": "runner"}]
|
self.lowstate = [{"fun": "jobs.list_jobs", "client": "runner"}]
|
||||||
|
|
||||||
log.error("DISBATCH")
|
|
||||||
self.disbatch()
|
self.disbatch()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -313,20 +313,18 @@ class AllEventsHandler(
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=W0221
|
# pylint: disable=W0221
|
||||||
#@salt.ext.tornado.gen.coroutine
|
|
||||||
def get(self, token):
|
def get(self, token):
|
||||||
"""
|
"""
|
||||||
Check the token, returns a 401 if the token is invalid.
|
Check the token, returns a 401 if the token is invalid.
|
||||||
Else open the websocket connection
|
Else open the websocket connection
|
||||||
"""
|
"""
|
||||||
log.error("In the websocket get method")
|
log.debug("In the websocket get method")
|
||||||
self.token = token
|
self.token = token
|
||||||
# close the connection, if not authenticated
|
# close the connection, if not authenticated
|
||||||
if not self.application.auth.get_tok(token):
|
if not self.application.auth.get_tok(token):
|
||||||
log.debug("Refusing websocket connection, bad token!")
|
log.debug("Refusing websocket connection, bad token!")
|
||||||
self.send_error(401)
|
self.send_error(401)
|
||||||
return
|
return
|
||||||
log.error("In the websocket get method - get")
|
|
||||||
return super().get(token)
|
return super().get(token)
|
||||||
|
|
||||||
def open(self, token): # pylint: disable=W0221
|
def open(self, token): # pylint: disable=W0221
|
||||||
|
@ -334,7 +332,6 @@ class AllEventsHandler(
|
||||||
Return a websocket connection to Salt
|
Return a websocket connection to Salt
|
||||||
representing Salt's "real time" event stream.
|
representing Salt's "real time" event stream.
|
||||||
"""
|
"""
|
||||||
log.error("Open websocket")
|
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
@salt.ext.tornado.gen.coroutine
|
@salt.ext.tornado.gen.coroutine
|
||||||
|
@ -345,7 +342,7 @@ class AllEventsHandler(
|
||||||
These messages make up salt's
|
These messages make up salt's
|
||||||
"real time" event stream.
|
"real time" event stream.
|
||||||
"""
|
"""
|
||||||
log.error("Got websocket message %s", message)
|
log.debug("Got websocket message %s", message)
|
||||||
if message == "websocket client ready":
|
if message == "websocket client ready":
|
||||||
if self.connected:
|
if self.connected:
|
||||||
# TBD: Add ability to run commands in this branch
|
# TBD: Add ability to run commands in this branch
|
||||||
|
@ -372,7 +369,7 @@ class AllEventsHandler(
|
||||||
|
|
||||||
def on_close(self, *args, **kwargs):
|
def on_close(self, *args, **kwargs):
|
||||||
"""Cleanup."""
|
"""Cleanup."""
|
||||||
log.error("In the websocket close method")
|
log.debug("In the websocket close method")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def check_origin(self, origin):
|
def check_origin(self, origin):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import salt.ext.tornado
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import salt.ext.tornado
|
||||||
import salt.utils.json
|
import salt.utils.json
|
||||||
from salt.netapi.rest_tornado import saltnado
|
from salt.netapi.rest_tornado import saltnado
|
||||||
from tests.support.mock import MagicMock, patch
|
from tests.support.mock import MagicMock, patch
|
||||||
|
@ -16,6 +16,7 @@ def app_urls():
|
||||||
|
|
||||||
|
|
||||||
async def test_hook_can_handle_get_parameters(http_client, app, content_type_map):
|
async def test_hook_can_handle_get_parameters(http_client, app, content_type_map):
|
||||||
|
|
||||||
with patch("salt.utils.event.get_event") as get_event:
|
with patch("salt.utils.event.get_event") as get_event:
|
||||||
with patch.dict(app.mod_opts, {"webhook_disable_auth": True}):
|
with patch.dict(app.mod_opts, {"webhook_disable_auth": True}):
|
||||||
event = MagicMock()
|
event = MagicMock()
|
||||||
|
|
|
@ -27,7 +27,11 @@ def http_server_port(http_server):
|
||||||
|
|
||||||
|
|
||||||
async def test_websocket_handler_upgrade_to_websocket(
|
async def test_websocket_handler_upgrade_to_websocket(
|
||||||
http_client, auth_creds, content_type_map, http_server_port, io_loop,
|
http_client,
|
||||||
|
auth_creds,
|
||||||
|
content_type_map,
|
||||||
|
http_server_port,
|
||||||
|
io_loop,
|
||||||
):
|
):
|
||||||
response = await http_client.fetch(
|
response = await http_client.fetch(
|
||||||
"/login",
|
"/login",
|
||||||
|
|
|
@ -133,7 +133,7 @@ class HTTPTestCase(TestCase):
|
||||||
|
|
||||||
url = "http://{host}:{port}/".format(host=host, port=port)
|
url = "http://{host}:{port}/".format(host=host, port=port)
|
||||||
result = http.query(url, raise_error=False)
|
result = http.query(url, raise_error=False)
|
||||||
if sys.platform.strtswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
assert result == {"error": "[Errno 10061] Unknown error"}, result
|
assert result == {"error": "[Errno 10061] Unknown error"}, result
|
||||||
else:
|
else:
|
||||||
assert result == {"error": "[Errno 111] Connection refused"}, result
|
assert result == {"error": "[Errno 111] Connection refused"}, result
|
||||||
|
|
Loading…
Add table
Reference in a new issue