summaryrefslogtreecommitdiff
path: root/kitchen-tests
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-08-06 14:19:17 -0700
committerClaire McQuin <claire@getchef.com>2014-08-13 09:21:20 -0700
commit730a41775850f22bf76cc60ce31065d2bfc6b3fe (patch)
tree44d38344c1f6e5b808154ed565ecab6edfa1ebfd /kitchen-tests
parent0bbddd62b0c65781eacd43f2ca3334a1ed23c09e (diff)
downloadchef-730a41775850f22bf76cc60ce31065d2bfc6b3fe.tar.gz
Remove kitchen tests from spec/ directory, so tests can be run separately.
Diffstat (limited to 'kitchen-tests')
-rw-r--r--kitchen-tests/.chef/client.rb7
-rw-r--r--kitchen-tests/.kitchen.travis.yml39
-rw-r--r--kitchen-tests/.kitchen.yml18
-rw-r--r--kitchen-tests/Berksfile3
-rw-r--r--kitchen-tests/Gemfile14
-rw-r--r--kitchen-tests/README.md57
-rw-r--r--kitchen-tests/cookbooks/webapp/Berksfile5
-rw-r--r--kitchen-tests/cookbooks/webapp/README.md4
-rw-r--r--kitchen-tests/cookbooks/webapp/attributes/default.rb7
-rw-r--r--kitchen-tests/cookbooks/webapp/metadata.rb12
-rw-r--r--kitchen-tests/cookbooks/webapp/recipes/default.rb61
-rw-r--r--kitchen-tests/cookbooks/webapp/templates/default/index.html.erb5
-rw-r--r--kitchen-tests/cookbooks/webapp/templates/default/index.php.erb8
-rw-r--r--kitchen-tests/data_bags/passwords/mysql.json5
-rw-r--r--kitchen-tests/data_bags/passwords/webapp.json4
-rw-r--r--kitchen-tests/test/fixtures/platforms/ubuntu/12.04.json42
-rw-r--r--kitchen-tests/test/fixtures/serverspec_helper.rb74
-rw-r--r--kitchen-tests/test/integration/webapp/serverspec/localhost/default_spec.rb127
18 files changed, 492 insertions, 0 deletions
diff --git a/kitchen-tests/.chef/client.rb b/kitchen-tests/.chef/client.rb
new file mode 100644
index 0000000000..5eb200a939
--- /dev/null
+++ b/kitchen-tests/.chef/client.rb
@@ -0,0 +1,7 @@
+
+chef_dir = File.expand_path(File.dirame(__FILE__))
+repo_dir = File.expand_path(Fild.join(chef_dir, '..'))
+
+log_level :info
+chef_repo_path repo_dir
+local_mode true
diff --git a/kitchen-tests/.kitchen.travis.yml b/kitchen-tests/.kitchen.travis.yml
new file mode 100644
index 0000000000..6ea825fc12
--- /dev/null
+++ b/kitchen-tests/.kitchen.travis.yml
@@ -0,0 +1,39 @@
+---
+driver_config:
+ aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
+ aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
+ aws_ssh_key_id: <%= ENV['AWS_KEYPAIR_NAME'] %>
+ iam_profile_name: <%= ENV['IAM_PROFILE_NAME'] %>
+
+provisioner:
+ name: chef_solo
+ github: <%= ENV['TRAVIS_REPO_SLUG'] %>
+ branch: <%= ENV['TRAVIS_COMMIT'] %>
+ require_chef_omnibus: true
+ data_path: test/fixtures
+
+platforms:
+ - name: ubuntu-12.04
+ driver_plugin: ec2
+ driver_config:
+ region: "us-west-2"
+ availability_zone: "us-west-2b"
+ ssh_key: <%= ENV['EC2_SSH_KEY_PATH'] %>
+ security_group_ids: ["travis-ci"]
+ - name: rhel-7.0
+ driver_plugin: ec2
+ driver_config:
+ region: "us-west-2"
+ availability_zone: "us-west-2b"
+ ssh_key: <%= ENV['EC2_SSH_KEY_PATH'] %>
+ security_group_ids: ["travis-ci"]
+ image_id: ami-77d7a747
+ flavor_id: m3.medium
+ username: ec2-user
+
+suites:
+ - name: webapp
+ run_list:
+ - recipe[apt::default]
+ - recipe[webapp::default]
+ attributes:
diff --git a/kitchen-tests/.kitchen.yml b/kitchen-tests/.kitchen.yml
new file mode 100644
index 0000000000..651a606502
--- /dev/null
+++ b/kitchen-tests/.kitchen.yml
@@ -0,0 +1,18 @@
+---
+provisioner:
+ name: chef_solo
+ github: "opscode/chef"
+ branch: <%= %x(git rev-parse HEAD) %>
+ require_chef_omnibus: true
+ data_path: test/fixtures
+
+platforms:
+ - name: ubuntu-12.04
+ driver_plugin: vagrant
+
+suites:
+ - name: webapp
+ run_list:
+ - recipe[apt::default]
+ - recipe[webapp::default]
+ attributes:
diff --git a/kitchen-tests/Berksfile b/kitchen-tests/Berksfile
new file mode 100644
index 0000000000..66569ed97f
--- /dev/null
+++ b/kitchen-tests/Berksfile
@@ -0,0 +1,3 @@
+source "https://supermarket.getchef.com"
+
+cookbook "webapp", :path => "cookbooks/webapp"
diff --git a/kitchen-tests/Gemfile b/kitchen-tests/Gemfile
new file mode 100644
index 0000000000..60df7ef388
--- /dev/null
+++ b/kitchen-tests/Gemfile
@@ -0,0 +1,14 @@
+source "https://rubygems.org"
+
+group :end_to_end do
+ gem 'berkshelf'
+ # Once merged into test-kitchen/test-kitchen:master we can remove
+ # this and replace it with
+ # gem 'test-kitchen', :github => 'test-kitchen/test-kitchen'
+ # until the next test-kitchen gem release.
+ gem 'test-kitchen', :github => 'mcquin/test-kitchen',
+ :branch => 'mcquin/install_chef_from_github'
+
+ gem 'kitchen-vagrant' # Used for local testing
+ gem 'kitchen-ec2' # Used for remote (Travis) testing
+end
diff --git a/kitchen-tests/README.md b/kitchen-tests/README.md
new file mode 100644
index 0000000000..e5b205c1b6
--- /dev/null
+++ b/kitchen-tests/README.md
@@ -0,0 +1,57 @@
+# End-To-End Testing for Chef Client
+
+The goal is to provide end-to-end testing of `chef-client` and tools which ship
+with it. To accomplish this, we use Test Kitchen with the `chef-solo` provisioner
+to download Chef source code from GitHub, locally create and install the chef
+gem from the source code, and run functional tests. Currently, these tests can
+be run locally on your machine, or on Travis when you submit a pull request.
+
+## Testing
+### On your local machine
+By default, Test Kitchen uses the [kitchen-vagrant](https://github.com/test-kitchen/kitchen-vagrant)
+driver plugin to create local kitchen instances and installs Chef based on your
+latest commit to `github.com/opscode/chef`. Currently, for this to work you'll
+need to ensure that your latest commit has been pushed to GitHub. If you want to
+download Chef from a different commit, modify the `branch` line under
+`provisioner` to have that commit's SHA. For example, it may look something like this:
+
+```(yaml)
+# spec/e2e/.kitchen.yml
+---
+provisioner:
+ name: chef_solo
+ branch: c8a54df7ca24f1482a701d5f39879cdc6c836f8a
+ github: "github.com/opscode/chef"
+ require_chef_omnibus: true
+
+platforms:
+ - name: ubuntu-12.04
+ driver_plugin: vagrant
+```
+`branch` accepts any valid git reference.
+
+When you're ready to test, execute the following lines (this assumes your current
+working directory is the head of the chef source code, e.g. mine is`~/oc/chef/`):
+
+```
+$ pwd
+~/oc/chef
+$ cd spec/e2e
+$ bundle install
+$ bundle exec kitchen test
+```
+To change what Test Kitchen runs, modify your `spec/e2e/.kitchen.yml`.
+
+### On Travis
+By default, Test Kitchen uses the [kitchen-ec2](https://github.com/test-kitchen/kitchen-ec2)
+driver plugin to create kitchen instances on EC2 and installs Chef based on the
+latest pushed commit to your pull request on `github.com/opscode/chef`. That is,
+Travis installs Chef from the branch and commit it's testing. Travis runs automatically
+every time you publish your commits to a pull request, so please disable Test Kitchen
+in Travis (by commenting out the appropriate lines in your `.travis.yml`) or push
+new commits to your PR infrequently.
+
+To change what Test Kitchen runs, modify your `spec/e2e/.kitchen.travis.yml`.
+
+**IMPORTANT: Do not modify any of the values in the matrix under `env`!** These are carefully
+configured so that Travis can use EC2 and Test Kitchen.
diff --git a/kitchen-tests/cookbooks/webapp/Berksfile b/kitchen-tests/cookbooks/webapp/Berksfile
new file mode 100644
index 0000000000..4b6079016e
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/Berksfile
@@ -0,0 +1,5 @@
+source "https://api.berkshelf.com"
+
+metadata
+
+cookbook "apt"
diff --git a/kitchen-tests/cookbooks/webapp/README.md b/kitchen-tests/cookbooks/webapp/README.md
new file mode 100644
index 0000000000..e8de6ee467
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/README.md
@@ -0,0 +1,4 @@
+# webapp
+
+TODO: Enter the cookbook description here.
+
diff --git a/kitchen-tests/cookbooks/webapp/attributes/default.rb b/kitchen-tests/cookbooks/webapp/attributes/default.rb
new file mode 100644
index 0000000000..efe06b6549
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/attributes/default.rb
@@ -0,0 +1,7 @@
+default['apache']['remote_host_ip'] = '127.0.0.1'
+
+default['mysql']['version'] = "5.5"
+
+default['webapp']['database'] = 'webapp'
+default['webapp']['db_username'] = 'webapp'
+default['webapp']['path'] = '/var/www/'
diff --git a/kitchen-tests/cookbooks/webapp/metadata.rb b/kitchen-tests/cookbooks/webapp/metadata.rb
new file mode 100644
index 0000000000..ecfb419953
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/metadata.rb
@@ -0,0 +1,12 @@
+name 'webapp'
+maintainer ''
+maintainer_email ''
+license ''
+description 'Installs/Configures webapp'
+long_description 'Installs/Configures webapp'
+version '0.1.0'
+
+depends 'apache2'
+depends 'database'
+depends 'mysql'
+depends 'php'
diff --git a/kitchen-tests/cookbooks/webapp/recipes/default.rb b/kitchen-tests/cookbooks/webapp/recipes/default.rb
new file mode 100644
index 0000000000..82479e5137
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/recipes/default.rb
@@ -0,0 +1,61 @@
+#
+# Cookbook Name:: webapp
+# Recipe:: default
+#
+# Copyright (C) 2014
+#
+
+include_recipe "apache2"
+include_recipe "database::mysql"
+include_recipe "php"
+
+creds = Hash.new
+%w(mysql webapp).each do |item_name|
+ creds[item_name] = data_bag_item('passwords', item_name)
+end
+
+apache_site "default" do
+ enable true
+end
+
+mysql_service "default" do
+ server_root_password creds['mysql']['server_root_password']
+ server_repl_password creds['mysql']['server_repl_password']
+end
+
+mysql_database node['webapp']['database'] do
+ connection ({
+ :host => 'localhost',
+ :username => 'root',
+ :password => creds['mysql']['server_root_password']
+ })
+ action :create
+end
+
+mysql_database_user node['webapp']['db_username'] do
+ connection ({
+ :host => 'localhost',
+ :username => 'root',
+ :password => creds['mysql']['server_root_password']
+ })
+ password creds['webapp']['db_password']
+ database_name node['webapp']['database']
+ privileges [:select, :update, :insert, :create, :delete]
+ action :grant
+end
+
+directory node['webapp']['path'] do
+ owner "root"
+ group "root"
+ mode "0755"
+ action :create
+ recursive true
+end
+
+template "#{node['webapp']['path']}/index.html" do
+ source 'index.html.erb'
+end
+
+template "#{node['webapp']['path']}/index.php" do
+ source 'index.php.erb'
+end
diff --git a/kitchen-tests/cookbooks/webapp/templates/default/index.html.erb b/kitchen-tests/cookbooks/webapp/templates/default/index.html.erb
new file mode 100644
index 0000000000..6da0629b9e
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/templates/default/index.html.erb
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ <h1>Hello, World!</h1>
+ </body>
+</html>
diff --git a/kitchen-tests/cookbooks/webapp/templates/default/index.php.erb b/kitchen-tests/cookbooks/webapp/templates/default/index.php.erb
new file mode 100644
index 0000000000..b08b076614
--- /dev/null
+++ b/kitchen-tests/cookbooks/webapp/templates/default/index.php.erb
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>PHP Test</title>
+ </head>
+ <body>
+ <?php echo '<p>Hello, World!</p>'; ?>
+ </body>
+</html>
diff --git a/kitchen-tests/data_bags/passwords/mysql.json b/kitchen-tests/data_bags/passwords/mysql.json
new file mode 100644
index 0000000000..af02a6a858
--- /dev/null
+++ b/kitchen-tests/data_bags/passwords/mysql.json
@@ -0,0 +1,5 @@
+{
+ "id": "mysql",
+ "server_root_password": "ilikerandompasswordstoo",
+ "server_repl_password": "itoolikerandompasswords"
+}
diff --git a/kitchen-tests/data_bags/passwords/webapp.json b/kitchen-tests/data_bags/passwords/webapp.json
new file mode 100644
index 0000000000..43c0ae1ced
--- /dev/null
+++ b/kitchen-tests/data_bags/passwords/webapp.json
@@ -0,0 +1,4 @@
+{
+ "id": "webapp",
+ "db_password": "supersecretdbpassword"
+}
diff --git a/kitchen-tests/test/fixtures/platforms/ubuntu/12.04.json b/kitchen-tests/test/fixtures/platforms/ubuntu/12.04.json
new file mode 100644
index 0000000000..5e436a3cb0
--- /dev/null
+++ b/kitchen-tests/test/fixtures/platforms/ubuntu/12.04.json
@@ -0,0 +1,42 @@
+{
+ "apache": {
+ "package": "apache2",
+ "binary": "/usr/sbin/apache2",
+ "dir": "/etc/apache2",
+ "lib_dir": "/usr/lib/apache2",
+ "libexec_dir": "/usr/lib/apache2/modules",
+ "cache_dir": "/var/cache/apache2",
+ "cgibin_dir": "/usr/lib/cgi-bin",
+ "docroot_dir": "/var/www",
+ "conf": "/etc/apache2/apache2.conf",
+ "perl_pkg": "perl",
+ "log_dir": "/var/log/apache2",
+ "root_group": "root",
+ "service_name": "apache2",
+ "service_restart_command": "/usr/sbin/invoke-rc.d apache2 restart && sleep 1",
+ "service_reload_command": "/usr/sbin/invoke-rc.d apache2 reload && sleep 1",
+ "default_site_name": "000-default",
+ "default_site_enabled": false,
+ "default_modules": [
+ "status",
+ "alias",
+ "auth_basic",
+ "authn_file",
+ "authz_core",
+ "authz_groupfile",
+ "authz_host",
+ "authz_user",
+ "autoindex",
+ "dir",
+ "env",
+ "mime",
+ "negotiation",
+ "setenvif"
+ ]
+ },
+ "mysql": {
+ "server": {
+ "version": "5.5"
+ }
+ }
+}
diff --git a/kitchen-tests/test/fixtures/serverspec_helper.rb b/kitchen-tests/test/fixtures/serverspec_helper.rb
new file mode 100644
index 0000000000..3a2c05f9cf
--- /dev/null
+++ b/kitchen-tests/test/fixtures/serverspec_helper.rb
@@ -0,0 +1,74 @@
+# Shamelessly copied from opscode/onehealth-cookbooks/apache2/test/fixtures/serverspec_helper.rb
+# The commented-out platforms in the osmapping hash can be added once we have added them into
+# our .kitchen.yml and .kitchen.travis.yml and added the appropriate JSON under test/fixtures/platforms.
+
+require 'serverspec'
+require 'json'
+
+include SpecInfra::Helper::Exec
+include SpecInfra::Helper::DetectOS
+include SpecInfra::Helper::Properties
+
+# http://serverspec.org/advanced_tips.html
+# os[:family] # RedHat, Ubuntu, Debian and so on
+# os[:release] # OS release version (cleaned up in v2)
+# os[:arch]
+osmapping = {
+# 'RedHat' => {
+# :platform_family => 'rhel',
+# :platform => 'centos',
+# :platform_version => '6.5'
+# },
+# 'RedHat7' => {
+# :platform_family => 'rhel',
+# :platform => 'centos',
+# :platform_version => '7.0'
+# },
+# 'Fedora' => {
+# :platform_family => 'rhel',
+# :platform => 'fedora',
+# :platform_version => '20'
+# },
+ 'Ubuntu' => {
+ :platform_family => 'debian',
+ :platform => 'ubuntu',
+ :platform_version => '12.04'
+ }
+# 'Debian' => {
+# :platform_family => 'debian',
+# :platform => 'debian',
+# :platform_version => '7.4'
+# },
+# 'FreeBSD' => {
+# :platform_family => 'freebsd',
+# :platform => 'freebsd',
+# :platform_version => '9.2'
+# }
+}
+
+def ohai_platform(os, osmapping)
+ puts "serverspec os detected as: #{os[:family]} #{os[:release]} [#{os[:arch]}]"
+ ohaistub = {}
+ ohaistub[:platform_family] = osmapping[os[:family]][:platform_family]
+ ohaistub[:platform] = osmapping[os[:family]][:platform]
+ if os[:release]
+ ohaistub[:platform_version] = os[:release]
+ else
+ ohaistub[:platform_version] = osmapping[os[:family]][:platform_version]
+ end
+ ohaistub
+end
+
+def load_nodestub(ohai)
+ puts "loading #{ohai[:platform]}/#{ohai[:platform_version]}"
+ JSON.parse(IO.read("#{ENV['BUSSER_ROOT']}/../kitchen/data/platforms/#{ohai[:platform]}/#{ohai[:platform_version]}.json"), :symbolize_names => true)
+end
+
+RSpec.configure do |config|
+ set_property load_nodestub(ohai_platform(backend.check_os, osmapping))
+ config.before(:all) do
+ # centos-59 doesn't have /sbin in the default path,
+ # so we must ensure it's on serverspec's path
+ config.path = '/sbin'
+ end
+end
diff --git a/kitchen-tests/test/integration/webapp/serverspec/localhost/default_spec.rb b/kitchen-tests/test/integration/webapp/serverspec/localhost/default_spec.rb
new file mode 100644
index 0000000000..e604de8f7f
--- /dev/null
+++ b/kitchen-tests/test/integration/webapp/serverspec/localhost/default_spec.rb
@@ -0,0 +1,127 @@
+
+require "net/http"
+require "uri"
+
+require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"
+
+describe "webapp::default", :end_to_end => true do
+
+ describe "installed packages" do
+ shared_examples_for "a package" do
+ it "is installed" do
+ expect(package(package_name)).to be_installed
+ end
+ end
+
+ describe "#{property[:apache][:package]} package" do
+ include_examples "a package" do
+ let(:package_name) { property[:apache][:package] }
+ end
+ end
+
+ describe "mysql-server-#{property[:mysql][:server][:version]} package" do
+ include_examples "a package" do
+ let(:package_name) { "mysql-server-#{property[:mysql][:server][:version]}" }
+ end
+ end
+
+ describe "mysql-client package" do
+ include_examples "a package" do
+ let(:package_name) { "mysql-client" }
+ end
+ end
+
+ describe "php package" do
+ include_examples "a package" do
+ let(:package_name) { "php5" }
+ end
+ end
+ end
+
+ describe "enabled/running services" do
+ shared_examples_for "a service" do
+ it "is enabled" do
+ expect(service(service_name)).to be_enabled
+ end
+
+ it "is running" do
+ expect(service(service_name)).to be_enabled
+ end
+ end
+
+ describe "#{property[:apache][:service_name]} service" do
+ include_examples "a service" do
+ let(:service_name) { property[:apache][:service_name] }
+ end
+ end
+
+ describe "mysql service" do
+ include_examples "a service" do
+ let(:service_name) { "mysql" }
+ end
+ end
+
+ end
+
+ describe "mysql database" do
+ let(:db_query) { "mysql -u root -pilikerandompasswordstoo -e \"#{statement}\"" }
+ let(:statement) { "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='webapp'" }
+ it "creates a database called 'webapp'" do
+ expect(command(db_query)).to return_stdout(/webapp/)
+ end
+
+ describe "mysql database user 'webapp'" do
+ let(:statement) { "SELECT Host, Db FROM mysql.db WHERE User='webapp'\\G" }
+ it "adds user 'webapp' to database 'webapp@localhost'" do
+ expect(command(db_query)).to return_stdout(/Host: localhost\n Db: webapp/)
+ end
+
+ describe "grants" do
+ shared_examples_for "a privilege" do |priv|
+ let(:statement) {
+ "SELECT #{priv_query}" \
+ " FROM mysql.db" \
+ " WHERE Host='localhost' AND Db='webapp' AND User='webapp'\\G"
+ }
+ let(:priv_query) { "#{priv.capitalize}_priv" }
+
+ it "has privilege #{priv} on 'webapp@localhost'" do
+ expect(command(db_query)).to return_stdout(/#{priv_query}: Y/)
+ end
+ end
+
+ %w(select update insert delete create).each do |priv|
+ include_examples "a privilege", priv do
+ end
+ end
+ end
+ end
+ end
+
+ describe "generated webpages" do
+ let(:get_response) { Net::HTTP.get_response(uri) }
+ shared_examples_for "a webpage" do
+ it "exists" do
+ expect(get_response).to be_kind_of(Net::HTTPSuccess)
+ end
+
+ it "displays content" do
+ expect(get_response.body).to include(content)
+ end
+ end
+
+ describe "http://localhost/index.html" do
+ include_examples "a webpage" do
+ let(:uri) { URI.parse("http://localhost/index.html") }
+ let(:content) { "Hello, World!" }
+ end
+ end
+
+ describe "http://localhost/index.php" do
+ include_examples "a webpage" do
+ let(:uri) { URI.parse("http://localhost/index.php") }
+ let(:content) { "Hello, World!" }
+ end
+ end
+ end
+end