Test Kitchen Config Examples

From Bonus Bits
Jump to: navigation, search

Description

This article gives several Test Kitchen configuration examples. The integration test folder name has to match the test suite name for it to pick up the serverspec Ruby files. So, I've listed examples under each to help clarify what I mean. First I'll start with how to configure a proxy in Test Kitchen.

Gnome-sticky-notes-applet As of Test Kitchen 1.4.2 the Proxy info doesn't pass through for loading up the busser test framework. As a workaround you can add code to your cookbook to add the proxy info to the VirtualBox root environment (/etc/environment).


VirtualBox - Charles Proxy - No Creds

Here's a snippet of where to add proxy information if running Charles Proxy locally.

---
driver:
  name: vagrant
  customize:
    memory: 512
    cpus: 1
    natdnshostresolver1: "on"
    natdnsproxy1: "on"

provisioner:
  name: chef_zero
  require_chef_omnibus: latest
  client_rb:
    ssl_verify_mode: ":verify_none"
  http_proxy: http://10.0.2.2:8888
  https_proxy: http://10.0.2.2:8888
  ftp_proxy: http://10.0.2.2:8888
  no_proxy: 'localhost,127.0.0.1,10.0.2.,33.33.33.,.localdomain.com'


VirtualBox - Proxy - Creds

Here's a snippet of where to add proxy information.

---
driver:
  name: vagrant
  customize:
    memory: 512
    cpus: 1
    natdnshostresolver1: "on"
    natdnsproxy1: "on"

provisioner:
  name: chef_zero
  require_chef_omnibus: latest
  client_rb:
    ssl_verify_mode: ":verify_none"
  http_proxy: http://username:password@proxy.domain.com:8000
  https_proxy: https://username:password@proxy.domain.com:8000
  no_proxy: 'localhost,127.0.0.1,10.0.2.,33.33.33.,.localdomain.com'


VirtualBox - Single Suite - Single OS

---
driver:
  name: vagrant
  customize:
    memory: 512
    cpus: 1

provisioner:
  name: chef_zero
  require_chef_omnibus: latest
  client_rb:
    ssl_verify_mode: ":verify_none"

platforms:
  - name: centos-7.2

suites:
  - name: default
    run_list:
      - recipe[mycookbook]
    attributes: {}

Kitchen List

Instance           Driver   Provisioner  Verifier  Transport  Last Action
default-centos-72  Vagrant  ChefZero     Busser    Ssh        <Not Created>

Test Folder

test
└── integration
    ├── data_bags
    │   └── encrypted_data_bag_secret
    ├── default
    │   └── serverspec
    │       └── mycookbook_spec.rb
    └── helpers
        └── serverspec
            ├── base_spec.rb
            └── spec_helper.rb

Virtualbox - Multiple Suite - Multiple OS

---
driver:
  name: vagrant
  customize:
    memory: 512
    cpus: 1
    natdnshostresolver1: "on"
    natdnsproxy1: "on"

provisioner:
  name: chef_zero
  require_chef_omnibus: 12.5.1
  client_rb:
    ssl_verify_mode: ":verify_none"

platforms:
  - name: centos-6.7
  - name: centos-7.2
  - name: ubuntu-14.04
  - name: ubuntu-15.04

suites:
  - name: mycookbook_rh
    data_bags_path: "test/integration/data_bags"
    encrypted_data_bag_secret_key_path: "test/integration/data_bags/encrypted_data_bag_secret"
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['centos-6.7', 'centos-7.2']
  - name: mycookbook_deb
    data_bags_path: "test/integration/data_bags"
    encrypted_data_bag_secret_key_path: "test/integration/data_bags/encrypted_data_bag_secret"
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['ubuntu-14.04', 'ubuntu-15.04']

Kitchen List

Instance                    Driver   Provisioner  Verifier  Transport  Last Action
mycookbook-rh-centos-67     Vagrant  ChefZero     Busser    Ssh        <Not Created>
mycookbook-rh-centos-72     Vagrant  ChefZero     Busser    Ssh        <Not Created>
mycookbook-deb-ubuntu-1404  Vagrant  ChefZero     Busser    Ssh        <Not Created>
mycookbook-deb-ubuntu-1504  Vagrant  ChefZero     Busser    Ssh        <Not Created>

Test Folder

test
└── integration
    ├── data_bags
    │   └── encrypted_data_bag_secret
    ├── helpers
    │   └── serverspec
    │       ├── base_spec.rb
    │       └── spec_helper.rb
    ├── mycookbook_deb
    │   └── serverspec
    │       └── deb_spec.rb
    └── mycookbook_rh
        └── serverspec
            └── rh_spec.rb


AWS - Single Suite - Single OS

---
driver:
  name: ec2
  shared_credentials_profile: aws-creds-profile-name
  aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
  instance_type: t2.micro
  region: us-west-2
  security_group_ids:
    - sg-1ac02578
  subnet_id: subnet-bf6c02e9
  vpc_id: vpc-15d2d087
  require_chef_omnibus: latest
  iam_profile_name: my-instance-policy
  driver_config:
    ssl_verify_mode: ":verify_none"

transport:
  username: ec2-user
  ssh_key: <%= ENV['AWS_SSH_KEY_PATH'] %>

provisioner:
  name: chef_zero

platforms:
  - name: rhel7
    driver:
      image_id: ami-775e4f16

suites:
  - name: default
    driver:
      tags:
        Name: testkitchen-mycookbook-rhel7-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
    run_list:
      - recipe[mycookbook]
    attributes: {}

Kitchen List

Instance       Driver  Provisioner  Verifier  Transport  Last Action
default-rhel7  Ec2     ChefZero     Busser    Ssh        <Not Created>

Test Folder

test
└── integration
    ├── data_bags
    │   └── encrypted_data_bag_secret
    ├── default
    │   └── serverspec
    │       └── mycookbook_spec.rb
    └── helpers
        └── serverspec
            ├── base_spec.rb
            └── spec_helper.rb


AWS - Multiple Suite - Multiple OS

---

driver:
  name: ec2
  shared_credentials_profile: aws-creds-profile-name
  aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
  instance_type: t2.micro
  region: us-west-2
  security_group_ids:
    - sg-1ac02578
  subnet_id: subnet-bf6c02e9
  vpc_id: vpc-15d2d087
  require_chef_omnibus: 12.5.1
  iam_profile_name: my-instance-policy
  driver_config:
    ssl_verify_mode: ":verify_none"

transport:
  username: ec2-user
  ssh_key: <%= ENV['AWS_SSH_KEY_PATH'] %>

provisioner:
  name: chef_zero

platforms:
  - name: amzn2015091
    driver:
      image_id: ami-f0091d91
      tags:
        Name: testkitchen-mycookbook-centos6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: centos6
    driver:
      image_id: ami-07d4f737
      tags:
        Name: testkitchen-mycookbook-centos6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: centos7
    driver:
      image_id: ami-07e6c437
      tags:
        Name: testkitchen-mycookbook-centos7-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: rhel6
    driver:
      image_id: ami-0b5f073b
      tags:
        Name: testkitchen-mycookbook-rhel6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: rhel7
    driver:
      image_id: ami-775e4f16
      tags:
        Name: testkitchen-mycookbook-rhel7-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: suse12
    driver:
      image_id: ami-d2627db3
      tags:
        Name: testkitchen-mycookbook-suse12-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: suseleap42
    driver:
      image_id: ami-7c77641d
      tags:
        Name: testkitchen-mycookbook-suse12-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: ubuntu1404
    driver:
      image_id: ami-9abea4fb
      tags:
        Name: testkitchen-mycookbook-ubuntu1404-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>

