vagrant 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.md +48 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +2 -2
  6. data/Rakefile +22 -0
  7. data/bin/.gitignore +0 -0
  8. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  9. data/lib/vagrant/util/template_renderer.rb +2 -2
  10. data/lib/vagrant/version.rb +1 -1
  11. data/templates/Vagrantfile.erb +1 -1
  12. data/templates/nfs/exports.erb +4 -2
  13. data/test/test_helper.rb +128 -0
  14. data/test/vagrant/action/box/destroy_test.rb +30 -0
  15. data/test/vagrant/action/box/download_test.rb +141 -0
  16. data/test/vagrant/action/box/package_test.rb +25 -0
  17. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  18. data/test/vagrant/action/box/verify_test.rb +39 -0
  19. data/test/vagrant/action/builder_test.rb +218 -0
  20. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  21. data/test/vagrant/action/env/set_test.rb +24 -0
  22. data/test/vagrant/action/environment_test.rb +45 -0
  23. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  24. data/test/vagrant/action/general/package_test.rb +254 -0
  25. data/test/vagrant/action/vm/boot_test.rb +83 -0
  26. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  27. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  28. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  29. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  30. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  31. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  32. data/test/vagrant/action/vm/customize_test.rb +29 -0
  33. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  34. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  35. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  36. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  37. data/test/vagrant/action/vm/export_test.rb +135 -0
  38. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  39. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  40. data/test/vagrant/action/vm/halt_test.rb +69 -0
  41. data/test/vagrant/action/vm/import_test.rb +50 -0
  42. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  43. data/test/vagrant/action/vm/network_test.rb +246 -0
  44. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  45. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  46. data/test/vagrant/action/vm/package_test.rb +25 -0
  47. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  48. data/test/vagrant/action/vm/persist_test.rb +50 -0
  49. data/test/vagrant/action/vm/provision_test.rb +134 -0
  50. data/test/vagrant/action/vm/resume_test.rb +35 -0
  51. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  52. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  53. data/test/vagrant/action_test.rb +111 -0
  54. data/test/vagrant/active_list_test.rb +173 -0
  55. data/test/vagrant/box_test.rb +166 -0
  56. data/test/vagrant/command_test.rb +53 -0
  57. data/test/vagrant/commands/base_test.rb +139 -0
  58. data/test/vagrant/commands/box/add_test.rb +34 -0
  59. data/test/vagrant/commands/box/list_test.rb +32 -0
  60. data/test/vagrant/commands/box/remove_test.rb +41 -0
  61. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  62. data/test/vagrant/commands/destroy_test.rb +44 -0
  63. data/test/vagrant/commands/halt_test.rb +50 -0
  64. data/test/vagrant/commands/init_test.rb +71 -0
  65. data/test/vagrant/commands/package_test.rb +97 -0
  66. data/test/vagrant/commands/provision_test.rb +60 -0
  67. data/test/vagrant/commands/reload_test.rb +47 -0
  68. data/test/vagrant/commands/resume_test.rb +44 -0
  69. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  70. data/test/vagrant/commands/ssh_test.rb +129 -0
  71. data/test/vagrant/commands/status_test.rb +40 -0
  72. data/test/vagrant/commands/suspend_test.rb +44 -0
  73. data/test/vagrant/commands/up_test.rb +49 -0
  74. data/test/vagrant/config_test.rb +307 -0
  75. data/test/vagrant/downloaders/base_test.rb +28 -0
  76. data/test/vagrant/downloaders/file_test.rb +33 -0
  77. data/test/vagrant/downloaders/http_test.rb +70 -0
  78. data/test/vagrant/environment_test.rb +770 -0
  79. data/test/vagrant/hosts/base_test.rb +46 -0
  80. data/test/vagrant/hosts/bsd_test.rb +56 -0
  81. data/test/vagrant/hosts/linux_test.rb +56 -0
  82. data/test/vagrant/provisioners/base_test.rb +36 -0
  83. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  84. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  85. data/test/vagrant/provisioners/chef_test.rb +178 -0
  86. data/test/vagrant/ssh_session_test.rb +46 -0
  87. data/test/vagrant/ssh_test.rb +317 -0
  88. data/test/vagrant/systems/linux_test.rb +179 -0
  89. data/test/vagrant/util/busy_test.rb +106 -0
  90. data/test/vagrant/util/plain_logger_test.rb +17 -0
  91. data/test/vagrant/util/platform_test.rb +18 -0
  92. data/test/vagrant/util/resource_logger_test.rb +145 -0
  93. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  94. data/test/vagrant/util/template_renderer_test.rb +145 -0
  95. data/test/vagrant/util/translator_test.rb +61 -0
  96. data/test/vagrant/util_test.rb +27 -0
  97. data/test/vagrant/vm_test.rb +228 -0
  98. data/vagrant.gemspec +34 -0
  99. metadata +158 -43
