kitchen-vagrant 1.5.0 → 1.7.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
  SHA256:
3
- metadata.gz: 839cf2c46b31628eba46d5e379eb40d42215f68667320df8af7571cd4b544aab
4
- data.tar.gz: b1d80326940aeb6e119f8b0f4249db289032c05be5958dce7f26d9c1fa6a59ae
3
+ metadata.gz: 963b45a50eb74ce9d7bb16de1f63231ab44096c1459652be556bd7bc4c2d38d1
4
+ data.tar.gz: 5c0297d2879a29dd777b3976d6cda4167463fb9233dca540d848c5d741282145
5
5
  SHA512:
6
- metadata.gz: ed91d2530854f088194421cb6d79d3062fd93f2b494563150a9ab467b8c1f7b9ff1a20cd00ef1563d1cb10e66dea5ddee8bd08461a3b9d68cf4f310cb7d63a9e
7
- data.tar.gz: 562d85090622a80e6ee471ec39b92ae42575fb632bdbed24b25a7262e821f5d9e5253df1eae571d8a618602f08ff99d39d3a3216b14cfd507a51fdf582a9e361
6
+ metadata.gz: a84c39b2411b0f6f80ad9c5c6dbeeab0eabae479c57c4cec4e7ce9f40f86466a9d7051176da592783dbf94b236bb049831ad61cabd7fc68201dd75baf5b75314
7
+ data.tar.gz: 4658e11b0222d2fcee0c69739f5e7eae88a7a64f54f43009c142572f7e7e35d922aa4630ab3e26b007d37fdc7bf80fb77b9f0aa77e8cbda0c8cb64f7ffb75d65
@@ -76,6 +76,7 @@ module Kitchen
76
76
  sh.run_command
77
77
  debug("Local Command END #{Util.duration(sh.execution_time)}")
78
78
  raise "Failed: #{sh.stderr}" if sh.error?
79
+
79
80
  stdout = sanitize_stdout(sh.stdout)
80
81
  JSON.parse(stdout) if stdout.length > 2
81
82
  end
@@ -91,12 +92,13 @@ module Kitchen
91
92
  default_switch_object["Name"].empty?
92
93
  raise "Failed to find a default VM Switch."
93
94
  end
95
+
94
96
  default_switch_object["Name"]
95
97
  end
96
98
 
97
99
  def hyperv_default_switch_ps
98
100
  <<-VMSWITCH
99
- Get-DefaultVMSwitch #{ENV['KITCHEN_HYPERV_SWITCH']} | ConvertTo-Json
101
+ Get-DefaultVMSwitch #{ENV["KITCHEN_HYPERV_SWITCH"]} | ConvertTo-Json
100
102
  VMSWITCH
101
103
  end
102
104
 
@@ -104,6 +106,7 @@ module Kitchen
104
106
 
105
107
  def ruby_array_to_ps_array(list)
106
108
  return "@()" if list.nil? || list.empty?
109
+
107
110
  list.to_s.tr("[]", "()").prepend("@")
108
111
  end
109
112
  end
@@ -21,8 +21,8 @@ require "fileutils"
21
21
  require "rubygems/version"
22
22
 
23
23
  require "kitchen"
24
- require "kitchen/driver/vagrant_version"
25
- require "kitchen/driver/helpers"
24
+ require_relative "vagrant_version"
25
+ require_relative "helpers"
26
26
 
27
27
  module Kitchen
28
28
 
@@ -40,16 +40,20 @@ module Kitchen
40
40
 
41
41
  plugin_version Kitchen::Driver::VAGRANT_VERSION
42
42
 
43
- default_config(:box) { |driver| driver.default_box }
43
+ default_config(:box, &:default_box)
44
44
  required_config :box
45
45
 
46
46
  default_config :box_check_update, nil
47
47
 
48
+ default_config :box_auto_update, nil
49
+
50
+ default_config :box_auto_prune, nil
51
+
48
52
  default_config :box_download_insecure, nil
49
53
 
50
54
  default_config :box_download_ca_cert, nil
51
55
 
52
- default_config(:box_url) { |driver| driver.default_box_url }
56
+ default_config(:box_url, &:default_box_url)
53
57
 
54
58
  default_config :box_version, nil
55
59
 
@@ -109,6 +113,8 @@ module Kitchen
109
113
  def create(state)
110
114
  create_vagrantfile
111
115
  run_pre_create_command
