test-kitchen 2.11.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/lib/kitchen/cli.rb +2 -2
- data/lib/kitchen/command/console.rb +1 -1
- data/lib/kitchen/configurable.rb +1 -1
- data/lib/kitchen/data_munger.rb +2 -0
- data/lib/kitchen/lifecycle_hook/remote.rb +8 -2
- data/lib/kitchen/logger.rb +2 -2
- data/lib/kitchen/provisioner/base.rb +1 -3
- data/lib/kitchen/provisioner/chef/common_sandbox.rb +15 -10
- data/lib/kitchen/provisioner/chef/policyfile.rb +14 -4
- data/lib/kitchen/provisioner/chef_base.rb +3 -2
- data/lib/kitchen/provisioner/chef_infra.rb +167 -0
- data/lib/kitchen/provisioner/chef_zero.rb +3 -147
- data/lib/kitchen/provisioner.rb +3 -1
- data/lib/kitchen/transport/winrm.rb +24 -13
- data/lib/kitchen/verifier/base.rb +1 -3
- data/lib/kitchen/version.rb +1 -1
- data/test-kitchen.gemspec +3 -3
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc5e05dc50e7052b2002a94e950f5691d953c78d5e408b80a0f7f977ab63eb35
|
4
|
+
data.tar.gz: 43bc1979cc77277d4a3219f82d8fead18e7aa3cf068fb7484f5176ce422c8767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12453b3cbf1ef1dfb49b683667fca52502b10a888e9cf953d58c22589ce99dffc9864d550463c80341049f7073aa3c3fb98eb76c4e432aa266956b6a0a86c332
|
7
|
+
data.tar.gz: bc19f713f60acc0b5437c5b29ab241255a7a82de2b206ba714596bf2a251c0e9a3c21bc152a18e171461ca24d9291098b55baeec474e495f46824782487350b8
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
require "cucumber"
|
12
12
|
require "cucumber/rake/task"
|
13
13
|
Cucumber::Rake::Task.new(:features) do |t|
|
14
|
-
t.cucumber_opts = ["features", "-x", "--format progress", "--no-color", "--tags
|
14
|
+
t.cucumber_opts = ["features", "-x", "--format progress", "--no-color", "--tags 'not @ignore'"]
|
15
15
|
end
|
16
16
|
rescue LoadError
|
17
17
|
puts "cucumber is not available. (sudo) gem install cucumber to run tests."
|
data/lib/kitchen/cli.rb
CHANGED
@@ -285,7 +285,7 @@ module Kitchen
|
|
285
285
|
perform("exec", "exec", args)
|
286
286
|
end
|
287
287
|
|
288
|
-
desc "version", "Print Kitchen's version information"
|
288
|
+
desc "version", "Print Test Kitchen's version information"
|
289
289
|
def version
|
290
290
|
puts "Test Kitchen version #{Kitchen::VERSION}"
|
291
291
|
end
|
@@ -296,7 +296,7 @@ module Kitchen
|
|
296
296
|
perform("sink", "sink")
|
297
297
|
end
|
298
298
|
|
299
|
-
desc "console", "Kitchen Console!"
|
299
|
+
desc "console", "Test Kitchen Console!"
|
300
300
|
def console
|
301
301
|
perform("console", "console")
|
302
302
|
end
|
data/lib/kitchen/configurable.rb
CHANGED
@@ -149,7 +149,7 @@ module Kitchen
|
|
149
149
|
# @return [String] joined path for instance's os_type
|
150
150
|
def remote_path_join(*parts)
|
151
151
|
path = File.join(*parts)
|
152
|
-
windows_os? ? path.tr("/",
|
152
|
+
windows_os? ? path.tr("/", "\\") : path.tr("\\", "/")
|
153
153
|
end
|
154
154
|
|
155
155
|
# @return [TrueClass,FalseClass] true if `:os_type` is `"unix"` (or
|
data/lib/kitchen/data_munger.rb
CHANGED
@@ -720,12 +720,14 @@ module Kitchen
|
|
720
720
|
move_data_to!(:provisioner, suite, :attributes)
|
721
721
|
move_data_to!(:provisioner, suite, :run_list)
|
722
722
|
move_data_to!(:provisioner, suite, :named_run_list)
|
723
|
+
move_data_to!(:provisioner, suite, :policy_group)
|
723
724
|
end
|
724
725
|
|
725
726
|
data.fetch(:platforms, []).each do |platform|
|
726
727
|
move_data_to!(:provisioner, platform, :attributes)
|
727
728
|
move_data_to!(:provisioner, platform, :run_list)
|
728
729
|
move_data_to!(:provisioner, platform, :named_run_list)
|
730
|
+
move_data_to!(:provisioner, platform, :policy_group)
|
729
731
|
end
|
730
732
|
end
|
731
733
|
|
@@ -18,8 +18,14 @@ module Kitchen
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
begin
|
22
|
+
conn = instance.transport.connection(state_file.read)
|
23
|
+
conn.execute(command)
|
24
|
+
rescue Kitchen::Transport::SshFailed => e
|
25
|
+
return if hook[:skippable] && e.message.match(/^SSH exited \(\d{1,3}\) for command: \[.+\]$/)
|
26
|
+
|
27
|
+
raise
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
private
|
data/lib/kitchen/logger.rb
CHANGED
@@ -293,11 +293,11 @@ module Kitchen
|
|
293
293
|
logger = StdoutLogger.new(stdout)
|
294
294
|
if colorize
|
295
295
|
logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
296
|
-
Color.colorize(msg.to_s, color).concat("\n")
|
296
|
+
Color.colorize(msg.dup.to_s, color).concat("\n")
|
297
297
|
end
|
298
298
|
else
|
299
299
|
logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
300
|
-
msg.concat("\n")
|
300
|
+
msg.dup.concat("\n")
|
301
301
|
end
|
302
302
|
end
|
303
303
|
logger
|
@@ -177,11 +177,9 @@ module Kitchen
|
|
177
177
|
# @raise [ClientError] if the sandbox directory has no yet been created
|
178
178
|
# by calling `#create_sandbox`
|
179
179
|
def sandbox_path
|
180
|
-
@sandbox_path ||=
|
181
|
-
raise ClientError, "Sandbox directory has not yet " \
|
180
|
+
@sandbox_path ||= raise ClientError, "Sandbox directory has not yet " \
|
182
181
|
"been created. Please run #{self.class}#create_sandox before " \
|
183
182
|
"trying to access the path."
|
184
|
-
end
|
185
183
|
end
|
186
184
|
|
187
185
|
# Deletes the sandbox path. Without calling this method, the sandbox path
|
@@ -73,6 +73,10 @@ module Kitchen
|
|
73
73
|
# @api private
|
74
74
|
attr_reader :sandbox_path
|
75
75
|
|
76
|
+
# @return [String] name of the policy_group, nil results in "local"
|
77
|
+
# @api private
|
78
|
+
attr_reader :policy_group
|
79
|
+
|
76
80
|
# Generates a list of all files in the cookbooks directory in the
|
77
81
|
# sandbox path.
|
78
82
|
#
|
@@ -281,19 +285,17 @@ module Kitchen
|
|
281
285
|
end
|
282
286
|
|
283
287
|
def update_dna_for_policyfile
|
284
|
-
|
285
|
-
|
286
|
-
"kitchen config. The run_list in your config will be ignored.")
|
287
|
-
warn("Ignored run_list: #{config[:run_list].inspect}")
|
288
|
-
end
|
289
|
-
policy = Chef::Policyfile.new(policyfile, sandbox_path,
|
288
|
+
policy = Chef::Policyfile.new(
|
289
|
+
policyfile, sandbox_path,
|
290
290
|
logger: logger,
|
291
|
-
always_update: config[:always_update_cookbooks]
|
291
|
+
always_update: config[:always_update_cookbooks],
|
292
|
+
policy_group: policy_group
|
293
|
+
)
|
292
294
|
Kitchen.mutex.synchronize do
|
293
295
|
policy.compile
|
294
296
|
end
|
295
297
|
policy_name = JSON.parse(IO.read(policy.lockfile))["name"]
|
296
|
-
policy_group = "local"
|
298
|
+
policy_group = config[:policy_group] || "local"
|
297
299
|
config[:attributes].merge(policy_name: policy_name, policy_group: policy_group)
|
298
300
|
end
|
299
301
|
|
@@ -302,9 +304,12 @@ module Kitchen
|
|
302
304
|
# @api private
|
303
305
|
def resolve_with_policyfile
|
304
306
|
Kitchen.mutex.synchronize do
|
305
|
-
Chef::Policyfile.new(
|
307
|
+
Chef::Policyfile.new(
|
308
|
+
policyfile, sandbox_path,
|
306
309
|
logger: logger,
|
307
|
-
always_update: config[:always_update_cookbooks]
|
310
|
+
always_update: config[:always_update_cookbooks],
|
311
|
+
policy_group: config[:policy_group]
|
312
|
+
).resolve
|
308
313
|
end
|
309
314
|
end
|
310
315
|
|
@@ -41,11 +41,12 @@ module Kitchen
|
|
41
41
|
# cookbooks
|
42
42
|
# @param logger [Kitchen::Logger] a logger to use for output, defaults
|
43
43
|
# to `Kitchen.logger`
|
44
|
-
def initialize(policyfile, path, logger: Kitchen.logger, always_update: false)
|
44
|
+
def initialize(policyfile, path, logger: Kitchen.logger, always_update: false, policy_group: nil)
|
45
45
|
@policyfile = policyfile
|
46
46
|
@path = path
|
47
47
|
@logger = logger
|
48
48
|
@always_update = always_update
|
49
|
+
@policy_group = policy_group
|
49
50
|
end
|
50
51
|
|
51
52
|
# Loads the library code required to use the resolver.
|
@@ -59,8 +60,13 @@ module Kitchen
|
|
59
60
|
# Performs the cookbook resolution and vendors the resulting cookbooks
|
60
61
|
# in the desired path.
|
61
62
|
def resolve
|
62
|
-
|
63
|
-
|
63
|
+
if policy_group
|
64
|
+
info("Exporting cookbook dependencies from Policyfile #{path} with policy_group #{policy_group} using `#{cli_path} export`...")
|
65
|
+
run_command("#{cli_path} export #{escape_path(policyfile)} #{escape_path(path)} --policy_group #{policy_group} --force")
|
66
|
+
else
|
67
|
+
info("Exporting cookbook dependencies from Policyfile #{path} using `#{cli_path} export`...")
|
68
|
+
run_command("#{cli_path} export #{escape_path(policyfile)} #{escape_path(path)} --force")
|
69
|
+
end
|
64
70
|
end
|
65
71
|
|
66
72
|
# Runs `chef install` to determine the correct cookbook set and
|
@@ -104,6 +110,10 @@ module Kitchen
|
|
104
110
|
# @api private
|
105
111
|
attr_reader :always_update
|
106
112
|
|
113
|
+
# @return [String] name of the policy_group, nil results in "local"
|
114
|
+
# @api private
|
115
|
+
attr_reader :policy_group
|
116
|
+
|
107
117
|
# Escape spaces in a path in way that works with both Sh (Unix) and
|
108
118
|
# Windows.
|
109
119
|
#
|
@@ -118,7 +128,7 @@ module Kitchen
|
|
118
128
|
# Windows command line parsing libraries. This covers the 99% case of
|
119
129
|
# spaces in the path without breaking other stuff.
|
120
130
|
if /[ \t\n\v"]/.match?(path)
|
121
|
-
"\"#{path.gsub(/[ \t\n\v\"\\]/) { |m|
|
131
|
+
"\"#{path.gsub(/[ \t\n\v\"\\]/) { |m| "\\" + m[0] }}\""
|
122
132
|
else
|
123
133
|
path
|
124
134
|
end
|
@@ -46,6 +46,7 @@ module Kitchen
|
|
46
46
|
default_config :chef_omnibus_install_options, nil
|
47
47
|
default_config :chef_license, nil
|
48
48
|
default_config :run_list, []
|
49
|
+
default_config :policy_group, nil
|
49
50
|
default_config :attributes, {}
|
50
51
|
default_config :config_path, nil
|
51
52
|
default_config :log_file, nil
|
@@ -63,7 +64,7 @@ module Kitchen
|
|
63
64
|
default_config :berksfile_path, nil
|
64
65
|
# If set to true (which is the default from `chef generate`), try to update
|
65
66
|
# backend cookbook downloader on every kitchen run.
|
66
|
-
default_config :always_update_cookbooks,
|
67
|
+
default_config :always_update_cookbooks, true
|
67
68
|
default_config :cookbook_files_glob, %w(
|
68
69
|
README.* VERSION metadata.{json,rb} attributes.rb recipe.rb
|
69
70
|
attributes/**/* definitions/**/* files/**/* libraries/**/*
|
@@ -441,7 +442,7 @@ module Kitchen
|
|
441
442
|
if obj.is_a?(String) && obj =~ /^:/
|
442
443
|
obj
|
443
444
|
elsif obj.is_a?(String)
|
444
|
-
%{"#{obj.gsub(/\\/,
|
445
|
+
%{"#{obj.gsub(/\\/, "\\\\\\\\")}"}
|
445
446
|
elsif obj.is_a?(Array)
|
446
447
|
%{[#{obj.map { |i| format_value(i) }.join(", ")}]}
|
447
448
|
else
|
@@ -0,0 +1,167 @@
|
|
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
|
+
require_relative "chef_base"
|
19
|
+
|
20
|
+
module Kitchen
|
21
|
+
module Provisioner
|
22
|
+
# Chef Zero provisioner.
|
23
|
+
#
|
24
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
25
|
+
class ChefInfra < ChefBase
|
26
|
+
kitchen_provisioner_api_version 2
|
27
|
+
|
28
|
+
plugin_version Kitchen::VERSION
|
29
|
+
|
30
|
+
default_config :client_rb, {}
|
31
|
+
default_config :named_run_list, {}
|
32
|
+
default_config :json_attributes, true
|
33
|
+
default_config :chef_zero_host, nil
|
34
|
+
default_config :chef_zero_port, 8889
|
35
|
+
|
36
|
+
default_config :chef_client_path do |provisioner|
|
37
|
+
provisioner
|
38
|
+
.remote_path_join(%W{#{provisioner[:chef_omnibus_root]} bin chef-client})
|
39
|
+
.tap { |path| path.concat(".bat") if provisioner.windows_os? }
|
40
|
+
end
|
41
|
+
|
42
|
+
default_config :ruby_bindir do |provisioner|
|
43
|
+
provisioner
|
44
|
+
.remote_path_join(%W{#{provisioner[:chef_omnibus_root]} embedded bin})
|
45
|
+
end
|
46
|
+
|
47
|
+
# (see Base#create_sandbox)
|
48
|
+
def create_sandbox
|
49
|
+
super
|
50
|
+
prepare_validation_pem
|
51
|
+
prepare_config_rb
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_command
|
55
|
+
cmd = "#{sudo(config[:chef_client_path])} --local-mode".tap { |str| str.insert(0, "& ") if powershell_shell? }
|
56
|
+
|
57
|
+
chef_cmd(cmd)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Adds optional flags to a chef-client command, depending on
|
63
|
+
# configuration data. Note that this method mutates the incoming Array.
|
64
|
+
#
|
65
|
+
# @param args [Array<String>] array of flags
|
66
|
+
# @api private
|
67
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
68
|
+
def add_optional_chef_client_args!(args)
|
69
|
+
if config[:json_attributes]
|
70
|
+
json = remote_path_join(config[:root_path], "dna.json")
|
71
|
+
args << "--json-attributes #{json}"
|
72
|
+
end
|
73
|
+
|
74
|
+
args << "--logfile #{config[:log_file]}" if config[:log_file]
|
75
|
+
|
76
|
+
# these flags are chef-client local mode only and will not work
|
77
|
+
# on older versions of chef-client
|
78
|
+
if config[:chef_zero_host]
|
79
|
+
args << "--chef-zero-host #{config[:chef_zero_host]}"
|
80
|
+
end
|
81
|
+
|
82
|
+
if config[:chef_zero_port]
|
83
|
+
args << "--chef-zero-port #{config[:chef_zero_port]}"
|
84
|
+
end
|
85
|
+
|
86
|
+
args << "--profile-ruby" if config[:profile_ruby]
|
87
|
+
|
88
|
+
if config[:slow_resource_report]
|
89
|
+
if config[:slow_resource_report].is_a?(Integer)
|
90
|
+
args << "--slow-report #{config[:slow_resource_report]}"
|
91
|
+
else
|
92
|
+
args << "--slow-report"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
97
|
+
|
98
|
+
# Returns an Array of command line arguments for the chef client.
|
99
|
+
#
|
100
|
+
# @return [Array<String>] an array of command line arguments
|
101
|
+
# @api private
|
102
|
+
def chef_args(client_rb_filename)
|
103
|
+
level = config[:log_level]
|
104
|
+
args = [
|
105
|
+
"--config #{remote_path_join(config[:root_path], client_rb_filename)}",
|
106
|
+
"--log_level #{level}",
|
107
|
+
"--force-formatter",
|
108
|
+
"--no-color",
|
109
|
+
]
|
110
|
+
add_optional_chef_client_args!(args)
|
111
|
+
|
112
|
+
args
|
113
|
+
end
|
114
|
+
|
115
|
+
# Generates a string of shell environment variables needed for the
|
116
|
+
# chef-client-zero.rb shim script to properly function.
|
117
|
+
#
|
118
|
+
# @return [String] a shell script string
|
119
|
+
# @api private
|
120
|
+
def chef_client_zero_env
|
121
|
+
root = config[:root_path]
|
122
|
+
gem_home = gem_path = remote_path_join(root, "chef-client-zero-gems")
|
123
|
+
gem_cache = remote_path_join(gem_home, "cache")
|
124
|
+
|
125
|
+
[
|
126
|
+
shell_env_var("CHEF_REPO_PATH", root),
|
127
|
+
shell_env_var("GEM_HOME", gem_home),
|
128
|
+
shell_env_var("GEM_PATH", gem_path),
|
129
|
+
shell_env_var("GEM_CACHE", gem_cache),
|
130
|
+
].join("\n").concat("\n")
|
131
|
+
end
|
132
|
+
|
133
|
+
# Writes a fake (but valid) validation.pem into the sandbox directory.
|
134
|
+
#
|
135
|
+
# @api private
|
136
|
+
def prepare_validation_pem
|
137
|
+
info("Preparing validation.pem")
|
138
|
+
debug("Using a dummy validation.pem")
|
139
|
+
|
140
|
+
source = File.join(File.dirname(__FILE__),
|
141
|
+
%w{.. .. .. support dummy-validation.pem})
|
142
|
+
FileUtils.cp(source, File.join(sandbox_path, "validation.pem"))
|
143
|
+
end
|
144
|
+
|
145
|
+
# Returns the command that will run a backwards compatible shim script
|
146
|
+
# that approximates local mode in a modern chef-client run.
|
147
|
+
#
|
148
|
+
# @return [String] the command string
|
149
|
+
# @api private
|
150
|
+
def shim_command
|
151
|
+
ruby = remote_path_join(config[:ruby_bindir], "ruby")
|
152
|
+
.tap { |path| path.concat(".exe") if windows_os? }
|
153
|
+
shim = remote_path_join(config[:root_path], "chef-client-zero.rb")
|
154
|
+
|
155
|
+
"#{chef_client_zero_env}\n#{sudo(ruby)} #{shim}"
|
156
|
+
end
|
157
|
+
|
158
|
+
# This provisioner supports policyfiles, so override the default (which
|
159
|
+
# is false)
|
160
|
+
# @return [true] always returns true
|
161
|
+
# @api private
|
162
|
+
def supports_policyfile?
|
163
|
+
true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -1,156 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
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
|
-
require_relative "chef_base"
|
1
|
+
# Deprecated AS PER THE PR - https://github.com/test-kitchen/test-kitchen/pull/1730
|
2
|
+
require_relative "chef_infra"
|
19
3
|
|
20
4
|
module Kitchen
|
21
5
|
module Provisioner
|
22
6
|
# Chef Zero provisioner.
|
23
7
|
#
|
24
8
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
25
|
-
class ChefZero <
|
26
|
-
kitchen_provisioner_api_version 2
|
27
|
-
|
28
|
-
plugin_version Kitchen::VERSION
|
29
|
-
|
30
|
-
default_config :client_rb, {}
|
31
|
-
default_config :named_run_list, {}
|
32
|
-
default_config :json_attributes, true
|
33
|
-
default_config :chef_zero_host, nil
|
34
|
-
default_config :chef_zero_port, 8889
|
35
|
-
|
36
|
-
default_config :chef_client_path do |provisioner|
|
37
|
-
provisioner
|
38
|
-
.remote_path_join(%W{#{provisioner[:chef_omnibus_root]} bin chef-client})
|
39
|
-
.tap { |path| path.concat(".bat") if provisioner.windows_os? }
|
40
|
-
end
|
41
|
-
|
42
|
-
default_config :ruby_bindir do |provisioner|
|
43
|
-
provisioner
|
44
|
-
.remote_path_join(%W{#{provisioner[:chef_omnibus_root]} embedded bin})
|
45
|
-
end
|
46
|
-
|
47
|
-
# (see Base#create_sandbox)
|
48
|
-
def create_sandbox
|
49
|
-
super
|
50
|
-
prepare_validation_pem
|
51
|
-
prepare_config_rb
|
52
|
-
end
|
53
|
-
|
54
|
-
def run_command
|
55
|
-
cmd = "#{sudo(config[:chef_client_path])} --local-mode".tap { |str| str.insert(0, "& ") if powershell_shell? }
|
56
|
-
|
57
|
-
chef_cmd(cmd)
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
# Adds optional flags to a chef-client command, depending on
|
63
|
-
# configuration data. Note that this method mutates the incoming Array.
|
64
|
-
#
|
65
|
-
# @param args [Array<String>] array of flags
|
66
|
-
# @api private
|
67
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
68
|
-
def add_optional_chef_client_args!(args)
|
69
|
-
if config[:json_attributes]
|
70
|
-
json = remote_path_join(config[:root_path], "dna.json")
|
71
|
-
args << "--json-attributes #{json}"
|
72
|
-
end
|
73
|
-
args << "--logfile #{config[:log_file]}" if config[:log_file]
|
74
|
-
|
75
|
-
# these flags are chef-client local mode only and will not work
|
76
|
-
# on older versions of chef-client
|
77
|
-
if config[:chef_zero_host]
|
78
|
-
args << "--chef-zero-host #{config[:chef_zero_host]}"
|
79
|
-
end
|
80
|
-
if config[:chef_zero_port]
|
81
|
-
args << "--chef-zero-port #{config[:chef_zero_port]}"
|
82
|
-
end
|
83
|
-
args << "--profile-ruby" if config[:profile_ruby]
|
84
|
-
end
|
85
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
86
|
-
|
87
|
-
# Returns an Array of command line arguments for the chef client.
|
88
|
-
#
|
89
|
-
# @return [Array<String>] an array of command line arguments
|
90
|
-
# @api private
|
91
|
-
def chef_args(client_rb_filename)
|
92
|
-
level = config[:log_level]
|
93
|
-
args = [
|
94
|
-
"--config #{remote_path_join(config[:root_path], client_rb_filename)}",
|
95
|
-
"--log_level #{level}",
|
96
|
-
"--force-formatter",
|
97
|
-
"--no-color",
|
98
|
-
]
|
99
|
-
add_optional_chef_client_args!(args)
|
100
|
-
|
101
|
-
args
|
102
|
-
end
|
103
|
-
|
104
|
-
# Generates a string of shell environment variables needed for the
|
105
|
-
# chef-client-zero.rb shim script to properly function.
|
106
|
-
#
|
107
|
-
# @return [String] a shell script string
|
108
|
-
# @api private
|
109
|
-
def chef_client_zero_env
|
110
|
-
root = config[:root_path]
|
111
|
-
gem_home = gem_path = remote_path_join(root, "chef-client-zero-gems")
|
112
|
-
gem_cache = remote_path_join(gem_home, "cache")
|
113
|
-
|
114
|
-
[
|
115
|
-
shell_env_var("CHEF_REPO_PATH", root),
|
116
|
-
shell_env_var("GEM_HOME", gem_home),
|
117
|
-
shell_env_var("GEM_PATH", gem_path),
|
118
|
-
shell_env_var("GEM_CACHE", gem_cache),
|
119
|
-
].join("\n").concat("\n")
|
120
|
-
end
|
121
|
-
|
122
|
-
# Writes a fake (but valid) validation.pem into the sandbox directory.
|
123
|
-
#
|
124
|
-
# @api private
|
125
|
-
def prepare_validation_pem
|
126
|
-
info("Preparing validation.pem")
|
127
|
-
debug("Using a dummy validation.pem")
|
128
|
-
|
129
|
-
source = File.join(File.dirname(__FILE__),
|
130
|
-
%w{.. .. .. support dummy-validation.pem})
|
131
|
-
FileUtils.cp(source, File.join(sandbox_path, "validation.pem"))
|
132
|
-
end
|
133
|
-
|
134
|
-
# Returns the command that will run a backwards compatible shim script
|
135
|
-
# that approximates local mode in a modern chef-client run.
|
136
|
-
#
|
137
|
-
# @return [String] the command string
|
138
|
-
# @api private
|
139
|
-
def shim_command
|
140
|
-
ruby = remote_path_join(config[:ruby_bindir], "ruby")
|
141
|
-
.tap { |path| path.concat(".exe") if windows_os? }
|
142
|
-
shim = remote_path_join(config[:root_path], "chef-client-zero.rb")
|
143
|
-
|
144
|
-
"#{chef_client_zero_env}\n#{sudo(ruby)} #{shim}"
|
145
|
-
end
|
146
|
-
|
147
|
-
# This provisioner supports policyfiles, so override the default (which
|
148
|
-
# is false)
|
149
|
-
# @return [true] always returns true
|
150
|
-
# @api private
|
151
|
-
def supports_policyfile?
|
152
|
-
true
|
153
|
-
end
|
9
|
+
class ChefZero < ChefInfra
|
154
10
|
end
|
155
11
|
end
|
156
12
|
end
|
data/lib/kitchen/provisioner.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
3
3
|
#
|
4
4
|
# Copyright (C) 2013, Fletcher Nichol
|
5
|
+
# Copyright (C) Chef Software Inc.
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
8
|
# you may not use this file except in compliance with the License.
|
@@ -25,7 +26,7 @@ module Kitchen
|
|
25
26
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
26
27
|
module Provisioner
|
27
28
|
# Default provisioner to use
|
28
|
-
DEFAULT_PLUGIN = "
|
29
|
+
DEFAULT_PLUGIN = "chef_infra".freeze
|
29
30
|
|
30
31
|
# Returns an instance of a provisioner given a plugin type string.
|
31
32
|
#
|
@@ -34,6 +35,7 @@ module Kitchen
|
|
34
35
|
# @return [Provisioner::Base] a provisioner instance
|
35
36
|
# @raise [ClientError] if a provisioner instance could not be created
|
36
37
|
def self.for_plugin(plugin, config)
|
38
|
+
plugin, config[:name] = "chef_infra", "chef_infra" if plugin == "chef_zero"
|
37
39
|
Kitchen::Plugin.load(self, plugin, config)
|
38
40
|
end
|
39
41
|
end
|
@@ -365,11 +365,9 @@ module Kitchen
|
|
365
365
|
# @return [Winrm::Shells::Elevated] the elevated shell
|
366
366
|
# @api private
|
367
367
|
def elevated_session(retry_options = {})
|
368
|
-
@elevated_session ||=
|
369
|
-
|
370
|
-
|
371
|
-
shell.password = options[:elevated_password]
|
372
|
-
end
|
368
|
+
@elevated_session ||= connection(retry_options).shell(:elevated).tap do |shell|
|
369
|
+
shell.username = options[:elevated_username]
|
370
|
+
shell.password = options[:elevated_password]
|
373
371
|
end
|
374
372
|
end
|
375
373
|
|
@@ -441,18 +439,31 @@ module Kitchen
|
|
441
439
|
elevated_username: data[:elevated_username] || data[:username],
|
442
440
|
elevated_password: elevated_password,
|
443
441
|
}
|
444
|
-
opts.merge!(additional_transport_args(opts[:transport]))
|
442
|
+
opts.merge!(additional_transport_args(data, opts[:transport]))
|
443
|
+
if opts[:transport].to_sym == :ssl && opts.key?(:client_cert) && opts.key?(:client_key)
|
444
|
+
opts.delete(:user)
|
445
|
+
opts.delete(:password)
|
446
|
+
end
|
445
447
|
opts
|
446
448
|
end
|
447
449
|
|
448
|
-
def additional_transport_args(transport_type)
|
450
|
+
def additional_transport_args(data, transport_type)
|
451
|
+
opts = {
|
452
|
+
disable_sspi: false,
|
453
|
+
basic_auth_only: false,
|
454
|
+
}
|
455
|
+
|
449
456
|
case transport_type.to_sym
|
450
|
-
when :ssl
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
457
|
+
when :ssl
|
458
|
+
if data.key?(:client_cert) && data.key?(:client_key)
|
459
|
+
opts[:client_cert] = data[:client_cert]
|
460
|
+
opts[:client_key] = data[:client_key]
|
461
|
+
end
|
462
|
+
opts[:no_ssl_peer_verification] = data.key?(:no_ssl_peer_verification) ? data[:no_ssl_peer_verification] : true
|
463
|
+
opts
|
464
|
+
when :negotiate
|
465
|
+
opts[:no_ssl_peer_verification] = true
|
466
|
+
opts
|
456
467
|
when :plaintext
|
457
468
|
{
|
458
469
|
disable_sspi: true,
|
@@ -169,11 +169,9 @@ module Kitchen
|
|
169
169
|
# @raise [ClientError] if the sandbox directory has no yet been created
|
170
170
|
# by calling `#create_sandbox`
|
171
171
|
def sandbox_path
|
172
|
-
@sandbox_path ||=
|
173
|
-
raise ClientError, "Sandbox directory has not yet " \
|
172
|
+
@sandbox_path ||= raise ClientError, "Sandbox directory has not yet " \
|
174
173
|
"been created. Please run #{self.class}#create_sandox before " \
|
175
174
|
"trying to access the path."
|
176
|
-
end
|
177
175
|
end
|
178
176
|
|
179
177
|
# Sets the API version for this verifier. If the verifier does not set
|
data/lib/kitchen/version.rb
CHANGED
data/test-kitchen.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.executables = %w{kitchen}
|
21
21
|
gem.require_paths = ["lib"]
|
22
22
|
|
23
|
-
gem.required_ruby_version = ">= 2.
|
23
|
+
gem.required_ruby_version = ">= 2.6"
|
24
24
|
|
25
25
|
gem.add_dependency "mixlib-shellout", ">= 1.2", "< 4.0"
|
26
26
|
gem.add_dependency "net-scp", ">= 1.1", "< 4.0" # pinning until we can confirm 4+ works
|
@@ -44,9 +44,9 @@ Gem::Specification.new do |gem|
|
|
44
44
|
|
45
45
|
gem.add_development_dependency "aruba", "~> 0.11", "< 1.0"
|
46
46
|
gem.add_development_dependency "fakefs", "~> 1.0"
|
47
|
-
gem.add_development_dependency "minitest", "~> 5.3", "< 5.
|
47
|
+
gem.add_development_dependency "minitest", "~> 5.3", "< 5.15"
|
48
48
|
gem.add_development_dependency "mocha", "~> 1.1"
|
49
|
-
gem.add_development_dependency "cucumber", ">= 2.1", "<
|
49
|
+
gem.add_development_dependency "cucumber", ">= 2.1", "< 8.0"
|
50
50
|
gem.add_development_dependency "countloc", "~> 0.4"
|
51
51
|
gem.add_development_dependency "maruku", "~> 0.6"
|
52
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-kitchen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fletcher Nichol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -313,7 +313,7 @@ dependencies:
|
|
313
313
|
version: '5.3'
|
314
314
|
- - "<"
|
315
315
|
- !ruby/object:Gem::Version
|
316
|
-
version: '5.
|
316
|
+
version: '5.15'
|
317
317
|
type: :development
|
318
318
|
prerelease: false
|
319
319
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -323,7 +323,7 @@ dependencies:
|
|
323
323
|
version: '5.3'
|
324
324
|
- - "<"
|
325
325
|
- !ruby/object:Gem::Version
|
326
|
-
version: '5.
|
326
|
+
version: '5.15'
|
327
327
|
- !ruby/object:Gem::Dependency
|
328
328
|
name: mocha
|
329
329
|
requirement: !ruby/object:Gem::Requirement
|
@@ -347,7 +347,7 @@ dependencies:
|
|
347
347
|
version: '2.1'
|
348
348
|
- - "<"
|
349
349
|
- !ruby/object:Gem::Version
|
350
|
-
version: '
|
350
|
+
version: '8.0'
|
351
351
|
type: :development
|
352
352
|
prerelease: false
|
353
353
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -357,7 +357,7 @@ dependencies:
|
|
357
357
|
version: '2.1'
|
358
358
|
- - "<"
|
359
359
|
- !ruby/object:Gem::Version
|
360
|
-
version: '
|
360
|
+
version: '8.0'
|
361
361
|
- !ruby/object:Gem::Dependency
|
362
362
|
name: countloc
|
363
363
|
requirement: !ruby/object:Gem::Requirement
|
@@ -449,6 +449,7 @@ files:
|
|
449
449
|
- lib/kitchen/provisioner/chef/policyfile.rb
|
450
450
|
- lib/kitchen/provisioner/chef_apply.rb
|
451
451
|
- lib/kitchen/provisioner/chef_base.rb
|
452
|
+
- lib/kitchen/provisioner/chef_infra.rb
|
452
453
|
- lib/kitchen/provisioner/chef_solo.rb
|
453
454
|
- lib/kitchen/provisioner/chef_zero.rb
|
454
455
|
- lib/kitchen/provisioner/dummy.rb
|
@@ -512,14 +513,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
512
513
|
requirements:
|
513
514
|
- - ">="
|
514
515
|
- !ruby/object:Gem::Version
|
515
|
-
version: '2.
|
516
|
+
version: '2.6'
|
516
517
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
517
518
|
requirements:
|
518
519
|
- - ">="
|
519
520
|
- !ruby/object:Gem::Version
|
520
521
|
version: '0'
|
521
522
|
requirements: []
|
522
|
-
rubygems_version: 3.
|
523
|
+
rubygems_version: 3.2.22
|
523
524
|
signing_key:
|
524
525
|
specification_version: 4
|
525
526
|
summary: Test Kitchen is an integration tool for developing and testing infrastructure
|