@@ -0,0 +1,72 @@
1
+ require "test_helper"
2
+
3
+ class ClearForwardedPortsVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearForwardedPorts
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @vm.stubs(:name).returns("foo")
10
+ @env["vm"] = @vm
11
+
12
+ @instance = @klass.new(@app, @env)
13
+ end
14
+
15
+ context "calling" do
16
+ should "call the proper methods and continue chain" do
17
+ seq = sequence('seq')
18
+ @instance.expects(:clear).in_sequence(seq)
19
+ @app.expects(:call).with(@env).in_sequence(seq)
20
+ @instance.call(@env)
21
+ end
22
+ end
23
+
24
+ context "clearing forwarded ports" do
25
+ setup do
26
+ @instance.stubs(:used_ports).returns([:a])
27
+ @instance.stubs(:clear_ports)
28
+ end
29
+
30
+ should "call destroy on all forwarded ports" do
31
+ @instance.expects(:clear_ports).once
32
+ @vm.expects(:reload!)
33
+ @instance.clear
34
+ end
35
+
36
+ should "do nothing if there are no forwarded ports" do
37
+ @instance.stubs(:used_ports).returns([])
38
+ @vm.expects(:reload!).never
39
+ @instance.clear
40
+ end
41
+ end
42
+
43
+ context "clearing ports" do
44
+ def mock_fp
45
+ fp = mock("fp")
46
+ fp.expects(:destroy).once
47
+ fp
48
+ end
49
+
50
+ setup do
51
+ VirtualBox.stubs(:version).returns("3.2.8")
52
+ @adapters = []
53
+ @internal_vm = mock("internal_vm")
54
+ @internal_vm.stubs(:network_adapters).returns(@adapters)
55
+ @vm.stubs(:vm).returns(@internal_vm)
56
+ end
57
+
58
+ def mock_adapter
59
+ na = mock("adapter")
60
+ engine = mock("engine")
61
+ engine.stubs(:forwarded_ports).returns([mock_fp])
62
+ na.stubs(:nat_driver).returns(engine)
63
+ na
64
+ end
65
+
66
+ should "destroy each forwarded port" do
67
+ @adapters << mock_adapter
68
+ @adapters << mock_adapter
69
+ @instance.clear_ports
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+
3
+ class ClearNFSExportsActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearNFSExports
6
+ @app, @env = mock_action_data
7
+ @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env))
8
+
9
+ @instance = @klass.new(@app, @env)
10
+ end
11
+
12
+ should "include the NFS helpers module" do
13
+ assert @klass.included_modules.include?(Vagrant::Action::VM::NFSHelpers)
14
+ end
15
+
16
+ should "clear NFS exports then continue chain" do
17
+ seq = sequence("seq")
18
+ @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
19
+ @app.expects(:call).with(@env).in_sequence(seq)
20
+ @instance.call(@env)
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require "test_helper"
2
+
3
+ class ClearSharedFoldersVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::ClearSharedFolders
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ should "call the proper methods in sequence" do
19
+ seq = sequence("seq")
20
+ @instance.expects(:clear_shared_folders).once.in_sequence(seq)
21
+ @app.expects(:call).with(@env).once
22
+ @instance.call(@env)
23
+ end
24
+ end
25
+
26
+ context "clearing shared folders" do
27
+ setup do
28
+ @shared_folder = mock("shared_folder")
29
+ @shared_folders = [@shared_folder]
30
+ @internal_vm.stubs(:shared_folders).returns(@shared_folders)
31
+ end
32
+
33
+ should "call destroy on each shared folder then reload" do
34
+ destroy_seq = sequence("destroy")
35
+ @shared_folders.each do |sf|
36
+ sf.expects(:destroy).once.in_sequence(destroy_seq)
37
+ end
38
+
39
+ @vm.expects(:reload!).once.in_sequence(destroy_seq)
40
+ @instance.clear_shared_folders
41
+ end
42
+
43
+ should "do nothing if no shared folders existed" do
44
+ @shared_folders.clear
45
+ @vm.expects(:reload!).never
46
+ @instance.clear_shared_folders
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class CustomizeVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Customize
6
+ @app, @env = mock_action_data
7
+ @instance = @klass.new(@app, @env)
8
+
9
+ @vm = mock("vm")
10
+ @env["vm"] = @vm
11
+
12
+ @internal_vm = mock("internal")
13
+ @vm.stubs(:vm).returns(@internal_vm)
14
+ end
15
+
16
+ should "not run anything if no customize blocks exist" do
17
+ @internal_vm.expects(:save).never
18
+ @app.expects(:call).with(@env).once
19
+ @instance.call(@env)
20
+ end
21
+
22
+ should "run the VM customization procs then save the VM" do
23
+ @env.env.config.vm.customize { |vm| }
24
+ @env.env.config.vm.expects(:run_procs!).with(@internal_vm)
25
+ @internal_vm.expects(:save).once
26
+ @app.expects(:call).with(@env).once
27
+ @instance.call(@env)
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class DestroyVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Destroy
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "destroying the VM" do
18
+ should "destroy VM and attached images" do
19
+ @internal_vm.expects(:destroy).with(:destroy_medium => :delete).once
20
+ @env["vm"].expects(:vm=).with(nil).once
21
+ @env.env.expects(:update_dotfile).once
22
+ @app.expects(:call).with(@env).once
23
+ @instance.call(@env)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class DestroyUnusedNetworkInterfacesVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DestroyUnusedNetworkInterfaces
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @network_adapters = []
20
+ @internal_vm.stubs(:network_adapters).returns(@network_adapters)
21
+ end
22
+
23
+ def stub_interface(length=5)
24
+ interface = mock("interface")
25
+ adapter = mock("adapter")
26
+ adapter.stubs(:host_interface_object).returns(interface)
27
+ interface.stubs(:attached_vms).returns(Array.new(length))
28
+
29
+ @network_adapters << adapter
30
+ interface
31
+ end
32
+
33
+ should "destroy only the unused network interfaces" do
34
+ stub_interface(5)
35
+ stub_interface(7)
36
+ results = [stub_interface(1), stub_interface(1)]
37
+
38
+ results.each do |result|
39
+ result.expects(:destroy).once
40
+ end
41
+
42
+ @app.expects(:call).with(@env).once
43
+ @instance.call(@env)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ class DisableNetworksVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DisableNetworks
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env.env.stubs(:vm).returns(@vm)
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+ @internal_vm.stubs(:network_adapters).returns([])
14
+
15
+ @instance = @klass.new(@app, @env)
16
+ end
17
+
18
+ def mock_adapter(type)
19
+ adapter = mock("adapter")
20
+ adapter.stubs(:attachment_type).returns(type)
21
+
22
+ if type == :host_only
23
+ adapter.expects(:enabled=).with(false)
24
+ adapter.expects(:save)
25
+ end
26
+
27
+ @internal_vm.network_adapters << adapter
28
+ end
29
+
30
+ should "remove all network adapters and continue chain" do
31
+ mock_adapter(:bridged)
32
+ mock_adapter(:host_only)
33
+ mock_adapter(:host_only)
34
+
35
+ @app.expects(:call).with(@env).once
36
+
37
+ @instance.call(@env)
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class DiscardStateVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::DiscardState
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @internal_vm.stubs(:saved?).returns(false)
20
+ end
21
+
22
+ should "do nothing if not saved and continue chain" do
23
+ @internal_vm.expects(:saved?).returns(false)
24
+ @app.expects(:call).with(@env).once
25
+ @instance.call(@env)
26
+ end
27
+
28
+ should "discard state and continue chain" do
29
+ seq = sequence("sequence")
30
+ @internal_vm.expects(:saved?).returns(true).in_sequence(seq)
31
+ @internal_vm.expects(:discard_state).in_sequence(seq)
32
+ @app.expects(:call).with(@env).once.in_sequence(seq)
33
+ @instance.call(@env)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,135 @@
1
+ require "test_helper"
2
+
3
+ class ExportVMActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Action::VM::Export
6
+ @app, @env = mock_action_data
7
+
8
+ @vm = mock("vm")
9
+ @env["vm"] = @vm
10
+
11
+ @internal_vm = mock("internal")
12
+ @vm.stubs(:vm).returns(@internal_vm)
13
+
14
+ @instance = @klass.new(@app, @env)
15
+ end
16
+
17
+ context "calling" do
18
+ setup do
19
+ @internal_vm.stubs(:powered_off?).returns(true)
20
+ end
21
+
22
+ should "call the proper methods then continue chain" do
23
+ seq = sequence("seq")
24
+ @instance.expects(:setup_temp_dir).in_sequence(seq)
25
+ @instance.expects(:export).in_sequence(seq)
26
+ @app.expects(:call).with(@env).in_sequence(seq)
27
+ @instance.expects(:cleanup).in_sequence(seq)
28
+
29
+ @instance.call(@env)
30
+ end
31
+
32
+ should "halt the chain if not powered off" do
33
+ @internal_vm.stubs(:powered_off?).returns(false)
34
+ @instance.expects(:setup_temp_dir).never
35
+ @instance.expects(:export).never
36
+ @app.expects(:call).with(@env).never
37
+ @instance.expects(:cleanup).never
38
+
39
+ @instance.call(@env)
40
+ assert @env.error?
41
+ assert_equal :vm_power_off_to_package, @env.error.first
42
+ end
43
+
44
+ should "halt the chain if env error" do
45
+ @internal_vm.stubs(:powered_off?).returns(true)
46
+ @instance.expects(:setup_temp_dir).never
47
+ @instance.expects(:export).never
48
+ @app.expects(:call).with(@env).never
49
+ @instance.expects(:cleanup).never
50
+
51
+ @env.error!(:interrupt)
52
+ @instance.call(@env)
53
+ end
54
+
55
+ should "halt the chain if env error when call is reached" do
56
+ @internal_vm.stubs(:powered_off?).returns(true)
57
+ @instance.expects(:setup_temp_dir).once
58
+ @instance.expects(:export).once.with() do
59
+ @env.error!(:interrupt)
60
+ true
61
+ end
62
+
63
+ @app.expects(:call).with(@env).never
64
+ @instance.expects(:cleanup).once
65
+
66
+ @instance.call(@env)
67
+ end
68
+ end
69
+
70
+ context "cleaning up" do
71
+ setup do
72
+ @temp_dir = "foo"
73
+ @instance.stubs(:temp_dir).returns(@temp_dir)
74
+ File.stubs(:exist?).returns(true)
75
+ end
76
+
77
+ should "delete the temporary file if it exists" do
78
+ File.expects(:unlink).with(@temp_dir).once
79
+ @instance.cleanup
80
+ end
81
+
82
+ should "not delete anything if it doesn't exist" do
83
+ File.stubs(:exist?).returns(false)
84
+ File.expects(:unlink).never
85
+ @instance.cleanup
86
+ end
87
+ end
88
+
89
+ context "setting up the temporary directory" do
90
+ setup do
91
+ @time_now = Time.now.to_i.to_s
92
+ Time.stubs(:now).returns(@time_now)
93
+
94
+ @tmp_path = "foo"
95
+ @env.env.stubs(:tmp_path).returns(@tmp_path)
96
+
97
+ @temp_dir = File.join(@env.env.tmp_path, @time_now)
98
+ FileUtils.stubs(:mkpath)
99
+ end
100
+
101
+ should "create the temporary directory using the current time" do
102
+ FileUtils.expects(:mkpath).with(@temp_dir).once
103
+ @instance.setup_temp_dir
104
+ end
105
+
106
+ should "set to the environment" do
107
+ @instance.setup_temp_dir
108
+ assert_equal @temp_dir, @env["export.temp_dir"]
109
+ assert_equal @temp_dir, @instance.temp_dir
110
+ end
111
+ end
112
+
113
+ context "exporting" do
114
+ setup do
115
+ @ovf_path = mock("ovf_path")
116
+ @instance.stubs(:ovf_path).returns(@ovf_path)
117
+ end
118
+
119
+ should "call export on the runner with the ovf path" do
120
+ @internal_vm.expects(:export).with(@ovf_path).once
121
+ @instance.export
122
+ end
123
+ end
124
+
125
+ context "path to OVF file" do
126
+ setup do
127
+ @temp_dir = "foo"
128
+ @env["export.temp_dir"] = @temp_dir
129
+ end
130
+
131
+ should "be the temporary directory joined with the OVF filename" do
132
+ assert_equal File.join(@temp_dir, @env.env.config.vm.box_ovf), @instance.ovf_path
133
+ end
134
+ end
135
+ end