Merge pull request #136 from fgrehm/136-updates-for-vagrant-1.3
Updates for Vagrant 1.3
This commit is contained in:
commit
660fb3f6c4
9 changed files with 65 additions and 45 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
IMPROVEMENTS:
|
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
|
- 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?`
|
installed with the newly added `Vagrant.has_plugin?`
|
||||||
|
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -3,8 +3,7 @@ source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
# FIXME: There are breaking changes on 1.3+
|
gem 'vagrant', github: 'mitchellh/vagrant'
|
||||||
gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.2.7'
|
|
||||||
gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
|
gem 'vagrant-cachier', github: 'fgrehm/vagrant-cachier'
|
||||||
gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
|
gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
|
||||||
gem 'vagrant-omnibus'
|
gem 'vagrant-omnibus'
|
||||||
|
|
|
@ -12,10 +12,9 @@ GIT
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/mitchellh/vagrant.git
|
remote: git://github.com/mitchellh/vagrant.git
|
||||||
revision: 7ec0ee1d00a916f80b109a298bab08e391945243
|
revision: 7b440339f3d801e60e2451823dec04aae772d86a
|
||||||
tag: v1.2.7
|
|
||||||
specs:
|
specs:
|
||||||
vagrant (1.2.7)
|
vagrant (1.3.2.dev)
|
||||||
childprocess (~> 0.3.7)
|
childprocess (~> 0.3.7)
|
||||||
erubis (~> 2.7.0)
|
erubis (~> 2.7.0)
|
||||||
i18n (~> 0.6.0)
|
i18n (~> 0.6.0)
|
||||||
|
|
|
@ -19,6 +19,11 @@ require 'vagrant-lxc/action/remove_temporary_files'
|
||||||
require 'vagrant-lxc/action/setup_package_files'
|
require 'vagrant-lxc/action/setup_package_files'
|
||||||
require 'vagrant-lxc/action/share_folders'
|
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 Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
@ -40,7 +45,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# This action boots the VM, assuming the VM is in a state that requires
|
# This action boots the VM, assuming the VM is in a state that requires
|
||||||
# a bootup (i.e. not saved).
|
# a bootup (i.e. not saved).
|
||||||
def self.action_boot
|
def self.action_boot
|
||||||
|
@ -52,6 +56,7 @@ module Vagrant
|
||||||
b.use Vagrant::Action::Builtin::SetHostname
|
b.use Vagrant::Action::Builtin::SetHostname
|
||||||
b.use ForwardPorts
|
b.use ForwardPorts
|
||||||
b.use Boot
|
b.use Boot
|
||||||
|
b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,6 +151,9 @@ module Vagrant
|
||||||
b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
|
b3.use Vagrant::Action::Builtin::EnvSet, :force_halt => true
|
||||||
b3.use action_halt
|
b3.use action_halt
|
||||||
b3.use Destroy
|
b3.use Destroy
|
||||||
|
if Vagrant::LXC.vagrant_1_3_or_later
|
||||||
|
b3.use Vagrant::Action::Builtin::ProvisionerCleanup
|
||||||
|
end
|
||||||
else
|
else
|
||||||
b3.use Message, :will_not_destroy
|
b3.use Message, :will_not_destroy
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,41 +15,9 @@ module Vagrant
|
||||||
|
|
||||||
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
||||||
env[:machine].provider.driver.start(config.customizations)
|
env[:machine].provider.driver.start(config.customizations)
|
||||||
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
|
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
46
lib/vagrant-lxc/action/wait_for_communicator.rb
Normal file
46
lib/vagrant-lxc/action/wait_for_communicator.rb
Normal 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
|
|
@ -78,7 +78,7 @@ module Vagrant
|
||||||
prune_customizations
|
prune_customizations
|
||||||
write_customizations(customizations + @customizations)
|
write_customizations(customizations + @customizations)
|
||||||
|
|
||||||
@cli.transition_to(:running) { |c| c.start(extra) }
|
@cli.start(extra)
|
||||||
end
|
end
|
||||||
|
|
||||||
def forced_halt
|
def forced_halt
|
||||||
|
@ -109,7 +109,7 @@ module Vagrant
|
||||||
@logger.info "Compressing '#{rootfs_path}' rootfs to #{target_path}"
|
@logger.info "Compressing '#{rootfs_path}' rootfs to #{target_path}"
|
||||||
@sudo_wrapper.run('rm', '-f', 'rootfs.tar.gz')
|
@sudo_wrapper.run('rm', '-f', 'rootfs.tar.gz')
|
||||||
@sudo_wrapper.run('tar', '--numeric-owner', '-czf', target_path, 'rootfs')
|
@sudo_wrapper.run('tar', '--numeric-owner', '-czf', target_path, 'rootfs')
|
||||||
|
|
||||||
@logger.info "Changing rootfs tarball owner"
|
@logger.info "Changing rootfs tarball owner"
|
||||||
|
|
||||||
user_details=Etc.getpwnam(Etc.getlogin)
|
user_details=Etc.getpwnam(Etc.getlogin)
|
||||||
|
|
|
@ -23,5 +23,9 @@ module Vagrant
|
||||||
Config
|
Config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.vagrant_1_3_or_later
|
||||||
|
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.3.0')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,7 +80,6 @@ describe Vagrant::LXC::Driver do
|
||||||
subject { described_class.new('name', sudo, cli) }
|
subject { described_class.new('name', sudo, cli) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
cli.stub(:transition_to).and_yield(cli)
|
|
||||||
subject.customizations << internal_customization
|
subject.customizations << internal_customization
|
||||||
subject.start(customizations)
|
subject.start(customizations)
|
||||||
end
|
end
|
||||||
|
@ -92,10 +91,6 @@ describe Vagrant::LXC::Driver do
|
||||||
it 'starts container with configured customizations' do
|
it 'starts container with configured customizations' do
|
||||||
cli.should have_received(:start)
|
cli.should have_received(:start)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'expects a transition to running state to take place' do
|
|
||||||
cli.should have_received(:transition_to).with(:running)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'halt' do
|
describe 'halt' do
|
||||||
|
|
Loading…
Reference in a new issue