kitchen-vagrant 2.1.3 → 2.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dacf84b53e50807b2391c69d3ae7f903965dde4ba59630d8074079ef90df5fc0
4
- data.tar.gz: d1858fb64df4930c100a6866cd92417419d230720f6a335857237ea719bc8aac
3
+ metadata.gz: 4abf5224b64f63f370ce34d71838b1aa1706a70a2a8f7285219388a977eb2bdf
4
+ data.tar.gz: 91b8de7ff382f07694a1df7d7714237e77be14be7b4faa854b509e97dc31fc31
5
5
  SHA512:
6
- metadata.gz: 3030c84bcf25c246c201cb851beded8c826ec25a6d54c4b37f63ae50f3099d58fc03a0cabeda3f761b3e7041bba12db9dadb8556f3a5c8a8b4b4f44801f78292
7
- data.tar.gz: c1e1b21e07c471ff3a8c963b9d98c66797904f69ab40a115520d8bc53facb220b3e8a0ed27d55c0aff2ff4c65b5f4bd2a25fb785cf4c1ed3a2925cd449c98de3
6
+ metadata.gz: 3b42b779d8c9726c89ef893e2ae4289775ae488eb26d2ff52d3a909e3efd97296db770801908a41beb73df703a9e065dae8836b82ce0fab7fc4dc9eb968ba02d
7
+ data.tar.gz: 4656b6f370e4c2233ad1c0fb8ab933599829599348fab18461f8ab487df9e180b040267e3fcd01124453b7c223f84792e276b7f8140ecf4e8c03377d62e79eb7
@@ -80,6 +80,8 @@ module Kitchen
80
80
 
81
81
  default_config :synced_folders, []
82
82
 
83
+ default_config :env, []
84
+
83
85
  default_config :use_cached_chef_client, false
84
86
 
85
87
  default_config :vagrant_binary, "vagrant"
@@ -116,6 +118,7 @@ module Kitchen
116
118
  def create(state)
117
119
  create_vagrantfile
118
120
  run_pre_create_command
121
+ check_box_outdated
119
122
  run_box_auto_update
120
123
  run_box_auto_prune
121
124
  run_vagrant_up
@@ -335,6 +338,25 @@ module Kitchen
335
338
  .gsub("{{vagrant_root}}", vagrant_root)
336
339
  end
337
340
 
341
+ # Formats synced folder options for use in the Vagrantfile.
342
+ # Accepts either a Hash (converts to Ruby hash syntax) or a String (returns as-is).
343
+ # Supports SMB options like smb_username, smb_password, etc.
344
+ #
345
+ # @param options [Hash, String, nil] synced folder options
346
+ # @return [String] formatted options string for Vagrantfile
347
+ # @api private
348
+ def format_synced_folder_options(options)
349
+ return "nil" if options.nil?
350
+ return options if options.is_a?(String)
351
+
352
+ # Convert Hash to Ruby hash literal syntax
353
+ if options.is_a?(Hash)
354
+ options.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")
355
+ else
356
+ options.to_s
357
+ end
358
+ end
359
+
338
360
  # Replaces an `%{instance_name}` tokens in the synced folder items.
339
361
  #
340
362
  # @api private
@@ -347,7 +369,7 @@ module Kitchen
347
369
  config[:kitchen_root]
348
370
  ),
349
371
  destination.gsub("%{instance_name}", instance.name),
350
- options || "nil",
372
+ format_synced_folder_options(options),
351
373
  ]
352
374
  end
353
375
  add_extra_synced_folders!
@@ -474,6 +496,81 @@ module Kitchen
474
496
  end
475
497
  # rubocop:enable Metrics/CyclomaticComplexity
476
498
 
499
+ # Check if a newer version of the vagrant box is available and warn the user
500
+ #
501
+ # @api private
502
+ def check_box_outdated
503
+ # Skip if box_auto_update is enabled (they'll get the update anyway)
504
+ return if config[:box_auto_update]
505
+
506
+ cmd = "#{config[:vagrant_binary]} box outdated --box #{config[:box]}"
507
+ cmd += " --provider #{config[:provider]}" if config[:provider]
508
+
509
+ begin
510
+ output = run_silently(cmd)
511
+ warn_if_outdated(output)
512
+ rescue Kitchen::ShellOut::ShellCommandFailed => e
513
+ # If the box isn't installed yet or there's an error checking, silently continue
514
+ # This can happen on first run before the box is downloaded
515
+ debug("Unable to check if box is outdated: #{e.message}")
516
+ end
517
+ end
518
+
519
+ # Parse vagrant box outdated output and warn if a new version is available
520
+ #
521
+ # @param output [String] output from vagrant box outdated command
522
+ # @api private
523
+ def warn_if_outdated(output)
524
+ return unless box_is_outdated?(output)
525
+
526
+ current_version = extract_current_version(output)
527
+ latest_version = extract_latest_version(output)
528
+
529
+ warning_msg = "A new version of the '#{config[:box]}' box is available!"
530
+ if current_version && latest_version
531
+ warning_msg += " Current: #{current_version}, Latest: #{latest_version}."
532
+ end
533
+ warning_msg += " Run `vagrant box update --box #{config[:box]}` to update."
534
+
535
+ warn(warning_msg)
536
+ end
537
+
538
+ # Check if the vagrant box outdated output indicates an outdated box
539
+ #
540
+ # @param output [String] output from vagrant box outdated command
541
+ # @return [Boolean] true if box is outdated
542
+ # @api private
543
+ def box_is_outdated?(output)
544
+ # Check for various output patterns indicating an outdated box
545
+ # Use include? instead of complex regexes to avoid ReDoS vulnerabilities
546
+ output_downcase = output.downcase
547
+ output_downcase.include?("is outdated") ||
548
+ output_downcase.include?("newer version") && output_downcase.include?("available") ||
549
+ output_downcase.include?("newer version of the box")
550
+ end
551
+
552
+ # Extract current version from vagrant box outdated output
553
+ #
554
+ # @param output [String] output from vagrant box outdated command
555
+ # @return [String, nil] current version or nil if not found
556
+ # @api private
557
+ def extract_current_version(output)
558
+ match = output.match(/Current:\s+v?(\S+)/i) ||
559
+ output.match(/currently have version\s+'?v?([^'.\s]+)/i)
560
+ match ? match[1] : nil
561
+ end
562
+
563
+ # Extract latest version from vagrant box outdated output
564
+ #
565
+ # @param output [String] output from vagrant box outdated command
566
+ # @return [String, nil] latest version or nil if not found
567
+ # @api private
568
+ def extract_latest_version(output)
569
+ match = output.match(/Latest:\s+v?(\S+)/i) ||
570
+ output.match(/latest is version\s+'?v?([^'.\s]+)/i)
571
+ match ? match[1] : nil
572
+ end
573
+
477
574
  # Tell vagrant to update vagrant box to latest version
478
575
  def run_box_auto_update
479
576
  if config[:box_auto_update]
@@ -559,6 +656,38 @@ module Kitchen
559
656
  @vagrant_root
560
657
  end
561
658
 
659
+ # @return [true,false] whether or not we're running in WSL
660
+ # @api private
661
+ def wsl?
662
+ # Check for WSL via environment variables
663
+ return true if ENV["WSL_DISTRO_NAME"]
664
+ return true if ENV["VAGRANT_WSL_ENABLE_WINDOWS_ACCESS"]
665
+
666
+ # Check for WSL via /proc/version
667
+ if File.exist?("/proc/version")
668
+ version_content = File.read("/proc/version")
669
+ return true if version_content.match?(/microsoft|wsl/i)
670
+ end
671
+
672
+ false
673
+ rescue
674
+ false
675
+ end
676
+
677
+ # Converts a Windows path to a WSL path
678
+ # @param path [String] Windows path (e.g., "C:/Users/...")
679
+ # @return [String] WSL path (e.g., "/mnt/c/users/...")
680
+ # @api private
681
+ def windows_to_wsl_path(path)
682
+ # Only convert if it looks like a Windows path
683
+ if path.match?(%r{^[A-Za-z]:/})
684
+ # Convert C:/path to /mnt/c/path
685
+ path.gsub(/^([A-Za-z]):/, '/mnt/\1').downcase
686
+ else
687
+ path
688
+ end
689
+ end
690
+
562
691
  # @param type [Symbol] either `:ssh` or `:winrm`
563
692
  # @return [Hash] key/value pairs resulting from parsing a
564
693
  # `vagrant ssh-config` or `vagrant winrm-config` local command
@@ -568,7 +697,10 @@ module Kitchen
568
697
  lines = run_silently("#{config[:vagrant_binary]} #{type}-config")
569
698
  .split("\n").map do |line|
570
699
  tokens = line.strip.partition(" ")
571
- [tokens.first, tokens.last.delete('"')]
700
+ value = tokens.last.delete('"')
701
+ # Convert Windows paths to WSL paths when running in WSL
702
+ value = windows_to_wsl_path(value) if wsl? && tokens.first == "IdentityFile"
703
+ [tokens.first, value]
572
704
  end
573
705
  Hash[lines]
574
706
  end
@@ -20,6 +20,6 @@ module Kitchen
20
20
  module Driver
21
21
 
22
22
  # Version string for Vagrant Kitchen driver
23
- VAGRANT_VERSION = "2.1.3".freeze
23
+ VAGRANT_VERSION = "2.2.1".freeze
24
24
  end
25
25
  end
@@ -253,4 +253,14 @@ Vagrant.configure("2") do |c|
253
253
  <% end %>
254
254
  <% end %>
255
255
  end
256
+
257
+ <% if config[:env] && !config[:env].empty? %>
258
+ # Set environment variables
259
+ <% config[:env].each do |env_var| %>
260
+ c.vm.provision "shell", inline: <<-SHELL
261
+ echo 'export <%= env_var.gsub("'", "'\\\\''") %>' >> /etc/profile.d/kitchen.sh
262
+ SHELL
263
+ <% end %>
264
+ c.vm.provision "shell", inline: "chmod +x /etc/profile.d/kitchen.sh", run: "once"
265
+ <% end %>
256
266
  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: 2.1.3
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-29 00:00:00.000000000 Z
11
+ date: 2026-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.4'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.4'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4'
32
+ version: '5'
33
33
  description: Kitchen::Driver::Vagrant - A HashiCorp Vagrant Driver for Test Kitchen.
34
34
  email:
35
35
  - fnichol@nichol.ca