116
+ run_box_auto_update
117
+ run_box_auto_prune
112
118
  run_vagrant_up
113
119
  update_state(state)
114
120
  instance.transport.connection(state).wait_until_ready
@@ -149,7 +155,8 @@ module Kitchen
149
155
  if state[:hostname].nil?
150
156
  raise UserError, "Vagrant instance not created!"
151
157
  end
152
- if not (config[:ssh] && config[:ssh][:insert_key] == false)
158
+
159
+ unless config[:ssh] && config[:ssh][:insert_key] == false
153
160
  m = "Disable vagrant ssh key replacement to preserve the default key!"
154
161
  warn(m)
155
162
  end
@@ -171,6 +178,8 @@ module Kitchen
171
178
  def finalize_config!(instance)
172
179
  super
173
180
  finalize_vm_hostname!
181
+ finalize_box_auto_update!
182
+ finalize_box_auto_prune!
174
183
  finalize_pre_create_command!
175
184
  finalize_synced_folders!
176
185
  finalize_ca_cert!
@@ -247,7 +256,8 @@ module Kitchen
247
256
  # @api private
248
257
  def safe_share?(box)
249
258
  return false if config[:provider] =~ /(hyperv|libvirt)/
250
- box =~ /^bento\/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-/
259
+
260
+ box =~ %r{^bento/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-}
251
261
  end
252
262
 
253
263
  # Return true if we found the criteria to enable the cache_directory
@@ -255,6 +265,7 @@ module Kitchen
255
265
  def enable_cache?
256
266
  return false unless config[:cache_directory]
257
267
  return true if safe_share?(config[:box])
268
+
258
269
  # Otherwise
259
270
  false
260
271
  end
@@ -291,10 +302,25 @@ module Kitchen
291
302
  def finalize_ca_cert!
292
303
  unless config[:box_download_ca_cert].nil?
293
304
  config[:box_download_ca_cert] = File.expand_path(
294
- config[:box_download_ca_cert], config[:kitchen_root])
305
+ config[:box_download_ca_cert], config[:kitchen_root]
306
+ )
295
307
  end
296
308
  end
297
309
 
310
+ # Create vagrant command to update box to the latest version
311
+ def finalize_box_auto_update!
312
+ return if config[:box_auto_update].nil?
313
+
314
+ config[:box_auto_update] = "vagrant box update #{'--insecure ' if config[:box_download_insecure]}--box #{config[:box]}"
315
+ end
316
+
317
+ # Create vagrant command to remove older versions of the box
318
+ def finalize_box_auto_prune!
319
+ return if config[:box_auto_prune].nil?
320
+
321
+ config[:box_auto_prune] = "vagrant box prune --name #{config[:box]}"
322
+ end
323
+
298
324
  # Replaces any `{{vagrant_root}}` tokens in the pre create command.
299
325
  #
300
326
  # @api private
@@ -344,8 +370,8 @@ module Kitchen
344
370
  def finalize_vm_hostname!
345
371
  string = config[:vm_hostname]
346
372
 
347
- if windows_os? && string.is_a?(String) && string.size >= 12
348
- config[:vm_hostname] = "#{string[0...10]}-#{string[-1]}"
373
+ if windows_os? && string.is_a?(String) && string.size > 15
374
+ config[:vm_hostname] = "#{string[0...12]}-#{string[-1]}"
349
375
  end
350
376
  end
351
377
 
@@ -382,10 +408,11 @@ module Kitchen
382
408
  # @api private
383
409
  def render_template
384
410
  template = File.expand_path(
385
- config[:vagrantfile_erb], config[:kitchen_root])
411
+ config[:vagrantfile_erb], config[:kitchen_root]
412
+ )
386
413
 
387
414
  if File.exist?(template)
388
- ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, "")
415
+ ERB.new(IO.read(template)).result(binding).gsub(/^\s*$\n/, "")
389
416
  else
390
417
  raise ActionFailed, "Could not find Vagrantfile template #{template}"
391
418
  end
@@ -432,8 +459,8 @@ module Kitchen
432
459
  env = merged[:environment]
433
460
  %w{BUNDLE_BIN_PATH BUNDLE_GEMFILE GEM_HOME GEM_PATH GEM_ROOT RUBYLIB
434
461
  RUBYOPT _ORIGINAL_GEM_PATH}.each do |var|
435
- env[var] = nil
436
- end
462
+ env[var] = nil
463
+ end
437
464
 
438
465
  # Altering the path seems to break vagrant. When the :environment
