SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
Test-Driven
Infrastructure with Chef
Principles & Tools
@kaktusmimi
Today
① Testing Principles
② Chef Testing Tools
③ Continuous Integration
Write 

Test
Run Test

(it fails)
Write 

Code
Test 

Passes
Refactor
TDD
BDD
TDDverification of a unit of code
specification of how code should
„behave“
T
DD
pitfall
Acceptance

Tests
Integration

Tests
Unit

Tests
To
d
ay
Today
① Testing Principles
② Chef Testing Tools
③ Continuous Integration
✔
ChefSpec
• Unit Testing Framework for Chef Cookbooks
• Runs locally without converging a (virtual) machine
$ gem install chefspec
!"" site-cookbooks

   !"" pt_jenkins

#"" recipes

$ !"" default.rb

   !"" spec

!"" default_spec.rb

execute "Install Jenkins from Ports" do

command "cd #{node['pt_jenkins']['jenkins_port_dir']} && make install clean BATCH="YES""

not_if {File.exist?(node['pt_jenkins']['jenkins_war_file'])}

end



directory node['pt_jenkins']['jenkins_home'] do

owner node['pt_jenkins']['jenkins_user']

group node['pt_jenkins']['jenkins_group']

mode '0766'

action :create

end



node.default['user']['git_ssh_wrapper'] = "/tmp/git_ssh_wrapper"

file node['user']['git_ssh_wrapper'] do

owner node['pt_jenkins']['jenkins_user']

group node['pt_jenkins']['jenkins_group']

mode 0777

content "/usr/bin/env ssh -A -o 'StrictHostKeyChecking=no' $1 $2"

action :create

end



cookbook_file 'Copy private vagrant key' do

path "/home/vagrant/.ssh/id_rsa"

source 'vagrant_private_key'

owner 'vagrant'

group 'vagrant'

backup false

mode 0600

action :create

end



cookbook_file 'Copy SSH config' do

path "/home/vagrant/.ssh/config"

source 'ssh_config'

owner 'vagrant'

group 'vagrant'

backup false

mode 0600

action :create

end



service node['pt_jenkins']['jenkins_service'] do

supports :status => true, :restart => true, :reload => true

action [ :enable, :start ]

end
require 'chefspec'



RSpec.configure do |config|

config.cookbook_path = [‚cookbooks','site-cookbooks']

config.role_path = 'roles'

end



describe 'pt_jenkins::default' do



let(:chef_run) do

ChefSpec::SoloRunner.new do |node|

node.set['jenkins']['plugins'] = {}

node.set['user']['git_ssh_wrapper'] = '/tmp/git_ssh_wrapper'

end.converge(described_recipe)

end



it 'installs Jenkins from Ports' do

expect(chef_run).to run_execute('Install Jenkins from Ports')

end



it 'creates a ssh wrapper file' do

expect(chef_run).to create_file('/tmp/git_ssh_wrapper')

end



it 'copies the ssh config' do

expect(chef_run).to create_cookbook_file('Copy SSH config')

end



it 'copies the private Vagrant key' do

expect(chef_run).to create_cookbook_file('Copy private vagrant key')

end



it 'starts the Jenkins service' do

expect(chef_run).to start_service('jenkins')

end

end
$ time bundle exec rspec site-cookbooks/pt_jenkins
pt_jenkins::default
installs Jenkins from Ports
creates a ssh wrapper file
copies the ssh config
copies the private Vagrant key
starts the Jenkins service
Finished in 0.34419 seconds
4 examples, 0 failures
1.43s user 0.24s system 76% cpu 2.186 total
Pros & Cons ChefSpec
Pro Contra
Fast White Box Testing
Can be run without
convergence
Harder to implement
Easy Setup Some tricky configuration
Don’t know what system
looks like at the end
ServerSpec
• Describe desired state
• Check whether convergence result matches
expectations
• Platform independent
• Run it „from inside“ or „from outside“
$ gem install serverspec
$ serverspec-init
Select OS type:
1) UN*X
2) Windows
Select number: 1
Select a backend type:
1) SSH
2) Exec (local)
Select number: 1
Vagrant instance y/n: y
Auto-configure Vagrant from Vagrantfile? y/n: y
$ rake -T
rake spec:pttech # Run serverspec tests to pttech
#"" site-cookbooks

$  !"" spec

