4.2.4. Test Server

The test server is created because this repositories tests are oversized for regular CI/CD jobs. Besides those usually run inside Docker containers and this tests can’t.

Thus we have a large test suite running weekly and a smaller one daily - each for the main and latest develop branch.

This is mainly based on tests by Molecule and virtualization by Incus:

../../_images/test_server.png

One big Incus VM continuously spawns shortliving Incus containers

See the previous example Examples -> Production -> Extended for information how to set up an Incus host itself.

In practice this VM is deployed on another Incus host thus using nested KVM virtualization.

This is roughly created with the following steps:

  • Create the VM itself:

$ incus launch images:debian/bookworm/cloud test-server --vm
  • Inside test-server install Ansible and get this repository as in previous examples

  • Set connection information for postfix mailgate or ssmtp dummy email address inside inventories/test/test_server/group_vars/test/vars.yml

  • Run the playbook locally:

$ ansible-playbook -i inventories/test/test_server/ -c local playbooks/test_server.yml
  • Verify it is working:

$ sudo su tester -s /bin/bash
$ crontab -l
$ cd /opt/git_repos/
$ bash large_on_develop.sh
  • From the outter Incus host create a snapshot and a cron job for daily restores:

$ incus snapshot create test-server setup
$ crontab -e
Add two lines to bottom:
0 1 * * * /bin/bash -c "(echo '' && date && echo 'Starting' && incus start test-server) >> /home/debian/test-server.log 2>&1"
0 12 * * * /bin/bash -c "(echo '' && date && echo 'Stopping and restoring' && incus stop test-server && incus snapshot restore test-server setup) >> /home/debian/test-server.log 2>&1"