From 2064dbf05a64e7b62e015d9b0e4a46679517af27 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 11 Sep 2013 21:44:41 -0300 Subject: [PATCH 1/6] Bump vagrant dependency --- Gemfile | 3 +-- Gemfile.lock | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index cec4d94..36ab7dc 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 7a2dacb..18f7f17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) From f13806626c7a9699428b0e86ac8ca6c8bc6ba2d3 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 11 Sep 2013 21:51:18 -0300 Subject: [PATCH 2/6] Use vagrant 1.3+ ProvisionerCleanup builtin action on destroy --- lib/vagrant-lxc/action.rb | 4 +++- lib/vagrant-lxc/plugin.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 1967595..8a592d3 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -40,7 +40,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 @@ -146,6 +145,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 diff --git a/lib/vagrant-lxc/plugin.rb b/lib/vagrant-lxc/plugin.rb index c3222cc..549a084 100644 --- a/lib/vagrant-lxc/plugin.rb +++ b/lib/vagrant-lxc/plugin.rb @@ -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 From 1da7b60cd80bae4e692ffd1dc5f8663bccdbcd2f Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 11 Sep 2013 22:33:22 -0300 Subject: [PATCH 3/6] "Backport" vagrant 1.3+ WaitForCommunicator action --- .../action/wait_for_communicator.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/vagrant-lxc/action/wait_for_communicator.rb diff --git a/lib/vagrant-lxc/action/wait_for_communicator.rb b/lib/vagrant-lxc/action/wait_for_communicator.rb new file mode 100644 index 0000000..2174536 --- /dev/null +++ b/lib/vagrant-lxc/action/wait_for_communicator.rb @@ -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 From 791a93fe9e92e3b562943bf66433381b42df8ef8 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 12 Sep 2013 01:10:11 -0300 Subject: [PATCH 4/6] Make use of the new WaitForCommunicator action on boot --- lib/vagrant-lxc/action.rb | 6 ++++++ lib/vagrant-lxc/action/boot.rb | 32 -------------------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 8a592d3..cd0c081 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -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 @@ -51,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 diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 9edb163..e6b162b 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -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 From cf73a843d0bdb3d03ef88d2206733038af002880 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 12 Sep 2013 01:12:07 -0300 Subject: [PATCH 5/6] Do not worry about transition to running state when starting a container, this is handled from outside --- lib/vagrant-lxc/driver.rb | 4 ++-- spec/unit/driver_spec.rb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index ed7b530..aa1133b 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -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 @@ -109,7 +109,7 @@ module Vagrant @logger.info "Compressing '#{rootfs_path}' rootfs to #{target_path}" @sudo_wrapper.run('rm', '-f', 'rootfs.tar.gz') @sudo_wrapper.run('tar', '--numeric-owner', '-czf', target_path, 'rootfs') - + @logger.info "Changing rootfs tarball owner" user_details=Etc.getpwnam(Etc.getlogin) diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index ab52f05..f54e1d6 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -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 From e4ee20c7ada4961c070b4a201cc4033588a33423 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 12 Sep 2013 01:13:36 -0300 Subject: [PATCH 6/6] Say hi to Vagrant 1.3+ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0e052..1472535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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?`