kitchen-vagrant 1.5.1 → 1.7.1

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: 7d71669b8b76e71c9a612e96ea3860d72e73c16bb3cbf9080c72dce0b083e9d3
4
- data.tar.gz: 1289fb40f6391d780efda4415c8ade2271e6c090aa88012534ccadd764a97d6f
3
+ metadata.gz: 6eea2b13ae661430bd3bb6d2f860790e92073f3e4c73953c7158524b6883fe78
4
+ data.tar.gz: 71492f51d07e28547642bd2cbbf0412e592b89101883a4b707f4758e7127ea47
5
5
  SHA512:
6
- metadata.gz: 625a7c1a111d11d423eaedb1711f4fffb0dc8cad2eb428e239484df14c39cc65781ac67bde09f00129fb7d17bd94aed939e7ed8eb6d13c80ff2176625ee1cc85
7
- data.tar.gz: bb8679a9b716e0eb071d01d4f0cf350d495d893c418137cac32043d310be8ca0b598e95179587bd8fd29d1b939d6391a345ee428540a5da9d04eb43473ff7f91
6
+ metadata.gz: 50493706587595344c62f3c19b44884c9a890a1f4dfad1e3566ab76f01dae6df0f8acf17a39bbc3b9b6925d3dda1f6a6a9984c6e64b95de8c999f7ec5c7f8735
7
+ data.tar.gz: bdbb2f2e15af0418a526ba5386affe68bf96dccc376d01c4bed55112648ae67e4a5c8356d0e4bc0cf49b5165fa0313c4d8a0c784cb16d42a650a2e5669889f22
@@ -15,9 +15,9 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require "mixlib/shellout"
19
- require "fileutils"
20
- require "json"
18
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
19
+ require "fileutils" unless defined?(FileUtils)
20
+ require "json" unless defined?(JSON)
21
21
 
22
22
  module Kitchen
23
23
  module Driver
@@ -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
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  #
3
2
  # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
3
  #
@@ -16,13 +15,13 @@
16
15
  # See the License for the specific language governing permissions and
17
16
  # limitations under the License.
18
17
 
19
- require "erb"
20
- require "fileutils"
18
+ require "erb" unless defined?(Erb)
19
+ require "fileutils" unless defined?(FileUtils)
21
20
  require "rubygems/version"
22
21
 
23
22
  require "kitchen"
24
- require "kitchen/driver/vagrant_version"
25
- require "kitchen/driver/helpers"
23
+ require_relative "vagrant_version"
24
+ require_relative "helpers"
26
25
 
27
26
  module Kitchen
28
27
 
@@ -40,16 +39,20 @@ module Kitchen
40
39
 
41
40
  plugin_version Kitchen::Driver::VAGRANT_VERSION
42
41
 
43
- default_config(:box) { |driver| driver.default_box }
42
+ default_config(:box, &:default_box)
44
43
  required_config :box
45
44
 
46
45
  default_config :box_check_update, nil
47
46
 
47
+ default_config :box_auto_update, nil
48
+
49
+ default_config :box_auto_prune, nil
50
+
48
51
  default_config :box_download_insecure, nil
49
52
 
50
53
  default_config :box_download_ca_cert, nil
51
54
 
52
- default_config(:box_url) { |driver| driver.default_box_url }
55
+ default_config(:box_url, &:default_box_url)
53
56
 
54
57
  default_config :box_version, nil
55
58
 
@@ -109,6 +112,8 @@ module Kitchen
109
112
  def create(state)
110
113
  create_vagrantfile
111
114
  run_pre_create_command
115
+ run_box_auto_update
116
+ run_box_auto_prune
112
117
  run_vagrant_up
113
118
  update_state(state)
114
119
  instance.transport.connection(state).wait_until_ready
@@ -149,7 +154,8 @@ module Kitchen
149
154
  if state[:hostname].nil?
150
155
  raise UserError, "Vagrant instance not created!"
151
156
  end
152
- if not (config[:ssh] && config[:ssh][:insert_key] == false)
157
+
158
+ unless config[:ssh] && config[:ssh][:insert_key] == false
153
159
  m = "Disable vagrant ssh key replacement to preserve the default key!"
154
160
  warn(m)
155
161
  end
@@ -171,6 +177,8 @@ module Kitchen
171
177
  def finalize_config!(instance)
172
178
  super
173
179
  finalize_vm_hostname!
180
+ finalize_box_auto_update!
181
+ finalize_box_auto_prune!
174
182
  finalize_pre_create_command!
175
183
  finalize_synced_folders!
176
184
  finalize_ca_cert!
@@ -246,8 +254,9 @@ module Kitchen
246
254
  # shared folders
247
255
  # @api private
248
256
  def safe_share?(box)
249
- return false if config[:provider] =~ /(hyperv|libvirt)/
250
- box =~ /^bento\/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-/
257
+ return false if /(hyperv|libvirt)/.match?(config[:provider])
258
+
259
+ box =~ %r{^bento/(centos|debian|fedora|opensuse|ubuntu|oracle|amazonlinux)-}
251
260
  end
252
261
 
253
262
  # Return true if we found the criteria to enable the cache_directory
@@ -255,6 +264,7 @@ module Kitchen
255
264
  def enable_cache?
256
265
  return false unless config[:cache_directory]
257
266
  return true if safe_share?(config[:box])
267
+
258
268
  # Otherwise
259
269
  false
260
270
  end
@@ -291,10 +301,25 @@ module Kitchen
291
301
  def finalize_ca_cert!
292
302
  unless config[:box_download_ca_cert].nil?
293
303
  config[:box_download_ca_cert] = File.expand_path(
294
- config[:box_download_ca_cert], config[:kitchen_root])
304
+ config[:box_download_ca_cert], config[:kitchen_root]
305
+ )
295
306
  end
296
307
  end
297
308
 
309
+ # Create vagrant command to update box to the latest version
310
+ def finalize_box_auto_update!
311
+ return if config[:box_auto_update].nil?
312
+
313
+ config[:box_auto_update] = "vagrant box update #{"--insecure " if config[:box_download_insecure]}--box #{config[:box]}"
314
+ end
315
+
316
+ # Create vagrant command to remove older versions of the box
317
+ def finalize_box_auto_prune!
318
+ return if config[:box_auto_prune].nil?
319
+
320
+ config[:box_auto_prune] = "vagrant box prune --keep-active-boxes --name #{config[:box]}"
321
+ end
322
+
298
323
  # Replaces any `{{vagrant_root}}` tokens in the pre create command.
299
324
  #
300
325
  # @api private
@@ -344,8 +369,8 @@ module Kitchen
344
369
  def finalize_vm_hostname!
345
370
  string = config[:vm_hostname]
346
371
 
347
- if windows_os? && string.is_a?(String) && string.size >= 12
348
- config[:vm_hostname] = "#{string[0...10]}-#{string[-1]}"
372
+ if windows_os? && string.is_a?(String) && string.size > 15
373
+ config[:vm_hostname] = "#{string[0...12]}-#{string[-1]}"
349
374
  end
350
375
  end
351
376
 
@@ -382,10 +407,11 @@ module Kitchen
382
407
  # @api private
383
408
  def render_template
384
409
  template = File.expand_path(
385
- config[:vagrantfile_erb], config[:kitchen_root])
410
+ config[:vagrantfile_erb], config[:kitchen_root]
411
+ )
386
412
 
387
413
  if File.exist?(template)
388
- ERB.new(IO.read(template)).result(binding).gsub(%r{^\s*$\n}, "")
414
+ ERB.new(IO.read(template)).result(binding).gsub(/^\s*$\n/, "")
389
415
  else
390
416
  raise ActionFailed, "Could not find Vagrantfile template #{template}"
