test-kitchen 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/bin/kitchen +7 -0
  2. data/config/Cheffile +55 -0
  3. data/config/Kitchenfile +39 -0
  4. data/config/Vagrantfile +109 -0
  5. data/cookbooks/test-kitchen/attributes/default.rb +25 -0
  6. data/cookbooks/test-kitchen/libraries/helpers.rb +25 -0
  7. data/cookbooks/test-kitchen/metadata.rb +27 -0
  8. data/cookbooks/test-kitchen/recipes/chef.rb +19 -0
  9. data/cookbooks/test-kitchen/recipes/compat.rb +39 -0
  10. data/cookbooks/test-kitchen/recipes/default.rb +51 -0
  11. data/cookbooks/test-kitchen/recipes/erlang.rb +19 -0
  12. data/cookbooks/test-kitchen/recipes/ruby.rb +40 -0
  13. data/lib/test-kitchen.rb +34 -0
  14. data/lib/test-kitchen/cli.rb +267 -0
  15. data/lib/test-kitchen/cli/destroy.rb +42 -0
  16. data/lib/test-kitchen/cli/init.rb +37 -0
  17. data/lib/test-kitchen/cli/platform_list.rb +37 -0
  18. data/lib/test-kitchen/cli/project_info.rb +44 -0
  19. data/lib/test-kitchen/cli/ssh.rb +36 -0
  20. data/lib/test-kitchen/cli/status.rb +36 -0
  21. data/lib/test-kitchen/cli/test.rb +60 -0
  22. data/lib/test-kitchen/dsl.rb +59 -0
  23. data/lib/test-kitchen/environment.rb +164 -0
  24. data/lib/test-kitchen/platform.rb +63 -0
  25. data/lib/test-kitchen/project.rb +23 -0
  26. data/lib/test-kitchen/project/base.rb +159 -0
  27. data/lib/test-kitchen/project/cookbook.rb +87 -0
  28. data/lib/test-kitchen/project/cookbook_copy.rb +58 -0
  29. data/lib/test-kitchen/project/ruby.rb +37 -0
  30. data/lib/test-kitchen/project/supported_platforms.rb +75 -0
  31. data/lib/test-kitchen/runner.rb +20 -0
  32. data/lib/test-kitchen/runner/base.rb +144 -0
  33. data/lib/test-kitchen/runner/vagrant.rb +92 -0
  34. data/lib/test-kitchen/scaffold.rb +73 -0
  35. data/lib/test-kitchen/ui.rb +73 -0
  36. data/lib/test-kitchen/version.rb +21 -0
  37. metadata +196 -0
