Changeset - fe8dc0049e18
[Not reviewed]
0 2 2
Branko Majic (branko) - 5 years ago 2018-11-27 20:48:36
branko@majic.rs
GC-28: Added initial set-up for running tests within Vagrant machine:

- Added Vagrantfile that deploys Debian 9 Stretch and provisions it.
- Added provisioning script that will set-up multiple Python versions.
- Updated development instructions to include information on how to
use Vagrant to run all the tests.
- Ignore Vagrant artifacts in gitignore.
4 files changed with 129 insertions and 0 deletions:
0 comments (0 inline, 0 general)
.gitignore
Show inline comments
 
@@ -22,3 +22,6 @@ coverage/
 

	
 
# Ignore project temporary directory.
 
tmp/
 

	
 
# Ignore Vagrant artifacts.
 
.vagrant
 
\ No newline at end of file
Vagrantfile
Show inline comments
 
new file 100644
 
# -*- mode: ruby -*-
 
# vi: set ft=ruby :
 

	
 
# All Vagrant configuration is done below. The "2" in Vagrant.configure
 
# configures the configuration version (we support older styles for
 
# backwards compatibility). Please don't change it unless you know what
 
# you're doing.
 
Vagrant.configure("2") do |config|
 
  config.vm.box = "debian/contrib-stretch64"
 
  config.vm.hostname = "gimmecert-testing"
 

	
 
  config.vm.provision "shell", path: "provision.sh"
 
end
docs/development.rst
Show inline comments
 
@@ -137,6 +137,44 @@ Tests can also be run using `tox <https://tox.readthedocs.io/>`_:
 
  tox -e doc,lint
 

	
 

	
 
Running tests on all supproted Python versions
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
With a range of different Python versions supported, it might be
 
somewhat difficult to run the tests against all the posible versions
 
of Python depending on distribution used for development.
 

	
 
The projects comes with a `Vagrantfile <https://www.vagrantup.com/>`_
 
to make this easier. To run all tests within a Vagrant machine,
 
perform the following steps:
 

	
 
1. Go to project root directory::
 

	
 
     workon gimmecert
 

	
 
2. Bring up the Vagrant machine (this may take a while since it will
 
   build the necessary Python versions)::
 

	
 
     vagrant up
 

	
 
3. Log-in into the Vagrant machine::
 

	
 
     vagrant ssh
 

	
 
4. Change directory::
 

	
 
     cd /vagrant
 

	
 
5. Clean Python caches to ensure your main development machine files
 
   do not interfere::
 

	
 
     py3clean
 

	
 
6. Run tests against all available environments::
 

	
 
     tox
 

	
 

	
 
Building documentation
 
----------------------
 

	
provision.sh
Show inline comments
 
new file 100755
 
#!/bin/bash
 
#
 
# Provisioning script for the Vagrant test environment. Do not run
 
# outside of vagrant machine.
 
#
 

	
 
# Fail as soon as a command fails.
 
set -e
 

	
 
hostname=$(hostname)
 

	
 
if [[ $hostname != "gimmecert-testing" ]]; then
 
    echo "Script should only be run on Vagrant testing machine."
 
    exit 1
 
fi
 

	
 
# Update apt caches.
 
apt-get update -qq
 

	
 
# Install development tools.
 
apt-get install -qq -y git virtualenv
 

	
 
# Install Python build dependencies.
 
apt-get install -qq -y make build-essential libssl1.0-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libffi-dev
 

	
 
# Clone the pyenv and pyenv-virtualenv tools for setting-up multiple
 
# Python installations.
 
if [[ ! -e /home/vagrant/.pyenv ]]; then
 
    sudo -i -u vagrant git clone https://github.com/pyenv/pyenv/ /home/vagrant/.pyenv
 
fi
 

	
 
if [[ ! -e /home/vagrant/.pyenv/plugins/pyenv-virtualenv ]]; then
 
    sudo -i -u vagrant git clone https://github.com/pyenv/pyenv-virtualenv.git /home/vagrant/.pyenv/plugins/pyenv-virtualenv
 
fi
 

	
 
# Enable pyenv for the user.
 
bash_profile="/home/vagrant/.bash_profile"
 

	
 
if [[ ! -e $bash_profile ]] || ! grep -q "export PYENV_ROOT" "$bash_profile"; then
 
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> "$bash_profile"
 
fi
 

	
 
if [[ ! -e $bash_profile ]] || ! grep -q "export PATH=" "$bash_profile"; then
 
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> "$bash_profile"
 
fi
 

	
 
if [[ ! -e $bash_profile ]] || ! grep -q 'pyenv init' "$bash_profile"; then
 
    echo 'eval "$(pyenv init -)"' >> "$bash_profile"
 
fi
 

	
 
chown vagrant:vagrant "$bash_profile"
 
chmod 0640 "$bash_profile"
 

	
 
# List of Python versions to install.
 
python_versions=("3.4.9" "3.5.6" "3.6.7" "3.7.1")
 

	
 
# Install various Python versions.
 
for python_version in "${python_versions[@]}"; do
 
    sudo -i -u vagrant pyenv install -s "$python_version"
 
done
 

	
 
# Register them globally.
 
sudo -i -u vagrant pyenv global system "${python_versions[@]}"
 

	
 
# Set-up virtual environment for running tox.
 
if [[ ! -f /home/vagrant/virtualenv-tox/bin/activate ]]; then
 
    sudo -i -u vagrant virtualenv --prompt '(tox) ' -q -p /usr/bin/python3 /home/vagrant/virtualenv-tox
 
fi
 

	
 
if [[ ! -e $bash_profile ]] || ! grep -q "source /home/vagrant/virtualenv-tox/bin/activate" "$bash_profile"; then
 
    echo 'source /home/vagrant/virtualenv-tox/bin/activate' >> "$bash_profile"
 
fi
 

	
 
# Install development requirements.
 
sudo -i -u vagrant pip install -q -e "/vagrant[devel]"
0 comments (0 inline, 0 general)