Compare commits

...

8 Commits

Author SHA1 Message Date
Christian Decker
c349654ff6
plugin: Exit if we fail to start a plugin
Signed-off-by: Christian Decker <@cdecker>
2018-11-25 18:33:56 +01:00
Christian Decker
a6a699b4c5
plugin: Make a common directory of plugins in contrib
No need to create a directory each.

Signed-off-by: Christian Decker <@cdecker>
2018-11-25 18:33:55 +01:00
Christian Decker
a8026ff599
pytest: Add a test for the plugin option passthrough
Signed-off-by: Christian Decker <@cdecker>
2018-11-25 18:33:54 +01:00
Christian Decker
3d36f4e63d
pytest: Use the pytest-timeout plugin to kill tasks
This will kill a test that was running for 550 seconds, so that we
get a traceback before the travis inactivity timeout of 600 seconds
kicks in. The traceback should show us which test got stuck and where
it got stuck.

Signed-off-by: Christian Decker <@cdecker>
2018-11-24 15:43:40 +01:00
Christian Decker
8d020933d9
pytest: Add two more dependencies
pytest was an indirect dependency so far, making that one
explicit, and the timeout plugin should allow us to kill a stuck test
before travis kills it, and thus allow us to see where it got stuck.

Signed-off-by: Christian Decker <@cdecker>
2018-11-24 15:43:39 +01:00
Christian Decker
50b6e21ce2
changelog: Add missing Changelog entry from PR #2075
Signed-off-by: Christian Decker <@cdecker>
2018-11-24 15:43:38 +01:00
Christian Decker
2282a306f4
docker: Update pytest dependencies in the builder image
Adds timeout and progress to the output.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-11-24 15:43:36 +01:00
Christian Decker
6e3ced1531
docs: Replace example method params with a long description
This matches the `verbose` field in `struct json_command`.

Signed-off-by: Christian Decker <@cdecker>
2018-11-24 15:00:11 +01:00
10 changed files with 78 additions and 14 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- JSON API: `getinfo` now returns `num_peers` `num_pending_channels`,
`num_active_channels` and `num_inactive_channels` fields.
- JSON API: use `\n\n` to terminate responses, for simplified parsing (pylightning now relies on this)
- Plugins: Added plugins to `lightningd` and implemented the option passthrough.
### Changed

View File

@ -38,7 +38,9 @@ ifeq ($(COMPAT),1)
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1
endif
PYTEST_OPTS := -v
# Timeout shortly before the 600 second travis silence timeout
# (method=thread to support xdist)
PYTEST_OPTS := -v --timeout=550 --timeout_method=thread
# This is where we add new features as bitcoin adds them.
FEATURES :=

View File

@ -51,4 +51,19 @@ RUN cd /tmp/ && \
rm -rf bitcoin.tar.gz /tmp/bitcoin-$BITCOIN_VERSION
RUN pip3 install --upgrade pip && \
python3 -m pip install python-bitcoinlib==0.7.0 pytest==3.0.5 setuptools==36.6.0 pytest-test-groups==1.0.3 flake8==3.5.0 pytest-rerunfailures==3.1 ephemeral-port-reserve==1.1.0 pytest-xdist==1.22.2 flaky==3.4.0 CherryPy==17.3.0 Flask==1.0.2
python3 -m pip install \
CherryPy==17.3.0 \
Flask==1.0.2 \
cheroot==6.5.2 \
ephemeral-port-reserve==1.1.0 \
flaky==3.4.0 \
pytest-benchmark==3.1.1 \
pytest-forked==0.2 \
pytest-timeout==1.3.3 \
pytest-xdist==1.22.2 \
pytest==3.8.1 \
python-bitcoinlib==0.7.0 \
tqdm==4.26.0 \
pytest-test-groups==1.0.3 \
flake8==3.5.0 \
pytest-rerunfailures==3.1

View File