suites:
  - name: mycookbook_rh
    data_bags_path: "test/integration/data_bags"
    encrypted_data_bag_secret_key_path: "test/integration/data_bags/encrypted_data_bag_secret"
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['amzn2015091', 'centos6', 'centos7', 'rhel6', 'rhel7']
  - name: mycookbook_deb
    data_bags_path: "test/integration/data_bags"
    encrypted_data_bag_secret_key_path: "test/integration/data_bags/encrypted_data_bag_secret"
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['ubuntu1404']
  - name: mycookbook_suse
    data_bags_path: "test/integration/data_bags"
    encrypted_data_bag_secret_key_path: "test/integration/data_bags/encrypted_data_bag_secret"
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['suse12', 'suseleap42']

Kitchen List

Instance                    Driver  Provisioner  Verifier  Transport  Last Action
mycookbook-rh-amzn2015091   Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-rh-centos6       Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-rh-centos7       Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-rh-rhel6         Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-rh-rhel7         Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-deb-ubuntu1404   Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-suse-suse12      Ec2     ChefZero     Busser    Ssh        <Not Created>
mycookbook-suse-suseleap42  Ec2     ChefZero     Busser    Ssh        <Not Created>

Test Folder

test
└── integration
    ├── data_bags
    │   └── encrypted_data_bag_secret
    ├── helpers
    │   └── serverspec
    │       ├── base_spec.rb
    │       └── spec_helper.rb
    ├── mycookbook_deb
    │   └── serverspec
    │       └── deb_spec.rb
    ├── mycookbook_rh
    │   └── serverspec
    │       └── rh_spec.rb
    └── mycookbook_suse
        └── serverspec
            └── suse_spec.rb


AWS - Single Suite - Multiple OS

---
driver:
  name: ec2
  shared_credentials_profile: aws-creds-profile-name
  aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
  instance_type: t2.micro
  region: us-west-2
  security_group_ids:
    - sg-1ac02578
  subnet_id: subnet-bf6c02e9
  vpc_id: vpc-15d2d087
  require_chef_omnibus: latest
  iam_profile_name: my-instance-policy
  driver_config:
    ssl_verify_mode: ":verify_none"

transport:
  username: ec2-user
  ssh_key: <%= ENV['AWS_SSH_KEY_PATH'] %>

provisioner:
  name: chef_zero

platforms:
  - name: amzn2015091
    driver:
      image_id: ami-f0091d91
      tags:
        Name: testkitchen-mycookbook-centos6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: centos6
    driver:
      image_id: ami-07d4f737
      tags:
        Name: testkitchen-mycookbook-centos6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: centos7
    driver:
      image_id: ami-07e6c437
      tags:
        Name: testkitchen-mycookbook-centos7-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: rhel6
    driver:
      image_id: ami-0b5f073b
      tags:
        Name: testkitchen-mycookbook-rhel6-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>
  - name: rhel7
    driver:
      image_id: ami-775e4f16
      tags:
        Name: testkitchen-mycookbook-rhel7-<%= ENV['USER'] %>
        Created-By: Test Kitchen
        ApplicationName: My Project
        EnvironmentName: Dev
        OWNER: <%= ENV['USER'] %>

suites:
  - name: default
    run_list:
      - recipe[mycookbook]
    attributes: {}
    includes: ['amzn2015091', 'centos6', 'centos7', 'rhel6', 'rhel7']

Kitchen List

Instance             Driver  Provisioner  Verifier  Transport  Last Action
default-amzn2015091  Ec2     ChefZero     Busser    Ssh        <Not Created>
default-centos6      Ec2     ChefZero     Busser    Ssh        <Not Created>
default-centos7      Ec2     ChefZero     Busser    Ssh        <Not Created>
default-rhel6        Ec2     ChefZero     Busser    Ssh        <Not Created>
default-rhel7        Ec2     ChefZero     Busser    Ssh        <Not Created>

Test Folder

test
└── integration
    ├── data_bags
    │   └── encrypted_data_bag_secret
    ├── default
    │   └── serverspec
    │       └── mycookbook_spec.rb
    └── helpers
        └── serverspec
            ├── base_spec.rb
            └── spec_helper.rb


Related Articles


formatted text
cat /var/log/messages

Icon-Tip-Square-Green.png
Gnome-sticky-notes-applet