439
466
  # is passed to a windows process with a PATH, Vagrant's batch installer
@@ -456,6 +483,20 @@ module Kitchen
456
483
  end
457
484
  # rubocop:enable Metrics/CyclomaticComplexity
458
485
 
486
+ # Tell vagrant to update vagrant box to latest version
487
+ def run_box_auto_update
488
+ if config[:box_auto_update]
489
+ run(config[:box_auto_update])
490
+ end
491
+ end
492
+
493
+ # Tell vagrant to remove older vagrant boxes
494
+ def run_box_auto_prune
495
+ if config[:box_auto_prune]
496
+ run(config[:box_auto_prune])
497
+ end
498
+ end
499
+
459
500
  # Runs a local command before `vagrant up` has been called.
460
501
  #
461
502
  # @api private
@@ -529,9 +570,9 @@ module Kitchen
529
570
  def vagrant_config(type)
530
571
  lines = run_silently("#{config[:vagrant_binary]} #{type}-config")
531
572
  .split("\n").map do |line|
532
- tokens = line.strip.partition(" ")
533
- [tokens.first, tokens.last.delete('"')]
534
- end
573
+ tokens = line.strip.partition(" ")
574
+ [tokens.first, tokens.last.delete('"')]
575
+ end
535
576
  Hash[lines]
536
577
  end
537
578
 
@@ -540,7 +581,8 @@ module Kitchen
540
581
  # @api private
541
582
  def vagrant_version
542
583
  self.class.vagrant_version ||= run_silently(
543
- "#{config[:vagrant_binary]} --version", cwd: Dir.pwd)
584
+ "#{config[:vagrant_binary]} --version", cwd: Dir.pwd
585
+ )
544
586
  .chomp.split(" ").last
545
587
  rescue Errno::ENOENT
546
588
  raise UserError, "Vagrant #{MIN_VER} or higher is not installed." \
@@ -583,7 +625,8 @@ module Kitchen
583
625
  return true if self.class.winrm_plugin_passed
584
626
 
585
627
  self.class.winrm_plugin_passed = run_silently(
586
- "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd)
628
+ "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd
629
+ )
587
630
  .split("\n").find { |line| line =~ /vagrant-winrm\s+/ }
588
631
  end
589
632
  end
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for Vagrant Kitchen driver
24
- VAGRANT_VERSION = "1.5.0".freeze
24
+ VAGRANT_VERSION = "1.7.0".freeze
25
25
  end
26
26
  end
@@ -92,7 +92,7 @@ Vagrant.configure("2") do |c|
92
92
  c.vm.provider :<%= config[:provider] %> do |p|
93
93
  <% case config[:provider]
94
94
  when "virtualbox" %>
95
- p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
95
+ p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>-<%= SecureRandom.uuid %>"
96
96
  <% end %>
97
97
 
98
98
  <% case config[:provider]
@@ -108,7 +108,7 @@ Vagrant.configure("2") do |c|
108
108
  p.linked_clone = <%= config[:linked_clone] %>
109
109
  <% end
110
110
  when "hyperv" %>
111
- p.vmname = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
111
+ p.vmname = "<%="kitchen-#{File.basename(config[:kitchen_root])}-#{instance.name}-#{SecureRandom.uuid}"[0..99].chomp('-') %>"
112
112
  <% if config[:linked_clone] == true || config[:linked_clone] == false %>
113
113
  p.linked_clone = <%= config[:linked_clone] %>
114
114
  <% end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: countloc
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +117,7 @@ homepage: https://github.com/test-kitchen/kitchen-vagrant/
111
117
  licenses:
112
118
  - Apache-2.0
113
119
  metadata: {}
114
- post_install_message:
120
+ post_install_message:
115
121
  rdoc_options: []
116
122
  require_paths:
117
123
  - lib
@@ -119,15 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
125
  requirements:
120
126
  - - ">="
121
127
  - !ruby/object:Gem::Version
122
- version: '0'
128
+ version: '2.3'
123
129
  required_rubygems_version: !ruby/object:Gem::Requirement
124
130
  requirements:
125
131
  - - ">="
126
132
  - !ruby/object:Gem::Version
127
133
  version: '0'
128
134
  requirements: []
129
- rubygems_version: 3.0.3
130
- signing_key:
135
+ rubygems_version: 3.1.2
136
+ signing_key:
131
137
  specification_version: 4
132
138
  summary: Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen.
133
139
  test_files: []