vagrant 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/config/default.rb CHANGED
@@ -9,6 +9,7 @@ Vagrant::Config.run do |config|
9
9
  config.ssh.host = "localhost"
10
10
  config.ssh.forwarded_port_key = "ssh"
11
11
  config.ssh.max_tries = 10
12
+ config.ssh.timeout = 10
12
13
 
13
14
  config.vm.box_ovf = "box.ovf"
14
15
  config.vm.base_mac = "0800279C2E42"
@@ -0,0 +1,50 @@
1
+ module Vagrant
2
+ module Actions
3
+ module VM
4
+ class Boot < Base
5
+ def execute!
6
+ @runner.invoke_around_callback(:boot) do
7
+ # Startup the VM
8
+ boot
9
+
10
+ # Wait for it to complete booting, or error if we could
11
+ # never detect it booted up successfully
12
+ if !wait_for_boot
13
+ error_and_exit(<<-error)
14
+ Failed to connect to VM! Failed to boot?
15
+ error
16
+ end
17
+ end
18
+ end
19
+
20
+ def collect_shared_folders
21
+ # The root shared folder for the project
22
+ ["vagrant-root", Env.root_path, Vagrant.config.vm.project_directory]
23
+ end
24
+
25
+ def boot
26
+ logger.info "Booting VM..."
27
+ @runner.vm.start(:headless, true)
28
+ end
29
+
30
+ def wait_for_boot(sleeptime=5)
31
+ logger.info "Waiting for VM to boot..."
32
+
33
+ Vagrant.config[:ssh][:max_tries].to_i.times do |i|
34
+ logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
35
+
36
+ if Vagrant::SSH.up?
37
+ logger.info "VM booted and ready for use!"
38
+ return true
39
+ end
40
+
41
+ sleep sleeptime
42
+ end
43
+
44
+ logger.info "Failed to connect to VM! Failed to boot?"
45
+ false
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,48 +2,15 @@ module Vagrant
2
2
  module Actions
3
3
  module VM
4
4
  class Start < Base
5
- def execute!
6
- @runner.invoke_around_callback(:boot) do
7
- # Startup the VM
8
- boot
5
+ def prepare
6
+ # Start is a "meta-action" so it really just queues up a bunch
7
+ # of other actions in its place:
8
+ steps = [ForwardPorts, SharedFolders, Boot]
9
9
 
10
- # Wait for it to complete booting, or error if we could
11
- # never detect it booted up successfully
12
- if !wait_for_boot
13
- error_and_exit(<<-error)
14
- Failed to connect to VM! Failed to boot?
15
- error
16
- end
10
+ steps.each do |action_klass|
11
+ @runner.add_action(action_klass)
17
12
  end
18
13
  end
19
-
20
- def collect_shared_folders
21
- # The root shared folder for the project
22
- ["vagrant-root", Env.root_path, Vagrant.config.vm.project_directory]
23
- end
24
-
25
- def boot
26
- logger.info "Booting VM..."
27
- @runner.vm.start(:headless, true)
28
- end
29
-
30
- def wait_for_boot(sleeptime=5)
31
- logger.info "Waiting for VM to boot..."
32
-
33
- Vagrant.config[:ssh][:max_tries].to_i.times do |i|
34
- logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
35
-
36
- if Vagrant::SSH.up?
37
- logger.info "VM booted and ready for use!"
38
- return true
39
- end
40
-
41
- sleep sleeptime
42
- end
43
-
44
- logger.info "Failed to connect to VM! Failed to boot?"
45
- false
46
- end
47
14
  end
48
15
  end
49
16
  end
@@ -3,9 +3,20 @@ module Vagrant
3
3
  module VM
4
4
  class Up < Base
5
5
  def prepare
6
+ # If the dotfile is not a file, raise error
7
+ if File.exist?(Env.dotfile_path) && !File.file?(Env.dotfile_path)
8
+ raise ActionException.new(<<-msg)
9
+ The dotfile which Vagrant uses to store the UUID of the project's
10
+ virtual machine already exists and is not a file! The dotfile is
11
+ currently configured to be `#{Env.dotfile_path}`
12
+
13
+ To change this value, please see `config.vagrant.dotfile_name`
14
+ msg
15
+ end
16
+
6
17
  # Up is a "meta-action" so it really just queues up a bunch
7
18
  # of other actions in its place:
8
- steps = [Import, ForwardPorts, SharedFolders, Start]
19
+ steps = [Import, ForwardPorts, SharedFolders, Boot]
9
20
  steps << Provision if Vagrant.config.chef.enabled
10
21
  steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
11
22
 
data/lib/vagrant/box.rb CHANGED
@@ -52,6 +52,22 @@ module Vagrant
52
52
  attr_accessor :temp_path
53
53
 
54
54
  class <<self
55
+ # Returns an array of all created boxes, as strings.
56
+ #
57
+ # @return [Array<String>]
58
+ def all
59
+ results = []
60
+
61
+ Dir.open(Env.boxes_path) do |dir|
62
+ dir.each do |d|
63
+ next if d == "." || d == ".." || !File.directory?(File.join(Env.boxes_path, d))
64
+ results << d.to_s
65
+ end
66
+ end
67
+
68
+ results
69
+ end
70
+
55
71
  # Finds a box with the given name. This method searches for a box
56
72
  # with the given name, returning `nil` if none is found or returning
57
73
  # a {Box} instance otherwise.
@@ -128,9 +128,9 @@ error
128
128
  # which action to take and calls the respective action method
129
129
  # (see {box_add} and {box_remove})
130
130
  def box(argv)
131
- Env.load!(:suppress_errors => true)
131
+ Env.load!
132
132
 
133
- sub_commands = ["add", "remove"]
133
+ sub_commands = ["list", "add", "remove"]
134
134
 
135
135
  if !sub_commands.include?(argv[0])
136
136
  error_and_exit(<<-error)
@@ -145,6 +145,22 @@ error
145
145
  send("box_#{argv[0]}", *argv[1..-1])
146
146
  end
147
147
 
148
+ # Lists all added boxes
149
+ def box_list
150
+ boxes = Box.all.sort
151
+
152
+ wrap_output do
153
+ if !boxes.empty?
154
+ puts "Installed Vagrant Boxes:\n\n"
155
+ boxes.each do |box|
156
+ puts box
157
+ end
158
+ else
159
+ puts "No Vagrant Boxes Added!"
160
+ end
161
+ end
162
+ end
163
+
148
164
  # Adds a box to the local filesystem, given a URI.
149
165
  def box_add(name, path)
150
166
  Box.add(name, path)
@@ -59,6 +59,7 @@ module Vagrant
59
59
  attr_accessor :host
60
60
  attr_accessor :forwarded_port_key
61
61
  attr_accessor :max_tries
62
+ attr_accessor :timeout
62
63
  end
63
64
 
64
65
  class VMConfig < Base
data/lib/vagrant/env.rb CHANGED
@@ -19,8 +19,8 @@ module Vagrant
19
19
  def tmp_path; File.join(home_path, "tmp"); end
20
20
  def boxes_path; File.join(home_path, "boxes"); end
21
21
 
22
- def load!(opts={})
23
- load_root_path!(Pathname.new(Dir.pwd), opts)
22
+ def load!
23
+ load_root_path!
24
24
  load_config!
25
25
  load_home_directory!
26
26
  load_box!
@@ -60,6 +60,8 @@ module Vagrant
60
60
  end
61
61
 
62
62
  def load_box!
63
+ return unless root_path
64
+
63
65
  @@box = Box.find(Vagrant.config.vm.box) if Vagrant.config.vm.box
64
66
 
65
67
  if @@box
@@ -69,7 +71,7 @@ module Vagrant
69
71
  end
70
72
 
71
73
  def load_vm!
72
- return unless root_path
74
+ return if !root_path || !File.file?(dotfile_path)
73
75
 
74
76
  File.open(dotfile_path) do |f|
75
77
  @@persisted_vm = Vagrant::VM.find(f.read)
@@ -84,17 +86,10 @@ module Vagrant
84
86
  end
85
87
  end
86
88
 
87
- def load_root_path!(path=Pathname.new(Dir.pwd), opts={})
88
- if path.to_s == '/'
89
- return false if opts[:suppress_errors]
90
- error_and_exit(<<-msg)
91
- A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
92
- since it describes the expected environment that vagrant is supposed
93
- to manage. Please create a #{ROOTFILE_NAME} and place it in your project
94
- root.
95
- msg
96
- return
97
- end
89
+ def load_root_path!(path=nil)
90
+ path ||= Pathname.new(Dir.pwd)
91
+
92
+ return false if path.to_s == '/'
98
93
 
