From b05628c5f4679f00451df4422defdf974bf5e996 Mon Sep 17 00:00:00 2001 From: mprahl Date: Dec 21 2018 17:14:42 +0000 Subject: Add a way to run the functional tests using Vagrant --- diff --git a/.gitignore b/.gitignore index 551c641..e46eaee 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ coverage.xml htmlcov greenwave-test-cache.dbm* .pytest_cache +.vagrant/ diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..403a4f0 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,75 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby ts=2 sw=2 ai et: + +$script = <<-'SCRIPT' + set -e + dnf -y builddep /opt/greenwave/greenwave.spec + dnf -y install \ + git-core \ + postgresql-server \ + postgresql-contrib \ + python3-gunicorn \ + python3-psycopg2 \ + vim + + systemctl enable postgresql + postgresql-setup --initdb --unit postgresql + # Don't require authentication when connecting to Postgres + sed -i "s/\(peer\|ident\)/trust/g" /var/lib/pgsql/data/pg_hba.conf + systemctl restart postgresql + + # Create a "vagrant" role since the functional tests don't specify a user, + # therefore, the user running the tests will automatically be used + psql -U postgres -c "CREATE ROLE vagrant LOGIN;" + psql -U postgres -c "ALTER ROLE vagrant WITH Superuser;" + + # Clone ResultsDB and WaiverDB for the functional tests + git clone https://pagure.io/taskotron/resultsdb.git /opt/resultsdb + git clone https://pagure.io/waiverdb.git /opt/waiverdb + # Install the proper dependencies for ResultsDB and WaiverDB + # We can't use the spec file to install the ResultsDB dependencies because + # the functional tests use Python 2 to launch ResultsDB and the spec file + # will install Python 3 dependencies since the OS is Fedora + dnf -y install \ + fedmsg \ + python2-fedmsg \ + python2-alembic \ + python2-flask \ + python2-flask-restful \ + python2-flask-sqlalchemy \ + python2-iso8601 \ + python2-psycopg2 \ + python2-six \ + python2-sqlalchemy + dnf -y builddep /opt/waiverdb/waiverdb.spec + + # Clean any pyc or pyo files + find /opt/greenwave -regex '.*\(pyc\|pyo\)$' | xargs rm -f +SCRIPT + +$make_devenv = </dev/null; then + # Go to working directory after login + echo "cd $code_dir" >> ~/.bashrc + fi +DEVENV + +Vagrant.configure("2") do |config| + config.vm.box = "fedora/28-cloud-base" + config.vm.synced_folder "./", "/opt/greenwave" + # Disable the default share + config.vm.synced_folder ".", "/vagrant", disabled: true + config.vm.network "forwarded_port", guest_ip: "0.0.0.0", guest: 5005, host: 5005 + config.vm.provision "shell", inline: $script + config.vm.provision "shell", inline: $make_devenv, privileged: false + config.vm.provider "libvirt" do |v, override| + # If libvirt is being used, use sshfs for bidirectional folder syncing + override.vm.synced_folder "./", "/opt/greenwave", type: "sshfs", sshfs_opts_append: "-o nonempty" + v.memory = 1024 + end + config.vm.provider "virtualbox" do |v| + v.memory = 1024 + end +end diff --git a/docs/dev-guide.rst b/docs/dev-guide.rst index 9957dfe..ce9c843 100644 --- a/docs/dev-guide.rst +++ b/docs/dev-guide.rst @@ -55,6 +55,15 @@ The functional tests assume you have ResultsDB and WaiverDB git checkouts in find them in a different location by passing ``RESULTSDB`` or ``WAIVERDB`` environment variables. +If you'd rather not install all the dependencies necessary to run the functional +tests, you may use Vagrant to provision a throw-away virtual machine to run +the tests: + +.. toctree:: + :maxdepth: 2 + + vagrant + You should run smoke test after deploying on stage: .. code-block:: console diff --git a/docs/vagrant.rst b/docs/vagrant.rst new file mode 100644 index 0000000..004a828 --- /dev/null +++ b/docs/vagrant.rst @@ -0,0 +1,60 @@ +Vagrant for Greenwave Testing +============================= + +Install Vagrant on Fedora +------------------------- + +.. code-block:: console + + $ sudo dnf install vagrant vagrant-sshfs + + +Running Vagrant +--------------- + +To create a virtual machine (VM) configured to develop Greenwave with, run: + +.. code-block:: console + + $ sudo vagrant up + +At this point, your VM will be provisioned and your local Greenwave git repo +will automatically sync with ``/opt/greenwave`` in the VM. + +To enter the VM, run: + +.. code-block:: console + + $ sudo vagrant ssh + + +To stop the VM, run: + +.. code-block:: console + + $ sudo vagrant halt + + +To delete the VM, run: + +.. code-block:: console + + $ sudo vagrant destroy --force + + +Running The Tests +----------------- + +To run the unit tests, run: + +.. code-block:: console + + $ sudo vagrant ssh -c 'py.test-3 greenwave/tests/' + + +To run the functional tests, run: + +.. code-block:: console + + $ sudo vagrant ssh -c 'py.test-3 functional-tests/' +