devoxx uk 2013: sandboxing with the vagrant-binding api

27
Real sandboxing with the Vagrant-Binding API

Upload: hendrik-ebbers

Post on 06-May-2015

1.757 views

Category:

Technology


2 download

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

Page 1: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Real sandboxing with the

Vagrant-Binding API

Page 2: Devoxx UK 2013: 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

[email protected]

Page 3: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Content

•Vagrant

•Puppet

•Vagrant-Binding API

Page 4: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant

Page 5: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 6: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant

•build on top of VirtualBox

•written in Ruby

access by shell &

Ruby

Page 7: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

$ 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

Page 8: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 9: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 10: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Puppet

Page 11: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Puppet

•configure your machines (nodes) by script

•install and configure software & services

•https://puppetlabs.com

Page 12: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 13: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Puppet

•package individual components in modules

•many online documentations & books out there

Page 14: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant&

Puppet

Page 15: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant & Puppet

•define your VM with Vagrant & configure it with Puppet

•Puppet is pre-installed on Vagrant boxes

Page 16: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 17: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant-Bindingconfigure & manage

VMs in Java

Page 18: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant-Binding

•Java Wrapper around Vagrant

•create & start VMs at runtime

•only VirtualBox is required

Page 19: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant-Binding

•Fluent Builder APIs

•JUnit support

•Puppet support

Page 20: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 21: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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?

Page 22: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 23: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 24: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

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

Page 25: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Vagrant-Binding

https://github.com/guigarage/vagrant-binding

fork me on github

Page 26: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Roadmap

•Switch to Vagrant 1.1.x and JRuby 1.7.x

•Remove VirtualBox as needed dependency (RackSpace & AWS support)

•Chef support

Page 27: Devoxx UK 2013: Sandboxing with the Vagrant-Binding API

Thanks for

watching@hendrikEbbers

[email protected]