kitchen-vagrant 2.3.0 → 2.4.0

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: cf0fbd431e7e5a52a144f6ce2e79edea1d2783c74c0ef212c3674a12e147683e
4
- data.tar.gz: fdde8621c74520cf97a5367bfa3098aedc814d8037ad564ef8cada2056237807
3
+ metadata.gz: eb41469b88a11508fe064bd6b04389da5cdb617ef027e5a633f47a1c88478be0
4
+ data.tar.gz: d4e9d511d64c4bff5a21121f2e2e9bcad8cd453efe7981de9a2c87597bb5f758
5
5
  SHA512:
6
- metadata.gz: 1877e0240f40b4d4880ba3032f9801a984252051a88ba2a8fc0bd5af9d314ac5aa701b1116e9df747614b6ca3adacbbf898be6fdfe1d3d104f41f2321d2aceaa
7
- data.tar.gz: eef20bc7471c539f0b11cbb31d80337bf7037905e7a1fecc9f7104d9b9335f57bd5d5437e376bb19942d5e80dcffb5193ba5ddab7836d8c3cb315aced9149361
6
+ metadata.gz: 8332c2ee9115ff0c69684420767948b5ad620051b4e99b5ac763e4b08636fe81caa4678ba9ccbbb5e662f6495438499c1fdafd9e7c127738c4219980d61f09f2
7
+ data.tar.gz: 163808d47b023456f260985e2180e7de2f46d0b0201729d828bb328d2f16d89c381b4eb7b43191e42a8d4645c14b2e39d6e630409e0847dd01c0e4497235af73
@@ -18,6 +18,13 @@
18
18
  require "erb" unless defined?(Erb)
19
19
  require "fileutils" unless defined?(FileUtils)
20
20
  require "rubygems/version"
21
+ # :nocov:
22
+ # Chefstyle's Chef/Ruby/UnlessDefinedRequire wants this guard, but the guard's
23
+ # other branch is unreachable: kitchen has already loaded "time" by here. The
24
+ # repo enforces a branch-coverage floor, so exclude the line rather than let
25
+ # the two rules fight.
26
+ require "time" unless defined?(Time.now.iso8601)
27
+ # :nocov:
21
28
 
22
29
  require "kitchen"
23
30
  require_relative "vagrant_version"
@@ -31,6 +38,10 @@ module Kitchen
31
38
  #
32
39
  # @author Fletcher Nichol <fnichol@nichol.ca>
33
40
  class Vagrant < Kitchen::Driver::Base
41
+ # Machine states Vagrant reports for a box that is up and reachable.
42
+ #
43
+ # @return [Array<String>]
44
+ LIVE_STATES = %w{running}.freeze
34
45
 
35
46
  include ShellOut
36
47
  include Kitchen::Driver::HypervHelpers
@@ -188,6 +199,27 @@ module Kitchen
188
199
  destroy(state)
189
200
  end
190
201
 
202
+ # Reports what Vagrant currently thinks of the machine.
203
+ #
204
+ # @param state [Hash] instance state naming the machine
205
+ # @return [Hash] a Test Kitchen status hash, or the base implementation's
206
+ # answer when there is nothing to ask Vagrant about
207
+ def status(state)
208
+ return super unless state[:hostname]
209
+
210
+ machine_state = vagrant_machine_state
211
+ return super unless machine_state
212
+
213
+ {
214
+ live: LIVE_STATES.include?(machine_state),
215
+ state: machine_state,
216
+ source: "driver",
217
+ resource_id: instance.name,
218
+ message: "Vagrant reports the machine as #{machine_state}",
219
+ checked_at: Time.now.utc.iso8601,
220
+ }
221
+ end
222
+
191
223
  # A lifecycle method that should be invoked when the object is about
192
224
  # ready to be used. A reference to an Instance is required as
193
225
  # configuration dependant data may be access through an Instance. This
@@ -225,6 +257,23 @@ module Kitchen
225
257
  end
226
258
  end
227
259
 
260
+ # Checks the host-side things a Vagrant run needs, reporting rather than
261
+ # raising so `kitchen doctor` can list every problem at once.
262
+ #
263
+ # {#verify_dependencies} already raises on an old or absent Vagrant, but
264
+ # it only runs on the actions that need it. This repeats the version rule
265
+ # as a report and adds the file and folder checks that nothing validates
266
+ # today.
267
+ #
268
+ # @param state [Hash] mutable instance and driver state
269
+ # @return [Boolean] true when a problem was reported
270
+ def doctor(state) # rubocop:disable Lint/UnusedMethodArgument
271
+ problems = vagrant_problems + template_problems + synced_folder_problems
272
+
273
+ problems.each { |problem| warn(problem) }
274
+ !problems.empty?
275
+ end
276
+
228
277
  # @return [TrueClass,FalseClass] whether or not the transport's name
