test-kitchen-rsync 3.0.0.pre.1

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.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +21 -0
  3. data/LICENSE +15 -0
  4. data/Rakefile +53 -0
  5. data/bin/zl-kitchen +11 -0
  6. data/lib/kitchen/base64_stream.rb +48 -0
  7. data/lib/kitchen/chef_utils_wiring.rb +40 -0
  8. data/lib/kitchen/cli.rb +413 -0
  9. data/lib/kitchen/collection.rb +52 -0
  10. data/lib/kitchen/color.rb +63 -0
  11. data/lib/kitchen/command/action.rb +41 -0
  12. data/lib/kitchen/command/console.rb +54 -0
  13. data/lib/kitchen/command/diagnose.rb +84 -0
  14. data/lib/kitchen/command/doctor.rb +39 -0
  15. data/lib/kitchen/command/exec.rb +37 -0
  16. data/lib/kitchen/command/list.rb +148 -0
  17. data/lib/kitchen/command/login.rb +39 -0
  18. data/lib/kitchen/command/package.rb +32 -0
  19. data/lib/kitchen/command/sink.rb +50 -0
  20. data/lib/kitchen/command/test.rb +47 -0
  21. data/lib/kitchen/command.rb +207 -0
  22. data/lib/kitchen/config.rb +344 -0
  23. data/lib/kitchen/configurable.rb +616 -0
  24. data/lib/kitchen/data_munger.rb +1024 -0
  25. data/lib/kitchen/diagnostic.rb +138 -0
  26. data/lib/kitchen/driver/base.rb +133 -0
  27. data/lib/kitchen/driver/dummy.rb +105 -0
  28. data/lib/kitchen/driver/exec.rb +70 -0
  29. data/lib/kitchen/driver/proxy.rb +70 -0
  30. data/lib/kitchen/driver/ssh_base.rb +351 -0
  31. data/lib/kitchen/driver.rb +40 -0
  32. data/lib/kitchen/errors.rb +243 -0
  33. data/lib/kitchen/generator/init.rb +254 -0
  34. data/lib/kitchen/instance.rb +726 -0
  35. data/lib/kitchen/lazy_hash.rb +148 -0
  36. data/lib/kitchen/lifecycle_hook/base.rb +78 -0
  37. data/lib/kitchen/lifecycle_hook/local.rb +53 -0
  38. data/lib/kitchen/lifecycle_hook/remote.rb +39 -0
  39. data/lib/kitchen/lifecycle_hooks.rb +92 -0
  40. data/lib/kitchen/loader/yaml.rb +377 -0
  41. data/lib/kitchen/logger.rb +422 -0
  42. data/lib/kitchen/logging.rb +52 -0
  43. data/lib/kitchen/login_command.rb +49 -0
  44. data/lib/kitchen/metadata_chopper.rb +49 -0
  45. data/lib/kitchen/platform.rb +64 -0
  46. data/lib/kitchen/plugin.rb +76 -0
  47. data/lib/kitchen/plugin_base.rb +60 -0
  48. data/lib/kitchen/provisioner/base.rb +269 -0
  49. data/lib/kitchen/provisioner/chef/berkshelf.rb +116 -0
  50. data/lib/kitchen/provisioner/chef/common_sandbox.rb +350 -0
  51. data/lib/kitchen/provisioner/chef/policyfile.rb +163 -0
  52. data/lib/kitchen/provisioner/chef_apply.rb +121 -0
  53. data/lib/kitchen/provisioner/chef_base.rb +705 -0
  54. data/lib/kitchen/provisioner/chef_infra.rb +167 -0
  55. data/lib/kitchen/provisioner/chef_solo.rb +82 -0
  56. data/lib/kitchen/provisioner/chef_zero.rb +12 -0
  57. data/lib/kitchen/provisioner/dummy.rb +75 -0
  58. data/lib/kitchen/provisioner/shell.rb +157 -0
  59. data/lib/kitchen/provisioner.rb +42 -0
  60. data/lib/kitchen/rake_tasks.rb +80 -0
  61. data/lib/kitchen/shell_out.rb +90 -0
  62. data/lib/kitchen/ssh.rb +289 -0
  63. data/lib/kitchen/state_file.rb +112 -0
  64. data/lib/kitchen/suite.rb +48 -0
  65. data/lib/kitchen/thor_tasks.rb +63 -0
  66. data/lib/kitchen/transport/base.rb +236 -0
  67. data/lib/kitchen/transport/dummy.rb +78 -0
  68. data/lib/kitchen/transport/exec.rb +145 -0
  69. data/lib/kitchen/transport/ssh.rb +579 -0
  70. data/lib/kitchen/transport/winrm.rb +546 -0
  71. data/lib/kitchen/transport.rb +40 -0
  72. data/lib/kitchen/util.rb +229 -0
  73. data/lib/kitchen/verifier/base.rb +243 -0
  74. data/lib/kitchen/verifier/busser.rb +275 -0
  75. data/lib/kitchen/verifier/dummy.rb +75 -0
  76. data/lib/kitchen/verifier/shell.rb +99 -0
  77. data/lib/kitchen/verifier.rb +39 -0
  78. data/lib/kitchen/version.rb +20 -0
  79. data/lib/kitchen/which.rb +26 -0
  80. data/lib/kitchen.rb +152 -0
  81. data/lib/vendor/hash_recursive_merge.rb +79 -0
  82. data/support/busser_install_command.ps1 +14 -0
  83. data/support/busser_install_command.sh +21 -0
  84. data/support/chef-client-fail-if-update-handler.rb +15 -0
  85. data/support/chef_base_init_command.ps1 +18 -0
  86. data/support/chef_base_init_command.sh +1 -0
  87. data/support/chef_base_install_command.ps1 +85 -0
  88. data/support/chef_base_install_command.sh +229 -0
  89. data/support/download_helpers.sh +109 -0
  90. data/support/dummy-validation.pem +27 -0
  91. data/templates/driver/CHANGELOG.md.erb +3 -0
  92. data/templates/driver/Gemfile.erb +3 -0
  93. data/templates/driver/README.md.erb +64 -0
  94. data/templates/driver/Rakefile.erb +21 -0
  95. data/templates/driver/driver.rb.erb +23 -0
  96. data/templates/driver/gemspec.erb +29 -0
  97. data/templates/driver/gitignore.erb +17 -0
  98. data/templates/driver/license_apachev2.erb +15 -0
  99. data/templates/driver/license_lgplv3.erb +16 -0
  100. data/templates/driver/license_mit.erb +22 -0
  101. data/templates/driver/license_reserved.erb +5 -0
  102. data/templates/driver/tailor.erb +4 -0
  103. data/templates/driver/travis.yml.erb +11 -0
  104. data/templates/driver/version.rb.erb +12 -0
  105. data/templates/init/chefignore.erb +2 -0
  106. data/templates/init/kitchen.yml.erb +18 -0
  107. data/test-kitchen.gemspec +52 -0
  108. metadata +528 -0