$ #"" pt

$ $ !"" jenkins_spec.rb

$    !"" spec_helper.rb

!"" Rakefile
require 'serverspec'

require 'net/ssh'

require 'tempfile'



set :backend, :ssh



if ENV['ASK_SUDO_PASSWORD']

begin

require 'highline/import'

rescue LoadError

fail "highline is not available. Try installing it."

end

set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }

else

set :sudo_password, ENV['SUDO_PASSWORD']

end



host = ENV['TARGET_HOST']



`vagrant up #{host}`



config = Tempfile.new('', Dir.tmpdir)

`vagrant ssh-config #{host} > #{config.path}`



options = Net::SSH::Config.for(host, [config.path])



options[:user] ||= Etc.getlogin



set :host, options[:host_name] || host

set :ssh_options, options
require 'rake'

require 'rspec/core/rake_task'



task :spec => 'spec:all'

task :default => :spec



namespace :spec do

targets = []

Dir.glob('./spec/*').each do |dir|

next unless File.directory?(dir)

targets << File.basename(dir)

end



task :all => targets

task :default => :all



targets.each do |target|

desc "Run serverspec tests on #{target}"

RSpec::Core::RakeTask.new(target.to_sym) do |t|

ENV['TARGET_HOST'] = target

t.pattern = "spec/#{target}/*_spec.rb"

end

end

end
$ rake
Server contains
- jenkins.war at the expected location
- a folder /usr/local/jenkins, owned by user jenkins
- a folder /usr/local/jenkins, with mode 766
jenkins_config = JSON.parse(File.open("#{File.dirname(__FILE__)}/../../roles/jenkins.json").read)

jenkins_config["override_attributes"]["jenkins"]["plugins"].each do | plugin_name, plugin_config |

describe "Plugin: #{plugin_name}" do



if plugin_config['enabled']

it "has expected .hpi file in plugins directory" do

expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi")).to be_file

end

end



if plugin_config['pinned']

it "is marked as pinned and has the .hpi.pinned file in the plugins directory" do

expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi.pinned")).to be_file

end

it "is listed as pinned in the Jenkins plugin status" do

expect(check_jenkins_plugin_pinned(plugin_name)).to be_truthy

end

else

it "isn't marked as pinned and has no .hpi.pinned file in the plugins directory" do

expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi.pinned")).not_to be_file

end

end



if plugin_config['version']

it "is version #{plugin_config['version']}" do

expect(check_jenkins_plugin_version(plugin_name, plugin_config['version'])).to be_truthy

end

end



end

end
Pros & Cons ServerSpec
Pro Contra
Easy Setup
& well documented
No specific Feedback
Black Box Tests Requires running Machine
Small but mighty
command set
Slow
(Easily?) extendable
Can only be run once per
convergence Run
Test Kitchen
• Test and Infrastructure Management
• Interesting for Cookbook Development
• Quite some (configuration) overhead
• Good Tutorial
• Bad Documentation
---

driver:

name: vagrant

network:

- ["private_network", {ip: "10.20.30.41", netmask: "255.255.255.0"}]



provisioner:

name: chef_zero

require_chef_omnibus: false

client_rb:

cookbook_path: ["/var/chef/cookbooks", "/var/chef/site-cookbooks"]



platforms:

- name: FreeBSD-10-PtTech-TestKitchen

driver:

name: vagrant

box: nanobsd-hosting-amd64.box-20140917

box_url: http:/vagrantbox.es/some-box-to-use

synced_folders:

- [".", "/var/chef", "create: true, type: :nfs"]



suites:

- name: server

run_list:

- recipe[testkitchen]

- role[jenkins]

attributes:
Pros & Cons TestKitchen
Pro Contra
Handles complex Setups
„Touches“ your Machine
after Convergence
Multi-platform Testing for
Cookbook Development
No ServerSpec via ssh
implemented
„Standard“ in many
Tutorials
Requires machine startup
from Scratch
Many Plugins
Foodcritic
• Linting for Chef Cookbooks
• Complex Rule Set far beyond Code Indentation
• Goals (from Foodcritic Website)
• To make it easier to flag problems in your Cookbooks
• Faster feedback.
• Automate checks for common problems
$ gem install foodcritic
$ foodcritic site-cookbooks/pt_jenkins -t FC001
# FC001 Use strings in preference to symbols to access node attributes
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/attributes/default.rb:55
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/attributes/default.rb:56
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/recipes/default.rb:21
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/recipes/default.rb:97
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/recipes/default.rb:98
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/recipes/default.rb:109
FC001: Use strings in preference to symbols to access node attributes:

site-cookbooks/pt_jenkins/recipes/default.rb:141
Further Testing Tools
• BATS: Bash Automated Testing System
• Shell Scripts 😟
• Cucumber Chef
• Great idea, but prototype state only
• Last commit > 1 year ago 😟
Today
① Testing Principles
② Chef Testing Tools
③ Continuous Integration
✔
✔
Deployment Stage
Knife Upload to

Chef Server
Acceptance Stage
Serverspec Test
Commit Stage
Build Project
ChefSpec Tests
Foodcritic
triggers uploads
Today
① Testing Principles
② Chef Testing Tools
③ Continuous Integration
✔
✔
✔
http://serverspec.org/
https://github.com/sethvargo/chefspec
http://kitchen.ci/
http://acrmp.github.io/foodcritic/
https://sethvargo.com/unit-testing-chef-cookbooks/
http://leopard.in.ua/2013/12/01/chef-and-tdd/

Weitere ähnliche Inhalte

Was ist angesagt?

Testing for infra code using test-kitchen,docker,chef
Testing for infra code using  test-kitchen,docker,chefTesting for infra code using  test-kitchen,docker,chef
Testing for infra code using test-kitchen,docker,chefkamalikamj
 
Test Driven Development with Chef
Test Driven Development with ChefTest Driven Development with Chef
Test Driven Development with ChefSimone Soldateschi
 
CLUG 2014-10 - Cookbook CI with Jenkins
CLUG 2014-10 - Cookbook CI with JenkinsCLUG 2014-10 - Cookbook CI with Jenkins
CLUG 2014-10 - Cookbook CI with JenkinsZachary Stevens
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chefMukta Aphale
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for DevelopersAntons Kranga
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with ChefJonathan Weiss
 
Compliance as Code
Compliance as CodeCompliance as Code
Compliance as CodeMatt Ray
 
Tips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefTips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefChef Software, Inc.
 
Server Installation and Configuration with Chef
Server Installation and Configuration with ChefServer Installation and Configuration with Chef
Server Installation and Configuration with ChefRaimonds Simanovskis
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Chef
 
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeIntroduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeJosh Padnick
 
Chef, Devops, and You
Chef, Devops, and YouChef, Devops, and You
Chef, Devops, and YouBryan Berry
 
Opscode Webinar: Cooking with Chef on Microsoft Windows
Opscode Webinar: Cooking with Chef on Microsoft WindowsOpscode Webinar: Cooking with Chef on Microsoft Windows
Opscode Webinar: Cooking with Chef on Microsoft WindowsChef Software, Inc.
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Software, Inc.
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 

Was ist angesagt? (20)

Testing for infra code using test-kitchen,docker,chef
Testing for infra code using  test-kitchen,docker,chefTesting for infra code using  test-kitchen,docker,chef
Testing for infra code using test-kitchen,docker,chef
 
Learning chef
Learning chefLearning chef
Learning chef
 
Test Driven Development with Chef
Test Driven Development with ChefTest Driven Development with Chef
Test Driven Development with Chef
 
CLUG 2014-10 - Cookbook CI with Jenkins
CLUG 2014-10 - Cookbook CI with JenkinsCLUG 2014-10 - Cookbook CI with Jenkins
CLUG 2014-10 - Cookbook CI with Jenkins
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chef
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Compliance as Code
Compliance as CodeCompliance as Code
Compliance as Code
 
Tips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefTips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with Chef
 
Server Installation and Configuration with Chef
Server Installation and Configuration with ChefServer Installation and Configuration with Chef
Server Installation and Configuration with Chef
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeIntroduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
 
Chef, Devops, and You
Chef, Devops, and YouChef, Devops, and You
Chef, Devops, and You
 
Chef introduction
Chef introductionChef introduction
Chef introduction
 
Opscode Webinar: Cooking with Chef on Microsoft Windows
Opscode Webinar: Cooking with Chef on Microsoft WindowsOpscode Webinar: Cooking with Chef on Microsoft Windows
Opscode Webinar: Cooking with Chef on Microsoft Windows
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Chef Cookbook Workflow
Chef Cookbook WorkflowChef Cookbook Workflow
Chef Cookbook Workflow
 
Vagrant to-aws-flow
Vagrant to-aws-flowVagrant to-aws-flow
Vagrant to-aws-flow
 

Ähnlich wie Test-Driven Infrastructure with Chef

Using Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooksUsing Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooksTimur Batyrshin
 
Cooking with Chef on Windows: 2015 Edition
Cooking with Chef on Windows: 2015 EditionCooking with Chef on Windows: 2015 Edition
Cooking with Chef on Windows: 2015 EditionJulian Dunn
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerGeorge Miranda
 
Modern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDModern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDSean Chittenden
 
Using Vagrant
Using VagrantUsing Vagrant
Using Vagrantandygale
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsFrancesco Bruni
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
 
Getting started with puppet and vagrant (1)
Getting started with puppet and vagrant (1)Getting started with puppet and vagrant (1)
Getting started with puppet and vagrant (1)Puppet
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Mischa Taylor
 
Cookbook testing with KitcenCI and Serverrspec
Cookbook testing with KitcenCI and ServerrspecCookbook testing with KitcenCI and Serverrspec
Cookbook testing with KitcenCI and ServerrspecDaniel Paulus
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 
Test Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeTest Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeCybera Inc.
 
[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration toolOSLL
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile InfrastructuresAntons Kranga
 
Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Sylvain Tissot
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresFrits Van Der Holst
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsNick Belhomme
 

Ähnlich wie Test-Driven Infrastructure with Chef (20)

Using Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooksUsing Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooks
 
Cooking with Chef on Windows: 2015 Edition
Cooking with Chef on Windows: 2015 EditionCooking with Chef on Windows: 2015 Edition
Cooking with Chef on Windows: 2015 Edition
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
Modern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDModern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSD
 
Using Vagrant
Using VagrantUsing Vagrant
Using Vagrant
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and Jenkins
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Getting started with puppet and vagrant (1)
Getting started with puppet and vagrant (1)Getting started with puppet and vagrant (1)
Getting started with puppet and vagrant (1)
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)
 
Cookbook testing with KitcenCI and Serverrspec
Cookbook testing with KitcenCI and ServerrspecCookbook testing with KitcenCI and Serverrspec
Cookbook testing with KitcenCI and Serverrspec
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Test Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeTest Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as Code
 
