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,179 @@
1
+ require "test_helper"
2
+
3
+ class LinuxSystemTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Systems::Linux
6
+ @ssh = mock("ssh")
7
+ @mock_env = mock_environment
8
+ @vm = mock("vm")
9
+ @vm.stubs(:env).returns(@mock_env)
10
+ @instance = @klass.new(@vm)
11
+ end
12
+
13
+ context "halting" do
14
+ setup do
15
+ @ssh_session = mock("ssh_session")
16
+ @ssh.stubs(:execute).yields(@ssh_session)
17
+ @vm.stubs(:ssh).returns(@ssh)
18
+
19
+ @real_vm = mock("real_vm")
20
+ @real_vm.stubs(:state).returns(:powered_off)
21
+ @vm.stubs(:vm).returns(@real_vm)
22
+ end
23
+
24
+ should "execute halt via SSH" do
25
+ @ssh_session.expects(:exec!).with("sudo halt").once
26
+ @instance.halt
27
+ end
28
+ end
29
+
30
+ context "mounting shared folders" do
31
+ setup do
32
+ @name = "foo"
33
+ @guestpath = "/bar"
34
+ end
35
+
36
+ should "create the dir, mount the folder, then set permissions" do
37
+ mount_seq = sequence("mount_seq")
38
+ @ssh.expects(:exec!).with("sudo mkdir -p #{@guestpath}").in_sequence(mount_seq)
39
+ @instance.expects(:mount_folder).with(@ssh, @name, @guestpath).in_sequence(mount_seq)
40
+ @ssh.expects(:exec!).with("sudo chown #{@vm.env.config.ssh.username} #{@guestpath}").in_sequence(mount_seq)
41
+
42
+ @instance.mount_shared_folder(@ssh, @name, @guestpath)
43
+ end
44
+ end
45
+
46
+ context "preparing unison" do
47
+ setup do
48
+ @ssh.stubs(:exec!)
49
+ @ssh.stubs(:upload!)
50
+ @vm.stubs(:ssh).returns(@ssh)
51
+ end
52
+
53
+ should "upload the script" do
54
+ @vm.ssh.expects(:upload!).with do |script, path|
55
+ assert_equal @mock_env.config.unison.script, path
56
+ true
57
+ end
58
+
59
+ @instance.prepare_unison(@ssh)
60
+ end
61
+
62
+ should "make the script executable" do
63
+ @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.unison.script}").once
64
+ @instance.prepare_unison(@ssh)
65
+ end
66
+
67
+ should "remove old crontab entry file" do
68
+ @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.unison.crontab_entry_file}", :error_check => false).once
69
+ @instance.prepare_unison(@ssh)
70
+ end
71
+ end
72
+
73
+ context "creating unison entry" do
74
+ setup do
75
+ @ssh.stubs(:exec!)
76
+ @options = {
77
+ :guestpath => "foo",
78
+ :original => { :guestpath => "bar!" }
79
+ }
80
+ end
81
+
82
+ should "render the crontab entry with proper variables" do
83
+ variables = {
84
+ :from => @options[:guestpath],
85
+ :to => @options[:original][:guestpath],
86
+ :options => @mock_env.config.unison.options,
87
+ :script => @mock_env.config.unison.script,
88
+ :log_file => @mock_env.config.unison.log_file % "bar-"
89
+ }
90
+ Vagrant::Util::TemplateRenderer.expects(:render).with('/unison/crontab_entry',
91
+ variables).once
92
+ @instance.create_unison(@ssh, @options)
93
+ end
94
+
95
+ should "remove the .unison directory" do
96
+ @ssh.expects(:exec!).with("sudo rm -rf ~/.unison")
97
+ @instance.create_unison(@ssh, @options)
98
+ end
99
+
100
+ should "remove the original guestpath" do
101
+ @ssh.expects(:exec!).with("sudo rm -rf #{@options[:original][:guestpath]}")
102
+ @instance.create_unison(@ssh, @options)
103
+ end
104
+
105
+ should "enable the crontab file" do
106
+ @ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}")
107
+ @instance.create_unison(@ssh, @options)
108
+ end
109
+ end
110
+
111
+ #-------------------------------------------------------------------
112
+ # "Private" methods tests
113
+ #-------------------------------------------------------------------
114
+ context "mounting the main folder" do
115
+ setup do
116
+ @name = "foo"
117
+ @guestpath = "bar"
118
+ @sleeptime = 0
119
+ @limit = 10
120
+
121
+ @success_return = false
122
+ end
123
+
124
+ def mount_folder
125
+ @instance.mount_folder(@ssh, @name, @guestpath, @sleeptime)
126
+ end
127
+
128
+ should "execute the proper mount command" do
129
+ @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@vm.env.config.ssh.username},gid=#{@vm.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
130
+ mount_folder
131
+ end
132
+
133
+ should "test type of text and text string to detect error" do
134
+ data = mock("data")
135
+ data.expects(:[]=).with(:result, !@success_return)
136
+
137
+ @ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
138
+ mount_folder
139
+ end
140
+
141
+ should "test type of text and test string to detect success" do
142
+ data = mock("data")
143
+ data.expects(:[]=).with(:result, @success_return)
144
+
145
+ @ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
146
+ mount_folder
147
+ end
148
+
149
+ should "raise an ActionException if the command fails constantly" do
150
+ @ssh.expects(:exec!).times(@limit).returns(!@success_return)
151
+
152
+ assert_raises(Vagrant::Action::ActionException) {
153
+ mount_folder
154
+ }
155
+ end
156
+
157
+ should "not raise any exception if the command succeeded" do
158
+ @ssh.expects(:exec!).once.returns(@success_return)
159
+
160
+ assert_nothing_raised {
161
+ mount_folder
162
+ }
163
+ end
164
+
165
+ should "add uid AND gid to mount" do
166
+ uid = "foo"
167
+ gid = "bar"
168
+ env = mock_environment do |config|
169
+ config.vm.shared_folder_uid = uid
170
+ config.vm.shared_folder_gid = gid
171
+ end
172
+
173
+ @vm.stubs(:env).returns(env)
174
+
175
+ @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
176
+ mount_folder
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,106 @@
1
+ require "test_helper"
2
+
3
+ class BusyUtilTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Util::Busy
6
+ end
7
+
8
+ context "registering" do
9
+ setup do
10
+ @callback = lambda { puts "FOO" }
11
+ Signal.stubs(:trap)
12
+ end
13
+
14
+ teardown do
15
+ @klass.registered.clear
16
+ end
17
+
18
+ should "trap the signal on the first registration" do
19
+ Signal.expects(:trap).with("INT").once
20
+ @klass.register(@callback)
21
+ @klass.register(lambda { puts "BAR" })
22
+ end
23
+
24
+ should "not register the same callback multiple times" do
25
+ @klass.register(@callback)
26
+ @klass.register(@callback)
27
+ @klass.register(@callback)
28
+ assert_equal 1, @klass.registered.length
29
+ assert_equal @callback, @klass.registered.first
30
+ end
31
+ end
32
+
33
+ context "unregistering" do
34
+ setup do
35
+ Signal.stubs(:trap)
36
+
37
+ @callback = lambda { puts "FOO" }
38
+ end
39
+
40
+ teardown do
41
+ @klass.registered.clear
42
+ end
43
+
44
+ should "remove the callback and set the trap to DEFAULT when removing final" do
45
+ @klass.register(@callback)
46
+ Signal.expects(:trap).with("INT", "DEFAULT").once
47
+ @klass.unregister(@callback)
48
+ assert @klass.registered.empty?
49
+ end
50
+
51
+ should "not reset signal trap if not final callback" do
52
+ @klass.register(@callback)
53
+ @klass.register(lambda { puts "BAR" })
54
+ Signal.expects(:trap).never
55
+ @klass.unregister(@callback)
56
+ end
57
+ end
58
+
59
+ context "marking for busy" do
60
+ setup do
61
+ @callback = lambda { "foo" }
62
+ end
63
+
64
+ should "register, call the block, then unregister" do
65
+ waiter = mock("waiting")
66
+ proc = lambda { waiter.ping! }
67
+
68
+ seq = sequence('seq')
69
+ @klass.expects(:register).with(@callback).in_sequence(seq)
70
+ waiter.expects(:ping!).in_sequence(seq)
71
+ @klass.expects(:unregister).with(@callback).in_sequence(seq)
72
+
73
+ @klass.busy(@callback, &proc)
74
+ end
75
+
76
+ should "unregister callback even if block raises exception" do
77
+ waiter = mock("waiting")
78
+ proc = lambda { waiter.ping! }
79
+
80
+ seq = sequence('seq')
81
+ @klass.expects(:register).with(@callback).in_sequence(seq)
82
+ waiter.expects(:ping!).raises(Exception.new("uh oh!")).in_sequence(seq)
83
+ @klass.expects(:unregister).with(@callback).in_sequence(seq)
84
+
85
+ assert_raises(Exception) { @klass.busy(@callback, &proc) }
86
+ end
87
+ end
88
+
89
+ context "firing callbacks" do
90
+ setup do
91
+ Signal.stubs(:trap)
92
+ end
93
+
94
+ teardown do
95
+ @klass.registered.clear
96
+ end
97
+
98
+ should "just call the registered callbacks" do
99
+ waiting = mock("waiting")
100
+ waiting.expects(:ping!).once
101
+
102
+ @klass.register(lambda { waiting.ping! })
103
+ @klass.fire_callbacks
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,17 @@
1
+ require "test_helper"
2
+
3
+ class PlainLoggerUtilTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Util::PlainLogger
6
+ @instance = @klass.new(nil)
7
+ end
8
+
9
+ should "inherit from the standard logger" do
10
+ assert @instance.is_a?(::Logger)
11
+ end
12
+
13
+ should "just add a newline to the message" do
14
+ msg = "foo bar baz"
15
+ assert_equal "#{msg}\n", @instance.format_message("1", "2", "3", msg)
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class PlatformTest < Test::Unit::TestCase
4
+ context "file options" do
5
+ should "include add binary bit to options on windows platform" do
6
+ # This constant is not defined on non-windows platforms, so define it here
7
+ File::BINARY = 4096 unless defined?(File::BINARY)
8
+
9
+ Mario::Platform.expects(:windows?).returns(true)
10
+ assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY
11
+ end
12
+
13
+ should "not include binary bit on other platforms" do
14
+ Mario::Platform.expects(:windows?).returns(false)
15
+ assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,145 @@
1
+ require "test_helper"
2
+
3
+ class ResourceLoggerUtilTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::Util::ResourceLogger
6
+ end
7
+
8
+ context "singleton logger" do
9
+ setup do
10
+ @klass.reset_singleton_logger!
11
+
12
+ @result = mock("result")
13
+ end
14
+
15
+ should "return a nil plain logger if no environment is given" do
16
+ Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
17
+ assert_equal @result, @klass.singleton_logger
18
+ end
19
+
20
+ should "return a nil plain logger if the config is not loaded" do
21
+ env = mock_environment
22
+ env.config.stubs(:loaded?).returns(false)
23
+
24
+ Vagrant::Util::PlainLogger.expects(:new).with(nil).returns(@result)
25
+ assert_equal @result, @klass.singleton_logger(env)
26
+ end
27
+
28
+ should "return a logger with the specified output if environment is ready" do
29
+ output = mock("output")
30
+ env = mock_environment
31
+ env.config.vagrant.log_output = output
32
+
33
+ Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
34
+ assert_equal @result, @klass.singleton_logger(env)
35
+ end
36
+
37
+ should "only load the logger once" do
38
+ output = mock("output")
39
+ env = mock_environment
40
+ env.config.vagrant.log_output = output
41
+
42
+ Vagrant::Util::PlainLogger.expects(:new).with(output).returns(@result)
43
+ assert_equal @result, @klass.singleton_logger(env)
44
+ assert_equal @result, @klass.singleton_logger(env)
45
+ assert_equal @result, @klass.singleton_logger(env)
46
+ end
47
+ end
48
+
49
+ context "initialization" do
50
+ should "setup the logger and attributes" do
51
+ env = mock_environment
52
+ resource = mock("resource")
53
+ result = mock("result")
54
+
55
+ @klass.expects(:singleton_logger).with(env).returns(result)
56
+ instance = @klass.new(resource, env)
57
+ assert_equal resource, instance.resource
58
+ assert_equal env, instance.env
59
+ assert_equal result, instance.logger
60
+ end
61
+ end
62
+
63
+ context "with an instance" do
64
+ setup do
65
+ @resource = "foo"
66
+ @env = mock_environment
67
+ @logger = mock("logger")
68
+
69
+ @klass.stubs(:singleton_logger).returns(@logger)
70
+ @instance = @klass.new(@resource, @env)
71
+ end
72
+
73
+ context "logging methods" do
74
+ setup do
75
+ @instance.stubs(:flush_progress)
76
+ @instance.stubs(:cl_reset).returns("")
77
+ end
78
+
79
+ [:debug, :info, :error, :fatal].each do |method|
80
+ should "log with the proper format on #{method}" do
81
+ message = "bar"
82
+ @logger.expects(method).with("[#{@resource}] #{message}").once
83
+ @instance.send(method, message)
84
+ end
85
+ end
86
+ end
87
+
88
+ context "reporting progress" do
89
+ setup do
90
+ @instance.stubs(:flush_progress)
91
+ end
92
+
93
+ should "flush progress" do
94
+ @instance.expects(:flush_progress).once
95
+ @instance.report_progress(72, 100)
96
+ end
97
+
98
+ should "add the reporter to the progress reporters" do
99
+ @instance.report_progress(72, 100)
100
+ assert @klass.progress_reporters.has_key?(@instance.resource)
101
+ end
102
+ end
103
+
104
+ context "clearing progress" do
105
+ setup do
106
+ @instance.stubs(:flush_progress)
107
+
108
+ @klass.progress_reporters.clear
109
+ @instance.report_progress(72, 100)
110
+ end
111
+
112
+ should "remove the key from the reporters" do
113
+ assert @klass.progress_reporters.has_key?(@instance.resource)
114
+ @instance.clear_progress
115
+ assert !@klass.progress_reporters.has_key?(@instance.resource)
116
+ end
117
+ end
118
+
119
+ context "command line reset" do
120
+ setup do
121
+ Mario::Platform.logger(nil)
122
+ end
123
+
124
+ context "on windows" do
125
+ setup do
126
+ Mario::Platform.forced = Mario::Platform::Windows7
127
+ end
128
+
129
+ should "just return \\r for the clear screen" do
130
+ assert_equal "\r", @instance.cl_reset
131
+ end
132
+ end
133
+
134
+ context "on other platforms" do
135
+ setup do
136
+ Mario::Platform.forced = Mario::Platform::Linux
137
+ end
138
+
139
+ should "return the full clear screen" do
140
+ assert_equal "\r\e[0K", @instance.cl_reset
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end