* Better documentation for the local backend

* Remove the fifos at the beginning of the test
This commit is contained in:
Fabio Manganiello 2017-12-22 02:52:56 +01:00
parent bdf964531f
commit 97adb1a191
2 changed files with 23 additions and 2 deletions

View file

@ -12,8 +12,22 @@ from platypush.message.request import Request
from platypush.message.response import Response
class LocalBackend(Backend):
""" Sends and receive messages on two distinct local FIFOs, one for
the requests and one for the responses """
"""
Sends and receive messages on two distinct local FIFOs, one for
the requests and one for the responses.
You can use this backend either to send local commands to push through
Pusher (or any other script), or debug. You can even send command on the
command line and read the responses in this way:
# Send the request. Remember: the JSON must be all on one line.
$ cat <<EOF > /tmp/platypush-requests.fifo
{"type": "request", "target": "node_name", "action": "shell.exec", "args": {"cmd":"echo ping"}, "origin": "node_name", "id": "put_an_id_here"}
EOF
$ cat /tmp/platypush-responses.fifo
ping
$
"""
def __init__(self, request_fifo, response_fifo, **kwargs):
super().__init__(**kwargs)

View file

@ -1,5 +1,6 @@
from .context import platypush, config_file, TestTimeoutException
import os
import sys
import logging
import unittest
@ -22,6 +23,12 @@ class TestLocal(unittest.TestCase):
backends = Config.get_backends()
self.assertTrue('local' in backends)
try: os.remove(Config.get_backends()['local']['request_fifo'])
except FileNotFoundError as e: pass
try: os.remove(Config.get_backends()['local']['response_fifo'])
except FileNotFoundError as e: pass
def test_local_shell_exec_flow(self):
self.start_sender()