Skip to content
This repository has been archived by the owner on Nov 30, 2017. It is now read-only.

Commit

Permalink
add test kitchen
Browse files Browse the repository at this point in the history
  • Loading branch information
dwradcliffe committed Jun 2, 2014
1 parent a1c0461 commit d71b3e0
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ chef.tar.gz
.rvmrc
chef/site-cookbooks/rubygems/files/default/rubygems.org*
chef/data_bags/secrets/*
.kitchen/
.kitchen.local.yml
56 changes: 56 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
driver:
name: vagrant

provisioner:
name: chef_solo

platforms:
- name: ubuntu-12.04

suites:
- name: base
run_list: ["role[base]", "role[vagrant]"]
roles_path: "chef/roles"
data_bags_path: "chef/data_bags"
- name: dbmaster
run_list: ["role[db_master]", "role[vagrant]"]
roles_path: "chef/roles"
data_bags_path: "chef/data_bags"
attributes:
- name: app
run_list: ["role[app]", "role[vagrant]"]
roles_path: "chef/roles"
data_bags_path: "chef/data_bags"
attributes:
application:
name: 'rubygems'
rails_env: vagrant
rails_root: "/applications/rubygems/staging"
server_names:
- "vagrant.rubygems.org"
use_ssl: true
force_ssl: true
ssl_key: rubygems.org.key
ssl_cert: rubygems.org.crt
app_server:
name: unicorn
concurrency: 4
- name: balancer
run_list: ["role[balancer]", "role[vagrant]"]
roles_path: "chef/roles"
data_bags_path: "chef/data_bags"
attributes:
application:
name: 'rubygems'
rails_env: vagrant
rails_root: "/applications/rubygems/staging"
server_names:
- "vagrant.rubygems.org"
use_ssl: true
force_ssl: true
ssl_key: rubygems.org.key
ssl_cert: rubygems.org.crt
app_server:
name: unicorn
concurrency: 4
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ gem 'fpm', '~> 0.3'
gem 'knife-solo', '~> 0.3'
gem 'rubocop', '~> 0.14'
gem 'berkshelf', '~> 2'

group :integration do
gem 'test-kitchen'
gem 'kitchen-vagrant'
end
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ GEM
i18n (0.6.9)
ipaddress (0.8.0)
json (1.7.7)
kitchen-vagrant (0.15.0)
test-kitchen (~> 1.0)
knife-solo (0.4.0)
chef (>= 10.12)
erubis (~> 2.7.0)
Expand All @@ -126,6 +128,8 @@ GEM
multi_json (1.8.2)
multipart-post (1.2.0)
net-http-persistent (2.9)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
Expand Down Expand Up @@ -180,6 +184,7 @@ GEM
powerpack (~> 0.0.6)
rainbow (>= 1.1.4)
rubyntlm (0.1.1)
safe_yaml (1.0.3)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
Expand All @@ -191,6 +196,12 @@ GEM
slop (3.4.6)
solve (0.8.2)
systemu (2.5.2)
test-kitchen (1.2.1)
mixlib-shellout (~> 1.2)
net-scp (~> 1.1)
net-ssh (~> 2.7)
safe_yaml (~> 1.0)
thor (~> 0.18)
thor (0.18.1)
timers (2.0.0)
hitimes
Expand Down Expand Up @@ -221,5 +232,7 @@ DEPENDENCIES
chef (~> 10.18)
foodcritic (~> 3.0)
fpm (~> 0.3)
kitchen-vagrant
knife-solo (~> 0.3)
rubocop (~> 0.14)
test-kitchen
10 changes: 10 additions & 0 deletions chef/roles/vagrant.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
name "vagrant"
description "The base vagrant role with a few overrides"

run_list(
"recipe[rubygems::purge_denyhosts]"
)

override_attributes(
"authorization" => {
"sudo" => {
"passwordless" => true
}
},
"denyhosts" => {
"allowed_hosts" => ["10.0.2.2"]
},
"sudo" => {
"add_vagrant" => true
},
"nginx" => {
"log_dir" => "/var/log/nginx"
}
)
1 change: 1 addition & 0 deletions chef/site-cookbooks/rubygems/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
recipe 'rubygems::monit', 'Configure monit logs and monitors'
recipe 'rubygems::nginx_source', 'Installs nginx from our pre-build package'
recipe 'rubygems::papertrail', 'Configures rsyslog to send logs to Papertrail'
recipe 'rubygems::purge_denyhosts', 'Purges all blocked hosts'
recipe 'rubygems::rails', 'Main app recipe'
recipe 'rubygems::rails_nginx', 'nginx config for app server'
recipe 'rubygems::stat-update', 'Installs stat-update from pre-built package'
Expand Down
23 changes: 23 additions & 0 deletions chef/site-cookbooks/rubygems/recipes/purge_denyhosts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Cookbook Name:: rubygems
# Recipe:: purge_denyhosts
#

node.default['denyhosts']['work_dir'] = '/var/lib/denyhosts'

%w(hosts hosts-restricted hosts-root hosts-valid user-hosts).each do |filename|
file File.join(node['denyhosts']['work_dir'], filename) do
content ''
notifies :restart, 'service[denyhosts]'
end
end

ruby_block "purge /etc/hosts.deny" do
block do
file = ::Chef::Util::FileEdit.new('/etc/hosts.deny')
file.search_file_delete_line(/^[^#|\s]/)
file.write_file
end
only_if { ::File.exists?('/etc/hosts.deny') }
notifies :restart, 'service[denyhosts]'
end
5 changes: 5 additions & 0 deletions test/integration/app/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS
include Serverspec::Helper::Properties
9 changes: 9 additions & 0 deletions test/integration/app/serverspec/stat-update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'rubygems::stat-update' do

describe package('stat-update') do
it { should be_installed }
end

end
5 changes: 5 additions & 0 deletions test/integration/base/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'rubygems::default' do

end
5 changes: 5 additions & 0 deletions test/integration/base/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS
include Serverspec::Helper::Properties
13 changes: 13 additions & 0 deletions test/integration/base/serverspec/system_ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe 'rubygems::system_ruby' do

describe package('ruby1.9.1-full') do
it { should be_installed }
end

describe command('ruby -v') do
it { should return_stdout(/ruby 1\.9\.3p0/) }
end

end
33 changes: 33 additions & 0 deletions test/integration/base/serverspec/users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

describe 'rubygems::users' do

describe user('deploy') do
it { should exist }
end

describe group('sysadmin') do
it { should exist }
end

describe user('dwradcliffe') do
it { should exist }
it { should belong_to_group 'sysadmin' }
end

describe user('evan') do
it { should exist }
it { should belong_to_group 'sysadmin' }
end

describe user('samkottler') do
it { should exist }
it { should belong_to_group 'sysadmin' }
end

describe user('qrush') do
it { should exist }
it { should belong_to_group 'sysadmin' }
end

end
18 changes: 18 additions & 0 deletions test/integration/dbmaster/serverspec/postgresql_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'

describe 'postgresql' do

describe package('postgresql-9.2') do
it { should be_installed }
end

describe command('psql --version') do
it { should return_stdout(/9.2.8/) }
end

describe service('postgresql') do
it { should be_enabled }
it { should be_running }
end

end
5 changes: 5 additions & 0 deletions test/integration/dbmaster/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS
include Serverspec::Helper::Properties
Binary file added vendor/cache/kitchen-vagrant-0.15.0.gem
Binary file not shown.
Binary file added vendor/cache/net-scp-1.2.1.gem
Binary file not shown.
Binary file added vendor/cache/safe_yaml-1.0.3.gem
Binary file not shown.
Binary file added vendor/cache/test-kitchen-1.2.1.gem
Binary file not shown.

0 comments on commit d71b3e0

Please sign in to comment.