99
94
  file = "#{path}/#{ROOTFILE_NAME}"
100
95
  if File.exist?(file)
@@ -102,10 +97,23 @@ msg
102
97
  return true
103
98
  end
104
99
 
105
- load_root_path!(path.parent, opts)
100
+ load_root_path!(path.parent)
101
+ end
102
+
103
+ def require_root_path
104
+ if !root_path
105
+ error_and_exit(<<-msg)
106
+ A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
107
+ since it describes the expected environment that vagrant is supposed
108
+ to manage. Please create a #{ROOTFILE_NAME} and place it in your project
109
+ root.
110
+ msg
111
+ end
106
112
  end
107
113
 
108
114
  def require_box
115
+ require_root_path
116
+
109
117
  if !box
110
118
  if !Vagrant.config.vm.box
111
119
  error_and_exit(<<-msg)
@@ -125,6 +133,8 @@ msg
125
133
  end
126
134
 
127
135
  def require_persisted_vm
136
+ require_root_path
137
+
128
138
  if !persisted_vm
129
139
  error_and_exit(<<-error)
130
140
  The task you're trying to run requires that the vagrant environment
data/lib/vagrant/ssh.rb CHANGED
@@ -26,13 +26,19 @@ module Vagrant
26
26
  end
27
27
 
28
28
  def up?
29
- Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => 5) do |ssh|
30
- return true
29
+ check_thread = Thread.new do
30
+ begin
31
+ Thread.current[:result] = false
32
+ Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => Vagrant.config.ssh.timeout) do |ssh|
33
+ Thread.current[:result] = true
34
+ end
35
+ rescue Errno::ECONNREFUSED, Net::SSH::Disconnect
36
+ # False, its defaulted above
37
+ end
31
38
  end
32
39
 
33
- false
34
- rescue Errno::ECONNREFUSED, Net::SSH::Disconnect
35
- false
40
+ check_thread.join(Vagrant.config.ssh.timeout)
41
+ return check_thread[:result]
36
42
  end
37
43
 
38
44
  def port(opts={})
data/lib/vagrant/util.rb CHANGED
@@ -4,6 +4,12 @@ module Vagrant
4
4
  base.extend Vagrant::Util
5
5
  end
6
6
 
7
+ def wrap_output
8
+ puts "====================================================================="
9
+ yield
10
+ puts "====================================================================="
11
+ end
12
+
7
13
  def error_and_exit(error)
8
14
  abort <<-error
9
15
  =====================================================================
data/lib/vagrant/vm.rb CHANGED
@@ -28,12 +28,7 @@ module Vagrant
28
28
  def start
29
29
  return if @vm.running?
30
30
 
31
- actions = [Actions::VM::ForwardPorts, Actions::VM::SharedFolders, Actions::VM::Start]
32
- actions.each do |action|
33
- add_action(action)
34
- end
35
-
36
- execute!
31
+ execute!(Actions::VM::Start)
37
32
  end
38
33
 
39
34
  def destroy
data/test/test_helper.rb CHANGED
@@ -31,6 +31,7 @@ class Test::Unit::TestCase
31
31
  config.ssh.host = "baz"
32
32
  config.ssh.forwarded_port_key = "ssh"
33
33
  config.ssh.max_tries = 10
34
+ config.ssh.timeout = 10
34
35
 
35
36
  config.vm.box = "foo"
36
37
  config.vm.box_ovf = "box.ovf"