229
278
  # implies a WinRM-based transport
230
279
  # @api private
@@ -503,6 +552,90 @@ module Kitchen
503
552
  end
504
553
  end
505
554
 
555
+ # Asks Vagrant for the machine state.
556
+ #
557
+ # `--machine-readable` is parsed rather than the human output because the
558
+ # human wording is localised and reworded between Vagrant releases, while
559
+ # the machine format is a stable comma-separated
560
+ # `timestamp,target,type,data` and the `state` row carries the raw value
561
+ # (`running`, `poweroff`, `not_created`, ...).
562
+ #
563
+ # @return [String, nil] the machine state, or nil when there is no
564
+ # Vagrantfile to ask about, the command fails, or no state row is found
565
+ # @api private
566
+ def vagrant_machine_state
567
+ return nil unless File.exist?(File.join(vagrant_root, "Vagrantfile"))
568
+
569
+ output = run("#{config[:vagrant_binary]} status --machine-readable")
570
+ parse_machine_state(output)
571
+ rescue ::StandardError => e
572
+ debug("Could not read the Vagrant machine state: #{e.message}")
573
+ nil
574
+ end
575
+
576
+ # Pulls the `state` row out of Vagrant's machine-readable output.
577
+ #
578
+ # @param output [String] the raw `--machine-readable` output
579
+ # @return [String, nil] the state value, or nil when no state row is present
580
+ # @api private
581
+ def parse_machine_state(output)
582
+ output.to_s.each_line do |line|
583
+ fields = line.strip.split(",")
584
+ return fields[3] if fields[2] == "state" && fields[3]
585
+ end
586
+ nil
587
+ end
588
+
589
+ # Vagrant itself: present, and new enough.
590
+ #
591
+ # @return [Array<String>] a problem, or an empty array
592
+ def vagrant_problems
593
+ found = vagrant_version
594
+ if Gem::Version.new(found) < Gem::Version.new(MIN_VER.dup)
595
+ return ["Vagrant #{found} is older than the #{MIN_VER} this driver " \
596
+ "needs. Upgrade from #{WEBSITE}."]
597
+ end
598
+
599
+ info("vagrant #{found} found at #{config[:vagrant_binary]}")
600
+ []
601
+ rescue UserError => e
602
+ [e.message]
603
+ rescue ::StandardError => e
604
+ ["Could not run #{config[:vagrant_binary]} --version: #{e.message}"]
605
+ end
606
+
607
+ # The Vagrantfile template, and any extra Vagrantfiles spliced into it.
608
+ # Both are `expand_path_for` settings, so a wrong relative path becomes
609
+ # an absolute path that simply is not there.
610
+ #
611
+ # @return [Array<String>] one problem per missing file
612
+ def template_problems
613
+ problems = []
614
+
615
+ unless File.exist?(config[:vagrantfile_erb].to_s)
616
+ problems << "vagrantfile_erb #{config[:vagrantfile_erb]} does not exist."
617
+ end
618
+
619
+ Array(config[:vagrantfiles]).each do |path|
620
+ problems << "vagrantfiles entry #{path} does not exist." unless File.exist?(path.to_s)
621
+ end
622
+
623
+ problems
624
+ end
625
+
626
+ # Host paths in `synced_folders`. Vagrant creates a missing host path
627
+ # silently for some providers and fails for others, so an absent source
628
+ # is worth naming either way.
629
+ #
630
+ # @return [Array<String>] one problem per missing host path
631
+ def synced_folder_problems
632
+ Array(config[:synced_folders]).filter_map do |source, destination, _options|
633
+ next if source.nil? || File.exist?(source.to_s)
634
+
635
+ "synced_folders source #{source} (mounted at #{destination}) does not exist."
636
+ end
637
+ end
638
+
506
639
  # Convenience method to run a command locally.
507
640
  #
508
641
  # @param cmd [String] command to run locally
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for Vagrant Kitchen driver
24
- VAGRANT_VERSION = "2.3.0".freeze
24
+ VAGRANT_VERSION = "2.4.0".freeze
25
25
  end
26
26
  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.3.0
4
+ version: 2.4.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: 2026-08-22 00:00:00.000000000 Z
11
+ date: 2026-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.4'
33
+ version: '3.0'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '5'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '1.4'
43
+ version: '3.0'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5'