kitchen-vagrant 0.17.0.beta.2 → 0.17.0.beta.3

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
  SHA1:
3
- metadata.gz: 94df56b1e97663dab0a57aa0812552ada2bc8900
4
- data.tar.gz: fe7c6c58c021e59c06b3a85e28f3074dd9ac1aee
3
+ metadata.gz: 7ad9a608e086a9198d09b3f11ff112b925c2b1f1
4
+ data.tar.gz: 2c72bf47c1513c8e85ca0d96464702134275917e
5
5
  SHA512:
6
- metadata.gz: 4950c2d33adadb78b39ae87189afa41b67225d642089df69e1186a9ca70175593f6cdfc87713a928921973525ddc5f3cc0a144d0b56e946a129cf669a8c2deac
7
- data.tar.gz: ee13d4bcd95b387f8d3ca2e9572897ca4e5663d22fcafa77cb1f89b7eb33ebfbeab02ec3b046a7b32717c209b1ff11f7651de9fda42b09fb305f2d0df62457a5
6
+ metadata.gz: 9c3e8457a349aa2c1544f3ae4cb423a3f1194f1fa933493b156b964e3eca44349c00c67c76b6e519f838ac271618eca764e243ed759d600165aece74c6fa0a06
7
+ data.tar.gz: 43f71f7c083f9d735f38a3c0c064f69b87f665b299d90315e38aaa2ae411b62636d2b46ac79f750bbcbd57421638c63f3d919ae22d49262a35521f3d363ac8e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.17.0.beta.3 / 2015-03-25
2
+
3
+ * Pull request [#155][]: Use the vagrant-winrm Vagrant plugin to resolve VM IP address. See PR for details. ([@fnichol][])
4
+
5
+
1
6
  ## 0.17.0.beta.2 / 2015-03-25
2
7
 
3
8
  * Relax version constraint on Test Kitchen. ([@fnichol][])
@@ -252,6 +257,7 @@ The initial release.
252
257
  [#148]: https://github.com/test-kitchen/kitchen-vagrant/issues/148
253
258
  [#151]: https://github.com/test-kitchen/kitchen-vagrant/issues/151
254
259
  [#154]: https://github.com/test-kitchen/kitchen-vagrant/issues/154
260
+ [#155]: https://github.com/test-kitchen/kitchen-vagrant/issues/155
255
261
  [@Annih]: https://github.com/Annih
256
262
  [@Igorshp]: https://github.com/Igorshp
257
263
  [@RobertRehberg]: https://github.com/RobertRehberg
data/README.md CHANGED
@@ -29,6 +29,10 @@ consider the [vagrant-wrapper][vagrant_wrapper] gem which helps manage both
29
29
  styles of Vagrant installations
30
30
  ([background details][vagrant_wrapper_background]).
31
31
 
32
+ If you are creating Windows VMs over a WinRM Transport, then the
33
+ [vagrant-winrm][vagrant_winrm] Vagrant plugin must be installed. As a
34
+ consequence, the minimum version of Vagrant required is 1.6 or higher.
35
+
32
36
  ### <a name="dependencies-virtualization"></a> Virtualbox and/or VMware Fusion/Workstation
33
37
 
34
38
  Currently this driver supports VirtualBox and VMware Fusion/Workstation.
@@ -442,6 +446,7 @@ Apache 2.0 (see [LICENSE][license])
442
446
  [vagrant_config_vmware]: http://docs.vagrantup.com/v2/vmware/configuration.html
443
447
  [vagrant_providers]: http://docs.vagrantup.com/v2/providers/index.html
444
448
  [vagrant_versioning]: https://docs.vagrantup.com/v2/boxes/versioning.html
449
+ [vagrant_winrm]: https://github.com/criteo/vagrant-winrm
445
450
  [vagrant_wrapper]: https://github.com/org-binbab/gem-vagrant-wrapper
446
451
  [vagrant_wrapper_background]: https://github.com/org-binbab/gem-vagrant-wrapper#background---aka-the-vagrant-gem-enigma
447
452
  [vmware_plugin]: http://www.vagrantup.com/vmware
@@ -48,10 +48,6 @@ module Kitchen
48
48
 
49
49
  default_config :network, []
50
50
 
51
- default_config :password do |driver|
52
- "vagrant" if driver.winrm_transport?
53
- end
54
-
55
51
  default_config :pre_create_command, nil
56
52
 
57
53
  default_config :provision, false
@@ -64,10 +60,6 @@ module Kitchen
64
60
 
65
61
  default_config :synced_folders, []
66
62
 
67
- default_config :username do |driver|
68
- "vagrant" if driver.winrm_transport?
69
- end
70
-
71
63
  default_config :vagrantfile_erb,
72
64
  File.join(File.dirname(__FILE__), "../../../templates/Vagrantfile.erb")
73
65
  expand_path_for :vagrantfile_erb
@@ -176,6 +168,18 @@ module Kitchen
176
168
  WEBSITE = "http://www.vagrantup.com/downloads.html".freeze
177
169
  MIN_VER = "1.1.0".freeze
178
170
 
171
+ class << self
172
+
173
+ # @return [true,false] whether or not the vagrant-winrm plugin is
174
+ # installed
175
+ # @api private
176
+ attr_accessor :winrm_plugin_passed
177
+
178
+ # @return [String] the version of Vagrant installed on the workstation
179
+ # @api private
180
+ attr_accessor :vagrant_version
181
+ end
182
+
179
183
  # Retuns a list of Vagrant base boxes produced by the Bento project
180
184
  # (https://github.com/chef/bento).
181
185
  #
@@ -254,6 +258,19 @@ module Kitchen
254
258
  end
255
259
  end
256
260
 
261
+ # Loads any required third party Ruby libraries or runs any shell out
262
+ # commands to prepare the plugin. This method will be called in the
263
+ # context of the main thread of execution and so does not necessarily
264
+ # have to be thread safe.
265
+ #
266
+ # @raise [ClientError] if any library loading fails or any of the
267
+ # dependency requirements cannot be satisfied
268
+ # @api private
269
+ def load_needed_dependencies!
270
+ super
271
+ verify_winrm_plugin if winrm_transport?
272
+ end
273
+
257
274
  # Renders the Vagrantfile ERb template.
258
275
  #
259
276
  # @return [String] the contents for a Vagrantfile
@@ -332,19 +349,14 @@ module Kitchen
332
349
  # @param state [Hash] mutable instance state
333
350
  # @api private
334
351
  def update_state(state)
335
- hash = vagrant_ssh_config
352
+ hash = winrm_transport? ? vagrant_config(:winrm) : vagrant_config(:ssh)
336
353
 
337
354
  state[:hostname] = hash["HostName"]
338
-
339
- if winrm_transport?
340
- state[:username] = config[:username]
341
- state[:password] = config[:password]
342
- else
343
- state[:username] = hash["User"]
344
- state[:ssh_key] = hash["IdentityFile"]
345
- state[:port] = hash["Port"]
346
- state[:proxy_command] = hash["ProxyCommand"] if hash["ProxyCommand"]
347
- end
355
+ state[:port] = hash["Port"]
356
+ state[:username] = hash["User"]
357
+ state[:password] = hash["Password"] if hash["Password"]
358
+ state[:ssh_key] = hash["IdentityFile"] if hash["IdentityFile"]
359
+ state[:proxy_command] = hash["ProxyCommand"] if hash["ProxyCommand"]
348
360
  end
349
361
 
350
362
  # @return [String] full local path to the directory containing the
@@ -357,11 +369,13 @@ module Kitchen
357
369
  )
358
370
  end
359
371
 
372
+ # @param type [Symbol] either `:ssh` or `:winrm`
360
373
  # @return [Hash] key/value pairs resulting from parsing a
361
- # `vagrant ssh-config` local command invocation
374
+ # `vagrant ssh-config` or `vagrant winrm-config` local command
375
+ # invocation
362
376
  # @api private
363
- def vagrant_ssh_config
364
- lines = run_silently("vagrant ssh-config").split("\n").map do |line|
377
+ def vagrant_config(type)
378
+ lines = run_silently("vagrant #{type}-config").split("\n").map do |line|
365
379
  tokens = line.strip.partition(" ")
366
380
  [tokens.first, tokens.last.gsub(/"/, "")]
367
381
  end
@@ -372,12 +386,43 @@ module Kitchen
372
386
  # @raise [UserError] if the `vagrant` command can not be found locally
373
387
  # @api private
374
388
  def vagrant_version
375
- @version ||= run_silently("vagrant --version", :cwd => Dir.pwd).
376
- chomp.split(" ").last
389
+ self.class.vagrant_version ||= run_silently(
390
+ "vagrant --version", :cwd => Dir.pwd).chomp.split(" ").last
377
391
  rescue Errno::ENOENT
378
392
  raise UserError, "Vagrant #{MIN_VER} or higher is not installed." \
379
393
  " Please download a package from #{WEBSITE}."
380
394
  end
395
+
396
+ # Verify that the vagrant-winrm plugin is installed and a suitable
397
+ # version of Vagrant is installed
398
+ #
399
+ # @api private
400
+ def verify_winrm_plugin
401
+ if Gem::Version.new(vagrant_version) < Gem::Version.new("1.6")
402
+ raise UserError, "Detected an old version of Vagrant " \
403
+ "(#{vagrant_version}) that cannot support the vagrant-winrm " \
404
+ "Vagrant plugin." \
405
+ " Please upgrade to version 1.6 or higher from #{WEBSITE}."
406
+ end
407
+
408
+ if !winrm_plugin_installed?
409
+ raise UserError, "WinRM Transport requires the vagrant-winrm " \
410
+ "Vagrant plugin to properly communicate with this Vagrant VM. " \
411
+ "Please install this plugin with: " \
412
+ "`vagrant plugin install vagrant-winrm' and try again."
413
+ end
414
+ end
415
+
416
+ # @return [true,false] whether or not the vagrant-winrm plugin is
417
+ # installed
418
+ # @api private
419
+ def winrm_plugin_installed?
420
+ return true if self.class.winrm_plugin_passed
421
+
422
+ self.class.winrm_plugin_passed = run_silently(
423
+ "vagrant plugin list", :cwd => Dir.pwd).
424
+ split("\n").find { |line| line =~ /^vagrant-winrm\s+/ }
425
+ end
381
426
  end
382
427
  end
383
428
  end
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for Vagrant Kitchen driver
24
- VAGRANT_VERSION = "0.17.0.beta.2"
24
+ VAGRANT_VERSION = "0.17.0.beta.3"
25
25
  end
26
26
  end
@@ -63,6 +63,11 @@ describe Kitchen::Driver::Vagrant do
63
63
 
64
64
  before { stub_const("ENV", env) }
65
65
 
66
+ after do
67
+ driver_object.class.send(:winrm_plugin_passed=, nil)
68
+ driver_object.class.send(:vagrant_version=, nil)
69
+ end
70
+
66
71
  describe "configuration" do
67
72
 
68
73
  context "for known bento platform names" do
@@ -328,32 +333,6 @@ describe Kitchen::Driver::Vagrant do
328
333
  expect(driver[:vm_hostname]).to eq("this-is-a--k")
329
334
  end
330
335
  end
331
-
332
- context "for non-WinRM-based transports" do
333
-
334
- before { allow(transport).to receive(:name).and_return("Coolness") }
335
-
336
- it "sets :username to nil by default" do
337
- expect(driver[:username]).to eq(nil)
338
- end
339
-
340
- it "sets :password to nil by default" do
341
- expect(driver[:password]).to eq(nil)
342
- end
343
- end
344
-
345
- context "for WinRM-based transports" do
346
-
347
- before { allow(transport).to receive(:name).and_return("WinRM") }
348
-
349
- it "sets :username to vagrant by default" do
350
- expect(driver[:username]).to eq("vagrant")
351
- end
352
-
353
- it "sets :password to vagrant by default" do
354
- expect(driver[:password]).to eq("vagrant")
355
- end
356
- end
357
336
  end
358
337
 
359
338
  describe "#verify_dependencies" do
@@ -373,7 +352,7 @@ describe Kitchen::Driver::Vagrant do
373
352
  end
374
353
 
375
354
  it "raises a UserError for a missing Vagrant command" do
376
- allow(driver).to receive(:run_command).
355
+ allow(driver_object).to receive(:run_command).
377
356
  with("vagrant --version", any_args).and_raise(Errno::ENOENT)
378
357
 
379
358
  expect { driver.verify_dependencies }.to raise_error(
@@ -382,6 +361,69 @@ describe Kitchen::Driver::Vagrant do
382
361
  end
383
362
  end
384
363
 
364
+ describe "#load_needed_dependencies!" do
365
+
366
+ describe "with winrm transport" do
367
+
368
+ before { allow(transport).to receive(:name).and_return("WinRM") }
369
+
370
+ it "old version of Vagrant raises UserError" do
371
+ with_vagrant("1.5.0")
372
+
373
+ expect { instance }.to raise_error(
374
+ Kitchen::Error, /Please upgrade to version 1.6 or higher/
375
+ )
376
+ end
377
+
378
+ it "modern vagrant without plugin installed raises UserError" do
379
+ with_modern_vagrant
380
+ allow(driver_object).to receive(:run_command).
381
+ with("vagrant plugin list", any_args).and_return("nope (1.2.3)")
382
+
383
+ expect { instance }.to raise_error(
384
+ Kitchen::Error, /vagrant plugin install vagrant-winrm/
385
+ )
386
+ end
387
+
388
+ it "modern vagrant with plugin installed succeeds" do
389
+ with_modern_vagrant
390
+ allow(driver_object).to receive(:run_command).
391
+ with("vagrant plugin list", any_args).
392
+ and_return("vagrant-winrm (1.2.3)")
393
+
394
+ instance
395
+ end
396
+ end
397
+
398
+ describe "without winrm transport" do
399
+
400
+ before { allow(transport).to receive(:name).and_return("Anything") }
401
+
402
+ it "old version of Vagrant succeeds" do
403
+ with_vagrant("1.5.0")
404
+
405
+ instance
406
+ end
407
+
408
+ it "modern vagrant without plugin installed succeeds" do
409
+ with_modern_vagrant
410
+ allow(driver_object).to receive(:run_command).
411
+ with("vagrant plugin list", any_args).and_return("nope (1.2.3)")
412
+
413
+ instance
414
+ end
415
+
416
+ it "modern vagrant with plugin installed succeeds" do
417
+ with_modern_vagrant
418
+ allow(driver_object).to receive(:run_command).
419
+ with("vagrant plugin list", any_args).
420
+ and_return("vagrant-winrm (1.2.3)")
421
+
422
+ instance
423
+ end
424
+ end
425
+ end
426
+
385
427
  describe "#create" do
386
428
 
387
429
  let(:cmd) { driver.create(state) }
@@ -480,35 +522,40 @@ describe Kitchen::Driver::Vagrant do
480
522
 
481
523
  describe "for state" do
482
524
 
483
- let(:output) do
484
- <<-OUTPUT.gsub(/^ {10}/, "")
485
- Host hehe
486
- HostName 192.168.32.64
487
- User vagrant
488
- Port 2022
489
- UserKnownHostsFile /dev/null
490
- StrictHostKeyChecking no
491
- PasswordAuthentication no
492
- IdentityFile /path/to/private_key
493
- IdentitiesOnly yes
494
- LogLevel FATAL
495
- OUTPUT
496
- end
525
+ context "for non-WinRM-based transports" do
497
526
 
498
- before do
499
- allow(driver).to receive(:run_command).
500
- with("vagrant ssh-config", any_args).and_return(output)
501
- end
527
+ let(:output) do
528
+ <<-OUTPUT.gsub(/^ {10}/, "")
529
+ Host hehe
530
+ HostName 192.168.32.64
531
+ User vagrant
532
+ Port 2022
533
+ UserKnownHostsFile /dev/null
534
+ StrictHostKeyChecking no
535
+ PasswordAuthentication no
536
+ IdentityFile /path/to/private_key
537
+ IdentitiesOnly yes
538
+ LogLevel FATAL
539
+ OUTPUT
540
+ end
502
541
 
503
- it "sets :hostname from ssh-config" do
504
- cmd
542
+ before do
543
+ allow(transport).to receive(:name).and_return("Coolness")
544
+ allow(driver).to receive(:run_command).
545
+ with("vagrant ssh-config", any_args).and_return(output)
546
+ end
505
547
 
506
- expect(state).to include(:hostname => "192.168.32.64")
507
- end
548
+ it "sets :hostname from ssh-config" do
549
+ cmd
508
550
 
509
- context "for non-WinRM-based transports" do
551
+ expect(state).to include(:hostname => "192.168.32.64")
552
+ end
553
+
554
+ it "sets :port from ssh-config" do
555
+ cmd
510
556
 
511
- before { allow(transport).to receive(:name).and_return("Coolness") }
557
+ expect(state).to include(:port => "2022")
558
+ end
512
559
 
513
560
  it "sets :username from ssh-config" do
514
561
  cmd
@@ -516,16 +563,23 @@ describe Kitchen::Driver::Vagrant do
516
563
  expect(state).to include(:username => "vagrant")
517
564
  end
518
565
 
519
- it "sets :ssh_key from ssh-config" do
566
+ it "does not set :password by default" do
520
567
  cmd
521
568
 
522
- expect(state).to include(:ssh_key => "/path/to/private_key")
569
+ expect(state.keys).to_not include(:password)
523
570
  end
524
571
 
525
- it "sets :port from ssh-config" do
572
+ it "sets :password if Password is in ssh-config" do
573
+ output.concat(" Password yep\n")
526
574
  cmd
527
575
 
528
- expect(state).to include(:port => "2022")
576
+ expect(state).to include(:password => "yep")
577
+ end
578
+
579
+ it "sets :ssh_key from ssh-config" do
580
+ cmd
581
+
582
+ expect(state).to include(:ssh_key => "/path/to/private_key")
529
583
  end
530
584
 
531
585
  it "does not set :proxy_command by default" do
@@ -544,20 +598,44 @@ describe Kitchen::Driver::Vagrant do
544
598
 
545
599
  context "for WinRM-based transports" do
546
600
 
547
- before { allow(transport).to receive(:name).and_return("WinRM") }
601
+ let(:output) do
602
+ <<-OUTPUT.gsub(/^ {10}/, "")
603
+ Host hehe
604
+ HostName 192.168.32.64
605
+ User vagrant
606
+ Password yep
607
+ Port 9999
608
+ OUTPUT
609
+ end
548
610
 
549
- it "sets :username from config" do
550
- config[:username] = "winuser"
611
+ before do
612
+ allow(transport).to receive(:name).and_return("WinRM")
613
+ allow(driver).to receive(:run_command).
614
+ with("vagrant winrm-config", any_args).and_return(output)
615
+ end
616
+
617
+ it "sets :hostname from winrm-config" do
551
618
  cmd
552
619
 
553
- expect(state).to include(:username => "winuser")
620
+ expect(state).to include(:hostname => "192.168.32.64")
554
621
  end
555
622
 
556
- it "sets :password from config" do
557
- config[:password] = "mysecret"
623
+ it "sets :port from winrm-config" do
558
624
  cmd
559
625
 
560
- expect(state).to include(:password => "mysecret")
626
+ expect(state).to include(:port => "9999")
627
+ end
628
+
629
+ it "sets :username from winrm-config" do
630
+ cmd
631
+
632
+ expect(state).to include(:username => "vagrant")
633
+ end
634
+
635
+ it "sets :password from winrm-config" do
636
+ cmd
637
+
638
+ expect(state).to include(:password => "yep")
561
639
  end
562
640
  end
563
641
  end
@@ -1226,13 +1304,16 @@ describe Kitchen::Driver::Vagrant do
1226
1304
  end
1227
1305
 
1228
1306
  def with_modern_vagrant
1229
- allow(driver).to receive(:run_command).
1230
- with("vagrant --version", any_args).and_return("Vagrant 1.7.2")
1307
+ with_vagrant("1.7.2")
1231
1308
  end
1232
1309
 
1233
1310
  def with_unsupported_vagrant
1234
- allow(driver).to receive(:run_command).
1235
- with("vagrant --version", any_args).and_return("Vagrant 1.0.5")
1311
+ with_vagrant("1.0.5")
1312
+ end
1313
+
1314
+ def with_vagrant(version)
1315
+ allow(driver_object).to receive(:run_command).
1316
+ with("vagrant --version", any_args).and_return("Vagrant #{version}")
1236
1317
  end
1237
1318
 
1238
1319
  def regexify(str, line = :whole_line)
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: 0.17.0.beta.2
4
+ version: 0.17.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fletcher Nichol
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen