Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin support. #941

Merged
merged 6 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ synapse) and place it within the homeserver configuration directory

.. _dictConfig: https://docs.python.org/2/library/logging.config.html#logging.config.dictConfig

Plugins
~~~~~~~

Sytest supports plugins. Plugins follow the same project structure as sytest and can be placed
valkum marked this conversation as resolved.
Show resolved Hide resolved
in the ``plugins`` directory. They should contain the ``lib/SyTest/HomeserverFactory`` and
``lib/SyTest/Homeserver``, or ``lib/SyTest/Output`` directories, similar to the root of the sytest repository.
The path of the plugins directory can be overridden via the ``SYTEST_PLUGINS`` environment variable.

Currently only ``Homeserver`` and ``Output`` implementations are supported in plugins.

See https://github.com/valkum/sytest_conduit for an example of a plugin.

Developing
----------

Expand Down
12 changes: 12 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ docker run --rm -it ... matrixdotorg/sytest-synapse:py37 tests/20profile-events.

The containers are built by executing `./build.sh`. You will then have to push
them up to Docker Hub with `./push.sh`.

## Loading sytest plugins at start

To utilize sytest plugins and automatically load them on start set the `PLUGINS` environment variable.
This should be one or more URLs to tar.gz files separated by whitespaces.

The bootstrap script will search for `${SYTEST_TARGET}_sytest.sh` in all plugins. This can be used to
execute custom scripts like the ones in `/scripts/`

```
docker run --rm -it -e PLUGINS="https://host/path/to/hs_plugin.tar.gz https://host2/path/to/output_plugin.tar.gz"
```
22 changes: 20 additions & 2 deletions docker/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ else

mkdir -p /sytest
tar -C /sytest --strip-components=1 -xf sytest.tar.gz

if [ -n "$PLUGINS" ]; then
valkum marked this conversation as resolved.
Show resolved Hide resolved
mkdir /sytest/plugins
echo "--- Downloading plugins for sytest"
IFS=' '; for plugin in $PLUGINS; do
plugindir=$(mktemp -d --tmpdir=/sytest/plugins)
wget -q $plugin -O plugin.tar.gz || {
echo "Failed to download plugin: $plugin" >&2
exit 1
}
tar -C $plugindir --strip-components=1 -xf plugin.tar.gz
done
fi
fi

echo "--- Preparing sytest for ${SYTEST_TARGET}"
Expand All @@ -51,6 +64,11 @@ elif [ -x "/sytest/docker/${SYTEST_TARGET}_sytest.sh" ]; then
exec "/sytest/docker/${SYTEST_TARGET}_sytest.sh" "$@"

else
echo "sytest runner script for ${SYTEST_TARGET} not found" >&2
exit 1
PLUGIN_RUNNER=$(find /sytest/plugins/ -type f -name "${SYTEST_TARGET}_sytest.sh" -print)
if [ -n PLUGIN_RUNNER ]; then
exec ${PLUGIN_RUNNER} "$@"
else
echo "sytest runner script for ${SYTEST_TARGET} not found" >&2
exit 1
fi
fi
8 changes: 7 additions & 1 deletion run-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Data::Dump qw( pp );
use File::Basename qw( basename );
use File::Spec::Functions qw( catdir );
use Getopt::Long qw( :config no_ignore_case gnu_getopt );
use IO::Socket::SSL;
use List::Util 1.33 qw( first all any maxstr max );
Expand All @@ -34,17 +35,22 @@
: undef;
});

my $plugin_dir = $ENV{"SYTEST_PLUGINS"} || "plugins"; # Read plugin dir from env var SYTEST_PLUGINS or fallback to plugins
richvdh marked this conversation as resolved.
Show resolved Hide resolved
my @plugins = grep { -d } glob(catdir($plugin_dir, "*")); # Read all plugins/<plugin>
my @lib_dirs = map { catdir($_, "lib") } @plugins;

use Module::Pluggable
sub_name => "output_formats",
search_path => [ "SyTest::Output" ],
search_dirs => \@lib_dirs,
require => 1;

use Module::Pluggable
sub_name => "homeserver_factories",
search_path => [ "SyTest::HomeserverFactory" ],
search_dirs => \@lib_dirs,
require => 1;


binmode(STDOUT, ":utf8");

our $WANT_TLS = 1; # This is shared with the test scripts
Expand Down