This document discusses testing programmable infrastructure. It describes testing different aspects of infrastructure including a cloud broker and Kubernetes cluster. It recommends applying software development testing practices like unit testing, integration testing, and acceptance testing to infrastructure code and configuration. Various tools are presented for different types of infrastructure testing including Serverspec, Bats, Goss, Terraform_validate, and using Test Kitchen with Inspec. The document emphasizes that testing is important for infrastructure but often overlooked, and that testers and operations teams should work together to address new challenges in testing programmable systems.
7. TESTING PROGRAMMABLE INFRASTRUCTURE
THE APPLICATION OF METHODS AND TOOLING
FROM SOFTWARE DEVELOPMENT TO
MANAGEMENT OF IT INFRASTRUCTURE
PROGRAMMABLE INFRASTRUCTURE IS..
THE INTERNET
24. TESTING PROGRAMMABLE INFRASTRUCTURE
BENEFITS
▸ Quick, easy provisioning
▸ one team previously took 3 months
▸ Common interface to cloud features
▸ Templates for common dev environments
▸ Built in best practice: monitoring, security
▸ Track spending
31. TESTING PROGRAMMABLE INFRASTRUCTURE
WHAT TO TEST?
Do our deployment
scripts work?
Does the VPN server work?
Can instances
access one another?
Are services running?
Can I SSH into a server?
33. TESTING PROGRAMMABLE INFRASTRUCTURE
Does the VPN box work?
Can I SSH into a server?
Do our deployment scripts work?
Are services running?
ANOTHER TESTING PYRAMID?
credit: Ubuntu dev quality guide
https://developer.ubuntu.com/en/phone/platform/quality/
Can instances access one another?
38. TESTING PROGRAMMABLE INFRASTRUCTURE
SH UNIT 2
▸ Shell unit testing framework
▸ Runs on all Bourne shells
▸ sh, BASH, DASH, ksh, zsh
▸ No activity or support?
40. TESTING PROGRAMMABLE INFRASTRUCTURE
GOSS
▸ Go based
▸ Specs in YAML
▸ Minimal, fast, and simple
▸ Some neat features
▸ .. have to run on the server
▸ .. no Windows support
45. TESTING PROGRAMMABLE INFRASTRUCTURE
TEST KITCHEN
▸ Orchestrates setup, test, teardown
▸ Runs BATS, shUnit2, RSpec,
Serverspec
▸ Popular in the Chef community
▸ Not suitable for our cloud broker
55. TESTING PROGRAMMABLE INFRASTRUCTURE
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
56. TESTING PROGRAMMABLE INFRASTRUCTURE
Background:
Given environment has been created
And the following user details:
| user_alias | username | public_key |
| userA | envoy | 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
57. TESTING PROGRAMMABLE INFRASTRUCTURE
Background:
Given environment has been created
And the following user details:
| user_alias | username | public_key |
| userA | envoy | 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
58. TESTING PROGRAMMABLE INFRASTRUCTURE
Background:
Given environment has been created
And the following user details:
| user_alias | username | public_key |
| userA | envoy | 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
59. TESTING PROGRAMMABLE INFRASTRUCTURE
Background:
Given environment has been created
And the following user details:
| user_alias | username | public_key |
| userA | envoy | 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
60. TESTING PROGRAMMABLE INFRASTRUCTURE
UNDER THE CUCUMBER, PLAIN RUBY
Then(/^I should be able to echo "([^"]*)"$/) do |text|
cmd = "echo #{text}"
output = @session.exec!(cmd)
close_ssh(@session)
expect(output.to_s.strip).to eql(text)
end
62. TESTING PROGRAMMABLE INFRASTRUCTURE
THE GOOD
▸ Specialised tests for each layer
▸ Really quick, expressive
ServerSpec tests
▸ Power of a full programming
language for user tests
79. TESTING PROGRAMMABLE INFRASTRUCTURE
TERRAFORM_VALIDATE
▸ Python based unit testing
▸ NOT to be confused with 'validate' command
▸ Builds map of resources & properties
▸ Totally offline
▸ New and incomplete
https://github.com/elmundio87/terraform_validate
82. TESTING PROGRAMMABLE INFRASTRUCTURE
GOSS
▸ Easy to get up and running
▸ Doesn’t support remote
# example usage: ./goss-test.sh 34.248.91.167
TARGET='centos@'$1
SSH_KEY_PATH=~/.ssh/aws
ssh -t -t -i $SSH_KEY_PATH $TARGET 'curl -fsSL https://goss.rocks/install | sudo sh'
scp ./goss.json $TARGET:~/goss.yaml
ssh -t -t -i $SSH_KEY_PATH $TARGET 'goss validate'
https://gist.github.com/burythehammer/081d6ee11cc33c2f4c4729ae67622f5b
83. TESTING PROGRAMMABLE INFRASTRUCTURE
▸ Terraform compatibility
▸ Already a talk about this
▸ “Untangling Infrastructure Code” by
Nell Shamrell-Harrington
TEST KITCHEN + INSPEC
100. TESTING PROGRAMMABLE INFRASTRUCTURE
THE APPLICATION OF METHODS AND TOOLING
FROM SOFTWARE DEVELOPMENT TO
MANAGEMENT OF IT INFRASTRUCTURE
PROGRAMMABLE INFRASTRUCTURE IS..
101. TESTING IS A SOFTWARE
DEVELOPMENT METHOD
WE SHOULD APPLY IT TO
INFRASTRUCTURE