Merge branch 'check-for-redir' of https://github.com/zeroem/vagrant-lxc
This commit is contained in:
commit
ee37b9e2e7
4 changed files with 26 additions and 4 deletions
|
@ -10,12 +10,13 @@ module Vagrant
|
|||
def call(env)
|
||||
@env = env
|
||||
|
||||
# Continue, we need the VM to be booted in order to grab its IP
|
||||
@app.call env
|
||||
|
||||
# Get the ports we're forwarding
|
||||
env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config)
|
||||
|
||||
if @env[:forwarded_ports].any? and not redir_installed?
|
||||
raise Errors::RedirNotInstalled
|
||||
end
|
||||
|
||||
# Warn if we're port forwarding to any privileged ports
|
||||
env[:forwarded_ports].each do |fp|
|
||||
if fp[:host] <= 1024
|
||||
|
@ -24,6 +25,9 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# Continue, we need the VM to be booted in order to grab its IP
|
||||
@app.call env
|
||||
|
||||
if @env[:forwarded_ports].any?
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
||||
forward_ports
|
||||
|
@ -79,6 +83,10 @@ module Vagrant
|
|||
pid_file.write(redir_pid)
|
||||
end
|
||||
end
|
||||
|
||||
def redir_installed?
|
||||
system "sudo which redir > /dev/null"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,9 @@ module Vagrant
|
|||
class IncompatibleBox < Vagrant::Errors::VagrantError
|
||||
error_key(:lxc_incompatible_box)
|
||||
end
|
||||
class RedirNotInstalled < Vagrant::Errors::VagrantError
|
||||
error_key(:lxc_redir_not_installed)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,3 +44,6 @@ en:
|
|||
lxc_template_file_missing: |-
|
||||
The template file used for creating the container was not found for %{name}
|
||||
box.
|
||||
|
||||
lxc_redir_not_installed: |-
|
||||
`redir` is not installed or is not accessible on the PATH.
|
||||
|
|
|
@ -23,19 +23,27 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
|||
|
||||
subject.stub(exec: true)
|
||||
subject.stub(spawn: pid)
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
after { FileUtils.rm_rf data_dir.to_s }
|
||||
|
||||
it 'forwards ports using redir' do
|
||||
subject.stub(system: true)
|
||||
subject.call(env)
|
||||
subject.should have_received(:spawn).with(
|
||||
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
|
||||
)
|
||||
end
|
||||
|
||||
it "stores redir pids on machine's data dir" do
|
||||
subject.stub(system: true)
|
||||
subject.call(env)
|
||||
pid_file = data_dir.join('pids', "redir_#{host_port}.pid").read
|
||||
pid_file.should == pid
|
||||
end
|
||||
|
||||
it 'raises RedirNotInstalled error if `redir` is not installed' do
|
||||
subject.stub(system: false)
|
||||
lambda { subject.call(env) }.should raise_error(Vagrant::LXC::Errors::RedirNotInstalled)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue