vagrantup 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/README.md +2 -2
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/config/default.rb +13 -3
  7. data/lib/vagrant.rb +10 -13
  8. data/lib/vagrant/actions/base.rb +14 -2
  9. data/lib/vagrant/actions/box/download.rb +2 -7
  10. data/lib/vagrant/actions/box/verify.rb +1 -1
  11. data/lib/vagrant/actions/runner.rb +0 -1
  12. data/lib/vagrant/actions/vm/boot.rb +2 -6
  13. data/lib/vagrant/actions/vm/customize.rb +7 -5
  14. data/lib/vagrant/actions/vm/destroy.rb +4 -3
  15. data/lib/vagrant/actions/vm/down.rb +6 -3
  16. data/lib/vagrant/actions/vm/export.rb +2 -4
  17. data/lib/vagrant/actions/vm/forward_ports.rb +77 -16
  18. data/lib/vagrant/actions/vm/halt.rb +10 -2
  19. data/lib/vagrant/actions/vm/import.rb +2 -4
  20. data/lib/vagrant/actions/vm/move_hard_drive.rb +2 -2
  21. data/lib/vagrant/actions/vm/network.rb +120 -0
  22. data/lib/vagrant/actions/vm/package.rb +11 -7
  23. data/lib/vagrant/actions/vm/provision.rb +3 -3
  24. data/lib/vagrant/actions/vm/reload.rb +2 -9
  25. data/lib/vagrant/actions/vm/shared_folders.rb +19 -39
  26. data/lib/vagrant/actions/vm/start.rb +10 -2
  27. data/lib/vagrant/actions/vm/up.rb +5 -6
  28. data/lib/vagrant/active_list.rb +23 -13
  29. data/lib/vagrant/box.rb +2 -2
  30. data/lib/vagrant/busy.rb +3 -3
  31. data/lib/vagrant/command.rb +2 -2
  32. data/lib/vagrant/commands/base.rb +40 -20
  33. data/lib/vagrant/commands/destroy.rb +17 -3
  34. data/lib/vagrant/commands/halt.rb +23 -3
  35. data/lib/vagrant/commands/package.rb +54 -14
  36. data/lib/vagrant/commands/provision.rb +31 -0
  37. data/lib/vagrant/commands/reload.rb +16 -3
  38. data/lib/vagrant/commands/resume.rb +16 -3
  39. data/lib/vagrant/commands/ssh.rb +25 -3
  40. data/lib/vagrant/commands/ssh_config.rb +20 -5
  41. data/lib/vagrant/commands/status.rb +107 -40
  42. data/lib/vagrant/commands/suspend.rb +16 -3
  43. data/lib/vagrant/commands/up.rb +26 -7
  44. data/lib/vagrant/config.rb +82 -12
  45. data/lib/vagrant/downloaders/base.rb +8 -1
  46. data/lib/vagrant/downloaders/http.rb +31 -19
  47. data/lib/vagrant/environment.rb +146 -49
  48. data/lib/vagrant/provisioners/base.rb +19 -5
  49. data/lib/vagrant/provisioners/chef.rb +12 -4
  50. data/lib/vagrant/provisioners/chef_server.rb +13 -6
  51. data/lib/vagrant/provisioners/chef_solo.rb +7 -3
  52. data/lib/vagrant/resource_logger.rb +126 -0
  53. data/lib/vagrant/ssh.rb +109 -8
  54. data/lib/vagrant/systems/base.rb +70 -0
  55. data/lib/vagrant/systems/linux.rb +137 -0
  56. data/lib/vagrant/util.rb +1 -45
  57. data/lib/vagrant/util/error_helper.rb +13 -0
  58. data/lib/vagrant/util/glob_loader.rb +22 -0
  59. data/lib/vagrant/util/output_helper.rb +9 -0
  60. data/lib/vagrant/util/plain_logger.rb +12 -0
  61. data/lib/vagrant/util/platform.rb +7 -2
  62. data/lib/vagrant/util/template_renderer.rb +2 -2
  63. data/lib/vagrant/util/translator.rb +35 -0
  64. data/lib/vagrant/vm.rb +91 -10
  65. data/templates/crontab_entry.erb +1 -0
  66. data/templates/network_entry.erb +8 -0
  67. data/templates/ssh_config.erb +1 -0
  68. data/templates/{errors.yml → strings.yml} +111 -3
  69. data/templates/sync.erb +14 -0
  70. data/test/test_helper.rb +46 -3
  71. data/test/vagrant/actions/box/download_test.rb +0 -17
  72. data/test/vagrant/actions/vm/boot_test.rb +3 -10
  73. data/test/vagrant/actions/vm/customize_test.rb +6 -0
  74. data/test/vagrant/actions/vm/destroy_test.rb +6 -5
  75. data/test/vagrant/actions/vm/down_test.rb +5 -11
  76. data/test/vagrant/actions/vm/export_test.rb +1 -0
  77. data/test/vagrant/actions/vm/forward_ports_test.rb +92 -15
  78. data/test/vagrant/actions/vm/halt_test.rb +36 -4
  79. data/test/vagrant/actions/vm/import_test.rb +2 -0
  80. data/test/vagrant/actions/vm/network_test.rb +237 -0
  81. data/test/vagrant/actions/vm/package_test.rb +35 -5
  82. data/test/vagrant/actions/vm/provision_test.rb +3 -3
  83. data/test/vagrant/actions/vm/reload_test.rb +1 -1
  84. data/test/vagrant/actions/vm/shared_folders_test.rb +41 -74
  85. data/test/vagrant/actions/vm/start_test.rb +41 -3
  86. data/test/vagrant/actions/vm/up_test.rb +10 -21
  87. data/test/vagrant/active_list_test.rb +28 -43
  88. data/test/vagrant/commands/base_test.rb +25 -4
  89. data/test/vagrant/commands/destroy_test.rb +24 -12
  90. data/test/vagrant/commands/halt_test.rb +33 -11
  91. data/test/vagrant/commands/package_test.rb +77 -57
  92. data/test/vagrant/commands/provision_test.rb +50 -0
  93. data/test/vagrant/commands/reload_test.rb +27 -11
  94. data/test/vagrant/commands/resume_test.rb +25 -14
  95. data/test/vagrant/commands/ssh_config_test.rb +40 -17
  96. data/test/vagrant/commands/ssh_test.rb +52 -13
  97. data/test/vagrant/commands/status_test.rb +21 -1
  98. data/test/vagrant/commands/suspend_test.rb +25 -14
  99. data/test/vagrant/commands/up_test.rb +25 -19
  100. data/test/vagrant/config_test.rb +74 -18
  101. data/test/vagrant/downloaders/base_test.rb +2 -1
  102. data/test/vagrant/downloaders/http_test.rb +18 -8
  103. data/test/vagrant/environment_test.rb +245 -77
  104. data/test/vagrant/provisioners/base_test.rb +4 -4
  105. data/test/vagrant/provisioners/chef_server_test.rb +18 -7
  106. data/test/vagrant/provisioners/chef_solo_test.rb +17 -7
  107. data/test/vagrant/provisioners/chef_test.rb +22 -9
  108. data/test/vagrant/resource_logger_test.rb +144 -0
  109. data/test/vagrant/ssh_session_test.rb +46 -0
  110. data/test/vagrant/ssh_test.rb +42 -2
  111. data/test/vagrant/systems/linux_test.rb +174 -0
  112. data/test/vagrant/util/error_helper_test.rb +5 -0
  113. data/test/vagrant/util/output_helper_test.rb +5 -0
  114. data/test/vagrant/util/plain_logger_test.rb +17 -0
  115. data/test/vagrant/util/platform_test.rb +18 -0
  116. data/test/vagrant/util/{errors_test.rb → translator_test.rb} +25 -21
  117. data/test/vagrant/util_test.rb +12 -49
  118. data/test/vagrant/vm_test.rb +133 -11
  119. data/vagrant.gemspec +39 -15
  120. metadata +38 -14
  121. data/lib/vagrant/commands/down.rb +0 -16
  122. data/lib/vagrant/util/errors.rb +0 -36
  123. data/lib/vagrant/util/progress_meter.rb +0 -33
  124. data/test/vagrant/commands/down_test.rb +0 -17
  125. data/test/vagrant/util/progress_meter_test.rb +0 -33
@@ -7,13 +7,13 @@ class BaseProvisionerTest < Test::Unit::TestCase
7
7
 
8
8
  context "base instance" do
9
9
  setup do
10
- @env = mock_environment
11
- @base = Vagrant::Provisioners::Base.new(@env)
10
+ @vm = mock("vm")
11
+ @base = Vagrant::Provisioners::Base.new(@vm)
12
12
  end
13
13
 
14
14
  should "set the environment" do
15
- base = Vagrant::Provisioners::Base.new(@env)
16
- assert_equal @env, base.env
15
+ base = Vagrant::Provisioners::Base.new(@vm)
16
+ assert_equal @vm, base.vm
17
17
  end
18
18
 
19
19
  should "implement provision! which does nothing" do
@@ -2,13 +2,15 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefServerProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @env = mock_environment
6
- @action = Vagrant::Provisioners::ChefServer.new(@env)
5
+ @vm = mock_vm
6
+ @env = @vm.env
7
+ @action = Vagrant::Provisioners::ChefServer.new(@vm)
7
8
  end
8
9
 
9
10
  context "provisioning" do
10
11
  should "run the proper sequence of methods in order" do
11
12
  prov_seq = sequence("prov_seq")
13
+ @action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq)
12
14
  @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
13
15
  @action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
14
16
  @action.expects(:upload_validation_key).once.in_sequence(prov_seq)
@@ -106,7 +108,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
106
108
  should "create the folder using the dirname of the path" do
107
109
  ssh = mock("ssh")
108
110
  ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
109
- @env.ssh.expects(:execute).yields(ssh)
111
+ @vm.ssh.expects(:execute).yields(ssh)
110
112
  @action.create_client_key_folder
111
113
  end
112
114
  end
@@ -115,7 +117,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
115
117
  should "upload the validation key to the provisioning path" do
116
118
  @action.expects(:validation_key_path).once.returns("foo")
117
119
  @action.expects(:guest_validation_key_path).once.returns("bar")
118
- @env.ssh.expects(:upload!).with("foo", "bar").once
120
+ @vm.ssh.expects(:upload!).with("foo", "bar").once
119
121
  @action.upload_validation_key
120
122
  end
121
123
  end
@@ -155,10 +157,19 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
155
157
  end
156
158
 
157
159
  context "running chef client" do
160
+ setup do
161
+ @ssh = mock("ssh")
162
+ @vm.ssh.stubs(:execute).yields(@ssh)
163
+ end
164
+
158
165
  should "cd into the provisioning directory and run chef client" do
159
- ssh = mock("ssh")
160
- ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
161
- @env.ssh.expects(:execute).yields(ssh)
166
+ @ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
167
+ @action.run_chef_client
168
+ end
169
+
170
+ should "check the exit status if that is given" do
171
+ @ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
172
+ @ssh.expects(:check_exit_status).with(:foo, anything).once
162
173
  @action.run_chef_client
163
174
  end
164
175
  end
@@ -2,8 +2,9 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefSoloProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @env = mock_environment
6
- @action = Vagrant::Provisioners::ChefSolo.new(@env)
5
+ @vm = mock_vm
6
+ @env = @vm.env
7
+ @action = Vagrant::Provisioners::ChefSolo.new(@vm)
7
8
  end
8
9
 
9
10
  context "preparing" do
@@ -21,6 +22,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
21
22
  context "provisioning" do
22
23
  should "run the proper sequence of methods in order" do
23
24
  prov_seq = sequence("prov_seq")
25
+ @action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq)
24
26
  @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
25
27
  @action.expects(:setup_json).once.in_sequence(prov_seq)
26
28
  @action.expects(:setup_solo_config).once.in_sequence(prov_seq)
@@ -28,7 +30,6 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
28
30
  @action.provision!
29
31
  end
30
32
  end
31
-
32
33
  context "sharing cookbook folders" do
33
34
  setup do
34
35
  @host_cookbook_paths = ["foo", "bar"]
@@ -148,7 +149,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
148
149
 
149
150
  context "generating and uploading chef solo configuration file" do
150
151
  setup do
151
- @env.ssh.stubs(:upload!)
152
+ @vm.ssh.stubs(:upload!)
152
153
  end
153
154
 
154
155
  should "call setup_config with proper variables" do
@@ -163,10 +164,19 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
163
164
  end
164
165
 
165
166
  context "running chef solo" do
167
+ setup do
168
+ @ssh = mock("ssh")
169
+ @vm.ssh.stubs(:execute).yields(@ssh)
170
+ end
171
+
166
172
  should "cd into the provisioning directory and run chef solo" do
167
- ssh = mock("ssh")
168
- ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
169
- @env.ssh.expects(:execute).yields(ssh)
173
+ @ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
174
+ @action.run_chef_solo
175
+ end
176
+
177
+ should "check the exit status if that is given" do
178
+ @ssh.stubs(:exec!).yields(nil, :exit_status, :foo)
179
+ @ssh.expects(:check_exit_status).with(:foo, anything).once
170
180
  @action.run_chef_solo
171
181
  end
172
182
  end
@@ -2,8 +2,9 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
2
 
3
3
  class ChefProvisionerTest < Test::Unit::TestCase
4
4
  setup do
5
- @env = mock_environment
6
- @action = Vagrant::Provisioners::Chef.new(@env)
5
+ @vm = mock_vm
6
+ @env = @vm.env
7
+ @action = Vagrant::Provisioners::Chef.new(@vm)
7
8
  end
8
9
 
9
10
  context "preparing" do
@@ -61,20 +62,32 @@ class ChefProvisionerTest < Test::Unit::TestCase
61
62
  end
62
63
  end
63
64
 
65
+ context "verifying binary" do
66
+ setup do
67
+ @ssh = mock("ssh")
68
+ @vm.ssh.stubs(:execute).yields(@ssh)
69
+ end
70
+
71
+ should "verify binary exists" do
72
+ binary = "foo"
73
+ @ssh.expects(:exec!).with("which #{binary}", :error_key => :chef_not_detected, :error_data => { :binary => binary }).once
74
+ @action.verify_binary(binary)
75
+ end
76
+ end
64
77
  context "permissions on provisioning folder" do
65
78
  should "create and chown the folder to the ssh user" do
66
79
  ssh_seq = sequence("ssh_seq")
67
80
  ssh = mock("ssh")
68
81
  ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
69
82
  ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
70
- @env.ssh.expects(:execute).yields(ssh)
83
+ @vm.ssh.expects(:execute).yields(ssh)
71
84
  @action.chown_provisioning_folder
72
85
  end
73
86
  end
74
87
 
75
88
  context "generating and uploading chef configuration file" do
76
89
  setup do
77
- @env.ssh.stubs(:upload!)
90
+ @vm.ssh.stubs(:upload!)
78
91
 
79
92
  @template = "template"
80
93
  @filename = "foo.rb"
@@ -88,7 +101,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
88
101
  Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data)
89
102
  StringIO.expects(:new).with(template_data).returns(string_io)
90
103
  File.expects(:join).with(@env.config.chef.provisioning_path, @filename).once.returns("bar")
91
- @env.ssh.expects(:upload!).with(string_io, "bar")
104
+ @vm.ssh.expects(:upload!).with(string_io, "bar")
92
105
 
93
106
  @action.setup_config(@template, @filename, {})
94
107
  end
@@ -124,7 +137,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
124
137
 
125
138
  context "generating and uploading json" do
126
139
  def assert_json
127
- @env.ssh.expects(:upload!).with do |json, path|
140
+ @vm.ssh.expects(:upload!).with do |json, path|
128
141
  data = JSON.parse(json.read)
129
142
  yield data
130
143
  true
@@ -142,20 +155,20 @@ class ChefProvisionerTest < Test::Unit::TestCase
142
155
 
143
156
  should "add the directory as a special case to the JSON" do
144
157
  assert_json do |data|
145
- assert_equal @env.config.vm.project_directory, data["vagrant"]["directory"]
158
+ assert_equal @env.config.vm.shared_folders["v-root"][:guestpath], data["vagrant"]["directory"]
146
159
  end
147
160
  end
148
161
 
149
162
  should "add the config to the JSON" do
150
163
  assert_json do |data|
151
- assert_equal @env.config.vm.project_directory, data["vagrant"]["config"]["vm"]["project_directory"]
164
+ assert_equal @env.config.ssh.username, data["vagrant"]["config"]["ssh"]["username"]
152
165
  end
153
166
  end
154
167
 
155
168
  should "upload a StringIO to dna.json" do
156
169
  StringIO.expects(:new).with(anything).returns("bar")
157
170
  File.expects(:join).with(@env.config.chef.provisioning_path, "dna.json").once.returns("baz")
158
- @env.ssh.expects(:upload!).with("bar", "baz").once
171
+ @vm.ssh.expects(:upload!).with("bar", "baz").once
159
172
  @action.setup_json
160
173
  end
161
174
  end
@@ -0,0 +1,144 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ResourceLoggerTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = Vagrant::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
+ should "log with the proper format" do
80
+ message = "bar"
81
+ @logger.expects(:info).with("[#{@resource}] #{message}").once
82
+
83
+ @instance.info(message)
84
+ end
85
+ end
86
+
87
+ context "reporting progress" do
88
+ setup do
89
+ @instance.stubs(:flush_progress)
90
+ end
91
+
92
+ should "flush progress" do
93
+ @instance.expects(:flush_progress).once
94
+ @instance.report_progress(72, 100)
95
+ end
96
+
97
+ should "add the reporter to the progress reporters" do
98
+ @instance.report_progress(72, 100)
99
+ assert @klass.progress_reporters.has_key?(@instance.resource)
100
+ end
101
+ end
102
+
103
+ context "clearing progress" do
104
+ setup do
105
+ @instance.stubs(:flush_progress)
106
+
107
+ @klass.progress_reporters.clear
108
+ @instance.report_progress(72, 100)
109
+ end
110
+
111
+ should "remove the key from the reporters" do
112
+ assert @klass.progress_reporters.has_key?(@instance.resource)
113
+ @instance.clear_progress
114
+ assert !@klass.progress_reporters.has_key?(@instance.resource)
115
+ end
116
+ end
117
+
118
+ context "command line reset" do
119
+ setup do
120
+ Mario::Platform.logger(nil)
121
+ end
122
+
123
+ context "on windows" do
124
+ setup do
125
+ Mario::Platform.forced = Mario::Platform::Windows7
126
+ end
127
+
128
+ should "just return \\r for the clear screen" do
129
+ assert_equal "\r", @instance.cl_reset
130
+ end
131
+ end
132
+
133
+ context "on other platforms" do
134
+ setup do
135
+ Mario::Platform.forced = Mario::Platform::Linux
136
+ end
137
+
138
+ should "return the full clear screen" do
139
+ assert_equal "\r\e[0K", @instance.cl_reset
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class SshTest < Test::Unit::TestCase
4
+ setup do
5
+ @session = mock("session")
6
+
7
+ @klass = Vagrant::SSH::Session
8
+ @instance = @klass.new(@session)
9
+ end
10
+
11
+ context "exec!" do
12
+ should "retry 5 times" do
13
+ @session.expects(:open_channel).times(5).raises(IOError)
14
+ assert_raises(IOError) {
15
+ @instance.exec!("foo")
16
+ }
17
+ end
18
+ end
19
+
20
+ context "checking exit status" do
21
+ should "raise an ActionException if its non-zero" do
22
+ assert_raises(Vagrant::Actions::ActionException) {
23
+ @instance.check_exit_status(1, "foo")
24
+ }
25
+ end
26
+
27
+ should "raise the given exception if specified" do
28
+ options = {
29
+ :error_key => :foo,
30
+ :error_data => {}
31
+ }
32
+ result = Exception.new
33
+ Vagrant::Actions::ActionException.expects(:new).with(options[:error_key], options[:error_data]).once.returns(result)
34
+
35
+ assert_raises(Exception) {
36
+ @instance.check_exit_status(1, "foo", options)
37
+ }
38
+ end
39
+
40
+ should "raise nothing if its zero" do
41
+ assert_nothing_raised {
42
+ @instance.check_exit_status(0, "foo")
43
+ }
44
+ end
45
+ end
46
+ end
@@ -6,6 +6,13 @@ class SshTest < Test::Unit::TestCase
6
6
  yield config if block_given?
