test-kitchen 1.10.2 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c365d365930afd27da95bdfd0ba7215b0c062d34
4
- data.tar.gz: 4b356e57b52d46ffa351fc06e79d2ab530d31cdb
3
+ metadata.gz: 18c07230017975d3394e829c8325bce98a9d29e7
4
+ data.tar.gz: 7beebf652866a5046898dcb9b0b21ac5b82d4e8e
5
5
  SHA512:
6
- metadata.gz: c53f55c6469483d23333d7df71316f91ed005340aab50161edae21af70bd294ca67be3462eda45318b77527a9902dfea94a1009f58d160ed6296dae4a8b80fce
7
- data.tar.gz: aea64bb5f8ab4add497688f808bcfdae894361b42f76dab1275f3001a8428621325dc7f9cea6778fb8d88a91e7f1b4af011751758505b6cf9c871cb8a1181e15
6
+ metadata.gz: 197303853148d6c9f2ca5add5d67c6683089bc4dd26cefb7e5b22b3b6f612adb68b82146027acaee6fdba7091bb5b49371429f0ecc1b92f8cb42c2895762b04e
7
+ data.tar.gz: 03bd9a05645d7e5860cf72a99569dd6b57fd7fdd795c90cc004b247eeccce3be31c9ae3b1b94aa6b5102bdaad494bb096cb667d6619f46afa362f83f6a833c4a
@@ -23,4 +23,4 @@ verifier:
23
23
  suites:
24
24
  - name: default
25
25
  run_list:
26
- - recipe[filezilla]
26
+ - recipe[test_cookbook::default]
data/Berksfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "https://supermarket.chef.io"
2
2
 