391
417
  end
@@ -432,8 +458,8 @@ module Kitchen
432
458
  env = merged[:environment]
433
459
  %w{BUNDLE_BIN_PATH BUNDLE_GEMFILE GEM_HOME GEM_PATH GEM_ROOT RUBYLIB
434
460
  RUBYOPT _ORIGINAL_GEM_PATH}.each do |var|
435
- env[var] = nil
436
- end
461
+ env[var] = nil
462
+ end
437
463
 
438
464
  # Altering the path seems to break vagrant. When the :environment
439
465
  # is passed to a windows process with a PATH, Vagrant's batch installer
@@ -456,6 +482,20 @@ module Kitchen
456
482
  end
457
483
  # rubocop:enable Metrics/CyclomaticComplexity
458
484
 
485
+ # Tell vagrant to update vagrant box to latest version
486
+ def run_box_auto_update
487
+ if config[:box_auto_update]
488
+ run(config[:box_auto_update])
489
+ end
490
+ end
491
+
492
+ # Tell vagrant to remove older vagrant boxes
493
+ def run_box_auto_prune
494
+ if config[:box_auto_prune]
495
+ run(config[:box_auto_prune])
496
+ end
497
+ end
498
+
459
499
  # Runs a local command before `vagrant up` has been called.
460
500
  #
461
501
  # @api private
@@ -529,9 +569,9 @@ module Kitchen
529
569
  def vagrant_config(type)
530
570
  lines = run_silently("#{config[:vagrant_binary]} #{type}-config")
531
571
  .split("\n").map do |line|
532
- tokens = line.strip.partition(" ")
533
- [tokens.first, tokens.last.delete('"')]
534
- end
572
+ tokens = line.strip.partition(" ")
573
+ [tokens.first, tokens.last.delete('"')]
574
+ end
535
575
  Hash[lines]
536
576
  end
537
577
 
@@ -540,7 +580,8 @@ module Kitchen
540
580
  # @api private
541
581
  def vagrant_version
542
582
  self.class.vagrant_version ||= run_silently(
543
- "#{config[:vagrant_binary]} --version", cwd: Dir.pwd)
583
+ "#{config[:vagrant_binary]} --version", cwd: Dir.pwd
584
+ )
544
585
  .chomp.split(" ").last
545
586
  rescue Errno::ENOENT
546
587
  raise UserError, "Vagrant #{MIN_VER} or higher is not installed." \
@@ -583,7 +624,8 @@ module Kitchen
583
624
  return true if self.class.winrm_plugin_passed
584
625
 
585
626
  self.class.winrm_plugin_passed = run_silently(
586
- "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd)
627
+ "#{config[:vagrant_binary]} plugin list", cwd: Dir.pwd
628
+ )
587
629
  .split("\n").find { |line| line =~ /vagrant-winrm\s+/ }
588
630
  end
589
631
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  #
3
2
  # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
3
  #
@@ -21,6 +20,6 @@ module Kitchen
21
20
  module Driver
22
21
 
23
22
  # Version string for Vagrant Kitchen driver
24
- VAGRANT_VERSION = "1.5.1".freeze
23
+ VAGRANT_VERSION = "1.7.1".freeze
25
24
  end
26
25
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.7.1
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-19 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -117,7 +117,7 @@ homepage: https://github.com/test-kitchen/kitchen-vagrant/
117
117
  licenses:
118
118
  - Apache-2.0
119
119
  metadata: {}
120
- post_install_message:
120
+ post_install_message:
121
121
  rdoc_options: []
122
122
  require_paths:
123
123
  - lib
@@ -125,15 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - ">="
127
127
  - !ruby/object:Gem::Version
128
- version: '0'
128
+ version: '2.3'
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.0.3
136
- signing_key:
135
+ rubygems_version: 3.1.4
136
+ signing_key:
137
137
  specification_version: 4
138
138
  summary: Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen.
139
139
  test_files: []