vagrant 0.4.0 → 0.4.1
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.
- data/VERSION +1 -1
- data/lib/vagrant/actions/vm/forward_ports.rb +80 -31
- data/lib/vagrant/actions/vm/up.rb +14 -0
- data/lib/vagrant/commands/provision.rb +1 -1
- data/lib/vagrant/commands/ssh.rb +36 -2
- data/lib/vagrant/resource_logger.rb +11 -11
- data/lib/vagrant/ssh.rb +14 -2
- data/lib/vagrant/util/translator.rb +2 -2
- data/templates/strings.yml +20 -0
- data/test/vagrant/actions/vm/forward_ports_test.rb +167 -48
- data/test/vagrant/actions/vm/up_test.rb +1 -0
- data/test/vagrant/commands/provision_test.rb +10 -0
- data/test/vagrant/commands/ssh_test.rb +58 -0
- data/test/vagrant/resource_logger_test.rb +6 -5
- data/test/vagrant/ssh_session_test.rb +1 -1
- data/test/vagrant/ssh_test.rb +8 -2
- data/vagrant.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
@@ -11,22 +11,10 @@ module Vagrant
|
|
11
11
|
# report the collisions detected or will attempt to fix them
|
12
12
|
# automatically if the port is configured to do so.
|
13
13
|
def external_collision_check
|
14
|
-
|
15
|
-
# flat list.
|
16
|
-
used_ports = VirtualBox::VM.all.collect do |vm|
|
17
|
-
if vm.running? && vm.uuid != runner.uuid
|
18
|
-
vm.forwarded_ports.collect do |fp|
|
19
|
-
fp.hostport.to_s
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
used_ports.flatten!
|
25
|
-
used_ports.uniq!
|
26
|
-
|
14
|
+
existing = used_ports
|
27
15
|
runner.env.config.vm.forwarded_ports.each do |name, options|
|
28
|
-
if
|
29
|
-
handle_collision(name, options,
|
16
|
+
if existing.include?(options[:hostport].to_s)
|
17
|
+
handle_collision(name, options, existing)
|
30
18
|
end
|
31
19
|
end
|
32
20
|
end
|
@@ -34,7 +22,7 @@ module Vagrant
|
|
34
22
|
# Handles any collisions. This method will either attempt to
|
35
23
|
# fix the collision automatically or will raise an error if
|
36
24
|
# auto fixing is disabled.
|
37
|
-
def handle_collision(name, options,
|
25
|
+
def handle_collision(name, options, existing_ports)
|
38
26
|
if !options[:auto]
|
39
27
|
# Auto fixing is disabled for this port forward, so we
|
40
28
|
# must throw an error so the user can fix it.
|
@@ -46,7 +34,7 @@ module Vagrant
|
|
46
34
|
# left with available ports.
|
47
35
|
range = runner.env.config.vm.auto_port_range.to_a
|
48
36
|
range -= runner.env.config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i }
|
49
|
-
range -=
|
37
|
+
range -= existing_ports
|
50
38
|
|
51
39
|
if range.empty?
|
52
40
|
raise ActionException.new(:vm_port_auto_empty, :vm_name => @runner.name, :name => name, :options => options)
|
@@ -55,7 +43,7 @@ module Vagrant
|
|
55
43
|
# Set the port up to be the first one and add that port to
|
56
44
|
# the used list.
|
57
45
|
options[:hostport] = range.shift
|
58
|
-
|
46
|
+
existing_ports << options[:hostport]
|
59
47
|
|
60
48
|
# Notify the user
|
61
49
|
logger.info "Fixed port collision: #{name} now on port #{options[:hostport]}"
|
@@ -67,10 +55,9 @@ module Vagrant
|
|
67
55
|
end
|
68
56
|
|
69
57
|
def clear
|
70
|
-
if
|
58
|
+
if used_ports.length > 0
|
71
59
|
logger.info "Deleting any previously set forwarded ports..."
|
72
|
-
|
73
|
-
fp.collect { |p| p.destroy }
|
60
|
+
clear_ports
|
74
61
|
runner.reload!
|
75
62
|
end
|
76
63
|
end
|
@@ -78,28 +65,90 @@ module Vagrant
|
|
78
65
|
def forward_ports
|
79
66
|
logger.info "Forwarding ports..."
|
80
67
|
|
81
|
-
|
68
|
+
runner.env.config.vm.forwarded_ports.each do |name, options|
|
82
69
|
adapter = options[:adapter]
|
83
70
|
|
84
71
|
# Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking.
|
85
72
|
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
|
86
73
|
# attachment types has uncertain behaviour.
|
87
74
|
if @runner.vm.network_adapters[adapter].attachment_type == :nat
|
88
|
-
|
89
|
-
|
90
|
-
port.name = name
|
91
|
-
port.hostport = options[:hostport]
|
92
|
-
port.guestport = options[:guestport]
|
93
|
-
port.instance = adapter
|
94
|
-
@runner.vm.forwarded_ports << port
|
75
|
+
logger.info "Forwarding \"#{name}\": #{options[:guestport]} on adapter \##{adapter+1} => #{options[:hostport]}"
|
76
|
+
forward_port(name, options)
|
95
77
|
else
|
96
78
|
logger.info "VirtualBox adapter \##{adapter+1} not configured as \"NAT\"."
|
97
79
|
logger.info "Skipped port forwarding \"#{name}\": #{options[:guestport]} on adapter\##{adapter+1} => #{options[:hostport]}"
|
98
80
|
end
|
99
81
|
end
|
100
82
|
|
101
|
-
|
102
|
-
|
83
|
+
runner.vm.save
|
84
|
+
runner.reload!
|
85
|
+
end
|
86
|
+
|
87
|
+
#------------------------------------------------------------
|
88
|
+
# VirtualBox version-specific helpers below. VirtualBox 3.2
|
89
|
+
# introduced a breaking change into the way that forwarded
|
90
|
+
# ports are handled. For backwards compatability with 3.1, we
|
91
|
+
# need this trickery.
|
92
|
+
#------------------------------------------------------------
|
93
|
+
# TODO In a future version, fix this.
|
94
|
+
|
95
|
+
# Returns an array of used ports. This method is implemented
|
96
|
+
# differently depending on the VirtualBox version, but the
|
97
|
+
# behavior is the same.
|
98
|
+
#
|
99
|
+
# @return [Array<String>]
|
100
|
+
def used_ports
|
101
|
+
result = VirtualBox::VM.all.collect do |vm|
|
102
|
+
if vm.running? && vm.uuid != runner.uuid
|
103
|
+
if VirtualBox.version =~ /^3\.1\./
|
104
|
+
# VirtualBox 3.1.x uses forwarded ports via extra-data
|
105
|
+
vm.forwarded_ports.collect do |fp|
|
106
|
+
fp.hostport.to_s
|
107
|
+
end
|
108
|
+
else
|
109
|
+
# VirtualBox 3.2.x uses forwarded ports via NAT engines
|
110
|
+
vm.network_adapters.collect do |na|
|
111
|
+
na.nat_driver.forwarded_ports.collect do |fp|
|
112
|
+
fp.hostport.to_s
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
result.flatten.uniq
|
120
|
+
end
|
121
|
+
|
122
|
+
# Deletes existing forwarded ports.
|
123
|
+
def clear_ports
|
124
|
+
if VirtualBox.version =~ /^3\.1\./
|
125
|
+
fp = runner.vm.forwarded_ports.dup
|
126
|
+
fp.each { |p| p.destroy }
|
127
|
+
else
|
128
|
+
runner.vm.network_adapters.each do |na|
|
129
|
+
na.nat_driver.forwarded_ports.dup.each do |fp|
|
130
|
+
fp.destroy
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Forwards a port.
|
137
|
+
def forward_port(name, options)
|
138
|
+
if VirtualBox.version =~ /^3\.1\./
|
139
|
+
port = VirtualBox::ForwardedPort.new
|
140
|
+
port.name = name
|
141
|
+
port.hostport = options[:hostport]
|
142
|
+
port.guestport = options[:guestport]
|
143
|
+
port.instance = options[:adapter]
|
144
|
+
runner.vm.forwarded_ports << port
|
145
|
+
else
|
146
|
+
port = VirtualBox::NATForwardedPort.new
|
147
|
+
port.name = name
|
148
|
+
port.guestport = options[:guestport]
|
149
|
+
port.hostport = options[:hostport]
|
150
|
+
runner.vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
151
|
+
end
|
103
152
|
end
|
104
153
|
end
|
105
154
|
end
|
@@ -21,6 +21,7 @@ module Vagrant
|
|
21
21
|
def after_import
|
22
22
|
update_dotfile
|
23
23
|
setup_mac_address
|
24
|
+
check_guest_additions
|
24
25
|
end
|
25
26
|
|
26
27
|
def update_dotfile
|
@@ -33,6 +34,19 @@ module Vagrant
|
|
33
34
|
@runner.vm.network_adapters.first.mac_address = @runner.env.config.vm.base_mac
|
34
35
|
@runner.vm.save
|
35
36
|
end
|
37
|
+
|
38
|
+
def check_guest_additions
|
39
|
+
# Use the raw interface for now, while the virtualbox gem
|
40
|
+
# doesn't support guest properties (due to cross platform issues)
|
41
|
+
version = @runner.vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
|
42
|
+
if version.empty?
|
43
|
+
logger.error Translator.t(:vm_additions_not_detected)
|
44
|
+
elsif version != VirtualBox.version
|
45
|
+
logger.error Translator.t(:vm_additions_version_mismatch,
|
46
|
+
:guest_additions_version => version,
|
47
|
+
:virtualbox_version => VirtualBox.version)
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
38
52
|
end
|
data/lib/vagrant/commands/ssh.rb
CHANGED
@@ -11,7 +11,34 @@ module Vagrant
|
|
11
11
|
|
12
12
|
def execute(args=[])
|
13
13
|
args = parse_options(args)
|
14
|
-
|
14
|
+
if !options[:execute].empty?
|
15
|
+
vms = args[0] ? {args[0] => env.vms[args[0].to_sym]} : env.vms
|
16
|
+
vms.each do |name, vm|
|
17
|
+
ssh_execute(name, vm)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
ssh_connect(args[0])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def ssh_execute(name, vm)
|
25
|
+
if vm.nil?
|
26
|
+
error_and_exit(:unknown_vm, :vm => name)
|
27
|
+
return # for tests
|
28
|
+
elsif !vm.created?
|
29
|
+
error_and_exit(:environment_not_created)
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
vm.ssh.execute do |ssh|
|
34
|
+
options[:execute].each do |command|
|
35
|
+
vm.env.logger.info("Execute: #{command}")
|
36
|
+
ssh.exec!(command) do |channel, type, data|
|
37
|
+
# TODO: Exit status checking?
|
38
|
+
vm.env.logger.info("#{type}: #{data}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
15
42
|
end
|
16
43
|
|
17
44
|
def ssh_connect(name)
|
@@ -37,7 +64,14 @@ module Vagrant
|
|
37
64
|
end
|
38
65
|
|
39
66
|
def options_spec(opts)
|
40
|
-
opts.banner = "Usage: vagrant ssh"
|
67
|
+
opts.banner = "Usage: vagrant ssh [--execute COMMAND]"
|
68
|
+
|
69
|
+
# Defaults
|
70
|
+
options[:execute] = []
|
71
|
+
|
72
|
+
opts.on("-e", "--execute COMMAND", "A command to execute. Multiple -e's may be specified.") do |value|
|
73
|
+
options[:execute] << value
|
74
|
+
end
|
41
75
|
end
|
42
76
|
end
|
43
77
|
end
|
@@ -61,19 +61,19 @@ module Vagrant
|
|
61
61
|
@logger = self.class.singleton_logger(env)
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
[:debug, :info, :error, :fatal].each do |method|
|
65
|
+
define_method(method) do |message|
|
66
|
+
@@writer_lock.synchronize do
|
67
|
+
# We clear the line in case progress reports have been going
|
68
|
+
# out.
|
69
|
+
print(cl_reset)
|
70
|
+
logger.send(method, "[#{resource}] #{message}")
|
71
|
+
end
|
65
72
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# out.
|
70
|
-
print(cl_reset)
|
71
|
-
logger.info("[#{resource}] #{message}")
|
73
|
+
# Once again flush the progress reporters since we probably
|
74
|
+
# cleared any existing ones.
|
75
|
+
flush_progress
|
72
76
|
end
|
73
|
-
|
74
|
-
# Once again flush the progress reporters since we probably
|
75
|
-
# cleared any existing ones.
|
76
|
-
flush_progress
|
77
77
|
end
|
78
78
|
|
79
79
|
# Sets a progress report for the resource that this logger
|
data/lib/vagrant/ssh.rb
CHANGED
@@ -132,8 +132,20 @@ module Vagrant
|
|
132
132
|
return pnum if pnum
|
133
133
|
|
134
134
|
# Check if we have an SSH forwarded port
|
135
|
-
|
136
|
-
|
135
|
+
if VirtualBox.version =~ /^3\.1\./
|
136
|
+
pnum = env.vm.vm.forwarded_ports.detect do |fp|
|
137
|
+
fp.name == env.config.ssh.forwarded_port_key
|
138
|
+
end
|
139
|
+
else
|
140
|
+
# VirtualBox 3.2 specific
|
141
|
+
pnum = nil
|
142
|
+
env.vm.vm.network_adapters.each do |na|
|
143
|
+
pnum = na.nat_driver.forwarded_ports.detect do |fp|
|
144
|
+
fp.name == env.config.ssh.forwarded_port_key
|
145
|
+
end
|
146
|
+
|
147
|
+
break if pnum
|
148
|
+
end
|
137
149
|
end
|
138
150
|
|
139
151
|
return pnum.hostport if pnum
|
@@ -6,7 +6,7 @@ module Vagrant
|
|
6
6
|
class Translator
|
7
7
|
@@strings = nil
|
8
8
|
|
9
|
-
class <<self
|
9
|
+
class << self
|
10
10
|
# Resets the internal strings hash to nil, forcing a reload on the next
|
11
11
|
# access of {strings}.
|
12
12
|
def reset!
|
@@ -32,4 +32,4 @@ module Vagrant
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/templates/strings.yml
CHANGED
@@ -40,6 +40,26 @@
|
|
40
40
|
Path: <%= data["path"] %>
|
41
41
|
Created at: <%= Time.at(data["created_at"]) %>
|
42
42
|
|
43
|
+
#---------------------------------------------------------------------
|
44
|
+
# CATEGORY: Warning Messages
|
45
|
+
#---------------------------------------------------------------------
|
46
|
+
:vm_additions_not_detected: |-
|
47
|
+
WARNING!
|
48
|
+
No guest additions were detected on the base box for this VM! Guest
|
49
|
+
additions are required for forwarded ports, shared folders, host only
|
50
|
+
networking, and more. If SSH fails on this machine, please install
|
51
|
+
the guest additions and repackage the box to continue.
|
52
|
+
:vm_additions_version_mismatch: |-
|
53
|
+
WARNING!
|
54
|
+
The guest additions on this VM do not match the install version of
|
55
|
+
VirtualBox! This often causes things such as forwared ports, shared
|
56
|
+
folders, and more to not work properly. If any of those things fail on
|
57
|
+
this machine, please update the guest additions and repackage the
|
58
|
+
box.
|
59
|
+
|
60
|
+
Guest Additions Version: <%= guest_additions_version %>
|
61
|
+
VirtualBox Version: <%= virtualbox_version %>
|
62
|
+
|
43
63
|
#---------------------------------------------------------------------
|
44
64
|
# CATEGORY: Error Messages
|
45
65
|
#---------------------------------------------------------------------
|
@@ -15,18 +15,6 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
context "checking for colliding external ports" do
|
17
17
|
setup do
|
18
|
-
@forwarded_port = mock("forwarded_port")
|
19
|
-
@forwarded_port.stubs(:hostport)
|
20
|
-
@forwarded_ports = [@forwarded_port]
|
21
|
-
|
22
|
-
@vm = mock("vm")
|
23
|
-
@vm.stubs(:forwarded_ports).returns(@forwarded_ports)
|
24
|
-
@vm.stubs(:running?).returns(true)
|
25
|
-
@vm.stubs(:uuid).returns("foo")
|
26
|
-
@runner.stubs(:uuid).returns("bar")
|
27
|
-
vms = [@vm]
|
28
|
-
VirtualBox::VM.stubs(:all).returns(vms)
|
29
|
-
|
30
18
|
@env = mock_environment do |config|
|
31
19
|
config.vm.forwarded_ports.clear
|
32
20
|
config.vm.forward_port("ssh", 22, 2222)
|
@@ -34,29 +22,20 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
34
22
|
|
35
23
|
@runner.stubs(:env).returns(@env)
|
36
24
|
|
25
|
+
@used_ports = []
|
26
|
+
@action.stubs(:used_ports).returns(@used_ports)
|
27
|
+
|
37
28
|
# So no exceptions are raised
|
38
29
|
@action.stubs(:handle_collision)
|
39
30
|
end
|
40
31
|
|
41
|
-
should "ignore vms which aren't running" do
|
42
|
-
@vm.expects(:running?).returns(false)
|
43
|
-
@vm.expects(:forwarded_ports).never
|
44
|
-
@action.external_collision_check
|
45
|
-
end
|
46
|
-
|
47
|
-
should "ignore vms which are equivalent to ours" do
|
48
|
-
@runner.expects(:uuid).returns(@vm.uuid)
|
49
|
-
@vm.expects(:forwarded_ports).never
|
50
|
-
@action.external_collision_check
|
51
|
-
end
|
52
|
-
|
53
32
|
should "not raise any errors if no forwarded ports collide" do
|
54
|
-
@
|
33
|
+
@used_ports << "80"
|
55
34
|
assert_nothing_raised { @action.external_collision_check }
|
56
35
|
end
|
57
36
|
|
58
37
|
should "handle the collision if it happens" do
|
59
|
-
@
|
38
|
+
@used_ports << "2222"
|
60
39
|
@action.expects(:handle_collision).with("ssh", anything, anything).once
|
61
40
|
@action.external_collision_check
|
62
41
|
end
|
@@ -127,24 +106,11 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
127
106
|
@vm.expects(:network_adapters).returns([network_adapter])
|
128
107
|
network_adapter.expects(:attachment_type).returns(:nat)
|
129
108
|
|
130
|
-
@runner.env.config.vm.forwarded_ports.each do |name, opts|
|
131
|
-
forwarded_ports.expects(:<<).with do |port|
|
132
|
-
assert_equal name, port.name
|
133
|
-
assert_equal opts[:hostport], port.hostport
|
134
|
-
assert_equal opts[:guestport], port.guestport
|
135
|
-
assert_equal opts[:adapter], port.instance
|
136
|
-
true
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
141
109
|
@vm.expects(:save).once
|
142
110
|
@runner.expects(:reload!).once
|
143
111
|
@action.forward_ports
|
144
112
|
end
|
145
|
-
end
|
146
113
|
|
147
|
-
context "Not forwarding ports" do
|
148
114
|
should "No port forwarding for non NAT interfaces" do
|
149
115
|
forwarded_ports = mock("forwarded_ports")
|
150
116
|
network_adapter = mock("network_adapter")
|
@@ -158,23 +124,176 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|
158
124
|
end
|
159
125
|
|
160
126
|
context "clearing forwarded ports" do
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
port.expects(:destroy).once
|
166
|
-
forwarded_ports << port
|
167
|
-
end
|
127
|
+
setup do
|
128
|
+
@action.stubs(:used_ports).returns([:a])
|
129
|
+
@action.stubs(:clear_ports)
|
130
|
+
end
|
168
131
|
|
169
|
-
|
132
|
+
should "call destroy on all forwarded ports" do
|
133
|
+
@action.expects(:clear_ports).once
|
170
134
|
@runner.expects(:reload!)
|
171
135
|
@action.clear
|
172
136
|
end
|
173
137
|
|
174
138
|
should "do nothing if there are no forwarded ports" do
|
175
|
-
@
|
139
|
+
@action.stubs(:used_ports).returns([])
|
176
140
|
@runner.expects(:reload!).never
|
177
141
|
@action.clear
|
178
142
|
end
|
179
143
|
end
|
144
|
+
|
145
|
+
context "getting list of used ports" do
|
146
|
+
setup do
|
147
|
+
@vms = []
|
148
|
+
VirtualBox::VM.stubs(:all).returns(@vms)
|
149
|
+
VirtualBox.stubs(:version).returns("3.1.0")
|
150
|
+
@runner.stubs(:uuid).returns(:bar)
|
151
|
+
end
|
152
|
+
|
153
|
+
def mock_vm(options={})
|
154
|
+
options = {
|
155
|
+
:running? => true,
|
156
|
+
:uuid => :foo
|
157
|
+
}.merge(options)
|
158
|
+
|
159
|
+
vm = mock("vm")
|
160
|
+
options.each do |k,v|
|
161
|
+
vm.stubs(k).returns(v)
|
162
|
+
end
|
163
|
+
|
164
|
+
vm
|
165
|
+
end
|
166
|
+
|
167
|
+
def mock_fp(hostport)
|
168
|
+
fp = mock("fp")
|
169
|
+
fp.stubs(:hostport).returns(hostport.to_s)
|
170
|
+
fp
|
171
|
+
end
|
172
|
+
|
173
|
+
should "ignore VMs which aren't running" do
|
174
|
+
@vms << mock_vm(:running? => false)
|
175
|
+
@vms[0].expects(:forwarded_ports).never
|
176
|
+
@action.used_ports
|
177
|
+
end
|
178
|
+
|
179
|
+
should "ignore VMs of the same uuid" do
|
180
|
+
@vms << mock_vm(:uuid => @runner.uuid)
|
181
|
+
@vms[0].expects(:forwarded_ports).never
|
182
|
+
@action.used_ports
|
183
|
+
end
|
184
|
+
|
185
|
+
should "return the forwarded ports for VB 3.1.x" do
|
186
|
+
VirtualBox.stubs(:version).returns("3.1.4")
|
187
|
+
fps = [mock_fp(2222), mock_fp(80)]
|
188
|
+
@vms << mock_vm(:forwarded_ports => fps)
|
189
|
+
assert_equal %W[2222 80], @action.used_ports
|
190
|
+
end
|
191
|
+
|
192
|
+
should "return the forwarded ports for VB 3.2.x" do
|
193
|
+
VirtualBox.stubs(:version).returns("3.2.4")
|
194
|
+
fps = [mock_fp(2222), mock_fp(80)]
|
195
|
+
na = mock("na")
|
196
|
+
ne = mock("ne")
|
197
|
+
na.stubs(:nat_driver).returns(ne)
|
198
|
+
ne.stubs(:forwarded_ports).returns(fps)
|
199
|
+
@vms << mock_vm(:network_adapters => [na])
|
200
|
+
assert_equal %W[2222 80], @action.used_ports
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "clearing ports" do
|
205
|
+
def mock_fp
|
206
|
+
fp = mock("fp")
|
207
|
+
fp.expects(:destroy).once
|
208
|
+
fp
|
209
|
+
end
|
210
|
+
|
211
|
+
context "in VB 3.1.x" do
|
212
|
+
setup do
|
213
|
+
VirtualBox.stubs(:version).returns("3.1.4")
|
214
|
+
@fps = []
|
215
|
+
@vm.stubs(:forwarded_ports).returns(@fps)
|
216
|
+
end
|
217
|
+
|
218
|
+
should "destroy each forwarded port" do
|
219
|
+
@fps << mock_fp
|
220
|
+
@fps << mock_fp
|
221
|
+
@action.clear_ports
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context "in VB 3.2.x" do
|
226
|
+
setup do
|
227
|
+
VirtualBox.stubs(:version).returns("3.2.8")
|
228
|
+
@adapters = []
|
229
|
+
@vm.stubs(:network_adapters).returns(@adapters)
|
230
|
+
end
|
231
|
+
|
232
|
+
def mock_adapter
|
233
|
+
na = mock("adapter")
|
234
|
+
engine = mock("engine")
|
235
|
+
engine.stubs(:forwarded_ports).returns([mock_fp])
|
236
|
+
na.stubs(:nat_driver).returns(engine)
|
237
|
+
na
|
238
|
+
end
|
239
|
+
|
240
|
+
should "destroy each forwarded port" do
|
241
|
+
@adapters << mock_adapter
|
242
|
+
@adapters << mock_adapter
|
243
|
+
@action.clear_ports
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "forwarding ports" do
|
249
|
+
context "in VB 3.1.x" do
|
250
|
+
setup do
|
251
|
+
VirtualBox.stubs(:version).returns("3.1.4")
|
252
|
+
end
|
253
|
+
|
254
|
+
should "forward ports" do
|
255
|
+
forwarded_ports = mock("forwarded_ports")
|
256
|
+
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
257
|
+
@runner.env.config.vm.forwarded_ports.each do |name, opts|
|
258
|
+
forwarded_ports.expects(:<<).with do |port|
|
259
|
+
assert_equal name, port.name
|
260
|
+
assert_equal opts[:hostport], port.hostport
|
261
|
+
assert_equal opts[:guestport], port.guestport
|
262
|
+
assert_equal opts[:adapter], port.instance
|
263
|
+
true
|
264
|
+
end
|
265
|
+
|
266
|
+
@action.forward_port(name, opts)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context "in VB 3.2.x" do
|
272
|
+
setup do
|
273
|
+
VirtualBox.stubs(:version).returns("3.2.8")
|
274
|
+
end
|
275
|
+
|
276
|
+
should "forward ports" do
|
277
|
+
name, opts = @runner.env.config.vm.forwarded_ports.first
|
278
|
+
|
279
|
+
adapters = []
|
280
|
+
adapter = mock("adapter")
|
281
|
+
engine = mock("engine")
|
282
|
+
fps = mock("forwarded ports")
|
283
|
+
adapter.stubs(:nat_driver).returns(engine)
|
284
|
+
engine.stubs(:forwarded_ports).returns(fps)
|
285
|
+
fps.expects(:<<).with do |port|
|
286
|
+
assert_equal name, port.name
|
287
|
+
assert_equal opts[:hostport], port.hostport
|
288
|
+
assert_equal opts[:guestport], port.guestport
|
289
|
+
true
|
290
|
+
end
|
291
|
+
|
292
|
+
adapters[opts[:adapter]] = adapter
|
293
|
+
@vm.stubs(:network_adapters).returns(adapters)
|
294
|
+
|
295
|
+
@action.forward_port(name, opts)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
180
299
|
end
|
@@ -69,6 +69,7 @@ class UpActionTest < Test::Unit::TestCase
|
|
69
69
|
boot_seq = sequence("boot")
|
70
70
|
@action.expects(:update_dotfile).once.in_sequence(boot_seq)
|
71
71
|
@action.expects(:setup_mac_address).once.in_sequence(boot_seq)
|
72
|
+
@action.expects(:check_guest_additions).once.in_sequence(boot_seq)
|
72
73
|
@action.after_import
|
73
74
|
end
|
74
75
|
end
|
@@ -18,6 +18,7 @@ class CommandsProvisionTest < Test::Unit::TestCase
|
|
18
18
|
setup do
|
19
19
|
@foo_vm = mock("vm")
|
20
20
|
@foo_vm.stubs(:env).returns(@env)
|
21
|
+
@foo_vm.stubs(:created?).returns(true)
|
21
22
|
|
22
23
|
@vm_for_real = mock("vm for real")
|
23
24
|
@foo_vm.stubs(:vm).returns(@vm_for_real)
|
@@ -45,6 +46,15 @@ class CommandsProvisionTest < Test::Unit::TestCase
|
|
45
46
|
@foo_vm.expects(:provision).never
|
46
47
|
@instance.execute(["foo"])
|
47
48
|
end
|
49
|
+
|
50
|
+
should "do log to info if it's not created" do
|
51
|
+
logger = mock("logger")
|
52
|
+
logger.expects(:info)
|
53
|
+
@env.stubs(:logger).returns(logger)
|
54
|
+
@foo_vm.stubs(:created?).returns(false)
|
55
|
+
@foo_vm.expects(:provision).never
|
56
|
+
@instance.execute(["foo"])
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
60
|
end
|
@@ -18,6 +18,64 @@ class CommandsSSHTest < Test::Unit::TestCase
|
|
18
18
|
@instance.expects(:ssh_connect).with(nil).once
|
19
19
|
@instance.execute
|
20
20
|
end
|
21
|
+
|
22
|
+
should "execute if commands are given" do
|
23
|
+
@env.stubs(:vms).returns(:foo => mock("foo"))
|
24
|
+
@instance.expects(:ssh_execute).with("foo", @env.vms[:foo]).once
|
25
|
+
@instance.execute(["foo","-e","bar"])
|
26
|
+
end
|
27
|
+
|
28
|
+
should "execute over every VM if none is specified with a command" do
|
29
|
+
vms = {
|
30
|
+
:foo => mock("foo"),
|
31
|
+
:bar => mock("bar")
|
32
|
+
}
|
33
|
+
|
34
|
+
@env.stubs(:vms).returns(vms)
|
35
|
+
vms.each do |key, vm|
|
36
|
+
@instance.expects(:ssh_execute).with(key, vm).once
|
37
|
+
end
|
38
|
+
|
39
|
+
@instance.execute(["--execute", "bar"])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "ssh executing" do
|
44
|
+
setup do
|
45
|
+
@name = :foo
|
46
|
+
|
47
|
+
@ssh_conn = mock("connection")
|
48
|
+
@ssh_conn.stubs(:exec!)
|
49
|
+
|
50
|
+
@ssh = mock("ssh")
|
51
|
+
@ssh.stubs(:execute).yields(@ssh_conn)
|
52
|
+
|
53
|
+
@vm = mock("vm")
|
54
|
+
@vm.stubs(:created?).returns(true)
|
55
|
+
@vm.stubs(:ssh).returns(@ssh)
|
56
|
+
@vm.stubs(:env).returns(@env)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "error and exit if invalid VM given" do
|
60
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => @name).once
|
61
|
+
@instance.ssh_execute(@name, nil)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "error and exit if VM isn't created" do
|
65
|
+
@vm.stubs(:created?).returns(false)
|
66
|
+
@instance.expects(:error_and_exit).with(:environment_not_created).once
|
67
|
+
@instance.ssh_execute(@name, @vm)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "execute each command" do
|
71
|
+
commands = [:a,:b,:c]
|
72
|
+
@instance.stubs(:options).returns(:execute => commands)
|
73
|
+
commands.each do |cmd|
|
74
|
+
@ssh_conn.expects(:exec!).with(cmd).once
|
75
|
+
end
|
76
|
+
|
77
|
+
@instance.ssh_execute(@name, @vm)
|
78
|
+
end
|
21
79
|
end
|
22
80
|
|
23
81
|
context "ssh connecting" do
|
@@ -76,11 +76,12 @@ class ResourceLoggerTest < Test::Unit::TestCase
|
|
76
76
|
@instance.stubs(:cl_reset).returns("")
|
77
77
|
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
data/test/vagrant/ssh_test.rb
CHANGED
@@ -16,6 +16,10 @@ class SshTest < Test::Unit::TestCase
|
|
16
16
|
@ssh = Vagrant::SSH.new(@env)
|
17
17
|
end
|
18
18
|
|
19
|
+
setup do
|
20
|
+
VirtualBox.stubs(:version).returns("3.1.4")
|
21
|
+
end
|
22
|
+
|
19
23
|
context "connecting to external SSH" do
|
20
24
|
setup do
|
21
25
|
mock_ssh
|
@@ -93,6 +97,7 @@ class SshTest < Test::Unit::TestCase
|
|
93
97
|
setup do
|
94
98
|
mock_ssh
|
95
99
|
@ssh.stubs(:check_key_permissions)
|
100
|
+
@ssh.stubs(:port).returns(80)
|
96
101
|
end
|
97
102
|
|
98
103
|
should "check key permissions then attempt to start connection" do
|
@@ -206,10 +211,11 @@ class SshTest < Test::Unit::TestCase
|
|
206
211
|
context "getting the ssh port" do
|
207
212
|
setup do
|
208
213
|
mock_ssh
|
209
|
-
|
210
214
|
end
|
211
215
|
|
212
|
-
should "return the configured port by default" do
|
216
|
+
should "return the configured port by default in VB 3.1.x" do
|
217
|
+
VirtualBox.stubs(:version).returns("3.1.4")
|
218
|
+
|
213
219
|
port = 2222
|
214
220
|
fp = mock("fp")
|
215
221
|
fp.stubs(:name).returns(@env.config.ssh.forwarded_port_key)
|
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.4.
|
8
|
+
s.version = "0.4.1"
|
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-06-
|
12
|
+
s.date = %q{2010-06-17}
|
13
13
|
s.default_executable = %q{vagrant}
|
14
14
|
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
|
15
15
|
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
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-06-
|
18
|
+
date: 2010-06-17 00:00:00 -07:00
|
19
19
|
default_executable: vagrant
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|