@@ -0,0 +1,55 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class BootActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Boot)
6
+ @mock_vm.stubs(:invoke_callback)
7
+ mock_config
8
+ end
9
+
10
+ context "execution" do
11
+ should "invoke the 'boot' around callback" do
12
+ boot_seq = sequence("boot_seq")
13
+ @mock_vm.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields
14
+ @action.expects(:boot).in_sequence(boot_seq)
15
+ @action.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
16
+ @action.execute!
17
+ end
18
+
19
+ should "error and exit if the bootup failed" do
20
+ fail_boot_seq = sequence("fail_boot_seq")
21
+ @action.expects(:boot).once.in_sequence(fail_boot_seq)
22
+ @action.expects(:wait_for_boot).returns(false).in_sequence(fail_boot_seq)
23
+ @action.expects(:error_and_exit).once.in_sequence(fail_boot_seq)
24
+ @action.execute!
25
+ end
26
+ end
27
+
28
+ context "booting" do
29
+ should "start the VM in headless mode" do
30
+ @vm.expects(:start).with(:headless, true).once
31
+ @action.boot
32
+ end
33
+ end
34
+
35
+ context "waiting for boot" do
36
+ should "repeatedly ping the SSH port and return false with no response" do
37
+ seq = sequence('pings')
38
+ Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
39
+ Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq)
40
+ assert @action.wait_for_boot(0)
41
+ end
42
+
43
+ should "ping the max number of times then just return" do
44
+ Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false)
45
+ assert !@action.wait_for_boot(0)
46
+ end
47
+ end
48
+
49
+ context "callbacks" do
50
+ should "setup the root directory shared folder" do
51
+ expected = ["vagrant-root", Vagrant::Env.root_path, Vagrant.config.vm.project_directory]
52
+ assert_equal expected, @action.collect_shared_folders
53
+ end
54
+ end
55
+ end
@@ -3,53 +3,26 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class StartActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
6
- @mock_vm.stubs(:invoke_callback)
7
6
  mock_config
8
7
  end
9
8
 
10
- context "execution" do
11
- should "invoke the 'boot' around callback" do
12
- boot_seq = sequence("boot_seq")
13
- @mock_vm.expects(:invoke_around_callback).with(:boot).once.in_sequence(boot_seq).yields
14
- @action.expects(:boot).in_sequence(boot_seq)
15
- @action.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
16
- @action.execute!
9
+ context "sub-actions" do
10
+ setup do
11
+ File.stubs(:file?).returns(true)
12
+ File.stubs(:exist?).returns(true)
13
+ @default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
17
14
  end
18
15
 
19
- should "error and exit if the bootup failed" do
20
- fail_boot_seq = sequence("fail_boot_seq")
21
- @action.expects(:boot).once.in_sequence(fail_boot_seq)
22
- @action.expects(:wait_for_boot).returns(false).in_sequence(fail_boot_seq)
23
- @action.expects(:error_and_exit).once.in_sequence(fail_boot_seq)
24
- @action.execute!
16
+ def setup_action_expectations
17
+ default_seq = sequence("default_seq")
18
+ @default_order.each do |action|
19
+ @mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
20
+ end
25
21
  end
26
- end
27
-
28
- context "booting" do
29
- should "start the VM in headless mode" do
30
- @vm.expects(:start).with(:headless, true).once
31
- @action.boot
32
- end
33
- end
34
-
35
- context "waiting for boot" do
36
- should "repeatedly ping the SSH port and return false with no response" do
37
- seq = sequence('pings')
38
- Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i - 1).returns(false).in_sequence(seq)
39
- Vagrant::SSH.expects(:up?).once.returns(true).in_sequence(seq)
40
- assert @action.wait_for_boot(0)
41
- end
42
-
43
- should "ping the max number of times then just return" do
44
- Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false)
45
- assert !@action.wait_for_boot(0)
46
- end
47
- end
48
22
 
49
- context "callbacks" do
50
- should "setup the root directory shared folder" do
51
- expected = ["vagrant-root", Vagrant::Env.root_path, Vagrant.config.vm.project_directory]
52
- assert_equal expected, @action.collect_shared_folders
23
+ should "do the proper actions by default" do
24
+ setup_action_expectations
25
+ @action.prepare
53
26
  end
54
27
  end
55
28
  end
@@ -8,7 +8,9 @@ class UpActionTest < Test::Unit::TestCase
8
8
 
9
9
  context "sub-actions" do
10
10
  setup do
11
- @default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
11
+ File.stubs(:file?).returns(true)
12
+ File.stubs(:exist?).returns(true)
13
+ @default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
12
14
  end
13
15
 
14
16
  def setup_action_expectations
@@ -18,6 +20,26 @@ class UpActionTest < Test::Unit::TestCase
18
20
  end
19
21
  end
20
22
 
