Upgrade to Pro — share decks privately, control downloads, hide ads and more …

cucumber-nagios

 cucumber-nagios

A deep dive into Behavior Driven Infrastructure and why BDI matters.

This talk has been held in English at the OSMC 2012 in Nuremberg, Germany in front of a small audience of approx. 40 people.

Mike Adolphs

October 18, 2012
Tweet

More Decks by Mike Adolphs

Other Decks in Programming

Transcript

  1. WELCOME! ‣ Please rate this talk on spkr8.com/t/16231 ‣ Also

    follow me on twitter twitter.com/fooforge ‣ Or follow me on GitHub github.com/fooforge pablofausto Thursday, October 18, 12
  2. ‣ Speak up if something’s on your mind ‣ Too

    quiet/loud ‣ Blocking the view ‣ False assumptions CUCUMBER-NAGIOS A deep dive into Behavior Driven Infrastructure Thursday, October 18, 12
  3. Given my proposal was accepted When I am giving the

    talk Then I should introduce myself CUCUMBER-NAGIOS A deep dive into Behavior Driven Infrastructure Thursday, October 18, 12
  4. { “name”: “Mike Adolphs”, “profession”: “Sysadmin”, “interested_in”: [ “Infrastructure as

    code”, “Automation”, “Provisioning” ], “activities”: [ “Contributor to chef”, “Freelancing author” ], } Thursday, October 18, 12
  5. { “name”: “Mike Adolphs”, “profession”: “Sysadmin”, “interested_in”: [ “Infrastructure as

    code”, “Automation”, “Provisioning” ], “activities”: [ “Contributor to chef”, “Freelancing author” ], } Thursday, October 18, 12
  6. { “name”: “Mike Adolphs”, “profession”: “Sysadmin”, “interested_in”: [ “Infrastructure as

    code”, “Automation”, “Provisioning” ], “activities”: [ “Contributor to chef”, “Freelancing author” ], } Thursday, October 18, 12
  7. ... “Wait, what exactly is Behavior Driven Infrastructure about?” OK

    - Introduction done. Beer’o’clock! CUCUMBER-NAGIOS Thursday, October 18, 12
  8. ◦ → check_ssh -H fooforge.com -p 22 SSH OK -

    OpenSSH_5.5p1 Debian-6+squeeze2 (protocol 2.0) | ... Because that’s why: Why did this happen? Thursday, October 18, 12
  9. Test Driven Development Unit tests def test_negotiate_should_raise_error_if_response_was_unexpected socket.expect do |s,

    type, buffer| assert_equal SSH2_AGENT_REQUEST_VERSION, type s.return(255) end assert_raises(Net::SSH::Authentication::AgentError) { agent.negotiate! } end Thursday, October 18, 12
  10. Test Driven Development Integration tests def login_and_run_some_stuff # login_via_ssh #

    run_lsof # run_uptime # run a custom script # validate its output end Thursday, October 18, 12
  11. Test Driven Development Unit tests def test_negotiate_should_raise_error_if_response_was_unexpected socket.expect do |s,

    type, buffer| assert_equal SSH2_AGENT_REQUEST_VERSION, type s.return(255) end assert_raises(Net::SSH::Authentication::AgentError) { agent.negotiate! } end Thursday, October 18, 12
  12. Behavioral Driven Development Acceptance tests Story: User connects via SSH

    In order to do my job As a software developer I need to be able to connect to a server via SSH Thursday, October 18, 12
  13. Cucumber ‣ Tests written in plain text ‣ Separation of

    tests into two parts ‣ Supports 40+ languages ‣ Ruby, Java, .NET, Flex integration Thursday, October 18, 12
  14. Feature definitions Feature: fooforge.com ssh logins As a user of

    fooforge.com I need to login remotely Scenario: Basic login Given I have no public keys set Then I can ssh to "fooforge.com" with the following credentials: | username | password | | mike | foobar | Thursday, October 18, 12
  15. Feature definitions Ominaisuus: fooforge.com ssh logins Käyttäjäksi fooforge.com Minun täytyy

    kirjautumaan etäyhteydellä Tapaus: Perus login Koska minulla ei ole public keys asetettu Sitten voin ssh “fooforge.com” seuraavat käyttäjätiedot: | username | password | | mike | foobar | Thursday, October 18, 12
  16. Step definitions Given /^I have no public keys set$/ do

    # some code end Then /^I can ssh to hosts with these credentials:$/ do |table| # some code end Thursday, October 18, 12
  17. Running those tests $ rake ... ... Finished in 1.61

    seconds 364 examples, 0 failures, 1 pending ... ... 40 scenarios (40 passed) 251 steps (251 passed) 0m25.124s Thursday, October 18, 12
  18. Our SSH test as a Nagios plugin $ cucumber-nagios features/fooforge.com/ssh_access.feature

    CUCUMBER OK - Critical: 0, Warning: 0, 2 okay | passed=2; failed=0; nosteps=0; total=2; time=0 Thursday, October 18, 12
  19. cucumber-nagios ‣ Interaction with servers via Net::SSH ‣ uses Webrat

    and Mechanize for tests via HTTP ‣ Generator for projects and features Thursday, October 18, 12
  20. Creating a project $ cucumber-nagios-gen project fooforge.com Generating with project

    generator: [ADDED] .gitignore [ADDED] .bzrignore [ADDED] Gemfile [ADDED] README [ADDED] features/steps [ADDED] features/support Your new cucumber-nagios project can be found in /Users/madolphs/ Development/Personal/Repositories/cucumber-nagios_examples/ fooforge.com. Next, install the necessary RubyGems with: bundle install Your project has been initialised as a git repository. Thursday, October 18, 12
  21. Generating features $ cucumber-nagios-gen feature fooforge.com startpage Generating with feature

    generator: [ADDED] features/fooforge.com/startpage.feature [ADDED] features/fooforge.com/steps/startpage_steps.rb Thursday, October 18, 12
  22. Intelligent defaults # features/fooforge.com/startpage.feature Feature: fooforge.com It should be up

    Scenario: Visiting home page When I go to "http://fooforge.com" Then the request should succeed Thursday, October 18, 12
  23. Running the startpage feature $ cucumber-nagios features/fooforge.com/startpage.feature CUCUMBER OK -

    Critical: 0, Warning: 0, 2 okay | passed=2; failed=0; nosteps=0; total=2; time=0 Thursday, October 18, 12
  24. More verbose output via --pretty $ cucumber-nagios features/fooforge.com/startpage.feature --pretty Feature:

    fooforge.com It should be up Scenario: Visiting home page When I go to "http://fooforge.com" Then the request should succeed 1 scenario (1 passed) 2 steps (2 passed) 0m0.081s Thursday, October 18, 12
  25. More verbose output via --pretty $ cucumber-nagios features/fooforge.com/startpage.feature --pretty Feature:

    fooforge.com It should be up Scenario: Visiting home page When I go to "http://fooforge.com" getaddrinfo: nodename nor servname provided, or not known (SocketError) /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:560:in `initialize' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:560:in `open' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:560:in `connect' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/timeout.rb:53:in `timeout' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/timeout.rb:101:in `timeout' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:560:in `connect' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:553:in `do_start' /Users/madolphs/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/net/http.rb:548:in `start' ./features/steps/http_steps.rb:12:in `/^I go to "(.*)"$/' features/fooforge.com/startpage.feature:5:in `When I go to "http://fooforge.con"' Then the request should succeed # features/steps/http_steps.rb:64 Failing Scenarios: cucumber features/fooforge.com/startpage.feature:4 # Scenario: Visiting home page 1 scenario (1 failed) 2 steps (1 failed, 1 skipped) 0m0.050s Thursday, October 18, 12
  26. Predefined steps for ‣ AMQP ‣ DNS ‣ HTTP ‣

    SSH ‣ Benchmarks Thursday, October 18, 12
  27. A benchmark $ cucumber-nagios features/fooforge.com/benchmark_website.feature --pretty Feature: fooforge.com To provide

    the best performance fooforge.com must be responsive Scenario: Benchmark startpage Given I am benchmarking When I go to "http://fooforge.com" Then the elapsed time should be less than 2 seconds 1 scenario (1 passed) 3 steps (3 passed) 0m0.619s Thursday, October 18, 12
  28. A failing benchmark $ cucumber-nagios features/fooforge.com/startpage.feature --pretty Feature: fooforge.com It

    should be up Scenario: Visiting home page When I go to "http://fooforge.com" Then the request should succeed Scenario: Benchmark startpage When I go to "http://fooforge.com" Then the elapsed time should be less than 1 seconds expected: > -1 got: -1.368603 (RSpec::Expectations::ExpectationNotMetError) ./features/steps/benchmark_steps.rb:6:in `/^the elapsed time should be less than (\d+) seconds$/' features/fooforge.com/startpage.feature:11:in `Then the elapsed time should be less than 1 seconds' Failing Scenarios: cucumber features/fooforge.com/startpage.feature:8 # Scenario: Benchmark startpage 2 scenarios (1 failed, 1 passed) 5 steps (1 failed, 4 passed) 0m1.708s Thursday, October 18, 12
  29. Integration Monitoring Feature: XING logged_in_search As a user of xing.com

    I want to search for someone Scenario: Basic search Given I have the username “mike” and the password “foobar” When I login on “http://www.xing.com/” Then I can click on the search icon and lookup “Markus Lanz” Thursday, October 18, 12
  30. Benefits ‣ Monitoring’s a company-wide topic ‣ Implementing checks gets

    easier ‣ More fault-tolerant infrastructure Thursday, October 18, 12
  31. Drawbacks ‣ Ramp-up phase probably needed ‣ Dependencies for Operations

    grow ‣ Ruby 1.8.7 currently works best ‣ Development could be more active Thursday, October 18, 12
  32. Installation/Contribution ‣ Gem ‣ gem install cucumber-nagios ‣ Sources ‣

    github.com/auxesis/cucumber-nagios ‣ If interested check out the issue tracker Thursday, October 18, 12
  33. “Would you like to know more?” ‣ cukes.info ‣ The

    Cucumber Book Thursday, October 18, 12
  34. THANKS! ‣ Please rate this talk on spkr8.com/t/16231 ‣ Also

    follow me on twitter twitter.com/fooforge ‣ Or follow me on GitHub github.com/fooforge pablofausto Thursday, October 18, 12