From 7b68802dd2a273b1f34e4b4c27e9882acea13246 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Mar 2013 23:20:52 -0300 Subject: [PATCH] Make sure the machine is accessible when checking for the dhcp ip --- lib/vagrant-lxc/container.rb | 8 ++++++++ spec/support/unit_example_group.rb | 3 +++ 2 files changed, 11 insertions(+) diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index a42a7f3..0aa8981 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -121,6 +121,14 @@ module Vagrant if ip.empty? raise LXC::Errors::ExecuteError, 'Unable to identify container ip' end + + # Sometimes lxc reports the container as running before DNS is returning + # the right IP, so have to try a couple of times sometimes. + # Tks to https://github.com/neerolyte/vagueant/blob/master/bin/vagueant#L318-L330 + r = raw "ping -c 1 #{ip} > /dev/null 2>&1" + if r.exit_code != 0 + raise LXC::Errors::ExecuteError, 'Unable to reach container' + end end ip end diff --git a/spec/support/unit_example_group.rb b/spec/support/unit_example_group.rb index f6751a3..8ba8241 100644 --- a/spec/support/unit_example_group.rb +++ b/spec/support/unit_example_group.rb @@ -5,6 +5,9 @@ module UnitExampleGroup Object.any_instance.stub(:system) { |*args, &block| UnitExampleGroup.prevent_system_calls(*args, &block) } + Object.any_instance.stub(:`) { |*args, &block| + UnitExampleGroup.prevent_system_calls(*args, &block) + } require 'vagrant/util/subprocess' Vagrant::Util::Subprocess.stub(:execute) { |*args, &block| UnitExampleGroup.prevent_system_calls(*args, &block)