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
Slide 2
Slide 2 text
‣ 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
Slide 3
Slide 3 text
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
Slide 4
Slide 4 text
{
“name”: “Mike Adolphs”,
“profession”: “Sysadmin”,
“interested_in”: [
“Infrastructure as code”,
“Automation”,
“Provisioning” ],
“activities”: [
“Contributor to chef”,
“Freelancing author” ],
}
Thursday, October 18, 12
Slide 5
Slide 5 text
{
“name”: “Mike Adolphs”,
“profession”: “Sysadmin”,
“interested_in”: [
“Infrastructure as code”,
“Automation”,
“Provisioning” ],
“activities”: [
“Contributor to chef”,
“Freelancing author” ],
}
Thursday, October 18, 12
Slide 6
Slide 6 text
{
“name”: “Mike Adolphs”,
“profession”: “Sysadmin”,
“interested_in”: [
“Infrastructure as code”,
“Automation”,
“Provisioning” ],
“activities”: [
“Contributor to chef”,
“Freelancing author” ],
}
Thursday, October 18, 12
Slide 7
Slide 7 text
... “Wait, what exactly is Behavior
Driven Infrastructure about?”
OK - Introduction done. Beer’o’clock!
CUCUMBER-NAGIOS
Thursday, October 18, 12
Slide 8
Slide 8 text
slworking
Thursday, October 18, 12
Slide 9
Slide 9 text
raptortheangel
Thursday, October 18, 12
Slide 10
Slide 10 text
visitflanders
Thursday, October 18, 12
Slide 11
Slide 11 text
slworking
Thursday, October 18, 12
Slide 12
Slide 12 text
frenkieb
Thursday, October 18, 12
Slide 13
Slide 13 text
○ → 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
Slide 14
Slide 14 text
mfilej
Thursday, October 18, 12
Slide 15
Slide 15 text
Test Driven Development
‣ Unit tests
‣ Integration tests
Thursday, October 18, 12
Slide 16
Slide 16 text
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
Slide 17
Slide 17 text
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
Slide 18
Slide 18 text
RED
GREEN
REFACTOR
TDD
Thursday, October 18, 12
Slide 19
Slide 19 text
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
Slide 20
Slide 20 text
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
Slide 21
Slide 21 text
RED
GREEN
REFACTOR
BDD
Thursday, October 18, 12
Slide 22
Slide 22 text
BDD Frameworks
‣ rspec
‣ Cucumber
Thursday, October 18, 12
Slide 23
Slide 23 text
Cucumber
‣ Tests written in plain text
‣ Separation of tests into two parts
‣ Supports 40+ languages
‣ Ruby, Java, .NET, Flex integration
Thursday, October 18, 12
Slide 24
Slide 24 text
Coming back to our SSH example...
Thursday, October 18, 12
Slide 25
Slide 25 text
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
Slide 26
Slide 26 text
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
Slide 27
Slide 27 text
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
A smart guy did the math...
+
Thursday, October 18, 12
Slide 30
Slide 30 text
His name is
Lindsay Holmwood
‣ twitter.com/auxesis
‣ github.com/auxesis
Thursday, October 18, 12
Slide 31
Slide 31 text
Yer mates, back to the command line...
Thursday, October 18, 12
Slide 32
Slide 32 text
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
Slide 33
Slide 33 text
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
Slide 34
Slide 34 text
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
Slide 35
Slide 35 text
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
Slide 36
Slide 36 text
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
Slide 37
Slide 37 text
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
Slide 38
Slide 38 text
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
Slide 39
Slide 39 text
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
Slide 40
Slide 40 text
Predefined steps for
‣ AMQP
‣ DNS
‣ HTTP
‣ SSH
‣ Benchmarks
Thursday, October 18, 12
Slide 41
Slide 41 text
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
Slide 42
Slide 42 text
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
Slide 43
Slide 43 text
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
Slide 44
Slide 44 text
Product Owner QA Sysadmin
Developer
Thursday, October 18, 12
Slide 45
Slide 45 text
Product Owner
v
sashawolff
“User needs to login”
Thursday, October 18, 12
Slide 46
Slide 46 text
QA
v
69125796@N00
“As a User I want to...”
Thursday, October 18, 12
Slide 47
Slide 47 text
Developer
v
nikio
“def login_via_ssh
# some code
end”
Thursday, October 18, 12
Slide 48
Slide 48 text
v
Sysadmin
geeksrus
“cd /etc/nagios; git pull”
Thursday, October 18, 12
Slide 49
Slide 49 text
Benefits
‣ Monitoring’s a company-wide topic
‣ Implementing checks gets easier
‣ More fault-tolerant infrastructure
Thursday, October 18, 12
Slide 50
Slide 50 text
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
Slide 51
Slide 51 text
Installation/Contribution
‣ Gem
‣ gem install cucumber-nagios
‣ Sources
‣ github.com/auxesis/cucumber-nagios
‣ If interested check out the issue tracker
Thursday, October 18, 12
Slide 52
Slide 52 text
“Would you like to know more?”
‣ cukes.info
‣ The Cucumber Book
Thursday, October 18, 12
Slide 53
Slide 53 text
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