• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Get Your Facts Right
 

Get Your Facts Right

on

  • 5,506 views

Presentation from PuppetCamp

Presentation from PuppetCamp

Statistics

Views

Total Views
5,506
Views on SlideShare
5,022
Embed Views
484

Actions

Likes
2
Downloads
37
Comments
0

5 Embeds 484

http://l.lj-toys.com 283
http://lj-toys.com 187
http://www.slideshare.net 5
http://www.linkedin.com 5
https://www.linkedin.com 4

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Background - systems, development, agile, puppet. Builds on James’ talk, a good place to get started.
  • .Horror stories
  • we pushed a fact that worked when you ran it with facter, but not with puppet <br /> I think the confine was at the wrong level or something weird like that? <br /> had to clusterssh into many many many machines and remove it.. <br /> <br /> If I have to ssh into a box I&#x2019;ve failed
  • Simon Willison telling me one of Jesse Robbins (Amazon, now opscode) used to go around data centre and unplug things. <br /> Luke Kaines throw it out window
  • Bug #1
  • Infrastructure is code
  • Productive in 4 hours.
  • babel <br /> <br /> Language you might hear on list <br /> * TDD, BDD, WTF <br /> * problem - works on my machine! <br /> * problem - vague naming (domainname)
  • Capture intent
  • Systems view of testing - Testing from a sys admins view &apos;[&apos; <br /> Destructive testing (load tests, penetration testing) - Hammer <br /> Test system, test environment.
  • Dan north, way to describe testing, Whether at the code level, the application level or <br /> beyond, we can use the same thinking and the same linguistic <br /> constructs to describe behaviour at any level of granularity.
  • Why test <br /> * quality pyramid, internal external <br /> * spaghetti code <br /> * broken code - ec2 <br /> * red green refactor <br /> * inherent complexity in facter == difference between systems. <br /> * FEEDBACK and cost of change!
  • Simplest thing to get the test to pass
  • Our test is not actually testing what we want. <br /> How can we test so it works on my machine and your machine?
  • language, expectations,
  • mock objects

Get Your Facts Right Get Your Facts Right Presentation Transcript

  • Get your facts right Paul Nasrat • #puppetcamp 2009 @nasrat • pnasrat@googlemail.com
  • http://www.flickr.com/photos/tentalemonkey/2401988558
  • clustersshf**k
  • if Facter.hostname[0, 5] = "tstme" int_service_domain = "tst.example.local" ext_service_domain = "tst.example.com" else int_service_domain = "example.local" ext_service_domain = "example.com" end
  • = != ==
  • http://www.flickr.com/photos/lifeinelgin/2533204950/
  • http://www.history.navy.mil/photos/pers-us/uspers-h/g-hoppr.htm
  • def can_connect?(ip,port,wait_sec=2) Timeout::timeout(wait_sec) {open(ip, port)} return true rescue return false end
  • def can_connect?(ip,port,wait_sec=2) Timeout::timeout(wait_sec) {open(ip, port)} return true rescue return false end
  • def can_connect?(ip,port,wait_sec=2 url = "http://#{ip}:#{port}/" Timeout::timeout(wait_sec) {open(url)} return true rescue return false end
  • Bug #2
  • def can_connect?(ip,port,wait_sec=2 url = "http://#{ip}:#{port}/" Timeout::timeout(wait_sec) {open(url)} return true rescue return false end
  • def can_connect?(ip,port,wait_sec=2 url = "http://#{ip}:#{port}/" Timeout::timeout(wait_sec) {open(url)} return true rescue Timeout::Error return false rescue return false end
  • ops == code
  • Dev vs Ops http://www.flickr.com/photos/cayusa/627611844
  • IV
  • http://www.flickr.com/photos/thomasthomas/274884308/
  • Unit Testing
  • “Debugging is twice as hard as writing the code in the first place.” Brian Kernighan
  • [
  • Test-driven development
  • Behaviour driven development
  • £$€
  • Feedback http://www.flickr.com/photos/altemark/273968506
  • Tools • rspec • rake • git • mocha
  • cd spec rake (in /Users/pnasrat/Development/facter/spec) Virtual fact - should be zone on Solaris when a zone
  • require File.join(File.dirname(__FILE__), '..', 'spec_helper')
  • describe Facter::Util::HostnameResolver do it "should return 'foo.example.com' when hostname returns foo.example.com" end
  • spec --options spec.opts unit/hostname_spec.rb ./unit/hostname_spec.rb:3: uninitialized constant Facter::Util::HostnameResolver (NameError)
  • module Facter module Util class HostnameResolver end end end describe Facter::Util::HostnameResolver do it "should return 'foo.example.com' when hostname returns foo.example.com" end
  • Facter::Util::HostnameResolver - should return 'foo.example.com' when querying hostname returns foo.example.com (PENDING: Not Yet Implemented) Pending: Facter::Util::HostnameResolver should return 'foo.example.com' when querying hostname returns foo.example.com (Not Yet Implemented) ./unit/hostname_spec.rb:4 Finished in 0.0019 seconds 1 example, 0 failures, 1 pending
  • describe Facter::Util::HostnameResolver do it "should return 'foo.example.com' when querying hostname returns foo.example.com" do Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com" end end
  • spec --options spec.opts unit/hostname_spec.rb Facter::Util::HostnameResolver - should return 'foo.example.com' when querying hostname returns foo.example.com (FAILED - 1) 1) NoMethodError in 'Facter::Util::HostnameResolver should return 'foo.example.com' when querying hostname returns foo.example.com' undefined method `hostname' for #<Facter::Util::HostnameResolver:0x12e71f0> ./unit/hostname_spec.rb:12: Finished in 0.002085 seconds 1 example, 1 failure
  • module Facter module Util class HostnameResolver def hostname end end end end describe Facter::Util::HostnameResolver do it "should return 'foo.example.com' when querying hostname returns foo.example.com" do Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com" end end
  • 'Facter::Util::HostnameResolver should return 'foo.example.com' when querying hostname returns foo.example.com' FAILED expected: "foo.example.com", got: nil (using ==) ./unit/hostname_spec.rb:14:
  • module Facter module Util class HostnameResolver def hostname "foo.example.com" end end end end
  • Facter::Util::HostnameResolver - should return 'foo.example.com' when querying hostname returns foo.example.com Finished in 0.001872 seconds 1 example, 0 failures
  • mock objects
  • describe Facter::Util::HostnameResolver do it "should return 'foo.example.com' when querying hostname returns foo.example.com" do Facter::Util::Resolution.expects(:exec).with("hostname").returns("foo.example.com") Facter::Util::HostnameResolver.new.hostname.should == "foo.example.com" end end
  • Mocha::ExpectationError in 'Facter::Util::HostnameResolver should return 'foo.example.com' when querying hostname returns foo.example.com' not all expectations were satisfied unsatisfied expectations: - expected exactly once, not yet invoked: Facter::Util::Resolution.exec('hostname')
  • require 'facter/util/resolution' module Facter module Util class HostnameResolver def hostname Facter::Util::Resolution.exec("hostname") end end end end
  • Questions?
  • Further Info • rspec book - http://www.pragprog.com/ titles/achbd/the-rspec-book • TDD http://www.mockobjects.com/book/ tdd-introduction.html • IRC - #puppet #puppet-dev • github - other peoples code