7
7
  end
8
8
 
9
+ @forwarded_ports = []
10
+ @vm = mock("vm")
11
+ @vm.stubs(:forwarded_ports).returns(@forwarded_ports)
12
+
13
+ @env.stubs(:vm).returns(mock_vm(@env))
14
+ @env.vm.stubs(:vm).returns(@vm)
15
+
9
16
  @ssh = Vagrant::SSH.new(@env)
10
17
  end
11
18
 
@@ -111,6 +118,15 @@ class SshTest < Test::Unit::TestCase
111
118
  Net::SSH.expects(:start).with(@env.config.ssh.host, @env.config.ssh.username, anything).once
112
119
  @ssh.execute
113
120
  end
121
+
122
+ should "yield an SSH session object" do
123
+ raw = mock("raw")
124
+ Net::SSH.expects(:start).yields(raw)
125
+ @ssh.execute do |ssh|
126
+ assert ssh.is_a?(Vagrant::SSH::Session)
127
+ assert_equal raw, ssh.session
128
+ end
129
+ end
114
130
  end
115
131
 
116
132
  context "SCPing files to the remote host" do
@@ -121,11 +137,20 @@ class SshTest < Test::Unit::TestCase
121
137
  should "use Vagrant::SSH execute to setup an SCP connection and upload" do
122
138
  scp = mock("scp")
123
139
  ssh = mock("ssh")
140
+ sess = mock("session")
141
+ ssh.stubs(:session).returns(sess)
124
142
  scp.expects(:upload!).with("foo", "bar").once
125
- Net::SCP.expects(:new).with(ssh).returns(scp).once
143
+ Net::SCP.expects(:new).with(ssh.session).returns(scp).once
126
144
  @ssh.expects(:execute).yields(ssh).once
127
145
  @ssh.upload!("foo", "bar")
128
146
  end
147
+
148
+ should "retry 5 times" do
149
+ @ssh.expects(:execute).times(5).raises(IOError)
150
+ assert_raises(IOError) {
151
+ @ssh.upload!("foo", "bar")
152
+ }
153
+ end
129
154
  end
130
155
 
131
156
  context "checking if host is up" do
@@ -181,10 +206,17 @@ class SshTest < Test::Unit::TestCase
181
206
  context "getting the ssh port" do
182
207
  setup do
183
208
  mock_ssh
209
+
184
210
  end
185
211
 
186
212
  should "return the configured port by default" do
187
- assert_equal @env.config.vm.forwarded_ports[@env.config.ssh.forwarded_port_key][:hostport], @ssh.port
213
+ port = 2222
214
+ fp = mock("fp")
215
+ fp.stubs(:name).returns(@env.config.ssh.forwarded_port_key)
216
+ fp.stubs(:hostport).returns(port)
217
+ @forwarded_ports << fp
218
+
219
+ assert_equal port, @ssh.port
188
220
  end
189
221
 
190
222
  should "return the port given in options if it exists" do
@@ -203,6 +235,14 @@ class SshTest < Test::Unit::TestCase
203
235
  @stat = mock("stat")
204
236
  @stat.stubs(:owned?).returns(true)
205
237
  File.stubs(:stat).returns(@stat)
238
+
239
+ Mario::Platform.stubs(:windows?).returns(false)
240
+ end
241
+
242
+ should "do nothing if on windows" do
243
+ Mario::Platform.stubs(:windows?).returns(true)
244
+ File.expects(:stat).never
245
+ @ssh.check_key_permissions(@key_path)
206
246
  end
207
247
 
208
248
  should "do nothing if the user is not the owner" do