3
- cookbook "filezilla"
3
+ cookbook "test_cookbook", :path => "./test/cookbooks/test_cookbook"
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.11.0](https://github.com/test-kitchen/test-kitchen/tree/v1.11.0) (2016-08-11)
4
+ [Full Changelog](https://github.com/test-kitchen/test-kitchen/compare/v1.10.2...v1.11.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Provide some way for Chef to know it's running under test [\#458](https://github.com/test-kitchen/test-kitchen/issues/458)
9
+ - Dont set ssh key configuration if a password is specified [\#1095](https://github.com/test-kitchen/test-kitchen/pull/1095) ([mwrock](https://github.com/mwrock))
10
+ - Ability to work with Instances over SSH tunnel. [\#1091](https://github.com/test-kitchen/test-kitchen/pull/1091) ([EYurchenko](https://github.com/EYurchenko))
11
+ - Add environment variables $TEST\_KITCHEN and $CI [\#1081](https://github.com/test-kitchen/test-kitchen/pull/1081) ([coderanger](https://github.com/coderanger))
12
+ - Adding test\_base\_path CLI arg to the diagnose command [\#1076](https://github.com/test-kitchen/test-kitchen/pull/1076) ([tyler-ball](https://github.com/tyler-ball))
13
+ - Add legacy\_mode argument for chef\_solo provisioner [\#1073](https://github.com/test-kitchen/test-kitchen/pull/1073) ([SaltwaterC](https://github.com/SaltwaterC))
14
+ - Added support for Chef 10 [\#1072](https://github.com/test-kitchen/test-kitchen/pull/1072) ([acondrat](https://github.com/acondrat))
15
+
16
+ **Fixed bugs:**
17
+
18
+ - Escape paths before running policyfile commands [\#1085](https://github.com/test-kitchen/test-kitchen/pull/1085) ([coderanger](https://github.com/coderanger))
19
+
3
20
  ## [v1.10.2](https://github.com/test-kitchen/test-kitchen/tree/v1.10.2) (2016-06-23)
4
21
  [Full Changelog](https://github.com/test-kitchen/test-kitchen/compare/v1.10.1...v1.10.2)
5
22
 
data/Gemfile CHANGED
@@ -1,13 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  source "https://rubygems.org"
3
3
  gemspec
4
-
5
- group :guard do
6
- gem "guard-minitest"
7
- gem "guard-cucumber", "~> 1.4"
8
- gem "guard-rubocop"
9
- gem "guard-yard"
10
- end
4
+ gem "rack", "< 2.0"
11
5
 
12
6
  group :integration do
13
7
  gem "berkshelf", "~> 4.3"
@@ -20,6 +20,7 @@ receive a veto from the Lieutenant or the Project Lead.
20
20
  * [Kimball Johnson](https://github.com/drrk)
21
21
  * [Lamont Granquist](https://github.com/lamont-granquist)
22
22
  * [Matt Wrock](https://github.com/mwrock)
23
+ * [Noah Kantrowitz](https://github.com/coderanger)
23
24
  * [Robb Kidd](https://github.com/robbkidd)
24
25
  * [Sean Omeara](http://github.com/someara)
25
26
  * [Steven Murawski](http://github.com/smurawski)
data/Rakefile CHANGED
@@ -40,23 +40,8 @@ rescue LoadError
40
40
  puts "finstyle/rubocop is not available. gem install finstyle to do style checking."
41
41
  end
42
42
 
43
- begin
44
- if RUBY_ENGINE != "jruby"
45
- require "cane/rake_task"
46
- desc "Run cane to check quality metrics"
47
- Cane::RakeTask.new do |cane|
48
- cane.canefile = "./.cane"
49
- end
50
-
51
- desc "Run all quality tasks"
52
- task :quality => [:cane, :style, :stats]
53
- else
54
- desc "Run all quality tasks"
55
- task :quality => [:style, :stats]
56
- end
57
- rescue LoadError
58
- puts "cane is not available. (sudo) gem install cane to check quality metrics."
59
- end
43
+ desc "Run all quality tasks"
44
+ task :quality => [:style, :stats]
60
45
 
61
46
  begin
62
47
  require "yard"
@@ -135,6 +135,7 @@ module Kitchen
135
135
  :type => :boolean,
136
136
  :desc => "Include all diagnostics"
137
137
  log_options
138
+ test_base_path
138
139
  def diagnose(*args)
139
140
  update_config!
140
141
  perform("diagnose", "diagnose", args, :loader => @loader)
@@ -312,7 +312,11 @@ module Kitchen
312
312
  end
313
313
 
314
314
  def env_wrapped(code)
315
- (proxy_settings << code).join("\n")
315
+ code_parts = proxy_settings
316
+ code_parts << shell_env_var("TEST_KITCHEN", 1)
317
+ code_parts << shell_env_var("CI", ENV["CI"]) if ENV["CI"]
318
+ code_parts << code
319
+ code_parts.join("\n")
316
320
  end
317
321
 
318
322
  def proxy_setting_keys
@@ -16,6 +16,9 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
+ require "shellwords"
20
+ require "rbconfig"
21
+
19
22
  require "kitchen/errors"
20
23
  require "kitchen/logging"
21
24
  require "kitchen/shell_out"
@@ -36,7 +39,7 @@ module Kitchen
36
39
 
37
40
  # Creates a new cookbook resolver.
38
41
  #
39
- # @param berksfile [String] path to a Berksfile
42
+ # @param policyfile [String] path to a Policyfile
40
43
  # @param path [String] path in which to vendor the resulting
41
44
  # cookbooks
42
45
  # @param logger [Kitchen::Logger] a logger to use for output, defaults
@@ -59,7 +62,7 @@ module Kitchen
59
62
  # in the desired path.
60
63
  def resolve
61
64
  info("Exporting cookbook dependencies from Policyfile #{path}...")
62
- run_command("chef export #{policyfile} #{path} --force")
65
+ run_command("chef export #{escape_path(policyfile)} #{escape_path(path)} --force")
63
66
  end
64
67
 
65
68
  # Runs `chef install` to determine the correct cookbook set and
@@ -67,7 +70,7 @@ module Kitchen
67
70
  def compile
68
71
  info("Policy lock file doesn't exist, running `chef install` for "\
69
72
  "Policyfile #{policyfile}...")
70
- run_command("chef install #{policyfile}")
73
+ run_command("chef install #{escape_path(policyfile)}")
71
74
  end
72
75
 
73
76
  private
@@ -101,6 +104,29 @@ module Kitchen
101
104
  "Could not find the chef executable in your PATH."
102
105
  end
103
106
  end
107
+
108
+ # Escape spaces in a path in way that works with both Sh (Unix) and
109
+ # Windows.
110
+ #
111
+ # @param path [String] Path to escape
112
+ # @return [String]
113
+ # @api private
114
+ def escape_path(path)
115
+ if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
116
+ # I know what you're thinking: "just use Shellwords.escape". That
117
+ # method produces incorrect results on Windows with certain input
118
+ # which would be a metacharacter in Sh but is not for one or more of
119
+ # Windows command line parsing libraries. This covers the 99% case of
120
+ # spaces in the path without breaking other stuff.
121
+ if path =~ /[ \t\n\v"]/
122
+ "\"#{path.gsub(/[ \t\n\v\"\\]/) { |m| "\\" + m[0] }}\""
123
+ else
124
+ path
125
+ end
126
+ else
127
+ Shellwords.escape(path)
128
+ end
129
+ end
104
130
  end
105
131
  end
106
132
  end
@@ -45,20 +45,37 @@ module Kitchen
45
45
  prepare_solo_rb
46
46
  end
47
47
 
48
+ def modern?
49
+ version = config[:require_chef_omnibus]
50
+
51
+ case version
52
+ when nil, false, true, 11, "11", "latest"
53
+ true
54
+ else
55
+ if Gem::Version.correct?(version)
56
+ Gem::Version.new(version) >= Gem::Version.new("11.0") ? true : false
57
+ else
58
+ true
59
+ end
60
+ end
61
+ end
62
+
48
63
  # (see Base#run_command)
49
- def run_command # rubocop:disable Metrics/AbcSize
50
- level = config[:log_level]
64
+ # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize
65
+ def run_command
66
+ config[:log_level] = "info" if !modern? && config[:log_level] = "auto"
51
67
  cmd = sudo(config[:chef_solo_path]).dup.
52
68
  tap { |str| str.insert(0, "& ") if powershell_shell? }
53
69
  args = [
54
70
  "--config #{remote_path_join(config[:root_path], "solo.rb")}",
55
- "--log_level #{level}",
56
- "--force-formatter",
71
+ "--log_level #{config[:log_level]}",
57
72
  "--no-color",
58
73
  "--json-attributes #{remote_path_join(config[:root_path], "dna.json")}"
59
74
  ]
75
+ args << " --force-formatter" if modern?
60
76
  args << "--logfile #{config[:log_file]}" if config[:log_file]
61
77
  args << "--profile-ruby" if config[:profile_ruby]
78
+ args << "--legacy-mode" if config[:legacy_mode]
62
79
 
63
80
  prefix_command(
64
81
  wrap_shell_code(
@@ -19,6 +19,7 @@
19
19
  require "kitchen"
20
20
 
21
21
  require "net/ssh"
22
+ require "net/ssh/gateway"
22
23
  require "net/scp"
23
24
  require "timeout"
24
25
  require "benchmark"
@@ -53,6 +54,9 @@ module Kitchen
53
54
  default_config :connection_retry_sleep, 1
54
55
  default_config :max_wait_until_ready, 600
55
56
 
57
+ default_config :ssh_gateway, nil
58
+ default_config :ssh_gateway_username, nil
59
+
56
60
  default_config :ssh_key, nil
57
61
  expand_path_for :ssh_key
58
62
 
@@ -142,6 +146,11 @@ module Kitchen
142
146
  if options.key?(:forward_agent)
143
147
  args += %W[ -o ForwardAgent=#{options[:forward_agent] ? "yes" : "no"} ]
144
148
  end
149
+ if ssh_gateway
150
+ gateway_command = "ssh -q #{ssh_gateway_username}@#{ssh_gateway} nc #{hostname} #{port}"
151
+ # Should support other ports than 22 for ssh gateways
152
+ args += %W[ -o ProxyCommand=#{gateway_command} -p 22 ]
153
+ end
145
154
  Array(options[:keys]).each { |ssh_key| args += %W[ -i #{ssh_key} ] }
146
155
  args += %W[ -p #{port} ]
147
156
  args += %W[ #{username}@#{hostname} ]
@@ -226,6 +235,33 @@ module Kitchen
226
235
  # @api private
227
236
  attr_reader :port
228
237
 
238
+ # @return [String] The ssh gateway to use when connecting to the
239
+ # remote SSH host
240
+ # @api private
241
+ attr_reader :ssh_gateway
242
+
243
+ # @return [String] The username to use when using an ssh gateway
244
+ # @api private
245
+ attr_reader :ssh_gateway_username
246
+
247
+ # Establish an SSH session on the remote host using a gateway host.
248
+ #
249
+ # @param opts [Hash] retry options
250
+ # @option opts [Integer] :retries the number of times to retry before
251
+ # failing
252
+ # @option opts [Float] :delay the number of seconds to wait until
253
+ # attempting a retry
254
+ # @option opts [String] :message an optional message to be logged on
255
+ # debug (overriding the default) when a rescuable exception is raised
256
+ # @return [Net::SSH::Connection::Session] the SSH connection session
257
+ # @api private
258
+ def establish_connection_via_gateway(opts)
259
+ retry_connection(opts) do
260
+ Net::SSH::Gateway.new(ssh_gateway,
261
+ ssh_gateway_username, options).ssh(hostname, username, options)
262
+ end
263
+ end
264
+
229
265
  # Establish an SSH session on the remote host.
230
266
  #
231
267
  # @param opts [Hash] retry options
@@ -238,8 +274,27 @@ module Kitchen
238
274
  # @return [Net::SSH::Connection::Session] the SSH connection session
239
275
  # @api private
240
276
  def establish_connection(opts)
241
- logger.debug("[SSH] opening connection to #{self}")
242
- Net::SSH.start(hostname, username, options)
277
+ retry_connection(opts) do
278
+ Net::SSH.start(hostname, username, options)
279
+ end
280
+ end
281
+
282
+ # Connecto to a host executing passed block and properly handling retreis.
283
+ #
284
+ # @param opts [Hash] retry options
285
+ # @option opts [Integer] :retries the number of times to retry before
286
+ # failing
287
+ # @option opts [Float] :delay the number of seconds to wait until
288
+ # attempting a retry
289
+ # @option opts [String] :message an optional message to be logged on
290
+ # debug (overriding the default) when a rescuable exception is raised
291
+ # @return [Net::SSH::Connection::Session] the SSH connection session
292
+ # @api private
293
+ def retry_connection(opts)
294
+ log_msg = "[SSH] opening connection to #{self}"
295
+ log_msg += " via #{ssh_gateway_username}@#{ssh_gateway}" if ssh_gateway
296
+ logger.debug(log_msg)
297
+ yield
243
298
  rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH => e
244
299
  if (opts[:retries] -= 1) > 0
245
300
  message = if opts[:message]
@@ -298,6 +353,8 @@ module Kitchen
298
353
  @connection_retry_sleep = @options.delete(:connection_retry_sleep)
299
354
  @max_ssh_sessions = @options.delete(:max_ssh_sessions)
300
355
  @max_wait_until_ready = @options.delete(:max_wait_until_ready)
356
+ @ssh_gateway = @options.delete(:ssh_gateway)
357
+ @ssh_gateway_username = @options.delete(:ssh_gateway_username)
301
358
  end
302
359
 
303
360
  # Returns a connection session, or establishes one when invoked the
@@ -307,10 +364,17 @@ module Kitchen
307
364
  # @return [Net::SSH::Connection::Session] the SSH connection session
308
365
  # @api private
309
366
  def session(retry_options = {})
310
- @session ||= establish_connection({
311
- :retries => connection_retries.to_i,
312
- :delay => connection_retry_sleep.to_i
313
- }.merge(retry_options))
367
+ if ssh_gateway
368
+ @session ||= establish_connection_via_gateway({
369
+ :retries => connection_retries.to_i,
370
+ :delay => connection_retry_sleep.to_i
371
+ }.merge(retry_options))
372
+ else
373
+ @session ||= establish_connection({
374
+ :retries => connection_retries.to_i,
375
+ :delay => connection_retry_sleep.to_i
376
+ }.merge(retry_options))
377
+ end
314
378
  end
315
379
 
316
380
  # String representation of object, reporting its connection details and
@@ -347,12 +411,17 @@ module Kitchen
347
411
  :connection_retries => data[:connection_retries],
348
412
  :connection_retry_sleep => data[:connection_retry_sleep],
349
413
  :max_ssh_sessions => data[:max_ssh_sessions],
350
- :max_wait_until_ready => data[:max_wait_until_ready]
414
+ :max_wait_until_ready => data[:max_wait_until_ready],
415
+ :ssh_gateway => data[:ssh_gateway],
416
+ :ssh_gateway_username => data[:ssh_gateway_username]
351
417
  }
352
418
 
353
- opts[:keys_only] = true if data[:ssh_key]
354
- opts[:keys] = Array(data[:ssh_key]) if data[:ssh_key]
355
- opts[:auth_methods] = ["publickey"] if data[:ssh_key]
419
+ if data[:ssh_key] && !data.key?(:password)
420
+ opts[:keys_only] = true
421
+ opts[:keys] = Array(data[:ssh_key])
422
+ opts[:auth_methods] = ["publickey"]
423
+ end
424
+
356
425
  opts[:password] = data[:password] if data.key?(:password)
357
426
  opts[:forward_agent] = data[:forward_agent] if data.key?(:forward_agent)
358
427
  opts[:verbose] = data[:verbose].to_sym if data.key?(:verbose)
@@ -17,5 +17,5 @@
17
17
  # limitations under the License.
18
18
 
19
19
  module Kitchen
20
- VERSION = "1.10.2"
20
+ VERSION = "1.11.0"
21
21
  end
@@ -732,7 +732,8 @@ describe Kitchen::Configurable do
732
732
  ENV.replace("http_proxy" => nil, "HTTP_PROXY" => nil,
733
733
  "https_proxy" => nil, "HTTPS_PROXY" => nil,
734
734
  "ftp_proxy" => nil, "FTP_PROXY" => nil,
735
- "no_proxy" => nil, "NO_PROXY" => nil)
735
+ "no_proxy" => nil, "NO_PROXY" => nil,
736
+ "CI" => nil)
736
737
  end
737
738
 
738
739
  after do
@@ -747,6 +748,7 @@ describe Kitchen::Configurable do
747
748
  it "uses bourne shell (sh)" do
748
749
  cmd.must_equal(outdent!(<<-CODE.chomp))
749
750
  sh -c '
751
+ TEST_KITCHEN="1"; export TEST_KITCHEN
750
752
  mkdir foo
751
753
  '
752
754
  CODE
@@ -759,6 +761,7 @@ describe Kitchen::Configurable do
759
761
  sh -c '
760
762
  http_proxy="http://proxy"; export http_proxy
761
763
  HTTP_PROXY="http://proxy"; export HTTP_PROXY
764
+ TEST_KITCHEN="1"; export TEST_KITCHEN
762
765
  mkdir foo
763
766
  '
764
767
  CODE
@@ -771,6 +774,7 @@ describe Kitchen::Configurable do
771
774
  sh -c '
772
775
  https_proxy="https://proxy"; export https_proxy
773
776
  HTTPS_PROXY="https://proxy"; export HTTPS_PROXY
777
+ TEST_KITCHEN="1"; export TEST_KITCHEN
774
778
  mkdir foo
775
779
  '
776
780
  CODE
@@ -783,6 +787,7 @@ describe Kitchen::Configurable do
783
787
  sh -c '
784
788
  ftp_proxy="ftp://proxy"; export ftp_proxy
785
789
  FTP_PROXY="ftp://proxy"; export FTP_PROXY
790
+ TEST_KITCHEN="1"; export TEST_KITCHEN
786
791
  mkdir foo
787
792
  '
788
793
  CODE
@@ -801,6 +806,7 @@ describe Kitchen::Configurable do
801
806
  HTTPS_PROXY="https://proxy"; export HTTPS_PROXY
802
807
  ftp_proxy="ftp://proxy"; export ftp_proxy
803
808
  FTP_PROXY="ftp://proxy"; export FTP_PROXY
809
+ TEST_KITCHEN="1"; export TEST_KITCHEN
804
810
  mkdir foo
805
811
  '
806
812
  CODE
@@ -814,6 +820,7 @@ describe Kitchen::Configurable do
814
820
  sh -c '
815
821
  http_proxy="http://proxy"; export http_proxy
816
822
  HTTP_PROXY="http://proxy"; export HTTP_PROXY
823
+ TEST_KITCHEN="1"; export TEST_KITCHEN
817
824
  mkdir foo
818
825
  '
819
826
  CODE
@@ -827,6 +834,7 @@ describe Kitchen::Configurable do
827
834
  sh -c '
828
835
  https_proxy="https://proxy"; export https_proxy
829
836
  HTTPS_PROXY="https://proxy"; export HTTPS_PROXY
837
+ TEST_KITCHEN="1"; export TEST_KITCHEN
830
838
  mkdir foo
831
839
  '
832
840
  CODE
@@ -839,6 +847,7 @@ describe Kitchen::Configurable do
839
847
 
840
848
  cmd.must_equal(outdent!(<<-CODE.chomp))
841
849
  sh -c '
850
+ TEST_KITCHEN="1"; export TEST_KITCHEN
842
851
  mkdir foo
843
852
  '
844
853
  CODE
@@ -851,6 +860,7 @@ describe Kitchen::Configurable do
851
860
 
852
861
  cmd.must_equal(outdent!(<<-CODE.chomp))
853
862
  sh -c '
863
+ TEST_KITCHEN="1"; export TEST_KITCHEN
854
864
  mkdir foo
855
865
  '
856
866
  CODE
@@ -864,6 +874,7 @@ describe Kitchen::Configurable do
864
874
  sh -c '
865
875
  ftp_proxy="ftp://proxy"; export ftp_proxy
866
876
  FTP_PROXY="ftp://proxy"; export FTP_PROXY
877
+ TEST_KITCHEN="1"; export TEST_KITCHEN
867
878
  mkdir foo
868
879
  '
869
880
  CODE
@@ -874,6 +885,7 @@ describe Kitchen::Configurable do
874
885
 
875
886
  cmd.must_equal(outdent!(<<-CODE.chomp))
876
887
  sh -c '
888
+ TEST_KITCHEN="1"; export TEST_KITCHEN
877
889
  mkdir foo
878
890
  '
879
891
  CODE
@@ -891,6 +903,7 @@ describe Kitchen::Configurable do
891
903
  HTTP_PROXY="http://proxy"; export HTTP_PROXY
892
904
  no_proxy="http://no"; export no_proxy
893
905
  NO_PROXY="http://no"; export NO_PROXY
906
+ TEST_KITCHEN="1"; export TEST_KITCHEN
894
907
  mkdir foo
895
908
  '
896
909
  CODE
@@ -908,6 +921,7 @@ describe Kitchen::Configurable do
908
921
  HTTPS_PROXY="https://proxy"; export HTTPS_PROXY
909
922
  no_proxy="http://no"; export no_proxy
910
923
  NO_PROXY="http://no"; export NO_PROXY
924
+ TEST_KITCHEN="1"; export TEST_KITCHEN
911
925
  mkdir foo
912
926
  '
913
927
  CODE
@@ -925,6 +939,19 @@ describe Kitchen::Configurable do
925
939
  FTP_PROXY="ftp://proxy"; export FTP_PROXY
926
940
  no_proxy="http://no"; export no_proxy
927
941
  NO_PROXY="http://no"; export NO_PROXY
942
+ TEST_KITCHEN="1"; export TEST_KITCHEN
943
+ mkdir foo
944
+ '
945
+ CODE
946
+ end
947
+
948
+ it "exports CI when CI is set" do
949
+ ENV["CI"] = "1"
950
+
951
+ cmd.must_equal(outdent!(<<-CODE.chomp))
952
+ sh -c '
953
+ TEST_KITCHEN="1"; export TEST_KITCHEN
954
+ CI="1"; export CI
928
955
  mkdir foo
929
956
  '
930
957
  CODE
@@ -936,7 +963,7 @@ describe Kitchen::Configurable do
936
963
  before { platform.stubs(:shell_type).returns("powershell") }
937
964
 
938
965
  it "uses powershell shell" do
939
- cmd.must_equal("mkdir foo")
966
+ cmd.must_equal("$env:TEST_KITCHEN = \"1\"\nmkdir foo")
940
967
  end
941
968
 
942
969
  it "exports http_proxy & HTTP_PROXY when :http_proxy is set" do
@@ -945,6 +972,7 @@ describe Kitchen::Configurable do
945
972
  cmd.must_equal(outdent!(<<-CODE.chomp))
946
973
  $env:http_proxy = "http://proxy"
947
974
  $env:HTTP_PROXY = "http://proxy"
975
+ $env:TEST_KITCHEN = "1"
948
976
  mkdir foo
949
977
  CODE
950
978
  end
@@ -955,6 +983,7 @@ describe Kitchen::Configurable do
955
983
  cmd.must_equal(outdent!(<<-CODE.chomp))
956
984
  $env:https_proxy = "https://proxy"
957
985
  $env:HTTPS_PROXY = "https://proxy"
986
+ $env:TEST_KITCHEN = "1"
958
987
  mkdir foo
959
988
  CODE
960
989
  end
@@ -965,6 +994,7 @@ describe Kitchen::Configurable do
965
994
  cmd.must_equal(outdent!(<<-CODE.chomp))
966
995
  $env:ftp_proxy = "ftp://proxy"
967
996
  $env:FTP_PROXY = "ftp://proxy"
997
+ $env:TEST_KITCHEN = "1"
968
998
  mkdir foo
969
999
  CODE
970
1000
  end
@@ -981,6 +1011,7 @@ describe Kitchen::Configurable do
981
1011
  $env:HTTPS_PROXY = "https://proxy"
982
1012
  $env:ftp_proxy = "ftp://proxy"
983
1013
  $env:FTP_PROXY = "ftp://proxy"
1014
+ $env:TEST_KITCHEN = "1"
984
1015
  mkdir foo
985
1016
  CODE
986
1017
  end
@@ -992,6 +1023,7 @@ describe Kitchen::Configurable do
992
1023
  cmd.must_equal(outdent!(<<-CODE.chomp))
993
1024
  $env:http_proxy = "http://proxy"
994
1025
  $env:HTTP_PROXY = "http://proxy"
1026
+ $env:TEST_KITCHEN = "1"
995
1027
  mkdir foo
996
1028
  CODE
997
1029
  end
@@ -1003,6 +1035,7 @@ describe Kitchen::Configurable do
1003
1035
  cmd.must_equal(outdent!(<<-CODE.chomp))
1004
1036
  $env:https_proxy = "https://proxy"
1005
1037
  $env:HTTPS_PROXY = "https://proxy"
1038
+ $env:TEST_KITCHEN = "1"
1006
1039
  mkdir foo
1007
1040
  CODE
1008
1041
  end
@@ -1014,6 +1047,7 @@ describe Kitchen::Configurable do
1014
1047
  cmd.must_equal(outdent!(<<-CODE.chomp))
1015
1048
  $env:ftp_proxy = "ftp://proxy"
1016
1049
  $env:FTP_PROXY = "ftp://proxy"
1050
+ $env:TEST_KITCHEN = "1"
1017
1051
  mkdir foo
1018
1052
  CODE
1019
1053
  end
@@ -1029,6 +1063,7 @@ describe Kitchen::Configurable do
1029
1063
  $env:HTTP_PROXY = "http://proxy"
1030
1064
  $env:no_proxy = "http://no"
1031
1065
  $env:NO_PROXY = "http://no"
1066
+ $env:TEST_KITCHEN = "1"
1032
1067
  mkdir foo
1033
1068
  CODE
1034
1069
  end
@@ -1044,6 +1079,7 @@ describe Kitchen::Configurable do
1044
1079
  $env:HTTPS_PROXY = "https://proxy"
1045
1080
  $env:no_proxy = "http://no"
1046
1081
  $env:NO_PROXY = "http://no"
1082
+ $env:TEST_KITCHEN = "1"
1047
1083
  mkdir foo
1048
1084
  CODE
1049
1085
  end
@@ -1059,6 +1095,17 @@ describe Kitchen::Configurable do
1059
1095
  $env:FTP_PROXY = "ftp://proxy"
1060
1096
  $env:no_proxy = "http://no"
1061
1097
  $env:NO_PROXY = "http://no"
1098
+ $env:TEST_KITCHEN = "1"
1099
+ mkdir foo
1100
+ CODE
1101
+ end
1102
+
1103
+ it "exports CI when CI is set" do
1104
+ ENV["CI"] = "1"
1105
+
1106
+ cmd.must_equal(outdent!(<<-CODE.chomp))
1107
+ $env:TEST_KITCHEN = "1"
1108
+ $env:CI = "1"
1062
1109
  mkdir foo
1063
1110
  CODE
1064
1111
  end
@@ -0,0 +1,140 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Noah Kantrowitz
4
+ #
5
+ # Copyright (C) 2016, Noah Kantrowitz
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 "../../../spec_helper"
20
+ require "kitchen/provisioner/chef/policyfile"
21
+
22
+ describe Kitchen::Provisioner::Chef::Policyfile do
23
+ let(:policyfile) { "" }
24
+ let(:path) { "" }
25
+ let(:null_logger) do
26
+ stub(:fatal => nil, :error => nil, :warn => nil, :info => nil,
27
+ :debug => nil, :banner => nil)
28
+ end
29
+ let(:described_object) do
30
+ Kitchen::Provisioner::Chef::Policyfile.new(policyfile, path, null_logger)
31
+ end
32
+ let(:os) { "" }
33
+ before do
34
+ @original_rbconfig = RbConfig::CONFIG
35
+ verbose = $VERBOSE
36
+ $VERBOSE = nil
37
+ RbConfig.const_set(:CONFIG, "host_os" => os)
38
+ $VERBOSE = verbose
39
+ end
40
+ after do
41
+ verbose = $VERBOSE
42
+ $VERBOSE = nil
43
+ RbConfig.const_set(:CONFIG, @original_rbconfig)
44
+ $VERBOSE = verbose
45
+ end
46
+
47
+ # rubocop:disable Metrics/LineLength
48
+ describe "#resolve" do
49
+ subject { described_object.resolve }
50
+
51
+ describe "on Unix" do
52
+ let(:os) { "linux-gnu" }
53
+
54
+ describe "with simple paths" do
55
+ let(:policyfile) { "/home/user/cookbook/Policyfile.rb" }
56
+ let(:path) { "/tmp/kitchen/cookbooks" }
57
+ it do
58
+ described_object.expects(:run_command).with("chef export /home/user/cookbook/Policyfile.rb /tmp/kitchen/cookbooks --force")
59
+ subject
60
+ end
61
+ end
62
+
63
+ describe "with Jenkins-y paths" do
64
+ let(:policyfile) { "/home/jenkins/My Chef Cookbook/workspace/current/Policyfile.rb" }
65
+ let(:path) { "/tmp/kitchen/cookbooks" }
66
+ it do
67
+ described_object.expects(:run_command).with("chef export /home/jenkins/My\\ Chef\\ Cookbook/workspace/current/Policyfile.rb /tmp/kitchen/cookbooks --force")
68
+ subject
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "on Windows" do
74
+ let(:os) { "mswin" }
75
+
76
+ describe "with simple paths" do
77
+ let(:policyfile) { "C:\\cookbook\\Policyfile.rb" }
78
+ let(:path) { "C:\\Temp\\kitchen\\cookbooks" }
79
+ it do
80
+ described_object.expects(:run_command).with("chef export C:\\cookbook\\Policyfile.rb C:\\Temp\\kitchen\\cookbooks --force")
81
+ subject
82
+ end
83
+ end
84
+
85
+ describe "with Jenkins-y paths" do
86
+ let(:policyfile) { "C:\\Program Files\\Jenkins\\My Chef Cookbook\\workspace\\current\\Policyfile.rb" }
87
+ let(:path) { "C:\\Temp\\kitchen\\cookbooks" }
88
+ it do
89
+ described_object.expects(:run_command).with("chef export \"C:\\\\Program\\ Files\\\\Jenkins\\\\My\\ Chef\\ Cookbook\\\\workspace\\\\current\\\\Policyfile.rb\" C:\\Temp\\kitchen\\cookbooks --force")
90
+ subject
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "#compile" do
97
+ subject { described_object.compile }
98
+
99
+ describe "on Unix" do
100
+ let(:os) { "linux-gnu" }
101
+
102
+ describe "with simple paths" do
103
+ let(:policyfile) { "/home/user/cookbook/Policyfile.rb" }
104
+ it do
105
+ described_object.expects(:run_command).with("chef install /home/user/cookbook/Policyfile.rb")
106
+ subject
107
+ end
108
+ end
109
+
110
+ describe "with Jenkins-y paths" do
111
+ let(:policyfile) { "/home/jenkins/My Chef Cookbook/workspace/current/Policyfile.rb" }
112
+ it do
113
+ described_object.expects(:run_command).with("chef install /home/jenkins/My\\ Chef\\ Cookbook/workspace/current/Policyfile.rb")
114
+ subject
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "on Windows" do
120
+ let(:os) { "mswin" }
121
+
122
+ describe "with simple paths" do
123
+ let(:policyfile) { "C:\\cookbook\\Policyfile.rb" }
124
+ it do
125
+ described_object.expects(:run_command).with("chef install C:\\cookbook\\Policyfile.rb")
126
+ subject
127
+ end
128
+ end
129
+
130
+ describe "with Jenkins-y paths" do
131
+ let(:policyfile) { "C:\\Program Files\\Jenkins\\My Chef Cookbook\\workspace\\current\\Policyfile.rb" }
132
+ it do
133
+ described_object.expects(:run_command).with("chef install \"C:\\\\Program\\ Files\\\\Jenkins\\\\My\\ Chef\\ Cookbook\\\\workspace\\\\current\\\\Policyfile.rb\"")
134
+ subject
135
+ end
136
+ end
137
+ end
138
+ end
139
+ # rubocop:enable Metrics/LineLength
140
+ end
@@ -401,6 +401,11 @@ describe Kitchen::Provisioner::ChefSolo do
401
401
  cmd.must_match regexify(" --log_level auto", :partial_line)
402
402
  end
403
403
 
404
+ it "sets log level flag on chef-solo to info by default if running Chef < 11" do
405
+ config[:require_chef_omnibus] = "10.34.6"
406
+ cmd.must_match regexify(" --log_level info", :partial_line)
407
+ end
408
+
404
409
  it "set log level flag for custom level" do
405
410
  config[:log_level] = :extreme
406
411
 
@@ -411,6 +416,11 @@ describe Kitchen::Provisioner::ChefSolo do
411
416
  cmd.must_match regexify(" --force-formatter", :partial_line)
412
417
  end
413
418
 
419
+ it "does not set force formatter flag on chef-solo if running Chef < 11" do
420
+ config[:require_chef_omnibus] = "10.34.6"
421
+ cmd.wont_match regexify(" --force-formatter", :partial_line)
422
+ end
423
+
414
424
  it "sets no color flag on chef-solo" do
415
425
  cmd.must_match regexify(" --no-color", :partial_line)
416
426
  end
@@ -437,6 +447,18 @@ describe Kitchen::Provisioner::ChefSolo do
437
447
 
438
448
  cmd.wont_match regexify(" --profile-ruby", :partial_line)
439
449
  end
450
+
451
+ it "sets legacy-mode flag when config element is set" do
452
+ config[:legacy_mode] = true
453
+
454
+ cmd.must_match regexify(" --legacy-mode", :partial_line)
455
+ end
456
+
457
+ it "does not set legacy-mode flag when config element is falsey" do
458
+ config[:legacy_mode] = false
459
+
460
+ cmd.wont_match regexify(" --legacy-mode", :partial_line)
461
+ end
440
462
  end
441
463
 
442
464
  describe "for powershell shells on windows os types" do
@@ -531,6 +531,64 @@ describe Kitchen::Transport::Ssh do
531
531
  make_connection
532
532
  end
533
533
 
534
+ it "does not set :keys_only if :ssh_key is set in config but password is set" do
535
+ config[:ssh_key] = "ssh_key_from_config"
536
+ config[:password] = "password"
537
+
538
+ klass.expects(:new).with do |hash|
539
+ hash[:keys_only].nil?
540
+ end
541
+
542
+ make_connection
543
+ end
544
+
545
+ it "does not set :auth_methods if :ssh_key is set in config but password is set" do
546
+ config[:ssh_key] = "ssh_key_from_config"
547
+ config[:password] = "password"
548
+
549
+ klass.expects(:new).with do |hash|
550
+ hash[:auth_methods].nil?
551
+ end
552
+
553
+ make_connection
554
+ end
555
+
556
+ it "does not set :keys_only if :ssh_key is set in state but password is set" do
557
+ state[:ssh_key] = "ssh_key_from_config"
558
+ config[:ssh_key] = false
559
+ config[:password] = "password"
560
+
561
+ klass.expects(:new).with do |hash|
562
+ hash[:keys_only].nil?
563
+ end
564
+
565
+ make_connection
566
+ end
567
+
568
+ it "does not set :keys to an array if :ssh_key is set in config but password is set" do
569
+ config[:kitchen_root] = "/r"
570
+ config[:ssh_key] = "ssh_key_from_config"
571
+ config[:password] = "password"
572
+
573
+ klass.expects(:new).with do |hash|
574
+ hash[:keys].nil?
575
+ end
576
+
577
+ make_connection
578
+ end
579
+
580
+ it "does not set :keys to an array if :ssh_key is set in state but password is set" do
581
+ state[:ssh_key] = "ssh_key_from_state"
582
+ config[:ssh_key] = "ssh_key_from_config"
583
+ config[:password] = "password"
584
+
585
+ klass.expects(:new).with do |hash|
586
+ hash[:keys].nil?
587
+ end
588
+
589
+ make_connection
590
+ end
591
+
534
592
  it "passes in :password if set in config" do
535
593
  config[:password] = "password_from_config"
536
594
 
@@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency "mixlib-shellout", ">= 1.2", "< 3.0"
27
27
  gem.add_dependency "net-scp", "~> 1.1"
28
28
  gem.add_dependency "net-ssh", ">= 2.9", "< 4.0"
29
+ gem.add_dependency "net-ssh-gateway", "~> 1.2.0"
29
30
  gem.add_dependency "safe_yaml", "~> 1.0"
30
31
  gem.add_dependency "thor", "~> 0.18"
31
32
  gem.add_dependency "mixlib-install", "~> 1.0", ">= 1.0.4"
@@ -59,5 +60,4 @@ Gem::Specification.new do |gem|
59
60
  # may introduce new and undesireable style choices which would be immediately
60
61
  # enforced in CI
61
62
  gem.add_development_dependency "finstyle", "1.5.0"
62
- gem.add_development_dependency "cane", "2.6.2"
63
63
  end
@@ -0,0 +1,6 @@
1
+ name "test_cookbook"
2
+ maintainer "Maintainer"
3
+ maintainer_email "Maintainer@example.com"
4
+ license "Apache 2.0"
5
+ description "Used for testing test-kitchen"
6
+ version "0.1.0"
@@ -0,0 +1 @@
1
+ directory "/tk_test_directory"
@@ -1,3 +1,3 @@
1
- describe oneget("FileZilla Client 3.14.1") do
2
- it { should be_installed }
1
+ describe directory("/tk_test_directory") do
2
+ it { should exist }
3
3
  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: 1.10.2
4
+ version: 1.11.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: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '4.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: net-ssh-gateway
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.0
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 1.2.0
67
81
  - !ruby/object:Gem::Dependency
68
82
  name: safe_yaml
69
83
  requirement: !ruby/object:Gem::Requirement
@@ -406,20 +420,6 @@ dependencies:
406
420
  - - '='
407
421
  - !ruby/object:Gem::Version
408
422
  version: 1.5.0
409
- - !ruby/object:Gem::Dependency
410
- name: cane
411
- requirement: !ruby/object:Gem::Requirement
412
- requirements:
413
- - - '='
414
- - !ruby/object:Gem::Version
415
- version: 2.6.2
416
- type: :development
417
- prerelease: false
418
- version_requirements: !ruby/object:Gem::Requirement
419
- requirements:
420
- - - '='
421
- - !ruby/object:Gem::Version
422
- version: 2.6.2
423
423
  description: Test Kitchen is an integration tool for developing and testing infrastructure
424
424
  code and software on isolated target platforms.
425
425
  email:
@@ -429,7 +429,6 @@ executables:
429
429
  extensions: []
430
430
  extra_rdoc_files: []
431
431
  files:
432
- - ".cane"
433
432
  - ".gitattributes"
434
433
  - ".github/ISSUE_TEMPLATE.md"
435
434
  - ".gitignore"
@@ -557,6 +556,7 @@ files:
557
556
  - spec/kitchen/metadata_chopper_spec.rb
558
557
  - spec/kitchen/platform_spec.rb
559
558
  - spec/kitchen/provisioner/base_spec.rb
559
+ - spec/kitchen/provisioner/chef/policyfile_spec.rb
560
560
  - spec/kitchen/provisioner/chef_apply_spec.rb
561
561
  - spec/kitchen/provisioner/chef_base_spec.rb
562
562
  - spec/kitchen/provisioner/chef_solo_spec.rb
@@ -609,6 +609,8 @@ files:
609
609
  - templates/init/chefignore.erb
610
610
  - templates/init/kitchen.yml.erb
611
611
  - test-kitchen.gemspec
612
+ - test/cookbooks/test_cookbook/metadata.rb
613
+ - test/cookbooks/test_cookbook/recipes/default.rb
612
614
  - test/integration/default/default_spec.rb
613
615
  - testing_windows.md
614
616
  homepage: http://kitchen.ci
@@ -631,7 +633,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
631
633
  version: '0'
632
634
  requirements: []
633
635
  rubyforge_project:
634
- rubygems_version: 2.5.1
636
+ rubygems_version: 2.6.4
635
637
  signing_key:
636
638
  specification_version: 4
637
639
  summary: Test Kitchen is an integration tool for developing and testing infrastructure
@@ -677,6 +679,7 @@ test_files:
677
679
  - spec/kitchen/metadata_chopper_spec.rb
678
680
  - spec/kitchen/platform_spec.rb
679
681
  - spec/kitchen/provisioner/base_spec.rb
682
+ - spec/kitchen/provisioner/chef/policyfile_spec.rb
680
683
  - spec/kitchen/provisioner/chef_apply_spec.rb
681
684
  - spec/kitchen/provisioner/chef_base_spec.rb
682
685
  - spec/kitchen/provisioner/chef_solo_spec.rb
@@ -701,5 +704,6 @@ test_files:
701
704
  - spec/kitchen_spec.rb
702
705
  - spec/spec_helper.rb
703
706
  - spec/support/powershell_max_size_spec.rb
707
+ - test/cookbooks/test_cookbook/metadata.rb
708
+ - test/cookbooks/test_cookbook/recipes/default.rb
704
709
  - test/integration/default/default_spec.rb
705
- has_rdoc:
data/.cane DELETED
@@ -1,8 +0,0 @@
1
- --abc-max 20
2
- --style-measure 100
3
- --abc-exclude Kitchen::ThorTasks#define
4
- --abc-exclude Kitchen::Driver::SSHBase#converge
5
- --abc-exclude Kitchen::Driver::SSHBase#verify
6
- --abc-exclude Kitchen::Configurable#wrap_shell_code
7
- --style-exclude lib/vendor/**/*.rb
8
- --doc-exclude lib/vendor/**/.rb