23
+ should "raise an ActionException if a dotfile exists but is not a file" do
24
+ File.expects(:file?).with(Vagrant::Env.dotfile_path).returns(false)
25
+ assert_raises(Vagrant::Actions::ActionException) {
26
+ @action.prepare
27
+ }
28
+ end
29
+
30
+ should "not raise an ActionException if dotfile doesn't exist" do
31
+ setup_action_expectations
32
+ File.stubs(:exist?).returns(false)
33
+ assert_nothing_raised { @action.prepare }
34
+ end
35
+
36
+ should "not raise an ActionException if dotfile exists but is a file" do
37
+ File.stubs(:file?).returns(true)
38
+ File.stubs(:exist?).returns(true)
39
+ setup_action_expectations
40
+ assert_nothing_raised { @action.prepare }
41
+ end
42
+
21
43
  should "do the proper actions by default" do
22
44
  setup_action_expectations
23
45
  @action.prepare
@@ -2,6 +2,53 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class BoxTest < Test::Unit::TestCase
4
4
  context "class methods" do
5
+ context "listing all boxes" do
6
+ setup do
7
+ Dir.stubs(:open)
8
+ File.stubs(:directory?).returns(true)
9
+
10
+ @boxes_path = "foo"
11
+ Vagrant::Env.stubs(:boxes_path).returns(@boxes_path)
12
+ end
13
+
14
+ should "open the boxes directory" do
15
+ Dir.expects(:open).with(Vagrant::Env.boxes_path)
16
+ Vagrant::Box.all
17
+ end
18
+
19
+ should "return an array" do
20
+ result = Vagrant::Box.all
21
+ assert result.is_a?(Array)
22
+ end
23
+
24
+ should "not return the '.' and '..' directories" do
25
+ dir = [".", "..", "..", ".", ".."]
26
+ Dir.expects(:open).yields(dir)
27
+ result = Vagrant::Box.all
28
+ assert result.empty?
29
+ end
30
+
31
+ should "return the other directories" do
32
+ dir = [".", "foo", "bar", "baz"]
33
+ Dir.expects(:open).yields(dir)
34
+ result = Vagrant::Box.all
35
+ assert_equal ["foo", "bar", "baz"], result
36
+ end
37
+
38
+ should "ignore the files" do
39
+ dir = ["foo", "bar"]
40
+ files = [true, false]
41
+ Dir.expects(:open).yields(dir)
42
+ dir_sequence = sequence("directory")
43
+ dir.each_with_index do |dir, index|
44
+ File.expects(:directory?).with(File.join(@boxes_path, dir)).returns(files[index]).in_sequence(dir_sequence)
45
+ end
46
+
47
+ result = Vagrant::Box.all
48
+ assert_equal ["foo"], result
49
+ end
50
+ end
51
+
5
52
  context "finding" do
6
53
  setup do
7
54
  @dir = "foo"
@@ -7,6 +7,7 @@ class CommandsTest < Test::Unit::TestCase
7
7
  @persisted_vm = mock("persisted_vm")
8
8
  @persisted_vm.stubs(:execute!)
9
9
  Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
10
+ Vagrant::Env.stubs(:require_persisted_vm)
10
11
  end
11
12
 
12
13
  context "init" do
@@ -194,7 +195,7 @@ class CommandsTest < Test::Unit::TestCase
194
195
  end
195
196
 
196
197
  should "load the environment" do
197
- Vagrant::Env.expects(:load!).with(:suppress_errors => true).once
198
+ Vagrant::Env.expects(:load!).once
198
199
  Vagrant::Commands.box(["add"])
199
200
  end
200
201
 
@@ -219,6 +220,22 @@ class CommandsTest < Test::Unit::TestCase
219
220
  end
220
221
  end
221
222
 
223
+ context "box list" do
224
+ setup do
225
+ @boxes = ["foo", "bar"]
226
+
227
+ Vagrant::Box.stubs(:all).returns(@boxes)
228
+ Vagrant::Commands.stubs(:puts)
229
+ end
230
+
231
+ should "call all on box and sort the results" do
232
+ @all = mock("all")
233
+ @all.expects(:sort).returns(@boxes)
234
+ Vagrant::Box.expects(:all).returns(@all)
235
+ Vagrant::Commands.box_list
236
+ end
237
+ end
238
+
222
239
  context "box add" do
223
240
  setup do