[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool[MDBCI] Mariadb continuous integration tool
[MDBCI] Mariadb continuous integration tool
 
Testing Terraform
Testing TerraformTesting Terraform
Testing Terraform
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 

Kürzlich hochgeladen

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Kürzlich hochgeladen (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

Test-Driven Infrastructure with Chef

  • 3. Today ① Testing Principles ② Chef Testing Tools ③ Continuous Integration
  • 4. Write 
 Test Run Test
 (it fails) Write 
 Code Test 
 Passes Refactor TDD
  • 5. BDD TDDverification of a unit of code specification of how code should „behave“
  • 6.
  • 10. Today ① Testing Principles ② Chef Testing Tools ③ Continuous Integration ✔
  • 11. ChefSpec • Unit Testing Framework for Chef Cookbooks • Runs locally without converging a (virtual) machine
  • 12. $ gem install chefspec
  • 13. !"" site-cookbooks
    !"" pt_jenkins
 #"" recipes
 $ !"" default.rb
    !"" spec
 !"" default_spec.rb

  • 14. execute "Install Jenkins from Ports" do
 command "cd #{node['pt_jenkins']['jenkins_port_dir']} && make install clean BATCH="YES""
 not_if {File.exist?(node['pt_jenkins']['jenkins_war_file'])}
 end
 
 directory node['pt_jenkins']['jenkins_home'] do
 owner node['pt_jenkins']['jenkins_user']
 group node['pt_jenkins']['jenkins_group']
 mode '0766'
 action :create
 end
 
 node.default['user']['git_ssh_wrapper'] = "/tmp/git_ssh_wrapper"
 file node['user']['git_ssh_wrapper'] do
 owner node['pt_jenkins']['jenkins_user']
 group node['pt_jenkins']['jenkins_group']
 mode 0777
 content "/usr/bin/env ssh -A -o 'StrictHostKeyChecking=no' $1 $2"
 action :create
 end
 
 cookbook_file 'Copy private vagrant key' do
 path "/home/vagrant/.ssh/id_rsa"
 source 'vagrant_private_key'
 owner 'vagrant'
 group 'vagrant'
 backup false
 mode 0600
 action :create
 end
 
 cookbook_file 'Copy SSH config' do
 path "/home/vagrant/.ssh/config"
 source 'ssh_config'
 owner 'vagrant'
 group 'vagrant'
 backup false
 mode 0600
 action :create
 end
 
 service node['pt_jenkins']['jenkins_service'] do
 supports :status => true, :restart => true, :reload => true
 action [ :enable, :start ]
 end
  • 15. require 'chefspec'
 
 RSpec.configure do |config|
 config.cookbook_path = [‚cookbooks','site-cookbooks']
 config.role_path = 'roles'
 end
 
 describe 'pt_jenkins::default' do
 
 let(:chef_run) do
 ChefSpec::SoloRunner.new do |node|
 node.set['jenkins']['plugins'] = {}
 node.set['user']['git_ssh_wrapper'] = '/tmp/git_ssh_wrapper'
 end.converge(described_recipe)
 end
 
 it 'installs Jenkins from Ports' do
 expect(chef_run).to run_execute('Install Jenkins from Ports')
 end
 
 it 'creates a ssh wrapper file' do
 expect(chef_run).to create_file('/tmp/git_ssh_wrapper')
 end
 
 it 'copies the ssh config' do
 expect(chef_run).to create_cookbook_file('Copy SSH config')
 end
 
 it 'copies the private Vagrant key' do
 expect(chef_run).to create_cookbook_file('Copy private vagrant key')
 end
 
 it 'starts the Jenkins service' do
 expect(chef_run).to start_service('jenkins')
 end
 end
  • 16. $ time bundle exec rspec site-cookbooks/pt_jenkins pt_jenkins::default installs Jenkins from Ports creates a ssh wrapper file copies the ssh config copies the private Vagrant key starts the Jenkins service Finished in 0.34419 seconds 4 examples, 0 failures 1.43s user 0.24s system 76% cpu 2.186 total
  • 17. Pros & Cons ChefSpec Pro Contra Fast White Box Testing Can be run without convergence Harder to implement Easy Setup Some tricky configuration Don’t know what system looks like at the end
  • 18. ServerSpec • Describe desired state • Check whether convergence result matches expectations • Platform independent • Run it „from inside“ or „from outside“
  • 19. $ gem install serverspec $ serverspec-init Select OS type: 1) UN*X 2) Windows Select number: 1 Select a backend type: 1) SSH 2) Exec (local) Select number: 1 Vagrant instance y/n: y Auto-configure Vagrant from Vagrantfile? y/n: y
  • 20. $ rake -T rake spec:pttech # Run serverspec tests to pttech
  • 21. #"" site-cookbooks
 $  !"" spec
 $ #"" pt
 $ $ !"" jenkins_spec.rb
 $    !"" spec_helper.rb
 !"" Rakefile
  • 22. require 'serverspec'
 require 'net/ssh'
 require 'tempfile'
 
 set :backend, :ssh
 
 if ENV['ASK_SUDO_PASSWORD']
 begin
 require 'highline/import'
 rescue LoadError
 fail "highline is not available. Try installing it."
 end
 set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
 else
 set :sudo_password, ENV['SUDO_PASSWORD']
 end
 
 host = ENV['TARGET_HOST']
 
 `vagrant up #{host}`
 
 config = Tempfile.new('', Dir.tmpdir)
 `vagrant ssh-config #{host} > #{config.path}`
 
 options = Net::SSH::Config.for(host, [config.path])
 
 options[:user] ||= Etc.getlogin
 
 set :host, options[:host_name] || host
 set :ssh_options, options
  • 23. require 'rake'
 require 'rspec/core/rake_task'
 
 task :spec => 'spec:all'
 task :default => :spec
 
 namespace :spec do
 targets = []
 Dir.glob('./spec/*').each do |dir|
 next unless File.directory?(dir)
 targets << File.basename(dir)
 end
 
 task :all => targets
 task :default => :all
 
 targets.each do |target|
 desc "Run serverspec tests on #{target}"
 RSpec::Core::RakeTask.new(target.to_sym) do |t|
 ENV['TARGET_HOST'] = target
 t.pattern = "spec/#{target}/*_spec.rb"
 end
 end
 end
  • 24. $ rake Server contains - jenkins.war at the expected location - a folder /usr/local/jenkins, owned by user jenkins - a folder /usr/local/jenkins, with mode 766
  • 25. jenkins_config = JSON.parse(File.open("#{File.dirname(__FILE__)}/../../roles/jenkins.json").read)
 jenkins_config["override_attributes"]["jenkins"]["plugins"].each do | plugin_name, plugin_config |
 describe "Plugin: #{plugin_name}" do
 
 if plugin_config['enabled']
 it "has expected .hpi file in plugins directory" do
 expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi")).to be_file
 end
 end
 
 if plugin_config['pinned']
 it "is marked as pinned and has the .hpi.pinned file in the plugins directory" do
 expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi.pinned")).to be_file
 end
 it "is listed as pinned in the Jenkins plugin status" do
 expect(check_jenkins_plugin_pinned(plugin_name)).to be_truthy
 end
 else
 it "isn't marked as pinned and has no .hpi.pinned file in the plugins directory" do
 expect(file("/usr/local/jenkins/plugins/#{plugin_name}.hpi.pinned")).not_to be_file
 end
 end
 
 if plugin_config['version']
 it "is version #{plugin_config['version']}" do
 expect(check_jenkins_plugin_version(plugin_name, plugin_config['version'])).to be_truthy
 end
 end
 
 end
 end
  • 26. Pros & Cons ServerSpec Pro Contra Easy Setup & well documented No specific Feedback Black Box Tests Requires running Machine Small but mighty command set Slow (Easily?) extendable Can only be run once per convergence Run
  • 27. Test Kitchen • Test and Infrastructure Management • Interesting for Cookbook Development • Quite some (configuration) overhead • Good Tutorial • Bad Documentation
  • 28. ---
 driver:
 name: vagrant
 network:
 - ["private_network", {ip: "10.20.30.41", netmask: "255.255.255.0"}]
 
 provisioner:
 name: chef_zero
 require_chef_omnibus: false
 client_rb:
 cookbook_path: ["/var/chef/cookbooks", "/var/chef/site-cookbooks"]
 
 platforms:
 - name: FreeBSD-10-PtTech-TestKitchen
 driver:
 name: vagrant
 box: nanobsd-hosting-amd64.box-20140917
 box_url: http:/vagrantbox.es/some-box-to-use
 synced_folders:
 - [".", "/var/chef", "create: true, type: :nfs"]
 
 suites:
 - name: server
 run_list:
 - recipe[testkitchen]
 - role[jenkins]
 attributes:
  • 29. Pros & Cons TestKitchen Pro Contra Handles complex Setups „Touches“ your Machine after Convergence Multi-platform Testing for Cookbook Development No ServerSpec via ssh implemented „Standard“ in many Tutorials Requires machine startup from Scratch Many Plugins
  • 30. Foodcritic • Linting for Chef Cookbooks • Complex Rule Set far beyond Code Indentation • Goals (from Foodcritic Website) • To make it easier to flag problems in your Cookbooks • Faster feedback. • Automate checks for common problems
  • 31.
  • 32. $ gem install foodcritic $ foodcritic site-cookbooks/pt_jenkins -t FC001 # FC001 Use strings in preference to symbols to access node attributes FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/attributes/default.rb:55 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/attributes/default.rb:56 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/recipes/default.rb:21 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/recipes/default.rb:97 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/recipes/default.rb:98 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/recipes/default.rb:109 FC001: Use strings in preference to symbols to access node attributes:
 site-cookbooks/pt_jenkins/recipes/default.rb:141
  • 33. Further Testing Tools • BATS: Bash Automated Testing System • Shell Scripts 😟 • Cucumber Chef • Great idea, but prototype state only • Last commit > 1 year ago 😟
  • 34. Today ① Testing Principles ② Chef Testing Tools ③ Continuous Integration ✔ ✔
  • 35. Deployment Stage Knife Upload to
 Chef Server Acceptance Stage Serverspec Test Commit Stage Build Project ChefSpec Tests Foodcritic triggers uploads
  • 36. Today ① Testing Principles ② Chef Testing Tools ③ Continuous Integration ✔ ✔ ✔
  • 37.