test-kitchen-rsync 3.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +21 -0
- data/LICENSE +15 -0
- data/Rakefile +53 -0
- data/bin/zl-kitchen +11 -0
- data/lib/kitchen/base64_stream.rb +48 -0
- data/lib/kitchen/chef_utils_wiring.rb +40 -0
- data/lib/kitchen/cli.rb +413 -0
- data/lib/kitchen/collection.rb +52 -0
- data/lib/kitchen/color.rb +63 -0
- data/lib/kitchen/command/action.rb +41 -0
- data/lib/kitchen/command/console.rb +54 -0
- data/lib/kitchen/command/diagnose.rb +84 -0
- data/lib/kitchen/command/doctor.rb +39 -0
- data/lib/kitchen/command/exec.rb +37 -0
- data/lib/kitchen/command/list.rb +148 -0
- data/lib/kitchen/command/login.rb +39 -0
- data/lib/kitchen/command/package.rb +32 -0
- data/lib/kitchen/command/sink.rb +50 -0
- data/lib/kitchen/command/test.rb +47 -0
- data/lib/kitchen/command.rb +207 -0
- data/lib/kitchen/config.rb +344 -0
- data/lib/kitchen/configurable.rb +616 -0
- data/lib/kitchen/data_munger.rb +1024 -0
- data/lib/kitchen/diagnostic.rb +138 -0
- data/lib/kitchen/driver/base.rb +133 -0
- data/lib/kitchen/driver/dummy.rb +105 -0
- data/lib/kitchen/driver/exec.rb +70 -0
- data/lib/kitchen/driver/proxy.rb +70 -0
- data/lib/kitchen/driver/ssh_base.rb +351 -0
- data/lib/kitchen/driver.rb +40 -0
- data/lib/kitchen/errors.rb +243 -0
- data/lib/kitchen/generator/init.rb +254 -0
- data/lib/kitchen/instance.rb +726 -0
- data/lib/kitchen/lazy_hash.rb +148 -0
- data/lib/kitchen/lifecycle_hook/base.rb +78 -0
- data/lib/kitchen/lifecycle_hook/local.rb +53 -0
- data/lib/kitchen/lifecycle_hook/remote.rb +39 -0
- data/lib/kitchen/lifecycle_hooks.rb +92 -0
- data/lib/kitchen/loader/yaml.rb +377 -0
- data/lib/kitchen/logger.rb +422 -0
- data/lib/kitchen/logging.rb +52 -0
- data/lib/kitchen/login_command.rb +49 -0
- data/lib/kitchen/metadata_chopper.rb +49 -0
- data/lib/kitchen/platform.rb +64 -0
- data/lib/kitchen/plugin.rb +76 -0
- data/lib/kitchen/plugin_base.rb +60 -0
- data/lib/kitchen/provisioner/base.rb +269 -0
- data/lib/kitchen/provisioner/chef/berkshelf.rb +116 -0
- data/lib/kitchen/provisioner/chef/common_sandbox.rb +350 -0
- data/lib/kitchen/provisioner/chef/policyfile.rb +163 -0
- data/lib/kitchen/provisioner/chef_apply.rb +121 -0
- data/lib/kitchen/provisioner/chef_base.rb +705 -0
- data/lib/kitchen/provisioner/chef_infra.rb +167 -0
- data/lib/kitchen/provisioner/chef_solo.rb +82 -0
- data/lib/kitchen/provisioner/chef_zero.rb +12 -0
- data/lib/kitchen/provisioner/dummy.rb +75 -0
- data/lib/kitchen/provisioner/shell.rb +157 -0
- data/lib/kitchen/provisioner.rb +42 -0
- data/lib/kitchen/rake_tasks.rb +80 -0
- data/lib/kitchen/shell_out.rb +90 -0
- data/lib/kitchen/ssh.rb +289 -0
- data/lib/kitchen/state_file.rb +112 -0
- data/lib/kitchen/suite.rb +48 -0
- data/lib/kitchen/thor_tasks.rb +63 -0
- data/lib/kitchen/transport/base.rb +236 -0
- data/lib/kitchen/transport/dummy.rb +78 -0
- data/lib/kitchen/transport/exec.rb +145 -0
- data/lib/kitchen/transport/ssh.rb +579 -0
- data/lib/kitchen/transport/winrm.rb +546 -0
- data/lib/kitchen/transport.rb +40 -0
- data/lib/kitchen/util.rb +229 -0
- data/lib/kitchen/verifier/base.rb +243 -0
- data/lib/kitchen/verifier/busser.rb +275 -0
- data/lib/kitchen/verifier/dummy.rb +75 -0
- data/lib/kitchen/verifier/shell.rb +99 -0
- data/lib/kitchen/verifier.rb +39 -0
- data/lib/kitchen/version.rb +20 -0
- data/lib/kitchen/which.rb +26 -0
- data/lib/kitchen.rb +152 -0
- data/lib/vendor/hash_recursive_merge.rb +79 -0
- data/support/busser_install_command.ps1 +14 -0
- data/support/busser_install_command.sh +21 -0
- data/support/chef-client-fail-if-update-handler.rb +15 -0
- data/support/chef_base_init_command.ps1 +18 -0
- data/support/chef_base_init_command.sh +1 -0
- data/support/chef_base_install_command.ps1 +85 -0
- data/support/chef_base_install_command.sh +229 -0
- data/support/download_helpers.sh +109 -0
- data/support/dummy-validation.pem +27 -0
- data/templates/driver/CHANGELOG.md.erb +3 -0
- data/templates/driver/Gemfile.erb +3 -0
- data/templates/driver/README.md.erb +64 -0
- data/templates/driver/Rakefile.erb +21 -0
- data/templates/driver/driver.rb.erb +23 -0
- data/templates/driver/gemspec.erb +29 -0
- data/templates/driver/gitignore.erb +17 -0
- data/templates/driver/license_apachev2.erb +15 -0
- data/templates/driver/license_lgplv3.erb +16 -0
- data/templates/driver/license_mit.erb +22 -0
- data/templates/driver/license_reserved.erb +5 -0
- data/templates/driver/tailor.erb +4 -0
- data/templates/driver/travis.yml.erb +11 -0
- data/templates/driver/version.rb.erb +12 -0
- data/templates/init/chefignore.erb +2 -0
- data/templates/init/kitchen.yml.erb +18 -0
- data/test-kitchen.gemspec +52 -0
- metadata +528 -0
@@ -0,0 +1,207 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
3
|
+
#
|
4
|
+
# Copyright (C) 2013, Fletcher Nichol
|
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
|
+
module Kitchen
|
19
|
+
module Command
|
20
|
+
# Base class for CLI commands.
|
21
|
+
#
|
22
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
23
|
+
class Base
|
24
|
+
include Logging
|
25
|
+
|
26
|
+
# Contstructs a new Command object.
|
27
|
+
#
|
28
|
+
# @param cmd_args [Array] remainder of the arguments from processed ARGV
|
29
|
+
# @param cmd_options [Hash] hash of Thor options
|
30
|
+
# @param options [Hash] configuration options
|
31
|
+
# @option options [String] :action action to take, usually corresponding
|
32
|
+
# to the subcommand name (default: `nil`)
|
33
|
+
# @option options [proc] :help a callable that displays help for the
|
34
|
+
# command
|
35
|
+
# @option options [Config] :config a Config object (default: `nil`)
|
36
|
+
# @option options [Loader] :loader a Loader object (default: `nil`)
|
37
|
+
# @option options [String] :shell a Thor shell object
|
38
|
+
def initialize(cmd_args, cmd_options, options = {})
|
39
|
+
@args = cmd_args
|
40
|
+
@options = cmd_options
|
41
|
+
@action = options.fetch(:action, nil)
|
42
|
+
@help = options.fetch(:help, -> { "No help provided" })
|
43
|
+
@config = options.fetch(:config, nil)
|
44
|
+
@loader = options.fetch(:loader, nil)
|
45
|
+
@shell = options.fetch(:shell)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @return [Array] remainder of the arguments from processed ARGV
|
51
|
+
# @api private
|
52
|
+
attr_reader :args
|
53
|
+
|
54
|
+
# @return [Hash] hash of Thor options
|
55
|
+
# @api private
|
56
|
+
attr_reader :options
|
57
|
+
|
58
|
+
# @return [proc] a callable that displays help for the command
|
59
|
+
# @api private
|
60
|
+
attr_reader :help
|
61
|
+
|
62
|
+
# @return [Config] a Config object
|
63
|
+
# @api private
|
64
|
+
attr_reader :config
|
65
|
+
|
66
|
+
# @return [Thor::Shell] a Thor shell object
|
67
|
+
# @api private
|
68
|
+
attr_reader :shell
|
69
|
+
|
70
|
+
# @return [String] the action to perform
|
71
|
+
# @api private
|
72
|
+
attr_reader :action
|
73
|
+
|
74
|
+
# Emit an error message, display contextual help and then exit with a
|
75
|
+
# non-zero exit code.
|
76
|
+
#
|
77
|
+
# **Note** This method calls exit and will not return.
|
78
|
+
#
|
79
|
+
# @param msg [String] error message
|
80
|
+
# @api private
|
81
|
+
def die(msg)
|
82
|
+
error "\n#{msg}\n\n"
|
83
|
+
help.call
|
84
|
+
exit 1
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [Array<Instance>] an array of instances
|
88
|
+
# @raise [SystemExit] if no instances are returned
|
89
|
+
# @api private
|
90
|
+
def all_instances
|
91
|
+
result = @config.instances
|
92
|
+
|
93
|
+
if result.empty?
|
94
|
+
die "No instances defined"
|
95
|
+
else
|
96
|
+
result
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Return an array on instances whos name matches the regular expression.
|
101
|
+
#
|
102
|
+
# @param regexp [Regexp] a regular expression matching on instance names
|
103
|
+
# @return [Array<Instance>] an array of instances
|
104
|
+
# @raise [SystemExit] if no instances are returned or the regular
|
105
|
+
# expression is invalid
|
106
|
+
# @api private
|
107
|
+
def filtered_instances(regexp)
|
108
|
+
result = begin
|
109
|
+
@config.instances.get(regexp) ||
|
110
|
+
@config.instances.get_all(/#{regexp}/)
|
111
|
+
rescue RegexpError => e
|
112
|
+
die "Invalid Ruby regular expression, " \
|
113
|
+
"you may need to single quote the argument. " \
|
114
|
+
"Please try again or consult http://rubular.com/ (#{e.message})"
|
115
|
+
end
|
116
|
+
result = Array(result)
|
117
|
+
|
118
|
+
if result.empty?
|
119
|
+
die "No instances for regex `#{regexp}', try running `kitchen list'"
|
120
|
+
else
|
121
|
+
result
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [Logger] the common logger
|
126
|
+
# @api private
|
127
|
+
def logger
|
128
|
+
Kitchen.logger
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return an array on instances whos name matches the regular expression,
|
132
|
+
# the full instance name, or the `"all"` literal.
|
133
|
+
#
|
134
|
+
# @param arg [String] an instance name, a regular expression, the literal
|
135
|
+
# `"all"`, or `nil`
|
136
|
+
# @return [Array<Instance>] an array of instances
|
137
|
+
# @api private
|
138
|
+
def parse_subcommand(arg = nil)
|
139
|
+
arg == "all" ? all_instances : filtered_instances(arg)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Common module to execute a Kitchen action such as create, converge, etc.
|
144
|
+
#
|
145
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
146
|
+
module RunAction
|
147
|
+
# Run an instance action (create, converge, setup, verify, destroy) on
|
148
|
+
# a collection of instances. The instance actions will take place in a
|
149
|
+
# seperate thread of execution which may or may not be running
|
150
|
+
# concurrently.
|
151
|
+
#
|
152
|
+
# @param action [String] action to perform
|
153
|
+
# @param instances [Array<Instance>] an array of instances
|
154
|
+
def run_action(action, instances, *args)
|
155
|
+
concurrency = concurrency_setting(instances)
|
156
|
+
|
157
|
+
queue = Queue.new
|
158
|
+
instances.each { |i| queue << i }
|
159
|
+
concurrency.times { queue << nil }
|
160
|
+
|
161
|
+
threads = []
|
162
|
+
@action_errors = []
|
163
|
+
concurrency.times do
|
164
|
+
threads << Thread.new do
|
165
|
+
while (instance = queue.pop)
|
166
|
+
run_action_in_thread(action, instance, *args)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
Thread.abort_on_exception = true if options[:fail_fast]
|
171
|
+
threads.map(&:join)
|
172
|
+
report_errors
|
173
|
+
end
|
174
|
+
|
175
|
+
# private
|
176
|
+
|
177
|
+
def report_errors
|
178
|
+
unless @action_errors.empty?
|
179
|
+
msg = ["#{@action_errors.length} actions failed.",
|
180
|
+
@action_errors.map { |e| ">>>>>> #{e.message}" }].join("\n")
|
181
|
+
raise ActionFailed.new(msg, @action_errors)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def concurrency_setting(instances)
|
186
|
+
concurrency = 1
|
187
|
+
if options[:concurrency]
|
188
|
+
concurrency = options[:concurrency] || instances.size
|
189
|
+
concurrency = instances.size if concurrency > instances.size
|
190
|
+
end
|
191
|
+
concurrency
|
192
|
+
end
|
193
|
+
|
194
|
+
def run_action_in_thread(action, instance, *args)
|
195
|
+
instance.public_send(action, *args)
|
196
|
+
rescue Kitchen::InstanceFailure => e
|
197
|
+
@action_errors << e
|
198
|
+
rescue Kitchen::ActionFailed => e
|
199
|
+
new_error = Kitchen::ActionFailed.new("#{e.message} on #{instance.name}")
|
200
|
+
new_error.set_backtrace(e.backtrace)
|
201
|
+
@action_errors << new_error
|
202
|
+
ensure
|
203
|
+
instance.cleanup!
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,344 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
3
|
+
#
|
4
|
+
# Copyright (C) 2012, 2013, 2014, Fletcher Nichol
|
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
|
+
module Kitchen
|
19
|
+
# Base configuration class for Kitchen. This class exposes configuration such
|
20
|
+
# as the location of the Kitchen config file, instances, log_levels, etc.
|
21
|
+
# This object is a factory object, meaning that it is responsible for
|
22
|
+
# consuming the desired testing configuration in and returning Ruby objects
|
23
|
+
# which are used to perfom the work.
|
24
|
+
#
|
25
|
+
# Most internal objects are created with the expectation of being
|
26
|
+
# *immutable*, meaning that internal state cannot be modified after creation.
|
27
|
+
# Any data manipulation or thread-unsafe activity is performed in this object
|
28
|
+
# so that the subsequently created objects (such as Instances, Platforms,
|
29
|
+
# Drivers, etc.) can safely run in concurrent threads of execution. To
|
30
|
+
# prevent the re-creation of duplicate objects, most created objects are
|
31
|
+
# memoized. The consequence of this is that once the Instance Array has
|
32
|
+
# been requested (with the `#instances` message), you will always be returned
|
33
|
+
# the same Instance objects.
|
34
|
+
#
|
35
|
+
# @example fetching all instances
|
36
|
+
#
|
37
|
+
# Kitchen::Config.new.instances
|
38
|
+
#
|
39
|
+
# @example fetching an instance by name
|
40
|
+
#
|
41
|
+
# Kitchen::Config.new.instances.get("default-ubuntu-16.04")
|
42
|
+
#
|
43
|
+
# @example fetching all instances matching a regular expression
|
44
|
+
#
|
45
|
+
# Kitchen::Config.new.instances.get_all(/ubuntu/)
|
46
|
+
#
|
47
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
48
|
+
class Config
|
49
|
+
# @return [String] the absolute path to the root of a Test Kitchen project
|
50
|
+
# @api private
|
51
|
+
attr_reader :kitchen_root
|
52
|
+
|
53
|
+
# @return [String] the absolute path to the directory into which all Test
|
54
|
+
# Kitchen log files will be written
|
55
|
+
# @api private
|
56
|
+
attr_reader :log_root
|
57
|
+
|
58
|
+
# @return [#read] the data loader that responds to a `#read` message,
|
59
|
+
# returning a Hash data structure
|
60
|
+
# @api private
|
61
|
+
attr_reader :loader
|
62
|
+
|
63
|
+
# @return [Symbol] the logging verbosity level
|
64
|
+
# @api private
|
65
|
+
attr_accessor :log_level
|
66
|
+
|
67
|
+
# @return [Boolean] whether to overwrite the log file when
|
68
|
+
# Test Kitchen runs
|
69
|
+
# @api private
|
70
|
+
attr_accessor :log_overwrite
|
71
|
+
|
72
|
+
# @return [String] an absolute path to the directory containing test suites
|
73
|
+
# @api private
|
74
|
+
attr_accessor :test_base_path
|
75
|
+
|
76
|
+
# @return [Boolean] whether to force color output or not in logger
|
77
|
+
# @api private
|
78
|
+
attr_accessor :colorize
|
79
|
+
|
80
|
+
# @return [Boolean] whether to enable debugging in the provisioner/verifier plugin or not
|
81
|
+
# @api private
|
82
|
+
attr_accessor :debug
|
83
|
+
|
84
|
+
# Creates a new configuration, representing a particular testing
|
85
|
+
# configuration for a project.
|
86
|
+
#
|
87
|
+
# @param [Hash] options configuration
|
88
|
+
# @option options [#read] :loader an object that responds to `#read` with
|
89
|
+
# a Hash structure suitable for manipulating
|
90
|
+
# (default: `Kitchen::Loader::YAML.new`)
|
91
|
+
# @option options [String] :kitchen_root an absolute path to the root of a
|
92
|
+
# Test Kitchen project, usually containing a `.kitchen.yml` file
|
93
|
+
# (default `Dir.pwd`)
|
94
|
+
# @option options [String] :log_root an absolute path to the directory
|
95
|
+
# into which all Test Kitchen log files will be written
|
96
|
+
# (default: `"#{kitchen_root}/.kitchen/logs"`)
|
97
|
+
# @option options [String] :test_base_path an absolute path to the
|
98
|
+
# directory containing test suites and other testing-related files and
|
99
|
+
# directories (default: `"#{kitchen_root}/test/integration"`)
|
100
|
+
# @option options [Symbol] :log_level the log level verbosity that the
|
101
|
+
# loggers will use when outputing information (default: `:info`)
|
102
|
+
def initialize(options = {})
|
103
|
+
@loader = options.fetch(:loader) { Kitchen::Loader::YAML.new }
|
104
|
+
@kitchen_root = options.fetch(:kitchen_root) { Dir.pwd }
|
105
|
+
@log_level = options.fetch(:log_level) { Kitchen::DEFAULT_LOG_LEVEL }
|
106
|
+
@log_overwrite = options.fetch(:log_overwrite) { Kitchen::DEFAULT_LOG_OVERWRITE }
|
107
|
+
@colorize = options.fetch(:colorize) { Kitchen.tty? }
|
108
|
+
@log_root = options.fetch(:log_root) { default_log_root }
|
109
|
+
@test_base_path = options.fetch(:test_base_path) { default_test_base_path }
|
110
|
+
@debug = options.fetch(:debug) { false }
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Collection<Instance>] all instances, resulting from all
|
114
|
+
# platform and suite combinations
|
115
|
+
def instances
|
116
|
+
@instances ||= Collection.new(build_instances)
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [Collection<Platform>] all defined platforms which will be used
|
120
|
+
# in convergence integration
|
121
|
+
def platforms
|
122
|
+
@platforms ||= Collection.new(
|
123
|
+
data.platform_data.map { |pdata| Platform.new(pdata) }
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [Collection<Suite>] all defined suites which will be used in
|
128
|
+
# convergence integration
|
129
|
+
def suites
|
130
|
+
@suites ||= Collection.new(
|
131
|
+
data.suite_data.map { |sdata| Suite.new(sdata) }
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
# Builds the filtered list of Instance objects.
|
138
|
+
#
|
139
|
+
# @return [Array<Instance] an array of Instances
|
140
|
+
# @api private
|
141
|
+
def build_instances
|
142
|
+
filter_instances.map.with_index do |(suite, platform), index|
|
143
|
+
new_instance(suite, platform, index)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Returns an object which can generate configuration hashes for all the
|
148
|
+
# primary Test Kitchen objects such as Drivers, Provisioners, etc.
|
149
|
+
#
|
150
|
+
# @return [DataMunger] a data manipulator
|
151
|
+
# @api private
|
152
|
+
def data
|
153
|
+
@data ||= DataMunger.new(loader.read, kitchen_config)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Determines the default absolute path to a log directory, based on the
|
157
|
+
# value of `#kitchen_root`.
|
158
|
+
#
|
159
|
+
# @return [String] an absolute path to the log directory
|
160
|
+
# @api private
|
161
|
+
def default_log_root
|
162
|
+
File.join(kitchen_root, Kitchen::DEFAULT_LOG_DIR)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Determines the default absolute path to the testing files directory,
|
166
|
+
# based on the the value of `#kitchen_root`.
|
167
|
+
#
|
168
|
+
# @return [String] an absolute path to the testing files directory
|
169
|
+
# @api private
|
170
|
+
def default_test_base_path
|
171
|
+
File.join(kitchen_root, Kitchen::DEFAULT_TEST_DIR)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Generates a filtered Array of tuples (Suite/Platform pairs) which is the
|
175
|
+
# cartesian product of suites and platforms. A Suite has two optional
|
176
|
+
# arrays (`#includes` and `#excludes`) which can be used to drop or
|
177
|
+
# select certain Platforms with which to join.
|
178
|
+
#
|
179
|
+
# @return [Array<Array<Suite, Platform>>] an Array of Suite/Platform
|
180
|
+
# tuples
|
181
|
+
# @api private
|
182
|
+
def filter_instances
|
183
|
+
suites.product(platforms).select do |suite, platform|
|
184
|
+
if !suite.includes.empty?
|
185
|
+
suite.includes.include?(platform.name)
|
186
|
+
elsif !suite.excludes.empty?
|
187
|
+
!suite.excludes.include?(platform.name)
|
188
|
+
else
|
189
|
+
true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# Determines the String name for an Instance, given a Suite and a Platform.
|
195
|
+
#
|
196
|
+
# @param suite [Suite,#name] a Suite
|
197
|
+
# @param platform [Platform,#name] a Platform
|
198
|
+
# @return [String] an Instance name
|
199
|
+
# @api private
|
200
|
+
def instance_name(suite, platform)
|
201
|
+
Instance.name_for(suite, platform)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Generates the immutable Test Kitchen configuration and reasonable
|
205
|
+
# defaults for Drivers, Provisioners and Transports.
|
206
|
+
#
|
207
|
+
# @return [Hash] a configuration Hash
|
208
|
+
# @api private
|
209
|
+
def kitchen_config
|
210
|
+
@kitchen_config ||= {
|
211
|
+
defaults: {
|
212
|
+
driver: Driver::DEFAULT_PLUGIN,
|
213
|
+
provisioner: Provisioner::DEFAULT_PLUGIN,
|
214
|
+
verifier: Verifier::DEFAULT_PLUGIN,
|
215
|
+
transport: lambda do |_suite, platform|
|
216
|
+
/^win/i.match?(platform) ? "winrm" : Transport::DEFAULT_PLUGIN
|
217
|
+
end,
|
218
|
+
},
|
219
|
+
kitchen_root: kitchen_root,
|
220
|
+
test_base_path: test_base_path,
|
221
|
+
log_level: log_level,
|
222
|
+
log_overwrite: log_overwrite,
|
223
|
+
debug: debug,
|
224
|
+
}
|
225
|
+
end
|
226
|
+
|
227
|
+
# Builds a newly configured Driver object, for a given Suite and Platform.
|
228
|
+
#
|
229
|
+
# @param suite [Suite,#name] a Suite
|
230
|
+
# @param platform [Platform,#name] a Platform
|
231
|
+
# @return [Driver] a new Driver object
|
232
|
+
# @api private
|
233
|
+
def new_driver(suite, platform)
|
234
|
+
ddata = data.driver_data_for(suite.name, platform.name)
|
235
|
+
Driver.for_plugin(ddata[:name], ddata)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Builds a newly configured Instance object, for a given Suite and
|
239
|
+
# Platform.
|
240
|
+
#
|
241
|
+
# @param suite [Suite,#name] a Suite
|
242
|
+
# @param platform [Platform,#name] a Platform
|
243
|
+
# @param index [Integer] an index used for colorizing output
|
244
|
+
# @return [Instance] a new Instance object
|
245
|
+
# @api private
|
246
|
+
def new_instance(suite, platform, index)
|
247
|
+
sf = new_state_file(suite, platform)
|
248
|
+
|
249
|
+
Instance.new(
|
250
|
+
driver: new_driver(suite, platform),
|
251
|
+
lifecycle_hooks: new_lifecycle_hooks(suite, platform, sf),
|
252
|
+
logger: new_instance_logger(suite, platform, index),
|
253
|
+
suite: suite,
|
254
|
+
platform: platform,
|
255
|
+
provisioner: new_provisioner(suite, platform),
|
256
|
+
transport: new_transport(suite, platform),
|
257
|
+
verifier: new_verifier(suite, platform),
|
258
|
+
state_file: sf
|
259
|
+
)
|
260
|
+
end
|
261
|
+
|
262
|
+
# Builds a newly configured Logger object, for a given Suite and
|
263
|
+
# Platform.
|
264
|
+
#
|
265
|
+
# @param suite [Suite,#name] a Suite
|
266
|
+
# @param platform [Platform,#name] a Platform
|
267
|
+
# @param index [Integer] an index used for colorizing output
|
268
|
+
# @return [Logger] a new Logger object
|
269
|
+
# @api private
|
270
|
+
def new_instance_logger(suite, platform, index)
|
271
|
+
name = instance_name(suite, platform)
|
272
|
+
log_location = File.join(log_root, "#{name}.log").to_s
|
273
|
+
Logger.new(
|
274
|
+
stdout: STDOUT,
|
275
|
+
color: Color::COLORS[index % Color::COLORS.size].to_sym,
|
276
|
+
logdev: log_location,
|
277
|
+
level: Util.to_logger_level(log_level),
|
278
|
+
log_overwrite: log_overwrite,
|
279
|
+
progname: name,
|
280
|
+
colorize: @colorize
|
281
|
+
)
|
282
|
+
end
|
283
|
+
|
284
|
+
# Builds a newly configured LifecycleHooks object, for a given a Suite and
|
285
|
+
# Platform.
|
286
|
+
#
|
287
|
+
# @param suite [Suite,#name] a Suite
|
288
|
+
# @param platform [Platform,#name] a Platform
|
289
|
+
# @param state_file [Kitchen::StateFile] a SateFile
|
290
|
+
# @return [LifecycleHooks] a new LifecycleHooks object
|
291
|
+
# @api private
|
292
|
+
def new_lifecycle_hooks(suite, platform, state_file)
|
293
|
+
lhdata = data.lifecycle_hooks_data_for(suite.name, platform.name)
|
294
|
+
LifecycleHooks.new(lhdata, state_file)
|
295
|
+
end
|
296
|
+
|
297
|
+
# Builds a newly configured Provisioner object, for a given Suite and
|
298
|
+
# Platform.
|
299
|
+
#
|
300
|
+
# @param suite [Suite,#name] a Suite
|
301
|
+
# @param platform [Platform,#name] a Platform
|
302
|
+
# @return [Provisioner] a new Provisioner object
|
303
|
+
# @api private
|
304
|
+
def new_provisioner(suite, platform)
|
305
|
+
pdata = data.provisioner_data_for(suite.name, platform.name)
|
306
|
+
Provisioner.for_plugin(pdata[:name], pdata)
|
307
|
+
end
|
308
|
+
|
309
|
+
# Builds a newly configured StateFile object, for a given Suite and
|
310
|
+
# Platform.
|
311
|
+
#
|
312
|
+
# @param suite [Suite,#name] a Suite
|
313
|
+
# @param platform [Platform,#name] a Platform
|
314
|
+
# @return [StateFile] a new StateFile object
|
315
|
+
# @api private
|
316
|
+
def new_state_file(suite, platform)
|
317
|
+
StateFile.new(kitchen_root, instance_name(suite, platform))
|
318
|
+
end
|
319
|
+
|
320
|
+
# Builds a newly configured Transport object, for a given Suite and
|
321
|
+
# Platform.
|
322
|
+
#
|
323
|
+
# @param suite [Suite,#name] a Suite
|
324
|
+
# @param platform [Platform,#name] a Platform
|
325
|
+
# @return [Transport] a new Transport object
|
326
|
+
# @api private
|
327
|
+
def new_transport(suite, platform)
|
328
|
+
tdata = data.transport_data_for(suite.name, platform.name)
|
329
|
+
Transport.for_plugin(tdata[:name], tdata)
|
330
|
+
end
|
331
|
+
|
332
|
+
# Builds a newly configured Verifier object, for a given a Suite and
|
333
|
+
# Platform.
|
334
|
+
#
|
335
|
+
# @param suite [Suite,#name] a Suite
|
336
|
+
# @param platform [Platform,#name] a Platform
|
337
|
+
# @return [Verifier] a new Verifier object
|
338
|
+
# @api private
|
339
|
+
def new_verifier(suite, platform)
|
340
|
+
vdata = data.verifier_data_for(suite.name, platform.name)
|
341
|
+
Verifier.for_plugin(vdata[:name], vdata)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|