224
241
  @name = "foo"
@@ -6,6 +6,7 @@ class EnvTest < Test::Unit::TestCase
6
6
  filemock.expects(:read).returns("foo")
7
7
  Vagrant::VM.expects(:find).with("foo").returns(returnvalue)
8
8
  File.expects(:open).with(Vagrant::Env.dotfile_path).once.yields(filemock)
9
+ File.expects(:file?).with(Vagrant::Env.dotfile_path).once.returns(true)
9
10
  Vagrant::Env.load_vm!
10
11
  end
11
12
 
@@ -15,6 +16,16 @@ class EnvTest < Test::Unit::TestCase
15
16
  end
16
17
 
17
18
  context "requiring a VM" do
19
+ setup do
20
+ Vagrant::Env.stubs(:require_root_path)
21
+ Vagrant::Env.stubs(:error_and_exit)
22
+ end
23
+
24
+ should "require root path" do
25
+ Vagrant::Env.expects(:require_root_path).once
26
+ Vagrant::Env.require_persisted_vm
27
+ end
28
+
18
29
  should "error and exit if no persisted VM was found" do
19
30
  assert_nil Vagrant::Env.persisted_vm
20
31
  Vagrant::Env.expects(:error_and_exit).once
@@ -121,7 +132,7 @@ class EnvTest < Test::Unit::TestCase
121
132
  test "load! should load the config and set the persisted_uid" do
122
133
  Vagrant::Env.expects(:load_config!).once
123
134
  Vagrant::Env.expects(:load_vm!).once
124
- Vagrant::Env.expects(:load_root_path!).with(Pathname.new(Dir.pwd), {}).once
135
+ Vagrant::Env.expects(:load_root_path!).once
125
136
  Vagrant::Env.expects(:load_home_directory!).once
126
137
  Vagrant::Env.expects(:load_box!).once
127
138
  Vagrant::Env.load!
@@ -145,7 +156,11 @@ class EnvTest < Test::Unit::TestCase
145
156
  end
146
157
 
147
158
  context "loading the UUID out from the persisted file" do
148
- test "loading of the uuid from the dotfile" do
159
+ setup do
160
+ File.stubs(:file?).returns(true)
161
+ end
162
+
163
+ should "loading of the uuid from the dotfile" do
149
164
  mock_persisted_vm
150
165
  assert_equal 'foovm', Vagrant::Env.persisted_vm
151
166
  end
@@ -156,21 +171,39 @@ class EnvTest < Test::Unit::TestCase
156
171
  Vagrant::Env.load_vm!
157
172
  end
158
173
 
159
- test "uuid should be nil if dotfile didn't exist" do
174
+ should "do nothing if dotfile is not a file" do
175
+ File.expects(:file?).returns(false)
176
+ File.expects(:open).never
177
+ Vagrant::Env.load_vm!
178
+ end
179
+
180
+ should "uuid should be nil if dotfile didn't exist" do
160
181
  File.expects(:open).raises(Errno::ENOENT)
161
182
  Vagrant::Env.load_vm!
162
183
  assert_nil Vagrant::Env.persisted_vm
163
184
  end
164
185
 
165
- test "should build up the dotfile out of the root path and the dotfile name" do
186
+ should "should build up the dotfile out of the root path and the dotfile name" do
166
187
  assert_equal File.join(Vagrant::Env.root_path, Vagrant.config.vagrant.dotfile_name), Vagrant::Env.dotfile_path
167
188
  end
168
189
  end
169
190
 
170
191
  context "loading the root path" do
171
- test "should walk the parent directories looking for rootfile" do
172
- Vagrant::Env.expects(:error_and_exit).once
192
+ should "default the path to the pwd if nil" do
193
+ @path = mock("path")
194
+ @path.stubs(:to_s).returns("/")
195
+ Pathname.expects(:new).with(Dir.pwd).returns(@path)
196
+ Vagrant::Env.load_root_path!(nil)
197
+ end
173
198
 
199
+ should "not default the path to pwd if its not nil" do
200
+ @path = mock("path")
201
+ @path.stubs(:to_s).returns("/")
202
+ Pathname.expects(:new).never
203
+ Vagrant::Env.load_root_path!(@path)
204
+ end
205
+
206
+ should "should walk the parent directories looking for rootfile" do
174
207
  paths = [
175
208
  Pathname.new("/foo/bar/baz"),
176
209
  Pathname.new("/foo/bar"),
@@ -182,32 +215,15 @@ class EnvTest < Test::Unit::TestCase
182
215
  File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(false).in_sequence(search_seq)
183
216
  end
184
217
 
185
- assert_nil Vagrant::Env.load_root_path!(paths.first)
186
- end
187
-
188
- test "should print out an error and exit if not found" do
189
- path = Pathname.new("/")
190
-
191
- Vagrant::Env.expects(:error_and_exit).once
192
- Vagrant::Env.load_root_path!(path)
218
+ assert !Vagrant::Env.load_root_path!(paths.first)
193
219
  end
194
220
 
195
- should "return false if suppress errors is set and no root path is found" do
221
+ should "should return false if not found" do
196
222
  path = Pathname.new("/")
197
-
198
- Vagrant::Env.expects(:error_and_exit).never
199
- assert !Vagrant::Env.load_root_path!(path, :suppress_errors => true)
223
+ assert !Vagrant::Env.load_root_path!(path)
200
224
  end
201
225
 
202
- should "pipe suppress errors flag through recursion" do
203
- path = Pathname.new("/foo/bar/baz")
204
- File.expects(:exist?).times(3).returns(false)
205
-
206
- Vagrant::Env.expects(:error_and_exit).never
207
- assert !Vagrant::Env.load_root_path!(path, :suppress_errors => true)
208
- end
209
-
210
- test "should set the path for the rootfile" do
226
+ should "should set the path for the rootfile" do
211
227
  path = "/foo"
212
228
  File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)
213
229
 
@@ -239,6 +255,13 @@ class EnvTest < Test::Unit::TestCase
239
255
  @box = mock("box")
240
256
 
241
257
  Vagrant::Env.stubs(:load_config!)
258
+ Vagrant::Env.stubs(:root_path).returns("foo")
259
+ end
260
+
261
+ should "do nothing if the root path is nil" do
262
+ Vagrant::Box.expects(:find).never
263
+ Vagrant::Env.stubs(:root_path).returns(nil)
264
+ Vagrant::Env.load_vm!
242
265
  end
243
266
 
244
267
  should "not load the box if its not set" do
@@ -264,6 +287,16 @@ class EnvTest < Test::Unit::TestCase
264
287
  end
265
288
 
266
289
  context "requiring boxes" do
290
+ setup do
291
+ Vagrant::Env.stubs(:require_root_path)
292
+ Vagrant::Env.stubs(:error_and_exit)
293
+ end
294
+
295
+ should "require root path" do
296
+ Vagrant::Env.expects(:require_root_path).once
297
+ Vagrant::Env.require_box
298
+ end
299
+
267
300
  should "error and exit if no box is found" do
268
301
  mock_config do |config|
269
302
  config.vm.box = nil
@@ -290,4 +323,18 @@ class EnvTest < Test::Unit::TestCase
290
323
  Vagrant::Env.require_box
291
324
  end
292
325
  end
326
+
327
+ context "requiring root_path" do
328
+ should "error and exit if no root_path is set" do
329
+ Vagrant::Env.expects(:root_path).returns(nil)
330
+ Vagrant::Env.expects(:error_and_exit).once
331
+ Vagrant::Env.require_root_path
332
+ end
333
+
334
+ should "not error and exit if root_path is set" do
335
+ Vagrant::Env.expects(:root_path).returns("foo")
336
+ Vagrant::Env.expects(:error_and_exit).never
337
+ Vagrant::Env.require_root_path
338
+ end
339
+ end
293
340
  end
@@ -68,6 +68,14 @@ class SshTest < Test::Unit::TestCase
68
68
  assert !Vagrant::SSH.up?
69
69
  end
70
70
 
71
+ should "allow the thread the configured timeout time" do
72
+ @thread = mock("thread")
73
+ @thread.stubs(:[])
74
+ Thread.expects(:new).returns(@thread)
75
+ @thread.expects(:join).with(Vagrant.config.ssh.timeout).once
76
+ Vagrant::SSH.up?
77
+ end
78
+
71
79
  should "return false if the connection is refused" do
72
80
  Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
