Introducing Infrataster

Introducing Infrataster

Ff2949d62ab50cb0095c769882ffe018?s=128

Ryota Arai

May 19, 2014
Tweet

Transcript

  1. Infrataster ~ Infra Behavior Testing Framework ~ Ryota Arai

  2. Self Introduction

  3. Ryota Arai ߥҪ ྑଠ Infrastructure Engineer ! 2013.04~ GREE, Inc

    2014.03~ COOKPAD, Inc ! https://twitter.com/ryot_a_rai https://github.com/ryotarai
  4. Infrataster tast‧er [countable] 1. someone whose job is to test

    the quality of foods, teas, wines etc by tasting them (Longman Dictionary)
  5. Infrastructure as Code Automate building infra by code ! with

    Chef, Puppet, Ansible and also shell scripts # Example: Chef # install apache package 'apache2' do action :install end ! # start apache service 'apache2' do action :start end
  6. What is Infrataster? Infrastructure Behavior Testing Framework ! It tests

    infrastructure's behavior from outside of servers.
  7. What is Infrataster? describe server(:proxy) do describe http('http://app.example.com') do it

    "returns content including 'app'" do expect(response.body).to include('app') end end ! describe http('http://static.example.com') do it "returns content including 'static'" do expect(response.body).to include('static') end end end
  8. What is Infrataster? $ rspec ! server 'proxy' http 'http://app.example.com'

    returns content including 'app' http 'http://static.example.com' returns content including 'static' ! Finished in 8.87 seconds 2 examples, 0 failures
  9. Behavior Testing Framework? Apache MySQL Browser (User) Application server

  10. Behavior Testing Framework? Apache MySQL Browser (User) ☓ Application ☓

    server
  11. Behavior Testing Framework? Apache MySQL Browser (User) Application iptables GRANT

    server
  12. Behavior Testing Framework? ? Infrataster Check MySQL query response Check

    HTTP response target server
  13. Behavior Testing Framework? Apache MySQL Config Check file content Is

    Apache running? Is port 80 opened? Is MySQL running? ? whitebox blackbox Infrataster Check MySQL query response Check HTTP response target server Serverspec
  14. Test Driven Infrastructure RED GREEN RED GREEN Infrataster

  15. Getting Started $ bundle install $ rspec --init # spec/spec_helper.rb

    require 'infrataster/rspec' # Gemfile source 'https://rubygems.org' gem 'infrataster'
  16. Create VM with Vagrant # Vagrantfile Vagrant.configure("2") do |config| config.vm.box

    = "hashicorp/precise64" ! config.vm.define :proxy do |c| c.vm.network "private_network", ip: "192.168.33.10" c.vm.network "private_network", ip: "171.16.33.10", virtualbox__intnet: "infrataster-example" end ! config.vm.define :app do |c| c.vm.network "private_network", ip: "171.16.33.11", virtualbox__intnet: "infrataster-example" end end
  17. Define Servers VM Host Proxy 192.168.33.10 (172.16.33.10) Infrataster::Server.define( :proxy, #

    name '192.168.0.0/16', # ip address vagrant: true # for vagrant VM )
  18. Define Servers VM Host Proxy 192.168.33.10 (172.16.33.10) Infrataster::Server.define( :proxy, #

    name '192.168.0.0/16', # ip address vagrant: true # for vagrant VM ) Auto detect Auto SSH config
  19. Define Servers VM Host Proxy 192.168.33.10 (172.16.33.10) App 172.16.33.11 SSH

    Port Forwarding Infrataster::Server.define( :proxy, # name '192.168.0.0/16', # ip address vagrant: true # for vagrant VM ) ! Infrataster::Server.define( :app, # name '172.16.0.0/16', # ip address vagrant: true, # for vagrant VM from: :proxy # test from proxy )
  20. Define Servers VM Host Proxy 192.168.33.10 (172.16.33.10) App 172.16.33.11 SSH

    Port Forwarding Infrataster::Server.define( :proxy, # name '192.168.0.0/16', # ip address vagrant: true # for vagrant VM ) ! Infrataster::Server.define( :app, # name '172.16.0.0/16', # ip address vagrant: true, # for vagrant VM from: :proxy # test from proxy ) Access from proxy by SSH port forwarding
  21. 'http' resource describe server(:proxy) do # 192.168.33.10 describe http('http://app') do

    it "responds content including 'Hello Sinatra'" do expect(response.body).to include('Hello Sinatra') end end describe http('http://static') do it "responds content including 'Welcome to nginx!'" do expect(response.body).to include('Welcome to nginx!') end end end
  22. 'http'resource describe server(:proxy) do # 192.168.33.10 describe http('http://app') do it

    "responds content including 'Hello Sinatra'" do expect(response.body).to include('Hello Sinatra') end end describe http('http://static') do it "responds content including 'Welcome to nginx!'" do expect(response.body).to include('Welcome to nginx!') end end end Access from proxy by SSH port forwarding VirtualHost support (Host header manipulation) response is a Faraday::Response (You can check status, header too)
  23. ‘capybara' resource describe server(:app) do # Test from proxy server

    describe capybara('http://app') do it "responds content including 'Hello Sinatra'" do visit '/' expect(page).to have_content('Hello Sinatra') end end end
  24. 'capybara' resource PhantomJS (Poltergeist) SSH SSH (proxy) app Visit http://127.0.0.1:XXXX

    (with Host:app header) Forward from 127.0.0.1:XXXX to app:80 Listen 80 describe server(:app) do # Test from proxy server describe capybara('http://app') do it "responds content including 'Hello Sinatra'" do visit '/' expect(page).to have_content('Hello Sinatra') end end end
  25. 'capybara' resource (#2) describe server(:app) do describe capybara('http://app') do before

    { page.driver.clear_network_traffic } specify "all resources is loaded with success" do visit '/' page.driver.network_traffic.each do |req| req.response_parts.each do |res| expect(res.status).to be_between(200, 299) end end end end end
  26. 'mysql_query' resource describe server(:db) do describe mysql_query('SHOW STATUS') do it

    'responds uptime' do row = results.find do |r| r['Variable_name'] == 'Uptime' end expect(row['Value'].to_i).to be > 0 end end end https://github.com/ryotarai/infrataster-plugin-mysql
  27. Run Specs $ bundle exec rspec Run options: include {:focus=>true}

    ! All examples were filtered out; ignoring {:focus=>true} ! server 'app' from 'proxy' capybara 'http://app' responds content including 'Hello Sinatra' http 'http://app' responds content including 'Hello Sinatra' responds OK 200 responds as 'text/html' server 'proxy' http 'http://static' responds as 'text/html' responds content including 'Welcome to nginx!' … ! Finished in 17.92 seconds 11 examples, 0 failures ! Randomized with seed 12750
  28. After Infrataster Test Passed $ curl http://server_tested_with_infrataster It always works!

  29. infrataster.net