Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Forked from lazypower/00-README.md
Created February 22, 2014 00:28
Show Gist options
  • Save marcoceppi/9146615 to your computer and use it in GitHub Desktop.
Save marcoceppi/9146615 to your computer and use it in GitHub Desktop.

Testing Juju Charms with Vagrant

Notes:

Place the vagrant file in your $CHARM_DIR root. This may move at a later date, but for internal testing, just put it there and stop fighting me on this.

Also fetch the supporting juju-vagrant-setup.sh script - this is the driver behind the vagrant automation until we find a better process to execute the code. Embedding bash inline in a yaml file is supported: but the yaml parser chokes if you have #'s inline. It interprets the rest of the line as a comment regardless of scope. end. of. story.

Instructions on Use:

With the Vagrantfile, and juju-vagrant-setup.sh scripts in $CHARM_DIR

vagrant up

Vagrant will fetch the base box, import it into Virtualbox, and kick off a test execution.

The script does the following things for you:

  • Setup a clean Trusty Tahr server image with juju-core installed by default
  • Installs the Juju Local provider
  • Configures your local provider, and generates an SSH key for the vagrant user
  • Installs your tests pre-setup file 00-setup (this is a convention used by charm add tests)
  • Kicks off any tests to be run against the local provider, as long as they are chmod +x

If there are executable files in the tests directory - they will automatically be run.

Workflow

charm add tests

hack away at your awesome amulet test, making sure you add any dependencies to 00-setup

vagrant up

on your first test execution. Afterwords you are free to do

vagrant provision

your tests will be executed in place, and should be a faster run as the environment pre-setup and installation has already completed.

All bugreports against the basebox are welcome.

chuckbutler/juju-vagrant-veewee-definitions

echo "Installing juju-local provider support"
apt-get update
apt-get install -y juju-local
if [ ! -f /home/vagrant/.ssh/id_rsa ]; then
sudo -u vagrant -H ssh-keygen -t rsa -N '' -f id_rsa
fi
if [ ! -d /home/vagrant/.juju ]; then
sudo -u vagrant -H juju init
# set the admin key to vagrant
sed -i.bak s/#\ network-bridge\:\ lxcbr0/admin-secret\:\ vagrant/ /home/vagrant/.juju/environments.yaml
sudo -u vagrant -H juju switch local
fi
echo "Running test-pre-setup script"
sudo -u vagrant -H /bin/bash /vagrant/tests/00-setup
echo "running tests"
for test in `find /vagrant/tests -maxdepth 1 -perm -111 -type f \( ! -name "00-setup" \)`; do
cd /vagrant
sudo -u vagrant -H juju test -e local $test
done
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu-trusty-alpha2"
#Note! the size of this box is not trivial - coming in at 801 mb
config.vm.box_url = "http://dasroot.net/ubuntu-trusty-alpha2.box"
#Perform the provisioner tasks of doing setup
config.vm.provision "shell",
path: "juju-vagrant-setup.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment