Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active December 3, 2016 00:28
Show Gist options
  • Save renoirb/614f9cdf68aa70af0b17b4fb321e9ed0 to your computer and use it in GitHub Desktop.
Save renoirb/614f9cdf68aa70af0b17b4fb321e9ed0 to your computer and use it in GitHub Desktop.
Run integration-testing into Vagrant, installed via Ansible

Run AlayaCare/integration-testing into Vagrant, installed via Ansible

Instructions

On a machine you can clone code using Git

  1. Create a folder where we'll pull in code

     mkdir vagrant-ansible
     cd vagrant-ansible
    
  2. Clone the following

     git clone -b renoirb/QA-89 [email protected]:AlayaCare/cloud-ansible.git
     git clone -b feature/QA-89 [email protected]:AlayaCare/integration-testing.git
     ## ... git submodule in folders above. (No pip install)
     git clone [email protected]:AlayaCare/api.base.git base
    
  3. Copy Vagrantfile and patch

     curl -o Vagrantfile https://gist.githubusercontent.com/renoirb/614f9cdf68aa70af0b17b4fb321e9ed0/raw/Vagrantfile
     curl -o vagrant.setup.sh https://gist.githubusercontent.com/renoirb/614f9cdf68aa70af0b17b4fb321e9ed0/raw/vagrant.setup.sh
    
  4. Adjust cloud-ansible/ansible.cfg

     diff --git a/ansible.cfg b/ansible.cfg
     index 7c58e21..abb676b 100644
     --- a/ansible.cfg
     +++ b/ansible.cfg
     @@ -1,6 +1,6 @@
      [defaults]
      host_key_checking = False
     -roles_path = ./roles
     +roles_path = /vagrant/cloud-ansible/roles
      allow_world_readable_tmpfiles = True
      host_key_checking = False
    
  5. Vagrant up!

     vagrant up
    
  6. You have AlayaCare app running locally, right? (dignhy?)

  7. In the VM, run ansible

     vagrant ssh
     ansible-playbook /vagrant/cloud-ansible/playbooks/integration-testing.yml
    
  8. Exit the VM (lots of thing should have happened, we need new shell environment)

     vagrant ssh
     cd /vagrant/integration-testing
     make test
    
  9. You should be able to run tests

Running WebDriver with PyTest, Splinter, Google Chrome and WebDriver, Headlessly

#!/bin/bash
# Bootstrap Vagrant to use Ansible. There are other ways. That'll work for now.
set -e
# We gotta make this through Ansible #TODO
sudo sh -c "echo '192.168.99.100 localhost.docker' >> /etc/hosts"
# Vagrant trusty base image has both puppet and chef running. We dont need it
apt-get remove -y --purge puppet puppet-common chef-zero chef
# Run Ansible locally, for role development
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install -y ansible
rm -rf /etc/ansible/roles/
ln -s /vagrant/cloud-ansible/roles /etc/ansible/roles
echo Done
# Define VM memory usage through environment variables
MEMORY = ENV.fetch("VAGRANT_MEMORY", "1024")
RELEASE = ENV.fetch("VAGRANT_UBUNTU_RELEASE", "trusty")
Vagrant.configure(2) do |config|
if RELEASE == "xenial"
## Either use this one
config.vm.box = "ubuntu/xenial64"
config.vm.box_check_update = false
else
config.vm.box = "trusty-cloud"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
end
config.ssh.forward_agent = true
# ref: https://github.com/mitchellh/vagrant/issues/1673
config.vm.provision "fix-no-tty", type: "shell" do |s|
s.privileged = false
s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
end
config.vm.network "private_network", type: "dhcp"
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
config.cache.enable :apt
if RELEASE == "xenial"
config.cache.synced_folder_opts = {
owner: "_apt",
group: "_apt"
}
end
end
config.vm.synced_folder ".", "/vagrant"
config.vm.provider "virtualbox" do |v|
v.name = config.vm.hostname
# ref: http://www.virtualbox.org/manual/ch08.html
v.customize ["modifyvm", :id, "--memory", MEMORY]
v.customize ["modifyvm", :id, "--description", "Vagrant VM in " + File.dirname(__FILE__) ]
v.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"]
v.customize ["modifyvm", :id, "--pae", "on"]
end
config.vm.provision "setup", type: "shell" do |s|
s.inline = "/bin/bash /vagrant/vagrant.setup.sh"
end
end
@renoirb
Copy link
Author

renoirb commented Dec 3, 2016

@renoirb
Copy link
Author

renoirb commented Dec 3, 2016

Success screenshot

screen shot 2016-12-02 at 09 29 07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment