From 2116737989586386473e991394b40ca013cc3df3 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 27 Sep 2013 12:27:25 -0300 Subject: [PATCH] Dont worry about machine state when waiting for communicator [GH-142] [GH-146] --- lib/vagrant-lxc/action.rb | 2 +- .../action/wait_for_communicator.rb | 23 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index fdb486c..08ce0c0 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -56,7 +56,7 @@ module Vagrant b.use Vagrant::Action::Builtin::SetHostname b.use ForwardPorts b.use Boot - b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running] + b.use Vagrant::Action::Builtin::WaitForCommunicator end end diff --git a/lib/vagrant-lxc/action/wait_for_communicator.rb b/lib/vagrant-lxc/action/wait_for_communicator.rb index 2174536..9f8b72f 100644 --- a/lib/vagrant-lxc/action/wait_for_communicator.rb +++ b/lib/vagrant-lxc/action/wait_for_communicator.rb @@ -1,25 +1,25 @@ # This acts like a backport of Vagrant's built in action from 1.3+ for older versions +# and will probably be deprecated on 0.8+ # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb module Vagrant module LXC module Action class WaitForCommunicator - def initialize(app, env, states = []) + def initialize(app, env) @app = app - @states = states end def call(env) @env = env - raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot + + raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator + @app.call env end - # Stolen from the an old version of VagrantPlugins::ProviderVirtualBox::Action::Boot - def wait_for_boot - @env[:ui].info I18n.t("vagrant_lxc.messages.waiting_for_start") - - @env[:machine].config.ssh.max_tries.to_i.times do |i| + def wait_for_communicator + max_tries = @env[:machine].config.ssh.max_tries.to_i + max_tries.times do |i| if @env[:machine].communicate.ready? @env[:ui].info I18n.t("vagrant_lxc.messages.container_ready") return true @@ -29,12 +29,7 @@ module Vagrant # get shown return true if @env[:interrupted] - # If the VM is not starting or running, something went wrong - # and we need to show a useful error. - state = @env[:machine].provider.state.id - raise Vagrant::Errors::VMFailedToRun unless @states.include?(state) - - sleep 2 if !@env["vagrant.test"] + sleep 1 if !@env["vagrant.test"] end @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")