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.
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,254 @@
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 "rubygems/gem_runner"
19
+ require "thor/group"
20
+
21
+ module Kitchen
22
+ module Generator
23
+ # A project initialization generator, to help prepare a cookbook project
24
+ # for testing with Kitchen.
25
+ #
26
+ # @author Fletcher Nichol <fnichol@nichol.ca>
27
+ class Init < Thor::Group
28
+ include Thor::Actions
29
+
30
+ class_option :driver,
31
+ type: :array,
32
+ aliases: "-D",
33
+ default: %w{kitchen-vagrant},
34
+ desc: <<-D.gsub(/^\s+/, "").tr("\n", " ")
35
+ One or more Kitchen Driver gems to be installed or added to a
36
+ Gemfile
37
+ D
38
+
39
+ class_option :provisioner,
40
+ type: :string,
41
+ aliases: "-P",
42
+ default: "chef_solo",
43
+ desc: <<-D.gsub(/^\s+/, "").tr("\n", " ")
44
+ The default Kitchen Provisioner to use
45
+ D
46
+
47
+ class_option :create_gemfile,
48
+ type: :boolean,
49
+ default: false,
50
+ desc: <<-D.gsub(/^\s+/, "").tr("\n", " ")
51
+ Whether or not to create a Gemfile if one does not exist.
52
+ Default: false
53
+ D
54
+
55
+ # Invoke the command.
56
+ def init
57
+ self.class.source_root(Kitchen.source_root.join("templates", "init"))
58
+
59
+ create_kitchen_yaml
60
+ create_chefignore
61
+ prepare_rakefile
62
+ prepare_thorfile
63
+ create_test_dir
64
+ prepare_gitignore
65
+ prepare_gemfile
66
+ display_bundle_message
67
+ end
68
+
69
+ private
70
+
71
+ # Creates the `.kitchen.yml` file.
72
+ #
73
+ # @api private
74
+ def create_kitchen_yaml
75
+ cookbook_name = if File.exist?(File.expand_path("metadata.rb"))
76
+ MetadataChopper.extract("metadata.rb").first
77
+ end
78
+ run_list = cookbook_name ? "recipe[#{cookbook_name}::default]" : nil
79
+ driver_plugin = Array(options[:driver]).first || "dummy"
80
+
81
+ template("kitchen.yml.erb", "kitchen.yml",
82
+ driver_plugin: driver_plugin.sub(/^kitchen-/, ""),
83
+ provisioner: options[:provisioner],
84
+ run_list: Array(run_list))
85
+ end
86
+
87
+ # Creates the `chefignore` file.
88
+ #
89
+ # @api private
90
+ def create_chefignore
91
+ template("chefignore.erb", "chefignore")
92
+ end
93
+
94
+ # @return [true,false] whether or not a Gemfile needs to be initialized
95
+ # @api private
96
+ def init_gemfile?
97
+ File.exist?(File.join(destination_root, "Gemfile")) ||
98
+ options[:create_gemfile]
99
+ end
100
+
101
+ # @return [true,false] whether or not a Rakefile needs to be initialized
102
+ # @api private
103
+ def init_rakefile?
104
+ File.exist?(File.join(destination_root, "Rakefile")) &&
105
+ not_in_file?("Rakefile", %r{require 'kitchen/rake_tasks'})
106
+ end
107
+
108
+ # @return [true,false] whether or not a Thorfile needs to be initialized
109
+ # @api private
110
+ def init_thorfile?
111
+ File.exist?(File.join(destination_root, "Thorfile")) &&
112
+ not_in_file?("Thorfile", %r{require 'kitchen/thor_tasks'})
113
+ end
114
+
115
+ # @return [true,false] whether or not a test directory needs to be
116
+ # initialized
117
+ # @api private
118
+ def init_test_dir?
119
+ Util.list_directory("test/integration/").select { |d| File.directory?(d) }.empty?
120
+ end
121
+
122
+ # @return [true,false] whether or not a `.gitignore` file needs to be
123
+ # initialized
124
+ # @api private
125
+ def init_git?
126
+ File.directory?(File.join(destination_root, ".git"))
127
+ end
128
+
129
+ # Prepares a Rakefile.
130
+ #
131
+ # @api private
132
+ def prepare_rakefile
133
+ return unless init_rakefile?
134
+
135
+ rakedoc = <<-RAKE.gsub(/^ {10}/, "")
136
+
137
+ begin
138
+ require_relative '../rake_tasks'
139
+ Kitchen::RakeTasks.new
140
+ rescue LoadError
141
+ puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
142
+ end
143
+ RAKE
144
+ append_to_file(File.join(destination_root, "Rakefile"), rakedoc)
145
+ end
146
+
147
+ # Prepares a Thorfile.
148
+ #
149
+ # @api private
150
+ def prepare_thorfile
151
+ return unless init_thorfile?
152
+
153
+ thordoc = <<-THOR.gsub(/^ {10}/, "")
154
+
155
+ begin
156
+ require_relative '../thor_tasks'
157
+ Kitchen::ThorTasks.new
158
+ rescue LoadError
159
+ puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
160
+ end
161
+ THOR
162
+ append_to_file(File.join(destination_root, "Thorfile"), thordoc)
163
+ end
164
+
165
+ # Create the default test directory
166
+ #
167
+ # @api private
168
+ def create_test_dir
169
+ empty_directory "test/integration/default" if init_test_dir?
170
+ end
171
+
172
+ # Prepares the .gitignore file
173
+ #
174
+ # @api private
175
+ def prepare_gitignore
176
+ return unless init_git?
177
+
178
+ append_to_gitignore(".kitchen/")
179
+ append_to_gitignore(".kitchen.local.yml")
180
+ end
181
+
182
+ # Appends a line to the .gitignore file.
183
+ #
184
+ # @api private
185
+ def append_to_gitignore(line)
186
+ create_file(".gitignore") unless File.exist?(File.join(destination_root, ".gitignore"))
187
+
188
+ if IO.readlines(File.join(destination_root, ".gitignore")).grep(/^#{line}/).empty?
189
+ append_to_file(".gitignore", "#{line}\n")
190
+ end
191
+ end
192
+
193
+ # Prepares a Gemfile.
194
+ #
195
+ # @api private
196
+ def prepare_gemfile
197
+ return unless init_gemfile?
198
+
199
+ create_gemfile_if_missing
200
+ add_gem_to_gemfile
201
+ end
202
+
203
+ # Creates a Gemfile if missing
204
+ #
205
+ # @api private
206
+ def create_gemfile_if_missing
207
+ unless File.exist?(File.join(destination_root, "Gemfile"))
208
+ create_file("Gemfile", %{source "https://rubygems.org"\n\n})
209
+ end
210
+ end
211
+
212
+ # Appends entries to a Gemfile.
213
+ #
214
+ # @api private
215
+ def add_gem_to_gemfile
216
+ if not_in_file?("Gemfile", /gem ('|")test-kitchen('|")/)
217
+ append_to_file("Gemfile", %{gem "test-kitchen"\n})
218
+ @display_bundle_msg = true
219
+ end
220
+ end
221
+
222
+ # Displays a bundle warning message to the user.
223
+ #
224
+ # @api private
225
+ def display_bundle_message
226
+ if @display_bundle_msg
227
+ say "You must run `bundle install' to fetch any new gems.", :red
228
+ end
229
+ end
230
+
231
+ # Determines whether or not a pattern is found in a file.
232
+ #
233
+ # @param filename [String] filename to read
234
+ # @param regexp [Regexp] a regular expression
235
+ # @return [true,false] whether or not a pattern is found in a file
236
+ # @api private
237
+ def not_in_file?(filename, regexp)
238
+ IO.readlines(File.join(destination_root, filename)).grep(regexp).empty?
239
+ end
240
+
241
+ # Save off any Bundler/Ruby-related environment variables so that the
242
+ # yielded block can run "bundler-free" (and restore at the end).
243
+ #
244
+ # @api private
245
+ def unbundlerize
246
+ keys = ENV.keys.select { |key| key =~ /^BUNDLER?_/ } + %w{RUBYOPT}
247
+
248
+ keys.each { |key| ENV["__#{key}"] = ENV[key]; ENV.delete(key) }
249
+ yield
250
+ keys.each { |key| ENV[key] = ENV.delete("__#{key}") }
251
+ end
252
+ end
253
+ end
254
+ end