Streisand has a .travis.yml
file that powers continuous integration
tests. It works by installing required
test tools (e.g. shellcheck) and an Ansible environment on a Ubuntu Trusty
(14.04) machine.
The test/test.sh
wrapper script is invoked to perform tests and supports
an argument for specifying what actions should be taken. The following are
supported arguments:
-
"setup" prepares the local environment for running a Streisand LXC instance. The instance is managed via LXD.
-
"syntax" checks the Streisand playbooks for Ansible syntax errors.
-
"run" runs the CI tests. It assumes the local environment is already prepared from a previous "setup" run.
-
"ci" combines "setup" and "run".
-
"full" performs the same as "ci" but additionally adds verbose output to the Ansible run. This is very verbose but can be useful for diagnosing tricky broken builds.
-
By default the wrapper will run "syntax".
Some playbooks/tasks can't be run in CI because of limitations imposed by the
containerization or Travis. One example of this is installing a Tor relay. To
work around this playbooks/tasks that break in CI can be gated on the
streisand_ci
variable, which is true
only for CI runs. Where possible it's
best to minimize the use of this variable for conditional execution because we
want as much code to be tested as possible!
By design LXC containers share the Linux kernel they use with the host machine. This means playbooks/services that require a kernel module (e.g. Libreswan) must build the kernel module on the host machine.
For local testing Streisand includes a Vagrantfile
that creates two virtual
machines: streisand-host
and streisand-client
.
The streisand-host
machine is provisioned with the standard Streisand
playbooks and replicates a Streisand server created with a cloud provider, but
running on your local computer.
Note that a throwaway SSH key pair is created in the streisand-host
virtual
machine in the location specified in the Anisible variable
streisand_ssh_private_key
. This is not needed to SSH into the virtual machine
using vagrant ssh streisand-host
and is only used by the provisioning process.
The streisand-client
machine is provisioned specifically to act as a client of
the streisand-host
. It connects to the streiand-host
's HTTPS gateway to
download client configuration files that are used by test scripts to ensure that
services work "end-to-end".
-
Clone the Streisand repository and enter the directory.
git clone https://github.com/StreisandEffect/streisand.git && cd streisand
-
If this is your first time following these steps, create & start the
streisand-host
andstreisand-client
virtual machines with:`vagrant up`
-
To re-run the Streisand playbooks, the virtual machines can be re-provisioned with:
`vagrant up --provision`
For testing an existing Streisand server there is a Vagrantfile.remotetest
Vagrantifle. As compared to the stock Vagrantfile
for local testing the
Vagrantfile.remotetest
Vagrantfile does not include a streisand-host
machine. This remotetest variant is useful to "smoke test" an existing
Streisand server, or to provide end-to-end testing of a cloud provisioner.
-
Clone the Streisand repository and enter the directory.
git clone https://github.com/StreisandEffect/streisand.git && cd streisand
-
Run the
remote_test.sh
helper script and give it the remote server IP & gateway password when prompted:./tests/remote_test.sh
-
Clone the Streisand repository and enter the directory.
git clone https://github.com/StreisandEffect/streisand.git && cd streisand
-
Edit
Vagrantfile.remotetest
and replace thestreisand_ip
host variable with the IP of the remote server. -
Create the
generated-docs/gateway-password.txt
file with the gateway password of the Streisand server -
If this is your first time following these steps, create & start the
streisand-client
virtual machine with:VAGRANT_VAGRANTFILE=Vagrantfile.remotetest vagrant up
-
To re-run the Streisand playbooks, the virtual machines can be re-provisioned with:
VAGRANT_VAGRANTFILE=Vagrantfile.remotetest vagrant up --provision
-
Uncomment the lines setting the
ansible.verbose
value in the Vagrantfiles to increase the verbosity of the Ansible playbook runs. -
Skip the
./tests/remote_test.sh
prompts usingprintf
:STREISAND_SERVER_IP=XX.XX.XX.XX; STREISAND_PASSWORD='gateway-password-goes-here'; printf "$STREISAND_SERVER_IP\n$STREISAND_PASSWORD\n" | ./tests/remote_test.sh