test-kitchen 0.7.0 → 1.0.0.alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.travis.yml +11 -0
- data/.yardopts +3 -0
- data/Gemfile +13 -0
- data/Guardfile +11 -0
- data/LICENSE +15 -0
- data/README.md +131 -0
- data/Rakefile +69 -0
- data/bin/kitchen +9 -4
- data/features/cli.feature +17 -0
- data/features/cli_init.feature +156 -0
- data/features/support/env.rb +14 -0
- data/lib/kitchen/busser.rb +166 -0
- data/lib/kitchen/chef_data_uploader.rb +156 -0
- data/lib/kitchen/cli.rb +540 -0
- data/lib/kitchen/collection.rb +55 -0
- data/lib/kitchen/color.rb +46 -0
- data/lib/kitchen/config.rb +223 -0
- data/lib/kitchen/driver/base.rb +180 -0
- data/lib/kitchen/driver/dummy.rb +81 -0
- data/lib/kitchen/driver/ssh_base.rb +192 -0
- data/lib/kitchen/driver.rb +42 -0
- data/lib/kitchen/errors.rb +52 -0
- data/lib/kitchen/instance.rb +327 -0
- data/lib/kitchen/instance_actor.rb +42 -0
- data/lib/kitchen/loader/yaml.rb +105 -0
- data/lib/kitchen/logger.rb +145 -0
- data/{cookbooks/test-kitchen/libraries/helpers.rb → lib/kitchen/logging.rb} +13 -9
- data/lib/kitchen/manager.rb +45 -0
- data/lib/kitchen/metadata_chopper.rb +52 -0
- data/lib/kitchen/platform.rb +61 -0
- data/lib/kitchen/rake_tasks.rb +59 -0
- data/lib/kitchen/shell_out.rb +65 -0
- data/lib/kitchen/state_file.rb +88 -0
- data/lib/kitchen/suite.rb +76 -0
- data/lib/kitchen/thor_tasks.rb +62 -0
- data/lib/kitchen/util.rb +79 -0
- data/{cookbooks/test-kitchen/recipes/erlang.rb → lib/kitchen/version.rb} +9 -6
- data/lib/kitchen.rb +98 -0
- data/lib/vendor/hash_recursive_merge.rb +74 -0
- data/spec/kitchen/collection_spec.rb +80 -0
- data/spec/kitchen/color_spec.rb +54 -0
- data/spec/kitchen/config_spec.rb +201 -0
- data/spec/kitchen/driver/dummy_spec.rb +191 -0
- data/spec/kitchen/instance_spec.rb +162 -0
- data/spec/kitchen/loader/yaml_spec.rb +243 -0
- data/spec/kitchen/platform_spec.rb +48 -0
- data/spec/kitchen/state_file_spec.rb +122 -0
- data/spec/kitchen/suite_spec.rb +64 -0
- data/spec/spec_helper.rb +47 -0
- data/templates/plugin/driver.rb.erb +23 -0
- data/templates/plugin/license_apachev2.erb +15 -0
- data/templates/plugin/license_gplv2.erb +18 -0
- data/templates/plugin/license_gplv3.erb +16 -0
- data/templates/plugin/license_mit.erb +22 -0
- data/templates/plugin/license_reserved.erb +5 -0
- data/templates/plugin/version.rb.erb +12 -0
- data/test-kitchen.gemspec +44 -0
- metadata +290 -82
- data/config/Cheffile +0 -47
- data/config/Kitchenfile +0 -39
- data/config/Vagrantfile +0 -114
- data/cookbooks/test-kitchen/attributes/default.rb +0 -25
- data/cookbooks/test-kitchen/metadata.rb +0 -27
- data/cookbooks/test-kitchen/recipes/chef.rb +0 -19
- data/cookbooks/test-kitchen/recipes/compat.rb +0 -39
- data/cookbooks/test-kitchen/recipes/default.rb +0 -51
- data/cookbooks/test-kitchen/recipes/ruby.rb +0 -29
- data/lib/test-kitchen/cli/destroy.rb +0 -36
- data/lib/test-kitchen/cli/init.rb +0 -37
- data/lib/test-kitchen/cli/platform_list.rb +0 -37
- data/lib/test-kitchen/cli/project_info.rb +0 -44
- data/lib/test-kitchen/cli/ssh.rb +0 -36
- data/lib/test-kitchen/cli/status.rb +0 -36
- data/lib/test-kitchen/cli/test.rb +0 -68
- data/lib/test-kitchen/cli.rb +0 -282
- data/lib/test-kitchen/dsl.rb +0 -63
- data/lib/test-kitchen/environment.rb +0 -166
- data/lib/test-kitchen/platform.rb +0 -79
- data/lib/test-kitchen/project/base.rb +0 -159
- data/lib/test-kitchen/project/cookbook.rb +0 -97
- data/lib/test-kitchen/project/cookbook_copy.rb +0 -58
- data/lib/test-kitchen/project/ruby.rb +0 -37
- data/lib/test-kitchen/project/supported_platforms.rb +0 -75
- data/lib/test-kitchen/project.rb +0 -23
- data/lib/test-kitchen/runner/base.rb +0 -154
- data/lib/test-kitchen/runner/openstack/dsl.rb +0 -39
- data/lib/test-kitchen/runner/openstack/environment.rb +0 -141
- data/lib/test-kitchen/runner/openstack.rb +0 -147
- data/lib/test-kitchen/runner/vagrant.rb +0 -95
- data/lib/test-kitchen/runner.rb +0 -21
- data/lib/test-kitchen/scaffold.rb +0 -88
- data/lib/test-kitchen/ui.rb +0 -73
- data/lib/test-kitchen/version.rb +0 -21
- data/lib/test-kitchen.rb +0 -34
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'test-kitchen/environment'
|
2
|
-
require 'json'
|
3
|
-
require 'fog'
|
4
|
-
|
5
|
-
module TestKitchen
|
6
|
-
class Environment
|
7
|
-
class Openstack < TestKitchen::Environment
|
8
|
-
attr_reader :username, :password, :tenant, :auth_url
|
9
|
-
attr_reader :servers
|
10
|
-
|
11
|
-
def initialize(conf={})
|
12
|
-
super
|
13
|
-
@username = conf[:username] || config.username
|
14
|
-
@password = conf[:password] || config.password
|
15
|
-
@tenant = conf[:tenant] || config.tenant
|
16
|
-
@auth_url = conf[:auth_url] || config.auth_url
|
17
|
-
@servers = {}
|
18
|
-
load
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_server(platform_name, server_def)
|
22
|
-
@servers[platform_name] ||=
|
23
|
-
begin
|
24
|
-
server = connection.servers.create({ :name => server_def[:instance_name],
|
25
|
-
:image_ref => server_def[:image_id],
|
26
|
-
:flavor_ref => server_def[:flavor_id],
|
27
|
-
:key_name => server_def[:keyname]})
|
28
|
-
server.wait_for { ready? }
|
29
|
-
sleep(2) until tcp_test_ssh(server.public_ip_address['addr'])
|
30
|
-
save
|
31
|
-
server
|
32
|
-
end
|
33
|
-
|
34
|
-
# These won't persist on the fog objectso we have to set them every
|
35
|
-
# time. :(
|
36
|
-
@servers[platform_name].username = server_def[:ssh_user]
|
37
|
-
if server_def[:ssh_key]
|
38
|
-
@servers[platform_name].private_key_path = File.expand_path(server_def[:ssh_key])
|
39
|
-
end
|
40
|
-
@servers[platform_name]
|
41
|
-
end
|
42
|
-
|
43
|
-
def tcp_test_ssh(hostname)
|
44
|
-
tcp_socket = TCPSocket.new(hostname, '22')
|
45
|
-
IO.select([tcp_socket], nil, nil, 5)
|
46
|
-
rescue SocketError, Errno::ETIMEDOUT, Errno::EPERM,
|
47
|
-
Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH
|
48
|
-
false
|
49
|
-
ensure
|
50
|
-
tcp_socket && tcp_socket.close
|
51
|
-
end
|
52
|
-
|
53
|
-
def connection
|
54
|
-
@connection ||= Fog::Compute.new(:provider => 'OpenStack',
|
55
|
-
:openstack_username => username,
|
56
|
-
:openstack_api_key => password,
|
57
|
-
:openstack_auth_url => auth_url,
|
58
|
-
:openstack_tenant => tenant)
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
# The following functions all take a name of
|
63
|
-
# of a VM in our enironment
|
64
|
-
|
65
|
-
def status(name)
|
66
|
-
if @servers.has_key?(name)
|
67
|
-
@servers[name].state.to_s.downcase
|
68
|
-
else
|
69
|
-
"not created"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def destroy(name)
|
74
|
-
@servers[name].destroy if @servers.has_key?(name)
|
75
|
-
@servers.delete(name)
|
76
|
-
save
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
# Ideally we could use the #ssh and #scp functions on Fog's server '
|
81
|
-
# object. But these seem to be broken in the case of Openstack
|
82
|
-
|
83
|
-
def ssh_options(name)
|
84
|
-
if key = @servers[name].private_key_path
|
85
|
-
{:keys => [key]}
|
86
|
-
else
|
87
|
-
{}
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def ssh(name)
|
92
|
-
server = @servers[name]
|
93
|
-
Fog::SSH.new(server.public_ip_address['addr'], server.username, ssh_options(name))
|
94
|
-
end
|
95
|
-
|
96
|
-
def scp(name)
|
97
|
-
server = @servers[name]
|
98
|
-
Fog::SCP.new(server.public_ip_address['addr'], server.username, ssh_options(name))
|
99
|
-
end
|
100
|
-
|
101
|
-
# GROSS: Global config as a class variable
|
102
|
-
def config
|
103
|
-
@@config
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.config
|
107
|
-
@@config
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.config=(config)
|
111
|
-
@@config = config
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
|
116
|
-
# Store state in .openstack_state file,
|
117
|
-
# allowing us to re-use already created VMs
|
118
|
-
|
119
|
-
def state_file
|
120
|
-
File.join(root_path, ".openstack_state")
|
121
|
-
end
|
122
|
-
|
123
|
-
def load
|
124
|
-
if File.exists?(state_file)
|
125
|
-
state = JSON.parse(File.read(state_file))
|
126
|
-
state.each do |platform, id|
|
127
|
-
@servers[platform] = connection.servers.get(id)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def save
|
133
|
-
state = {}
|
134
|
-
@servers.each {|k,s| state[k] = s.id}
|
135
|
-
File.open(state_file, 'w') do |f|
|
136
|
-
f.write(state.to_json)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Steven Danna (<steve@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 'fog'
|
20
|
-
require 'test-kitchen/runner/openstack/environment'
|
21
|
-
|
22
|
-
module TestKitchen
|
23
|
-
module Runner
|
24
|
-
class Openstack < Base
|
25
|
-
|
26
|
-
|
27
|
-
# @vm: The TestKitchen::Platform::Version object
|
28
|
-
#
|
29
|
-
# @platform: From the parent constructor, contains the full name
|
30
|
-
# of the relevant platform if we were created by #for_platform
|
31
|
-
|
32
|
-
attr_accessor :vm
|
33
|
-
|
34
|
-
def initialize(env, options={})
|
35
|
-
super
|
36
|
-
|
37
|
-
if @platform
|
38
|
-
@vm = env.all_platforms[@platform]
|
39
|
-
end
|
40
|
-
|
41
|
-
@os_env = TestKitchen::Environment::Openstack.new()
|
42
|
-
end
|
43
|
-
|
44
|
-
def create
|
45
|
-
env.ui.msg "[#{platform}] Provisioning guest on Openstack", :green
|
46
|
-
@os_env.create_server(@platform,
|
47
|
-
{ :instance_name => (vm.instance_name || "cookbook-tester-#{platform}"),
|
48
|
-
:image_id => vm.image_id,
|
49
|
-
:flavor_id => vm.flavor_id,
|
50
|
-
:keyname => vm.keyname,
|
51
|
-
:ssh_key => vm.ssh_key,
|
52
|
-
:ssh_user => vm.ssh_user})
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
def converge
|
57
|
-
install_chef if vm.install_chef
|
58
|
-
move_repo
|
59
|
-
move_cookbooks
|
60
|
-
run_chef_solo
|
61
|
-
end
|
62
|
-
|
63
|
-
# status and destroy are expected to operate on all
|
64
|
-
# vm's in an environment
|
65
|
-
def status
|
66
|
-
env.all_platforms.each do |name, ver|
|
67
|
-
env.ui.msg "#{name}\t#{@os_env.status(name)}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def destroy
|
72
|
-
env.all_platforms.each do |name, platform|
|
73
|
-
env.ui.msg "[#{name}] Terminating openstack server", :yellow
|
74
|
-
@os_env.destroy name
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def execute_remote_command(platform_name, command, message=nil)
|
79
|
-
env.ui.msg("[#{platform_name}] #{message}", :green) if message
|
80
|
-
results = @os_env.ssh(platform_name).run(command) do |data|
|
81
|
-
stdout, stderr = data.map {|s| s.rstrip}
|
82
|
-
stdout.lines.each do |line|
|
83
|
-
env.ui.msg "[#{platform_name}] #{line}", :green
|
84
|
-
end
|
85
|
-
stderr.lines.each do |line|
|
86
|
-
env.ui.msg "[#{platform_name}] #{line}", :red
|
87
|
-
end
|
88
|
-
end
|
89
|
-
if results.first.status != 0
|
90
|
-
msg = message || "Remote command"
|
91
|
-
env.ui.msg "[#{platform_name}] #{msg} failed!", :red
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def install_chef(name=platform)
|
98
|
-
execute_remote_command(name, vm.install_chef_cmd, "Installing Chef")
|
99
|
-
end
|
100
|
-
|
101
|
-
def run_chef_solo(name=platform)
|
102
|
-
execute_remote_command(name, "echo '#{json_for_node}' > node.json",
|
103
|
-
"Creating node configuration JSON")
|
104
|
-
execute_remote_command(name, "echo 'cookbook_path [ \"#{remote_cookbook_dir}\" ]' > solo.rb",
|
105
|
-
"Creating chef-solo configuration")
|
106
|
-
execute_remote_command(name, "sudo chef-solo -j node.json -c solo.rb",
|
107
|
-
"Running chef-solo on host")
|
108
|
-
end
|
109
|
-
|
110
|
-
def move_cookbooks(name=platform)
|
111
|
-
env.ui.msg("[#{name}] Moving cookbooks via SCP", :green)
|
112
|
-
@os_env.scp(name).upload(File.join(env.tmp_path, "cookbooks"),
|
113
|
-
remote_cookbook_dir, :recursive => true)
|
114
|
-
end
|
115
|
-
|
116
|
-
def move_repo(name=platform)
|
117
|
-
env.ui.msg("[#{name}] Moving repo via SCP", :green)
|
118
|
-
execute_remote_command(name, "sudo mkdir -p #{remote_root_dir}")
|
119
|
-
execute_remote_command(name, "sudo chown #{vm.ssh_user} #{remote_root_dir}")
|
120
|
-
@os_env.scp(name).upload(File.join(env.tmp_path, "cookbook_under_test"),
|
121
|
-
configuration.guest_source_root,
|
122
|
-
{:recursive => true})
|
123
|
-
end
|
124
|
-
|
125
|
-
def json_for_node
|
126
|
-
{
|
127
|
-
'test-kitchen' => {
|
128
|
-
'project' => configuration.to_hash.merge('source_root' => configuration.guest_source_root,
|
129
|
-
'test_root' => configuration.guest_test_root)},
|
130
|
-
'run_list' => run_list
|
131
|
-
}.to_json
|
132
|
-
end
|
133
|
-
|
134
|
-
def run_list
|
135
|
-
configuration.run_list + [test_recipe_name]
|
136
|
-
end
|
137
|
-
|
138
|
-
def remote_root_dir
|
139
|
-
File.dirname(configuration.guest_source_root)
|
140
|
-
end
|
141
|
-
|
142
|
-
def remote_cookbook_dir
|
143
|
-
File.join(remote_root_dir, 'cookbooks')
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,95 +0,0 @@
|
|
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 'vagrant'
|
20
|
-
|
21
|
-
module TestKitchen
|
22
|
-
module Runner
|
23
|
-
class Vagrant < Base
|
24
|
-
|
25
|
-
def initialize(env, options={})
|
26
|
-
super
|
27
|
-
@env, @options = env, options
|
28
|
-
end
|
29
|
-
|
30
|
-
def create
|
31
|
-
vagrant_env.cli(vagrant_cli_argv(['up', '--no-provision']))
|
32
|
-
end
|
33
|
-
|
34
|
-
def converge
|
35
|
-
vagrant_env.cli(vagrant_cli_argv('provision'))
|
36
|
-
end
|
37
|
-
|
38
|
-
def status
|
39
|
-
vagrant_env.cli(vagrant_cli_argv('status'))
|
40
|
-
end
|
41
|
-
|
42
|
-
def destroy
|
43
|
-
vagrant_env.cli(vagrant_cli_argv(['destroy', '--force']))
|
44
|
-
end
|
45
|
-
|
46
|
-
def ssh
|
47
|
-
vagrant_env.cli(vagrant_cli_argv('ssh'))
|
48
|
-
end
|
49
|
-
|
50
|
-
def execute_remote_command(vm, command, message=nil)
|
51
|
-
vm = vagrant_env.vms[vm.to_sym] unless vm.kind_of?(::Vagrant::VM)
|
52
|
-
vm.ui.info(message, :color => :yellow) if message
|
53
|
-
vm.channel.execute(command, :error_check => false) do |type, data|
|
54
|
-
next if data =~ /stdin: is not a tty/
|
55
|
-
if [:stderr, :stdout].include?(type)
|
56
|
-
# Output the data with the proper color based on the stream.
|
57
|
-
color = type == :stdout ? :green : :red
|
58
|
-
vm.ui.info(data, :color => color, :prefix => false, :new_line => false)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def vagrant_env
|
66
|
-
@vagrant_env ||= begin
|
67
|
-
# massive hack
|
68
|
-
if test_recipe_name
|
69
|
-
vagrant_file = "test_recipe_name='#{test_recipe_name}'\n"
|
70
|
-
else
|
71
|
-
vagrant_file = 'test_recipe_name=nil'
|
72
|
-
end
|
73
|
-
vagrant_file += IO.read(TestKitchen.source_root.join('config', 'Vagrantfile'))
|
74
|
-
env.create_tmp_file('Vagrantfile', vagrant_file)
|
75
|
-
|
76
|
-
options = {
|
77
|
-
:ui_class => ::Vagrant::UI::Colored,
|
78
|
-
:cwd => env.tmp_path
|
79
|
-
}
|
80
|
-
|
81
|
-
env = ::Vagrant::Environment.new(options)
|
82
|
-
env.load!
|
83
|
-
env
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def vagrant_cli_argv(command)
|
88
|
-
argv = Array(command)
|
89
|
-
argv << platform if platform
|
90
|
-
argv
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
data/lib/test-kitchen/runner.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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/runner/base'
|
20
|
-
require 'test-kitchen/runner/vagrant'
|
21
|
-
require 'test-kitchen/runner/openstack'
|
@@ -1,88 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Andrew Crump (<andrew@kotirisoftware.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 'fileutils'
|
20
|
-
require 'chef/cookbook/metadata'
|
21
|
-
|
22
|
-
module TestKitchen
|
23
|
-
|
24
|
-
class Scaffold
|
25
|
-
|
26
|
-
def generate(output_dir)
|
27
|
-
|
28
|
-
scaffold_file '.gitignore',
|
29
|
-
<<-eos
|
30
|
-
.bundle
|
31
|
-
.cache
|
32
|
-
.kitchen
|
33
|
-
bin
|
34
|
-
eos
|
35
|
-
|
36
|
-
scaffold_file 'Gemfile',
|
37
|
-
<<-eos
|
38
|
-
source :rubygems
|
39
|
-
|
40
|
-
gem 'test-kitchen'
|
41
|
-
eos
|
42
|
-
|
43
|
-
scaffold_file 'test/kitchen/Kitchenfile',
|
44
|
-
<<-eos
|
45
|
-
#{project_type(output_dir)} "#{project_name(output_dir)}" do
|
46
|
-
|
47
|
-
end
|
48
|
-
eos
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def project_name(output_dir)
|
54
|
-
if has_metadata?(output_dir)
|
55
|
-
get_cookbook_name(output_dir)
|
56
|
-
else
|
57
|
-
File.basename(output_dir)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_cookbook_name(output_dir)
|
62
|
-
md = Chef::Cookbook::Metadata.new
|
63
|
-
md.from_file(File.join(output_dir, 'metadata.rb'))
|
64
|
-
md.name
|
65
|
-
end
|
66
|
-
|
67
|
-
def has_metadata?(output_dir)
|
68
|
-
File.exists?(File.join(output_dir, 'metadata.rb'))
|
69
|
-
end
|
70
|
-
|
71
|
-
def project_type(output_dir)
|
72
|
-
if has_metadata?(output_dir)
|
73
|
-
'cookbook'
|
74
|
-
else
|
75
|
-
'integration_test'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def scaffold_file(path, content)
|
80
|
-
FileUtils.mkdir_p(File.dirname(path))
|
81
|
-
unless File.exists?(path)
|
82
|
-
File.open(path, 'w') {|f| f.write(content.gsub(/^ {10}/, '')) }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
data/lib/test-kitchen/ui.rb
DELETED
@@ -1,73 +0,0 @@
|
|
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
|
-
module TestKitchen
|
20
|
-
class UI
|
21
|
-
|
22
|
-
attr_reader :stdout
|
23
|
-
attr_reader :stderr
|
24
|
-
attr_reader :stdin
|
25
|
-
|
26
|
-
def initialize(stdout, stderr, stdin, config)
|
27
|
-
@stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config
|
28
|
-
end
|
29
|
-
|
30
|
-
def highline
|
31
|
-
@highline ||= begin
|
32
|
-
require 'highline'
|
33
|
-
HighLine.new
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Prints a message to stdout. Aliased as +info+ for compatibility with
|
38
|
-
# the logger API.
|
39
|
-
def msg(message, *colors)
|
40
|
-
if colors
|
41
|
-
message = color(message, *colors)
|
42
|
-
end
|
43
|
-
stdout.puts message
|
44
|
-
end
|
45
|
-
|
46
|
-
alias :info :msg
|
47
|
-
|
48
|
-
# Prints a msg to stderr. Used for warn, error, and fatal.
|
49
|
-
def err(message)
|
50
|
-
stderr.puts message
|
51
|
-
end
|
52
|
-
|
53
|
-
# Print a warning message
|
54
|
-
def warn(message)
|
55
|
-
err("#{color('WARNING:', :yellow, :bold)} #{message}")
|
56
|
-
end
|
57
|
-
|
58
|
-
# Print an error message
|
59
|
-
def error(message)
|
60
|
-
err("#{color('ERROR:', :red, :bold)} #{message}")
|
61
|
-
end
|
62
|
-
|
63
|
-
# Print a message describing a fatal error.
|
64
|
-
def fatal(message)
|
65
|
-
err("#{color('FATAL:', :red, :bold)} #{message}")
|
66
|
-
end
|
67
|
-
|
68
|
-
def color(string, *colors)
|
69
|
-
highline.color(string, *colors)
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
data/lib/test-kitchen/version.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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
|
-
module TestKitchen
|
20
|
-
VERSION = "0.7.0"
|
21
|
-
end
|
data/lib/test-kitchen.rb
DELETED
@@ -1,34 +0,0 @@
|
|
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 'ripper'
|
20
|
-
require 'test-kitchen/cli'
|
21
|
-
require 'test-kitchen/dsl'
|
22
|
-
require 'test-kitchen/project'
|
23
|
-
require 'test-kitchen/runner'
|
24
|
-
require 'test-kitchen/version'
|
25
|
-
|
26
|
-
module TestKitchen
|
27
|
-
|
28
|
-
# The source root is the path to the root directory of
|
29
|
-
# the test-kitchen gem.
|
30
|
-
def self.source_root
|
31
|
-
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|