data/bin/kitchen ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
+ #require 'bundler/setup'
5
+ require 'test-kitchen'
6
+
7
+ TestKitchen::CLI::Kitchen.new.run
data/config/Cheffile ADDED
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'test-kitchen'
20
+
21
+ site 'http://community.opscode.com/api/v1'
22
+
23
+ # base test-kitchen cookbooks
24
+ cookbook 'apt', '1.4.6'
25
+ cookbook 'yum', '0.8.0'
26
+ cookbook 'build-essential', '1.1.0'
27
+ cookbook 'git', '1.0.0'
28
+ cookbook 'rvm',
29
+ :git => 'https://github.com/fnichol/chef-rvm.git',
30
+ :ref => 'c27a8942ed311ccce2c63c2e863201b049c70a0d'
31
+ cookbook 'test-kitchen',
32
+ :path => TestKitchen.source_root.join('cookbooks', 'test-kitchen').to_s
33
+
34
+ env = TestKitchen::Environment.new
35
+ env.load!
36
+
37
+ # include cookbook being tested if this is a cookbook project
38
+ if env.project.respond_to?(:cookbook_path)
39
+ cookbook env.project.name, :path => env.project.cookbook_path(env.root_path, env.tmp_path)
40
+ end
41
+
42
+ if env.project.run_list.include? 'recipe[minitest-handler]'
43
+ cookbook 'minitest-handler',
44
+ :git => 'git://github.com/kotiri/minitest-handler-cookbook.git'
45
+ end
46
+
47
+ # include user-provided cookbooks
48
+ if env.root_path.join('cookbooks').exist?
49
+ env.root_path.join('cookbooks').children.select(&:directory?).each do |c|
50
+ cookbook c.basename.to_s, :path => env.root_path.join('cookbooks', c.basename.to_s).to_s
51
+ end
52
+ if env.root_path.join('cookbooks', 'Cheffile').exist?
53
+ eval(File.read(env.root_path.join('cookbooks', 'Cheffile')))
54
+ end
55
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ platform :centos do
20
+ version '5.8' do
21
+ box "opscode-centos-5.8"
22
+ box_url "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-5.8.box"
23
+ end
24
+ version '6.3' do
25
+ box "opscode-centos-6.3"
26
+ box_url "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-6.3.box"
27
+ end
28
+ end
29
+
30
+ platform :ubuntu do
31
+ version '10.04' do
32
+ box "opscode-ubuntu-10.04"
33
+ box_url "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-10.04.box"
34
+ end
35
+ version '12.04' do
36
+ box "opscode-ubuntu-12.04"
37
+ box_url "https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box"
38
+ end
39
+ end
@@ -0,0 +1,109 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'test-kitchen'
20
+
21
+ def recipe_exists?(cookbook_path, recipe_name)
22
+ File.exists?(File.join(cookbook_path, "#{recipe_name}.rb".split('::').insert(1, 'recipes')))
23
+ end
24
+
25
+ def build_run_list(cookbook_paths, test_recipe_name)
26
+ run_list = []
27
+ if test_recipe_name
28
+ [test_recipe_name, test_recipe_name.sub('_test', '')].uniq.each do |recipe_name|
29
+ if cookbook_paths.any? {|path| recipe_exists?(path, recipe_name)}
30
+ run_list << recipe_name
31
+ end
32
+ end
33
+ end
34
+ run_list
35
+ end
36
+
37
+ tk_env = TestKitchen::Environment.new
38
+ tk_env.load!
39
+ tk_config = tk_env.config
40
+ project = tk_env.project
41
+
42
+ ::Vagrant::Config.run do |vagrant_config|
43
+
44
+ tk_env.platforms.values.each do |platform|
45
+
46
+ platform.versions.values.each do |version|
47
+
48
+ name = "#{platform.name}-#{version.name}"
49
+
50
+ vagrant_config.vm.define name do |vm_config|
51
+
52
+ host_name = name.gsub(/\./, '-')
53
+
54
+ vm_config.vm.customize [
55
+ "modifyvm", :id,
56
+ "--name", host_name,
57
+ "--memory", (project.memory || "256"),
58
+ "--cpus", "1",
59
+ "--nictype1", "82545EM",
60
+ "--nictype2", "82545EM",
61
+ "--audio", "none",
62
+ "--natdnsproxy1", "on",
63
+ "--usb", "off",
64
+ "--usbehci", "off"
65
+ ]
66
+
67
+ # Enable the host IO cache on the sata controller. Note that
68
+ # if this fails then its not a big deal, so we don't raise any
69
+ # errors. The Host IO cache vastly improves disk IO performance
70
+ # for VMs.
71
+ vm_config.vm.customize [
72
+ "storagectl", :id,
73
+ "--name", "SATA Controller",
74
+ "--hostiocache", "on"
75
+ ]
76
+
77
+ vm_config.vm.host_name = host_name
78
+ vm_config.vm.box = version.box
79
+ vm_config.vm.box_url = version.box_url
80
+
81
+ # Enable SSH agent forwarding for git clones
82
+ vm_config.ssh.forward_agent = true
83
+
84
+ # mount the local code checkout up in the VM for testing
85
+ vm_config.vm.share_folder "project", project.guest_source_root, project.root_path
86
+
87
+ # default chef attribute json
88
+ chef_json = {
89
+ 'test-kitchen' => {
90
+ 'project' => project.to_hash.merge(
91
+ 'source_root' => project.guest_source_root,
92
+ 'test_root' => project.guest_test_root
93
+ )
94
+ },
95
+ }
96
+
97
+ vm_config.vm.provision :chef_solo do |chef|
98
+ chef.cookbooks_path = tk_env.cookbook_paths
99
+ chef.run_list = project.run_list + build_run_list(tk_env.cookbook_paths, test_recipe_name)
100
+ chef.json = chef_json
101
+ chef.log_level = :debug
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ default['test-kitchen']['project'] = {
20
+ 'test_root' => "/test-kitchen/test",
21
+ 'source_root' => "/test-kitchen/source"
22
+ }
23
+
24
+ default['test-kitchen']['user'] = 'vagrant'
25
+ default['test-kitchen']['group'] = 'vagrant'
@@ -0,0 +1,25 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class Chef::Recipe
20
+ def recipe_for_project?(project_name)
21
+ run_context.cookbook_collection['test-kitchen'].recipe_files.any? do |rf|
22
+ rf =~ Regexp.new(project_name)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ maintainer "Opscode, Inc."
20
+ maintainer_email "cookbooks@opscode.com"
21
+ license "Apache 2.0"
22
+ description "Support cookbook for the test-kitchen gem"
23
+ version "1.0.0"
24
+
25
+ depends "apt"
26
+ depends "git"
27
+ depends "yum"
@@ -0,0 +1,19 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ include_recipe "test-kitchen::ruby"
@@ -0,0 +1,39 @@
1
+
2
+ # stop strict host key checking on github.com
3
+ execute 'no-github-key-checking' do
4
+ command "echo '\nHost github.com\n\tStrictHostKeyChecking no' >> /etc/ssh/ssh_config"
5
+ action :run
6
+ not_if "cat /etc/ssh/ssh_config | grep github.com"
7
+ end
8
+
9
+ # ensure sudo inherits the SSH_AUTH_SOCK
10
+ execute 'sudo-ssh-auth-sock' do
11
+ command "echo '\nDefaults env_keep+=SSH_AUTH_SOCK' >> /etc/sudoers"
12
+ action :run
13
+ not_if "cat /etc/sudoers | grep SSH_AUTH_SOCK"
14
+ end
15
+
16
+ # ensure the current chef-solo process honors SSH_AUTH_SOCK
17
+ # http://stackoverflow.com/questions/7211287/use-ssh-keys-with-passphrase-on-a-vagrantchef-setup
18
+ ruby_block "Give root access to the forwarded ssh agent" do
19
+ block do
20
+ # find a parent process' ssh agent socket
21
+ agents = {}
22
+ ppid = Process.ppid
23
+ Dir.glob('/tmp/ssh*/agent*').each do |fn|
24
+ agents[fn.match(/agent\.(\d+)$/)[1]] = fn
25
+ end
26
+ while ppid != '1'
27
+ if (agent = agents[ppid])
28
+ ENV['SSH_AUTH_SOCK'] = agent
29
+ break
30
+ end
31
+ File.open("/proc/#{ppid}/status", "r") do |file|
32
+ ppid = file.read().match(/PPid:\s+(\d+)/)[1]
33
+ end
34
+ end
35
+ # Uncomment to require that an ssh-agent be available
36
+ # fail "Could not find running ssh agent - Is config.ssh.forward_agent enabled in Vagrantfile?" unless ENV['SSH_AUTH_SOCK']
37
+ end
38
+ action :create
39
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ # Make sure that the package list is up to date
20
+ case node['platform']
21
+ when 'debian', 'ubuntu'
22
+ include_recipe 'apt'
23
+ # Force an update at compile-time to avoid failure when a cookbook attempts
24
+ # a package install at compile-time.
25
+ resources(:execute => "apt-get update").run_action(:run)
26
+ when 'centos','redhat'
27
+ include_recipe 'yum::epel'
28
+ end
29
+
30
+ include_recipe 'git'
31
+ include_recipe 'test-kitchen::compat'
32
+
33
+ project = node['test-kitchen']['project']
34
+ source_root = project['source_root']
35
+ test_root = project['test_root']
36
+
37
+ package "rsync" do
38
+ action :install
39
+ end
40
+
41
+ execute "stage project source to test root" do
42
+ command "rsync -aHv --update --progress --checksum #{source_root}/ #{test_root} "
43
+ end
44
+
45
+ # make the project_root available to other recipes
46
+ node.run_state['project'] = project
47
+
48
+ language = project['language'] || 'chef'
49
+
50
+ # ensure projects declared language toolchain is present
51
+ include_recipe "test-kitchen::#{language}"
@@ -0,0 +1,19 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ # TODO - write this!
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ project = node.run_state['project']
20
+
21
+ [File.join(project['test_root'], 'Gemfile'),
22
+ File.join(project['test_root'], 'test', 'Gemfile')].each do |gemfile_path|
23
+
24
+ # TODO - remove this when test-kitchen is public
25
+ ruby_block "remove test-kitchen entry in Gemfile - #{gemfile_path}" do
26
+ block do
27
+ require 'chef/util/file_edit'
28
+ fe = Chef::Util::FileEdit.new(gemfile_path)
29
+ fe.search_file_delete_line(/gem ['"]test-kitchen['"]/)
30
+ fe.write_file
31
+ end
32
+ only_if { File.exists?(gemfile_path) }
33
+ end
34
+
35
+ # ensure we blow away Gemfile.lock
36
+ file "#{gemfile_path}.lock" do
37
+ action :delete
38
+ end
39
+
40
+ end