mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix merged forwarded code and test
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
ad4821b87f
commit
e8a392577d
3 changed files with 9 additions and 13 deletions
|
@ -543,14 +543,15 @@ class RequestServer(salt.transport.base.DaemonizedRequestServer):
|
|||
await self._socket.send(self.encode_payload(reply))
|
||||
except asyncio.exceptions.TimeoutError:
|
||||
continue
|
||||
except salt.exceptions.SaltDeserializationError:
|
||||
await self._socket.send(self.encode_payload({"msg": "bad load"}))
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
log.error("Exception in request handler", exc_info=True)
|
||||
break
|
||||
|
||||
async def handle_message(self, stream, payload):
|
||||
payload = self.decode_payload(payload)
|
||||
try:
|
||||
payload = self.decode_payload(payload)
|
||||
except salt.exceptions.SaltDeserializationError:
|
||||
return {"msg": "bad load"}
|
||||
return await self.message_handler(payload)
|
||||
|
||||
def encode_payload(self, payload):
|
||||
|
|
|
@ -3,7 +3,6 @@ import pytest
|
|||
|
||||
import salt.config
|
||||
import salt.transport.zeromq
|
||||
from tests.support.mock import MagicMock
|
||||
|
||||
|
||||
async def test_req_server_garbage_request(io_loop):
|
||||
|
@ -22,14 +21,9 @@ async def test_req_server_garbage_request(io_loop):
|
|||
byts = msgpack.dumps({"foo": "bar"})
|
||||
badbyts = byts[:3] + b"^M" + byts[3:]
|
||||
|
||||
valid_response = msgpack.dumps("Invalid payload")
|
||||
|
||||
stream = MagicMock()
|
||||
request_server.stream = stream
|
||||
|
||||
try:
|
||||
await request_server.handle_message(stream, badbyts)
|
||||
ret = await request_server.handle_message(None, badbyts)
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
pytest.fail(f"Exception was raised {exc}")
|
||||
|
||||
request_server.stream.send.assert_called_once_with(valid_response)
|
||||
assert ret == {"msg": "bad load"}
|
||||
|
|
|
@ -27,6 +27,7 @@ from mock import (
|
|||
ANY,
|
||||
DEFAULT,
|
||||
FILTER_DIR,
|
||||
AsyncMock,
|
||||
MagicMock,
|
||||
Mock,
|
||||
NonCallableMagicMock,
|
||||
|
@ -202,7 +203,7 @@ class MockFH:
|
|||
)
|
||||
elif not self.binary_mode and content_type is not str:
|
||||
raise TypeError(
|
||||
"write() argument must be str, not {}".format(content_type.__name__)
|
||||
f"write() argument must be str, not {content_type.__name__}"
|
||||
)
|
||||
|
||||
def _writelines(self, lines):
|
||||
|
@ -233,7 +234,7 @@ class MockCall:
|
|||
ret = ret[:-2]
|
||||
else:
|
||||
for key, val in self.kwargs.items():
|
||||
ret += "{}={}".format(salt.utils.stringutils.to_str(key), repr(val))
|
||||
ret += f"{salt.utils.stringutils.to_str(key)}={repr(val)}"
|
||||
ret += ")"
|
||||
return ret
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue