Merge branch 'master' of github.com:fgrehm/vagrant-lxc into salt-feature-1
This commit is contained in:
commit
900db67d10
5 changed files with 29 additions and 4 deletions
|
@ -1,5 +1,8 @@
|
||||||
## [0.4.1](https://github.com/fgrehm/vagrant-lxc/compare/v0.4.0...master) (unreleased)
|
## [0.4.1](https://github.com/fgrehm/vagrant-lxc/compare/v0.4.0...master) (unreleased)
|
||||||
|
|
||||||
|
IMPROVEMENTS:
|
||||||
|
|
||||||
|
- Error out if `redir` is not installed but port forwarding was configured [#112](https://github.com/fgrehm/vagrant-lxc/issues/112)
|
||||||
|
|
||||||
## [0.4.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.4...v0.4.0) (Jul 18, 2013)
|
## [0.4.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.4...v0.4.0) (Jul 18, 2013)
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,13 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
@env = 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
|
# Get the ports we're forwarding
|
||||||
env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config)
|
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
|
# Warn if we're port forwarding to any privileged ports
|
||||||
env[:forwarded_ports].each do |fp|
|
env[:forwarded_ports].each do |fp|
|
||||||
if fp[:host] <= 1024
|
if fp[:host] <= 1024
|
||||||
|
@ -24,6 +25,9 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Continue, we need the VM to be booted in order to grab its IP
|
||||||
|
@app.call env
|
||||||
|
|
||||||
if @env[:forwarded_ports].any?
|
if @env[:forwarded_ports].any?
|
||||||
env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
||||||
forward_ports
|
forward_ports
|
||||||
|
@ -79,6 +83,10 @@ module Vagrant
|
||||||
pid_file.write(redir_pid)
|
pid_file.write(redir_pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redir_installed?
|
||||||
|
system "sudo which redir > /dev/null"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,9 @@ module Vagrant
|
||||||
class IncompatibleBox < Vagrant::Errors::VagrantError
|
class IncompatibleBox < Vagrant::Errors::VagrantError
|
||||||
error_key(:lxc_incompatible_box)
|
error_key(:lxc_incompatible_box)
|
||||||
end
|
end
|
||||||
|
class RedirNotInstalled < Vagrant::Errors::VagrantError
|
||||||
|
error_key(:lxc_redir_not_installed)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,3 +44,6 @@ en:
|
||||||
lxc_template_file_missing: |-
|
lxc_template_file_missing: |-
|
||||||
The template file used for creating the container was not found for %{name}
|
The template file used for creating the container was not found for %{name}
|
||||||
box.
|
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(exec: true)
|
||||||
subject.stub(spawn: pid)
|
subject.stub(spawn: pid)
|
||||||
subject.call(env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after { FileUtils.rm_rf data_dir.to_s }
|
after { FileUtils.rm_rf data_dir.to_s }
|
||||||
|
|
||||||
it 'forwards ports using redir' do
|
it 'forwards ports using redir' do
|
||||||
|
subject.stub(system: true)
|
||||||
|
subject.call(env)
|
||||||
subject.should have_received(:spawn).with(
|
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"
|
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "stores redir pids on machine's data dir" do
|
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 = data_dir.join('pids', "redir_#{host_port}.pid").read
|
||||||
pid_file.should == pid
|
pid_file.should == pid
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue