devoxx uk 2013: sandboxing with the vagrant-binding api
DESCRIPTION
Many developers are in need of complex test environments for different projects with customers. The ideal situation would be to have them running in a sandbox. With help of Vagrant and the vagrant-binding API it's possible to create VM based sandbox-environments "on the fly". Anytime, anywhere and above all reproducible. The Talk shows how fast you can create and configure a sandbox with the help of Vagrant and vagrant-binding even from within the Java runtime. Based on this different solutions for problems in QA and UnitTesting will be shown.TRANSCRIPT
Real sandboxing with the
Vagrant-Binding API
About me
•Hendrik Ebbers
•Lead of development at SIC GmbH in Dortmund, Germany
•Lead of JUG Dortmund
•DataFX, JFXtras Contributor @hendrikEbbers
Content
•Vagrant
•Puppet
•Vagrant-Binding API
Vagrant
Vagrant
•configure virtual machines by script
•create new instances on the fly
•manage the VM lifecycle
•http://www.vagrantup.com
Vagrant
VM
crea
te
man
age
Vagrant
•build on top of VirtualBox
•written in Ruby
access by shell &
Ruby
$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
$ vagrant init lucid32
$ vagrant up
$ vagrant destroy
Vagrantadd template VM to
Vagrant
creates VM configuration-script
start the virtual machine
Vagrant
•provides 2 template boxes by default
•simple config-files
•easy ssh connection, shared folder, etc.
Vagrant::Config.run do |config| config.vm.box = "lucid32"end
Ubuntu Lucid 32- & 64-bit
see great Vagrant documentation
Vagrant 1.1.x
•Released 2 weeks ago
•PlugIn API
•New Providers (AWS, RackSpace, VMWare Fusion)
Vagrant::Config.run do |config| config.vm.box = "lucid32"end
Vagrant.configure("1")
„1“ for Vagrant 1.0.x„2“ for Vagrant 1.1.x
Puppet
Puppet
•configure your machines (nodes) by script
•install and configure software & services
•https://puppetlabs.com
Puppet
class apache { exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], }}include apache
Apache2 is installed
& started on node
Puppet
•package individual components in modules
•many online documentations & books out there
Vagrant&
Puppet
Vagrant & Puppet
•define your VM with Vagrant & configure it with Puppet
•Puppet is pre-installed on Vagrant boxes
Vagrant & Puppet
Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "my_manifest.pp" endend path to Puppet script
Vagrantfile
Vagrant-Bindingconfigure & manage
VMs in Java
Vagrant-Binding
•Java Wrapper around Vagrant
•create & start VMs at runtime
•only VirtualBox is required
Vagrant-Binding
•Fluent Builder APIs
•JUnit support
•Puppet support
Builder API
VagrantVmConfig vmConfig = new VagrantVmConfigBuilder()! ! ! ! .withLucid32Box()! ! ! ! .withName("myLittleVm")! ! ! ! .withHostOnlyIp("192.168.50.4")! ! ! ! .build();
VagrantEnvironment environment = ...;
environment.up();! ! !environment.getVm(0).createConnection().execute("touch /tmp1");
environment.destroy();
builder API available
builder API for VM
manage VM lifecycle
ssh connection
JUnit support
@Testpublic void testJdbc() {
dbHandler = new MySql(ip, db, user, pwd);
dbHandler.createMyTable();
dbHandler.insertRow();
assertEquals(1, dbHandler.getRowCount());
dbHandler.close();}
what if table already exists?
what if host not reachable?
parallel processes?
JUnit support
@Rulepublic VagrantTestRule testRule = new VagrantTestRule(createConfig());
public static VagrantConfiguration createConfig() { //Configure VM with MySQL-Server & static ip}
create VM start VM run UnitTest destroy VM
JUnit annotation manage VM lifecycle
use builder API for VM specification
QA Portal with Vagrant
•Manage all test machines with Vagrant & Puppet
•Manage lifecycle with Java
Super App Nightly Build with MySQLDefault installation of the App with MySQL DB Server
Super App Nightly Build with Oracle DBDefault installation of the App with Oracle DB Server
Super App Nightly Build without DatabaseUse this to check the default Errors in UI at startup
state: down
state: runningstarted by: John
state: down
Puppet Forge access
File moduleFolder = new File("...");
PuppetForgeClient client = new PuppetForgeClient();! !! !List<PuppetForgeModuleDescription> allDescriptions = ! client.findModules("mongodb");! !
for(PuppetForgeModuleDescription desc : allDescriptions) {! System.out.println("Installing " + desc.getFullName());! PuppetForgeModule module = client.findModule(desc);! client.installToModulesDir(moduleFolder, module);}
search
install as module at
runtime
Vagrant-Binding
https://github.com/guigarage/vagrant-binding
fork me on github
Roadmap
•Switch to Vagrant 1.1.x and JRuby 1.7.x
•Remove VirtualBox as needed dependency (RackSpace & AWS support)
•Chef support