Write Serverspec tests. 2. Write files like chef-cookbook. 3. After tests passed, go back to 1. 4. Finally, The cookbook is completed! VM Serverspec Test Provision
it { should be_installed } end ! describe service('apache2') do it { should be_enabled } it { should be_running } end ! describe port(80) do it { should be_listening } end package 'apache2' do action :install end ! service 'apache2' do action :start end Serverspec Chef
web" >> /etc/hosts' $ curl -v http://web * About to connect() to 192.168.33.10 port 80 (#0) * Trying 192.168.33.10... (It takes long long time…) ^C $ telnet web 80 Trying 192.168.33.10... (It takes long long time…) ^C
NEW -m tcp -p tcp --dport 80 -j ACCEPT ! $ curl http://web <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html>
200 OK, when I send a HTTP request. describe http('http://app') do it "responds OK 200" do expect(response.code).to eq('200') end end This is what Infrataster is!
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
server describe capybara('http://app') do it "responds content including 'Hello Sinatra'" do visit '/' expect(page).to have_content('Hello Sinatra') end end end
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
server describe capybara('http://app') do it "responds content including 'Hello Sinatra'" do visit '/' expect(page).to have_content('Hello Sinatra') end end end Firefox SSH SSH App Server Visit http://127.0.0.1:XXXXX Forward from 127.0.0.1:XXXX to app:80 Listen 80
Rewrite HTTP header => Host: app Visit http://127.0.0.1:XXXXX 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
! 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