Merge pull request #136 from fgrehm/136-updates-for-vagrant-1.3

Updates for Vagrant 1.3
This commit is contained in:
Fabio Rehm 2013-09-11 21:17:01 -07:00
commit 660fb3f6c4
9 changed files with 65 additions and 45 deletions

View file

@ -2,6 +2,7 @@
IMPROVEMENTS:
- Compatibility with Vagrant 1.3+ [#136](https://github.com/fgrehm/vagrant-lxc/pull/136)
- Set plugin name to `vagrant-lxc` so that it is easier to check if the plugin is
installed with the newly added `Vagrant.has_plugin?`

View file

@ -3,8 +3,7 @@ source 'https://rubygems.org'
gemspec
group :development do
# FIXME: There are breaking changes on 1.3+
gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.2.7'
gem 'vagrant', github: 'mitchellh/vagrant'
gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
gem 'vagrant-omnibus'

View file

@ -12,10 +12,9 @@ GIT
GIT
remote: git://github.com/mitchellh/vagrant.git
revision: 7ec0ee1d00a916f80b109a298bab08e391945243
tag: v1.2.7
revision: 7b440339f3d801e60e2451823dec04aae772d86a
specs:
vagrant (1.2.7)
vagrant (1.3.2.dev)
childprocess (~> 0.3.7)
erubis (~> 2.7.0)
i18n (~> 0.6.0)

View file

@ -19,6 +19,11 @@ require 'vagrant-lxc/action/remove_temporary_files'
require 'vagrant-lxc/action/setup_package_files'
require 'vagrant-lxc/action/share_folders'
unless Vagrant::LXC.vagrant_1_3_or_later
require 'vagrant-lxc/action/wait_for_communicator'
Vagrant::Action::Builtin.const_set :WaitForCommunicator, Vagrant::LXC::Action::WaitForCommunicator
end
module Vagrant
module LXC
module Action
@ -40,7 +45,6 @@ module Vagrant
end
end
# This action boots the VM, assuming the VM is in a state that requires
# a bootup (i.e. not saved).
def self.action_boot
@ -52,6 +56,7 @@ module Vagrant
b.use Vagrant::Action::Builtin::SetHostname
b.use ForwardPorts
b.use Boot
b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running]
end
end
@ -146,6 +151,9 @@ module Vagrant
b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
b3.use action_halt
b3.use Destroy
if Vagrant::LXC.vagrant_1_3_or_later
b3.use Vagrant::Action::Builtin::ProvisionerCleanup
end
else
b3.use Message, :will_not_destroy
end

View file

@ -15,41 +15,9 @@ module Vagrant
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
env[:machine].provider.driver.start(config.customizations)
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
@app.call env
end
# Stolen from on 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|
if @env[:machine].communicate.ready?
@env[:ui].info I18n.t("vagrant_lxc.messages.container_ready")
return true
end
# Return true so that the vm_failed_to_boot error doesn't
# get shown
return true if @env[:interrupted]
# TODO: Find out if there is a command to check if the machine is
# starting, `lxc-monitor` shows this information, but I've
# never seen it on `lxc-info` which is what it is being used
# to determine container status
# 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 if state != :starting && state != :running
sleep 2 if !@env["vagrant.test"]
end
@env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
false
end
end
end
end

View file

@ -0,0 +1,46 @@
# This acts like a backport of Vagrant's built in action from 1.3+ for older versions
# 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 = [])
@app = app
@states = states
end
def call(env)
@env = env
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
@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|
if @env[:machine].communicate.ready?
@env[:ui].info I18n.t("vagrant_lxc.messages.container_ready")
return true
end
# Return true so that the vm_failed_to_boot error doesn't
# 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"]
end
@env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
false
end
end
end
end
end

View file

@ -78,7 +78,7 @@ module Vagrant
prune_customizations
write_customizations(customizations + @customizations)
@cli.transition_to(:running) { |c| c.start(extra) }
@cli.start(extra)
end
def forced_halt

View file

@ -23,5 +23,9 @@ module Vagrant
Config
end
end
def self.vagrant_1_3_or_later
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.3.0')
end
end
end

View file

@ -80,7 +80,6 @@ describe Vagrant::LXC::Driver do
subject { described_class.new('name', sudo, cli) }
before do
cli.stub(:transition_to).and_yield(cli)
subject.customizations << internal_customization
subject.start(customizations)
end
@ -92,10 +91,6 @@ describe Vagrant::LXC::Driver do
it 'starts container with configured customizations' do
cli.should have_received(:start)
end
it 'expects a transition to running state to take place' do
cli.should have_received(:transition_to).with(:running)
end
end
describe 'halt' do