TESTING PROGRAMMABLE INFRASTRUCTURE (WITH RUBY) @burythehammer - - PowerPoint PPT Presentation

testing programmable infrastructure with ruby
SMART_READER_LITE
LIVE PREVIEW

TESTING PROGRAMMABLE INFRASTRUCTURE (WITH RUBY) @burythehammer - - PowerPoint PPT Presentation

@burythehammer MATT LONG TESTING PROGRAMMABLE INFRASTRUCTURE (WITH RUBY) @burythehammer PROGRAMMABLE INFRASTRUCTURE IS GREAT, BUT WE'RE MISSING SOMETHING. TESTING. @burythehammer HELLO, I'M MATT I'M A TESTER @burythehammer


slide-1
SLIDE 1

@burythehammer

MATT LONG

TESTING PROGRAMMABLE INFRASTRUCTURE (WITH RUBY)

slide-2
SLIDE 2

@burythehammer

PROGRAMMABLE INFRASTRUCTURE IS GREAT, BUT WE'RE MISSING SOMETHING.

TESTING.

slide-3
SLIDE 3

@burythehammer

I'M A TESTER

HELLO, I'M MATT

@burythehammer

slide-4
SLIDE 4

@burythehammer

I WORK HERE ↑

slide-5
SLIDE 5

@burythehammer

I AM NOT A SYSADMIN

slide-6
SLIDE 6

@burythehammer

WHAT IS PROGRAMMABLE INFRASTRUCTURE?

slide-7
SLIDE 7

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

THE APPLICATION OF METHODS AND TOOLING FROM SOFTWARE DEVELOPMENT TO THE MANAGEMENT OF IT INFRASTRUCTURE PROGRAMMABLE INFRASTRUCTURE IS..

THE INTERNET

slide-8
SLIDE 8

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

WHAT DO WE MEAN BY THIS?

▸ Automated provisioning & configuration ▸ Configuration as code ▸ Version / source controlled

slide-9
SLIDE 9

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

TOOLING EXAMPLES

slide-10
SLIDE 10

@burythehammer

PROGRAMMABLE INFRASTRUCTURE IS AWESOME!

Credit: Vault Boy, Bethesda Softworks

slide-11
SLIDE 11

@burythehammer

BUT IT CAN GET COMPLEX

slide-12
SLIDE 12

@burythehammer

TESTING IS USED TO MITIGATE COMPLEXITY & RISK

slide-13
SLIDE 13

@burythehammer

BUT INFRA TESTING IS RARE

Credit: Gunshow, KC Green

slide-14
SLIDE 14

@burythehammer

TESTING A CLOUD BROKER

AN INFRASTRUCTURE HEAVY PRODUCT

slide-15
SLIDE 15

@burythehammer

THE PROBLEM

slide-16
SLIDE 16

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

WE WANT TO MOVE TO THE CLOUD... BUT WE'RE WARY OF LOCK IN

Large organisation

slide-17
SLIDE 17

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

USERS

CLOUD BROKER

slide-18
SLIDE 18

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

BENEFITS

▸ Quick, easy provisioning ▸ one team previously took 3 months ▸ Don't need to work at a low level ▸ Templates for common dev environments ▸ Built in best practice: monitoring, security ▸ Track spending

slide-19
SLIDE 19

@burythehammer

THIS IS A REALLY COMPLICATED APPLICATION

slide-20
SLIDE 20

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

slide-21
SLIDE 21

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

WORKFLOW

▸ Log into Web UI ▸ Fill in information about environment ▸ Broker creates and bootstraps resources ▸ SSH into resources

slide-22
SLIDE 22

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

WEB TESTING

▸ Log into Web UI ▸ Fill in information about environment

slide-23
SLIDE 23

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

???

▸ Broker creates and bootstraps resources ▸ SSH into resources

slide-24
SLIDE 24

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

INFRASTRUCTURE TESTING

▸ Broker creates and bootstraps resources ▸ SSH into resources

slide-25
SLIDE 25

@burythehammer

HOW DO YOU TEST INFRASTRUCTURE?

slide-26
SLIDE 26

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

WHAT TO TEST?

Deployment scripts unit tests? Does the VPN server work? Can instances 
 access one another? Are services running? Linting?

slide-27
SLIDE 27

@burythehammer

THIS SEEMS FAMILIAR..

slide-28
SLIDE 28

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Does the VPN box work?
 Can I SSH into a server? Do our deployment scripts work?
 Linting? Are services running?

ANOTHER TESTING PYRAMID?

credit: Ubuntu dev quality guide
 https://developer.ubuntu.com/en/phone/platform/quality/

Can instances access one another? expensive, slow cheap, fast

slide-29
SLIDE 29

@burythehammer

TOOLING

slide-30
SLIDE 30

@burythehammer

UNIT TESTING

▸ Bash scripts ▸ Ansible scripts ▸ Terraform scripts

slide-31
SLIDE 31

@burythehammer

LINTING

▸ Quick sanity check ▸ Available in all tools ▸ Run in CI before committing

slide-32
SLIDE 32

@burythehammer

UNIT TESTING IS HARD

▸ Cultural issues ▸ Technical issues ▸ Return on investment

slide-33
SLIDE 33

@burythehammer

INTEGRATION TESTING

▸ Packages installed ▸ Services running ▸ Ports listening

slide-34
SLIDE 34

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

▸ Ruby / RSpec based ▸ Great community ▸ Very readable ▸ Very quick! ▸ Can SSH into instances

SERVERSPEC

slide-35
SLIDE 35

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

SERVERSPEC EXAMPLE

describe package('jenkins') do it { should be_installed } end describe service('jenkins') do it { should be_enabled } it { should be_running } end describe port(8080) do it { should be_listening } end

slide-36
SLIDE 36

@burythehammer

ACCEPTANCE TESTING

▸ SSHing into machines ▸ Using applications ▸ e.g. samba, openvpn

slide-37
SLIDE 37

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

▸ Executable specifications ▸ Both test & business can read it ▸ Available in Ruby, Java, C#... etc ▸ Great reporting ▸ Good CI integration

CUCUMBER

slide-38
SLIDE 38

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Scenario: Searching for Wikipedia Given I am on the website "www.google.com" When I search for "Wikipedia" Then the first link should be "www.wikipedia.org"

CUCUMBER EXAMPLE

slide-39
SLIDE 39

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

RUBY

▸ Fantastic testing community ▸ More suitable for SSHing into boxes ▸ "Win RM" gem ▸ Ops already familiar with it ▸ Reduces tech stack

slide-40
SLIDE 40

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

TOOLS WE DIDN'T USE

▸ Bats ▸ ShUnit2 ▸ Goss ▸ Inspec / TestInfra ▸ AWS Spec ▸ Test Kitchen

slide-41
SLIDE 41

@burythehammer

OUR SOLUTION

slide-42
SLIDE 42

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

USERS

CLOUD BROKER

slide-43
SLIDE 43

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

USERS

WEB TEST FRAMEWORK

slide-44
SLIDE 44

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

USERS

WEB TESTS

https://github.com/opencredo/test-automation-quickstart

slide-45
SLIDE 45

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

USERS

INFRASTRUCTURE TEST FRAMEWORK

slide-46
SLIDE 46

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

INFRASTRUCTURE TESTS

Serverspec

slide-47
SLIDE 47

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

INFRASTRUCTURE TESTING STACK

/ Serverspec Linting tools

slide-48
SLIDE 48

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

SERVERSPEC SMOKE TESTS

▸ Run before everything else ▸ Really quick ▸ Catches obvious errors ▸ Not complex tasks

slide-49
SLIDE 49

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Background:
 Given environment has been created
 And the following user details:
 | user_alias | username | public_key |
 | userA | testuser | test | 
 
 Scenario: IPA - Login via SSH Key authentication succeeds
 Given user "userA" is authorised to access environment vms
 When user "userA" starts ssh session in host "env" 
 Then I should be able to echo "hello world"


CUCUMBER FOR ACCEPTANCE TESTING

slide-50
SLIDE 50

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Background:
 Given environment has been created
 And the following user details:
 | user_alias | username | public_key |
 | userA | testuser | test | 
 
 
 Scenario: IPA - Login via SSH Key authentication succeeds
 Given user "userA" is authorised to access environment vms
 When user "userA" starts ssh session in host "env" 
 Then I should be able to echo "hello world"


CUCUMBER FOR ACCEPTANCE TESTING

Cloud broker APIs

slide-51
SLIDE 51

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Background:
 Given environment has been created
 And the following user details:
 | user_alias | username | public_key |
 | userA | testuser | test | 
 
 
 Scenario: IPA - Login via SSH Key authentication succeeds
 Given user "userA" is authorised to access environment vms
 When user "userA" starts ssh session in host "env" 
 Then I should be able to echo "hello world"


CUCUMBER FOR ACCEPTANCE TESTING

Standard Ruby

slide-52
SLIDE 52

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

Background:
 Given environment has been created
 And the following user details:
 | user_alias | username | public_key |
 | userA | testuser | test | 
 
 
 Scenario: IPA - Login via SSH Key authentication succeeds
 Given user "userA" is authorised to access environment vms
 When user "userA" starts ssh session in host "env" 
 Then I should be able to echo "hello world"


CUCUMBER FOR ACCEPTANCE TESTING

RSpec assertions

slide-53
SLIDE 53

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

UNDER THE CUCUMBER, PLAIN RUBY

Then(/^I should be able to echo "([^"]*)"$/) do |text| cmd = "echo #{text}"

  • utput = @session.exec!(cmd)

close_ssh(@session) expect(output.to_s.strip).to eql(text) end

slide-54
SLIDE 54

@burythehammer

LESSONS LEARNED

THE GOOD, THE BAD, AND THE UGLY

slide-55
SLIDE 55

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

THE GOOD

▸ Specialised tests for each layer ▸ Quick, expressive ServerSpec

tests

▸ Power of a full programming

language for user tests

▸ ... it's also totally doable!

Credit: Overwatch, Blizzard Entertainment

slide-56
SLIDE 56

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

THE BAD

▸ Over reliance on

acceptance tests

▸ Context switching with

two suites

▸ Out of my comfort zone

Credit: Futurama, Fox

slide-57
SLIDE 57

@burythehammer

TESTING PROGRAMMABLE INFRASTRUCTURE

THE UGLY

▸ Starting infrastructure is SLOW. ▸ It's expensive...

slide-58
SLIDE 58

@burythehammer

IT WAS WORTH IT

DESPITE ALL THAT

slide-59
SLIDE 59

@burythehammer

CONCLUSIONS

slide-60
SLIDE 60

@burythehammer

TESTING IS IMPORTANT

BUT OFTEN IGNORED

slide-61
SLIDE 61

@burythehammer

TESTERS AND OPS SHOULD WORK TOGETHER

WE NEED TO GET OUT OF OUR COMFORT ZONES

slide-62
SLIDE 62

@burythehammer

TOOLS EXIST

BUT BE PREPARED TO HACK

slide-63
SLIDE 63

@burythehammer

FINALLY...

slide-64
SLIDE 64

TESTING PROGRAMMABLE INFRASTRUCTURE

@burythehammer

THE APPLICATION OF METHODS AND TOOLING FROM SOFTWARE DEVELOPMENT TO MANAGEMENT OF IT INFRASTRUCTURE PROGRAMMABLE INFRASTRUCTURE IS..

slide-65
SLIDE 65

@burythehammer

TESTING IS A SOFTWARE DEVELOPMENT METHOD

WE SHOULD APPLY IT TO INFRASTRUCTURE

slide-66
SLIDE 66

@burythehammer

THANKS! QUESTIONS?

matt.long@opencredo.com <-- sponsors booth on 5th floor! @burythehammer