diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00d58b77e56..49b5ca4cecd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1364,6 +1364,7 @@ repos: - msgpack==1.0.3 - packaging - looseversion + - tornado - repo: https://github.com/saltstack/invoke-pre-commit rev: v1.9.0 @@ -1387,6 +1388,7 @@ repos: - msgpack==1.0.3 - packaging - looseversion + - tornado - repo: https://github.com/saltstack/invoke-pre-commit rev: v1.9.0 diff --git a/salt/crypt.py b/salt/crypt.py index 067c84200b9..79ab58d617c 100644 --- a/salt/crypt.py +++ b/salt/crypt.py @@ -1308,7 +1308,7 @@ class SAuth(AsyncAuth): self.authenticate() 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 paradigm, it will update the master information from a fresh sign diff --git a/salt/netapi/rest_tornado/__init__.py b/salt/netapi/rest_tornado/__init__.py index b72b1c6bef4..ff0db64f6ea 100644 --- a/salt/netapi/rest_tornado/__init__.py +++ b/salt/netapi/rest_tornado/__init__.py @@ -39,8 +39,6 @@ def get_application(opts): except ImportError as err: log.error("ImportError! %s", err) return None - log = logging.getLogger() - log.setLevel(logging.DEBUG) mod_opts = opts.get(__virtualname__, {}) @@ -58,7 +56,6 @@ def get_application(opts): # if you have enabled websockets, add them! if mod_opts.get("websockets", False): - log.error("ENABEL WEBSOC") from . import saltnado_websockets token_pattern = r"([0-9A-Fa-f]{{{0}}})".format( @@ -76,11 +73,8 @@ def get_application(opts): (all_events_pattern, saltnado_websockets.AllEventsHandler), (formatted_events_pattern, saltnado_websockets.FormattedEventsHandler), ] - log.error("ENABEL WEBSOC - DONE") - application = salt.ext.tornado.web.Application( - paths, debug=True - ) + application = salt.ext.tornado.web.Application(paths, mod_opts.get("debug", False)) application.opts = opts application.mod_opts = mod_opts diff --git a/salt/netapi/rest_tornado/saltnado.py b/salt/netapi/rest_tornado/saltnado.py index e22fe7ec233..e5838afce90 100644 --- a/salt/netapi/rest_tornado/saltnado.py +++ b/salt/netapi/rest_tornado/saltnado.py @@ -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 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): """ 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 """ - log.error("BEGIN DISBATCH") ret = [] # 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.finish() except RuntimeError as exc: - log.exception("DISBATCH RUNTIME ERROR") - pass # Do we need any logging here? - log.error("END DISBATCH") + log.exception("Encountered Runtime Error") @salt.ext.tornado.gen.coroutine def get_minion_returns( @@ -1431,17 +1423,14 @@ class JobsSaltAPIHandler(SaltAPIHandler): # pylint: disable=W0223 """ # if you aren't authenticated, redirect to login if not self._verify_auth(): - log.error("AUTH ERROR") self.redirect("/login") return - log.error("LOWSTATE") if jid: self.lowstate = [{"fun": "jobs.list_job", "jid": jid, "client": "runner"}] else: self.lowstate = [{"fun": "jobs.list_jobs", "client": "runner"}] - log.error("DISBATCH") self.disbatch() diff --git a/salt/netapi/rest_tornado/saltnado_websockets.py b/salt/netapi/rest_tornado/saltnado_websockets.py index 449de985bae..e71db6cf99d 100644 --- a/salt/netapi/rest_tornado/saltnado_websockets.py +++ b/salt/netapi/rest_tornado/saltnado_websockets.py @@ -313,20 +313,18 @@ class AllEventsHandler( """ # pylint: disable=W0221 - #@salt.ext.tornado.gen.coroutine def get(self, token): """ Check the token, returns a 401 if the token is invalid. Else open the websocket connection """ - log.error("In the websocket get method") + log.debug("In the websocket get method") self.token = token # close the connection, if not authenticated if not self.application.auth.get_tok(token): log.debug("Refusing websocket connection, bad token!") self.send_error(401) return - log.error("In the websocket get method - get") return super().get(token) def open(self, token): # pylint: disable=W0221 @@ -334,7 +332,6 @@ class AllEventsHandler( Return a websocket connection to Salt representing Salt's "real time" event stream. """ - log.error("Open websocket") self.connected = False @salt.ext.tornado.gen.coroutine @@ -345,7 +342,7 @@ class AllEventsHandler( These messages make up salt's "real time" event stream. """ - log.error("Got websocket message %s", message) + log.debug("Got websocket message %s", message) if message == "websocket client ready": if self.connected: # TBD: Add ability to run commands in this branch @@ -372,7 +369,7 @@ class AllEventsHandler( def on_close(self, *args, **kwargs): """Cleanup.""" - log.error("In the websocket close method") + log.debug("In the websocket close method") self.close() def check_origin(self, origin): diff --git a/tests/pytests/functional/netapi/rest_tornado/test_webhooks_handler.py b/tests/pytests/functional/netapi/rest_tornado/test_webhooks_handler.py index a0f2f82d566..611a548937e 100644 --- a/tests/pytests/functional/netapi/rest_tornado/test_webhooks_handler.py +++ b/tests/pytests/functional/netapi/rest_tornado/test_webhooks_handler.py @@ -1,8 +1,8 @@ import urllib.parse -import salt.ext.tornado import pytest +import salt.ext.tornado import salt.utils.json from salt.netapi.rest_tornado import saltnado 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): + with patch("salt.utils.event.get_event") as get_event: with patch.dict(app.mod_opts, {"webhook_disable_auth": True}): event = MagicMock() diff --git a/tests/pytests/functional/netapi/rest_tornado/test_websockets_handler.py b/tests/pytests/functional/netapi/rest_tornado/test_websockets_handler.py index 92e7d785181..657f5770a3b 100644 --- a/tests/pytests/functional/netapi/rest_tornado/test_websockets_handler.py +++ b/tests/pytests/functional/netapi/rest_tornado/test_websockets_handler.py @@ -27,7 +27,11 @@ def http_server_port(http_server): 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( "/login", diff --git a/tests/unit/utils/test_http.py b/tests/unit/utils/test_http.py index d5f89183d9f..9f7a60ffa73 100644 --- a/tests/unit/utils/test_http.py +++ b/tests/unit/utils/test_http.py @@ -133,7 +133,7 @@ class HTTPTestCase(TestCase): url = "http://{host}:{port}/".format(host=host, port=port) 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 else: assert result == {"error": "[Errno 111] Connection refused"}, result