73
81
  assert_nothing_raised {
@@ -80,15 +80,8 @@ class VMTest < Test::Unit::TestCase
80
80
  @vm.start
81
81
  end
82
82
 
83
- should "add and execute the proper actions" do
84
- actions = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
85
-
86
- action_seq = sequence("action_seq")
87
- actions.each do |action|
88
- @vm.expects(:add_action).with(action).in_sequence(action_seq)
89
- end
90
-
91
- @vm.expects(:execute!).once.in_sequence(action_seq)
83
+ should "execute the start action" do
84
+ @vm.expects(:execute!).once.with(Vagrant::Actions::VM::Start)
92
85
  @vm.start
93
86
  end
94
87
  end
data/vagrant.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vagrant}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mitchell Hashimoto", "John Bender"]
12
- s.date = %q{2010-03-07}
12
+ s.date = %q{2010-03-08}
13
13
  s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
14
14
  s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
15
15
  s.executables = ["vagrant", "vagrant-box", "vagrant-down", "vagrant-halt", "vagrant-init", "vagrant-package", "vagrant-reload", "vagrant-resume", "vagrant-ssh", "vagrant-suspend", "vagrant-up"]
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "lib/vagrant/actions/box/download.rb",
45
45
  "lib/vagrant/actions/box/unpackage.rb",
46
46
  "lib/vagrant/actions/runner.rb",
47
+ "lib/vagrant/actions/vm/boot.rb",
47
48
  "lib/vagrant/actions/vm/destroy.rb",
48
49
  "lib/vagrant/actions/vm/down.rb",
49
50
  "lib/vagrant/actions/vm/export.rb",
@@ -79,6 +80,7 @@ Gem::Specification.new do |s|
79
80
  "test/vagrant/actions/box/download_test.rb",
80
81
  "test/vagrant/actions/box/unpackage_test.rb",
81
82
  "test/vagrant/actions/runner_test.rb",
83
+ "test/vagrant/actions/vm/boot_test.rb",
82
84
  "test/vagrant/actions/vm/destroy_test.rb",
83
85
  "test/vagrant/actions/vm/down_test.rb",
84
86
  "test/vagrant/actions/vm/export_test.rb",
@@ -120,6 +122,7 @@ Gem::Specification.new do |s|
120
122
  "test/vagrant/actions/box/download_test.rb",
121
123
  "test/vagrant/actions/box/unpackage_test.rb",
122
124
  "test/vagrant/actions/runner_test.rb",
125
+ "test/vagrant/actions/vm/boot_test.rb",
123
126
  "test/vagrant/actions/vm/destroy_test.rb",
124
127
  "test/vagrant/actions/vm/down_test.rb",
125
128
  "test/vagrant/actions/vm/export_test.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mitchell Hashimoto
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-07 00:00:00 -08:00
18
+ date: 2010-03-08 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -150,6 +150,7 @@ files:
150
150
  - lib/vagrant/actions/box/download.rb
151
151
  - lib/vagrant/actions/box/unpackage.rb
152
152
  - lib/vagrant/actions/runner.rb
153
+ - lib/vagrant/actions/vm/boot.rb
153
154
  - lib/vagrant/actions/vm/destroy.rb
154
155
  - lib/vagrant/actions/vm/down.rb
155
156
  - lib/vagrant/actions/vm/export.rb
@@ -185,6 +186,7 @@ files:
185
186
  - test/vagrant/actions/box/download_test.rb
186
187
  - test/vagrant/actions/box/unpackage_test.rb
187
188
  - test/vagrant/actions/runner_test.rb
189
+ - test/vagrant/actions/vm/boot_test.rb
188
190
  - test/vagrant/actions/vm/destroy_test.rb
189
191
  - test/vagrant/actions/vm/down_test.rb
190
192
  - test/vagrant/actions/vm/export_test.rb
@@ -250,6 +252,7 @@ test_files:
250
252
  - test/vagrant/actions/box/download_test.rb
251
253
  - test/vagrant/actions/box/unpackage_test.rb
252
254
  - test/vagrant/actions/runner_test.rb
255
+ - test/vagrant/actions/vm/boot_test.rb
253
256
  - test/vagrant/actions/vm/destroy_test.rb
254
257
  - test/vagrant/actions/vm/down_test.rb
255
258
  - test/vagrant/actions/vm/export_test.rb