@@ -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
@@ -0,0 +1,82 @@
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 Solo provisioner.
23
+ #
24
+ # @author Fletcher Nichol <fnichol@nichol.ca>
25
+ class ChefSolo < ChefBase
26
+ kitchen_provisioner_api_version 2
27
+
28
+ plugin_version Kitchen::VERSION
29
+
30
+ # ChefSolo is dependent on Berkshelf, which is not thread-safe.
31
+ # See discussion on https://github.com/test-kitchen/test-kitchen/issues/1307
32
+ no_parallel_for :converge
33
+
34
+ default_config :solo_rb, {}
35
+
36
+ default_config :chef_solo_path do |provisioner|
37
+ provisioner
38
+ .remote_path_join(%W{#{provisioner[:chef_omnibus_root]} bin chef-solo})
39
+ .tap { |path| path.concat(".bat") if provisioner.windows_os? }
40
+ end
41
+
42
+ # (see Base#config_filename)
43
+ def config_filename
44
+ "solo.rb"
45
+ end
46
+
47
+ # (see Base#create_sandbox)
48
+ def create_sandbox
49
+ super
50
+ prepare_config_rb
51
+ end
52
+
53
+ # (see Base#run_command)
54
+ def run_command
55
+ cmd = sudo(config[:chef_solo_path]).dup
56
+ .tap { |str| str.insert(0, "& ") if powershell_shell? }
57
+
58
+ chef_cmd(cmd)
59
+ end
60
+
61
+ private
62
+
63
+ # Returns an Array of command line arguments for the chef client.
64
+ #
65
+ # @return [Array<String>] an array of command line arguments
66
+ # @api private
67
+ def chef_args(solo_rb_filename)
68
+ args = [
69
+ "--config #{remote_path_join(config[:root_path], solo_rb_filename)}",
70
+ "--log_level #{config[:log_level]}",
71
+ "--force-formatter",
72
+ "--no-color",
73
+ "--json-attributes #{remote_path_join(config[:root_path], "dna.json")}",
74
+ ]
75
+ args << "--logfile #{config[:log_file]}" if config[:log_file]
76
+ args << "--profile-ruby" if config[:profile_ruby]
77
+ args << "--legacy-mode" if config[:legacy_mode]
78
+ args
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,12 @@
1
+ # Deprecated AS PER THE PR - https://github.com/test-kitchen/test-kitchen/pull/1730
2
+ require_relative "chef_infra"
3
+
4
+ module Kitchen
5
+ module Provisioner
6
+ # Chef Zero provisioner.
7
+ #
8
+ # @author Fletcher Nichol <fnichol@nichol.ca>
9
+ class ChefZero < ChefInfra
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,75 @@
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 "../../kitchen"
19
+
20
+ module Kitchen
21
+ module Provisioner
22
+ # Dummy provisioner for Kitchen. This driver does nothing but report what
23
+ # would happen if this provisioner did anything of consequence. As a result
24
+ # it may be a useful provisioner to use when debugging or developing new
25
+ # features or plugins.
26
+ #
27
+ # @author Fletcher Nichol <fnichol@nichol.ca>
28
+ class Dummy < Kitchen::Provisioner::Base
29
+ kitchen_provisioner_api_version 2
30
+
31
+ plugin_version Kitchen::VERSION
32
+
33
+ default_config :sleep, 0
34
+ default_config :random_failure, false
35
+
36
+ # (see Base#call)
37
+ def call(state)
38
+ info("[#{name}] Converge on instance=#{instance} with state=#{state}")
39
+ sleep_if_set
40
+ failure_if_set
41
+ debug("[#{name}] Converge completed (#{config[:sleep]}s).")
42
+ end
43
+
44
+ private
45
+
46
+ # Sleep for a period of time, if a value is set in the config.
47
+ #
48
+ # @api private
49
+ def sleep_if_set
50
+ sleep(config[:sleep].to_f) if config[:sleep].to_f > 0.0
51
+ end
52
+
53
+ # Simulate a failure in an action, if set in the config.
54
+ #
55
+ # @api private
56
+ def failure_if_set
57
+ if config[:fail]
58
+ debug("Failure for Provisioner #{name}.")
59
+ raise ActionFailed, "Action #converge failed for #{instance.to_str}."
60
+ elsif config[:random_failure] && randomly_fail?
61
+ debug("Random failure for Provisioner #{name}.")
62
+ raise ActionFailed, "Action #converge failed for #{instance.to_str}."
63
+ end
64
+ end
65
+
66
+ # Determine whether or not to randomly fail.
67
+ #
68
+ # @return [true, false]
69
+ # @api private
70
+ def randomly_fail?
71
+ [true, false].sample
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,157 @@
1
+ #
2
+ # Author:: Chris Lundquist (<chris.lundquist@github.com>)
3
+ #
4
+ # Copyright (C) 2013, Chris Lundquist
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 "shellwords" unless defined?(Shellwords)
19
+
20
+ require_relative "base"
21
+ require_relative "../version"
22
+
23
+ module Kitchen
24
+ module Provisioner
25
+ # Basic shell provisioner.
26
+ #
27
+ # @author Chris Lundquist (<chris.ludnquist@github.com>)
28
+ class Shell < Base
29
+ kitchen_provisioner_api_version 2
30
+
31
+ plugin_version Kitchen::VERSION
32
+
33
+ default_config :script do |provisioner|
34
+ src = provisioner.powershell_shell? ? "bootstrap.ps1" : "bootstrap.sh"
35
+ provisioner.calculate_path(src, type: :file)
36
+ end
37
+ expand_path_for :script
38
+
39
+ # Run a single command instead of managing and running a script.
40
+ default_config :command, nil
41
+
42
+ # Add extra arguments to the converge script.
43
+ default_config :arguments, []
44
+
45
+ default_config :data_path do |provisioner|
46
+ provisioner.calculate_path("data")
47
+ end
48
+ expand_path_for :data_path
49
+
50
+ # (see Base#create_sandbox)
51
+ def create_sandbox
52
+ super
53
+ prepare_data
54
+ prepare_script
55
+ end
56
+
57
+ # (see Base#init_command)
58
+ def init_command
59
+ return nil if config[:command]
60
+
61
+ root = config[:root_path]
62
+ data = remote_path_join(root, "data")
63
+
64
+ code = if powershell_shell?
65
+ Util.outdent!(<<-POWERSHELL)
66
+ if (Test-Path "#{data}") {
67
+ Remove-Item "#{data}" -Recurse -Force
68
+ }
69
+ if (-Not (Test-Path "#{root}")) {
70
+ New-Item "#{root}" -ItemType directory | Out-Null
71
+ }
72
+ POWERSHELL
73
+ else
74
+ "#{sudo("rm")} -rf #{data} ; mkdir -p #{root}"
75
+ end
76
+
77
+ prefix_command(wrap_shell_code(code))
78
+ end
79
+
80
+ # (see Base#prepare_command)
81
+ def prepare_command
82
+ # On a windows host, the supplied script does not get marked as executable
83
+ # due to windows not having the concept of an executable flag
84
+ #
85
+ # When the guest instance is *nix, `chmod +x` the script in the guest, prior to executing
86
+ return unless unix_os? && config[:script] && !config[:command]
87
+
88
+ debug "Marking script as executable"
89
+ script = remote_path_join(
90
+ config[:root_path],
91
+ File.basename(config[:script])
92
+ )
93
+ prefix_command(wrap_shell_code(sudo("chmod +x #{script}")))
94
+ end
95
+
96
+ # (see Base#run_command)
97
+ def run_command
98
+ return prefix_command(wrap_shell_code(config[:command])) if config[:command]
99
+ return unless config[:script]
100
+
101
+ script = remote_path_join(
102
+ config[:root_path],
103
+ File.basename(config[:script])
104
+ )
105
+
106
+ if config[:arguments] && !config[:arguments].empty?
107
+ if config[:arguments].is_a?(Array)
108
+ if powershell_shell?
109
+ script = ([script] + config[:arguments]).join(" ")
110
+ else
111
+ script = Shellwords.join([script] + config[:arguments])
112
+ end
113
+ else
114
+ script.concat(" ").concat(config[:arguments].to_s)
115
+ end
116
+ end
117
+
118
+ code = powershell_shell? ? %{& #{script}} : sudo(script)
119
+
120
+ prefix_command(wrap_shell_code(code))
121
+ end
122
+
123
+ private
124
+
125
+ # Creates a data directory in the sandbox directory, if a data directory
126
+ # can be found and copies in the tree.
127
+ #
128
+ # @api private
129
+ def prepare_data
130
+ return unless config[:data_path]
131
+
132
+ info("Preparing data")
133
+ debug("Using data from #{config[:data_path]}")
134
+
135
+ tmpdata_dir = File.join(sandbox_path, "data")
136
+ FileUtils.mkdir_p(tmpdata_dir)
137
+ FileUtils.cp_r(Util.list_directory(config[:data_path]), tmpdata_dir)
138
+ end
139
+
140
+ # Copies the executable script to the sandbox directory or creates a
141
+ # stub script if one cannot be found.
142
+ #
143
+ # @api private
144
+ def prepare_script
145
+ info("Preparing script")
146
+
147
+ if config[:script]
148
+ debug("Using script from #{config[:script]}")
149
+ FileUtils.cp_r(config[:script], sandbox_path)
150
+ else
151
+ info("No provisioner script file specified, skipping")
152
+ end
153
+ end
154
+
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
3
+ #
4
+ # Copyright (C) 2013, Fletcher Nichol
5
+ # Copyright (C) Chef Software Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative "plugin"
20
+
21
+ module Kitchen
22
+ # A provisioner is responsible for generating the commands necessary to
23
+ # install set up and use a configuration management tool such as Chef and
24
+ # Puppet.
25
+ #
26
+ # @author Fletcher Nichol <fnichol@nichol.ca>
27
+ module Provisioner
28
+ # Default provisioner to use
29
+ DEFAULT_PLUGIN = "chef_infra".freeze
30
+
31
+ # Returns an instance of a provisioner given a plugin type string.
32
+ #
33
+ # @param plugin [String] a provisioner plugin type, to be constantized
34
+ # @param config [Hash] a configuration hash to initialize the provisioner
35
+ # @return [Provisioner::Base] a provisioner instance
36
+ # @raise [ClientError] if a provisioner instance could not be created
37
+ def self.for_plugin(plugin, config)
38
+ plugin, config[:name] = "chef_infra", "chef_infra" if plugin == "chef_zero"
39
+ Kitchen::Plugin.load(self, plugin, config)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
3
+ #
4
+ # Copyright (C) 2012, 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 "rake/tasklib"
19
+
20
+ require_relative "../kitchen"
21
+
22
+ module Kitchen
23
+ # Kitchen Rake task generator.
24
+ #
25
+ # @author Fletcher Nichol <fnichol@nichol.ca>
26
+ class RakeTasks < ::Rake::TaskLib
27
+ # Creates Kitchen Rake tasks and allows the callee to configure it.
28
+ #
29
+ # @yield [self] gives itself to the block
30
+ def initialize(cfg = {})
31
+ @loader = Kitchen::Loader::YAML.new(
32
+ project_config: ENV["KITCHEN_YAML"],
33
+ local_config: ENV["KITCHEN_LOCAL_YAML"],
34
+ global_config: ENV["KITCHEN_GLOBAL_YAML"]
35
+ )
36
+ @config = Kitchen::Config.new(
37
+ { loader: @loader }.merge(cfg)
38
+ )
39
+ Kitchen.logger = Kitchen.default_file_logger(nil, false)
40
+ yield self if block_given?
41
+ define
42
+ end
43
+
44
+ # @return [Config] a Kitchen::Config
45
+ attr_reader :config
46
+
47
+ private
48
+
49
+ # Generates a test Rake task for each instance and one to test all
50
+ # instances in serial.
51
+ #
52
+ # @api private
53
+ def define
54
+ namespace "kitchen" do
55
+ kitchen_commands = %w{create converge setup verify destroy}
56
+ config.instances.each do |instance|
57
+ desc "Run #{instance.name} test instance"
58
+ task instance.name do
59
+ instance.test(:always)
60
+ end
61
+
62
+ kitchen_commands.each do |cmd|
63
+ namespace cmd do
64
+ task instance.name do
65
+ instance.send(cmd)
66
+ end
67
+ desc "Run all #{cmd} instances"
68
+ task "all" => config.instances.map(&:name)
69
+ end
70
+ end
71
+ end
72
+
73
+ desc "Run all test instances"
74
+ task "all" => config.instances.map(&:name)
75
+
76
+ kitchen_commands.each { |cmd| task cmd => "#{cmd}:all" }
77
+ end
78
+ end
79
+ end
80
+ end