@ -51,4 +51,19 @@ RUN cd /tmp/ && \
rm -rf bitcoin.tar.gz /tmp/bitcoin-$BITCOIN_VERSION
RUN pip3 install --upgrade pip && \
python3 -m pip install python-bitcoinlib==0.7.0 pytest==3.0.5 setuptools==36.6.0 pytest-test-groups==1.0.3 flake8==3.5.0 pytest-rerunfailures==3.1 ephemeral-port-reserve==1.1.0 pytest-xdist==1.22.2 flaky==3.4.0 CherryPy==17.3.0 Flask==1.0.2
python3 -m pip install \
CherryPy==17.3.0 \
Flask==1.0.2 \
cheroot==6.5.2 \
ephemeral-port-reserve==1.1.0 \
flaky==3.4.0 \
pytest-benchmark==3.1.1 \
pytest-forked==0.2 \
pytest-timeout==1.3.3 \
pytest-xdist==1.22.2 \
pytest==3.8.1 \
python-bitcoinlib==0.7.0 \
tqdm==4.26.0 \
pytest-test-groups==1.0.3 \
flake8==3.5.0 \
pytest-rerunfailures==3.1

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Simple plugin to show how to build new plugins for c-lightning
It demonstrates how a plugin communicates with c-lightning, how it registers
@ -19,7 +19,7 @@ def json_hello(request):
return greeting
def json_init(request):
def json_getmanifest(request):
global greeting
return {
"options": [
@ -37,7 +37,7 @@ def json_init(request):
}
def json_configure(request):
def json_init(request):
"""The main daemon is telling us the relevant cli options
"""
global greeting
@ -46,15 +46,10 @@ def json_configure(request):
return "ok"
def json_ping(request):
return "pong"
methods = {
'hello': json_hello,
'getmanifest': json_getmanifest,
'init': json_init,
'ping': json_ping,
'configure': json_configure,
}
partial = ""

View File

@ -68,7 +68,7 @@ this example:
{
"name": "gettime",
"description": "Returns the current time in {timezone}",
"params": ["timezone"]
"long_description": "Returns the current time in the timezone that is given as the only parameter.\nThis description may be quite long and is allowed to span multiple lines."
}
]
}

View File

@ -6,6 +6,7 @@
#include <ccan/opt/opt.h>
#include <ccan/pipecmd/pipecmd.h>
#include <ccan/tal/str/str.h>
#include <errno.h>
#include <lightningd/json.h>
#include <unistd.h>
@ -408,6 +409,10 @@ void plugins_init(struct plugins *plugins)
cmd[1] = NULL;
p->pid = pipecmdarr(&stdout, &stdin, NULL, cmd);
if (p->pid == -1)
fatal("error starting plugin '%s': %s", p->cmd,
strerror(errno));
list_head_init(&p->output);
p->buffer = tal_arr(p, char, 64);
p->used = 0;

View File

@ -1,3 +1,4 @@
pytest==3.8.1
CherryPy==17.3.0
Flask==1.0.2
cheroot==6.5.2
@ -8,3 +9,4 @@ pytest-forked==0.2
pytest-xdist==1.22.2
python-bitcoinlib==0.7.0
tqdm==4.26.0
pytest-timeout==1.3.3

29
tests/test_plugin.py Normal file
View File

@ -0,0 +1,29 @@
from fixtures import * # noqa: F401,F403
import subprocess
def test_option_passthrough(node_factory):
""" Ensure that registering options works.
First attempts without the plugin and then with the plugin.
"""
plugin_path = 'contrib/plugins/helloworld.py'
help_out = subprocess.check_output([
'lightningd/lightningd',
'--help'
]).decode('utf-8')
assert('--greeting' not in help_out)
help_out = subprocess.check_output([
'lightningd/lightningd',
'--plugin={}'.format(plugin_path),
'--help'
]).decode('utf-8')
assert('--greeting' in help_out)
# Now try to see if it gets accepted, would fail to start if the
# option didn't exist
n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Mars'})
n.stop()

View File

@ -772,7 +772,7 @@ class NodeFactory(object):
'valgrind',
'-q',
'--trace-children=yes',
'--trace-children-skip=*bitcoin-cli*',
'--trace-children-skip=*plugins*,*python*,*bitcoin-cli*',
'--error-exitcode=7',
'--log-file={}/valgrind-errors.%p'.format(node.daemon.lightning_dir)
]