From 0eddda3552ba8362c1621f272c9dcb959d803f72 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Aug 2012 18:54:52 -0700 Subject: [PATCH] Halt works with new machine. This required some modifications to the linux guest implementation. And the other guests will have to be modified as well. This is because `channel` is now `communicate`. --- lib/vagrant/plugin/v1/communicator.rb | 9 +++++++++ plugins/communicators/ssh/communicator.rb | 5 +++++ plugins/guests/linux/guest.rb | 22 +++++++++++---------- plugins/providers/virtualbox/action/halt.rb | 4 ++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/vagrant/plugin/v1/communicator.rb b/lib/vagrant/plugin/v1/communicator.rb index 517f3e417..7e4494dc3 100644 --- a/lib/vagrant/plugin/v1/communicator.rb +++ b/lib/vagrant/plugin/v1/communicator.rb @@ -83,6 +83,15 @@ module Vagrant # @see #execute def sudo(command, opts=nil) end + + # Executes a command and returns true if the command succeeded, + # and false otherwise. By default, this executes as a normal user, + # and it is up to the communicator implementation if they expose an + # option for running tests as an administrator. + # + # @see #execute + def test(command, opts=nil) + end end end end diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index a66ee3a33..c268e3b34 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -85,6 +85,11 @@ module VagrantPlugins end end + def test(command, opts=nil) + opts = { :error_check => false }.merge(opts || {}) + execute(command, opts) == 0 + end + def upload(from, to) @logger.debug("Uploading: #{from} to #{to}") diff --git a/plugins/guests/linux/guest.rb b/plugins/guests/linux/guest.rb index 49d40be0c..5033bba9a 100644 --- a/plugins/guests/linux/guest.rb +++ b/plugins/guests/linux/guest.rb @@ -16,23 +16,25 @@ module VagrantPlugins end def distro_dispatch - if @vm.channel.test("cat /etc/debian_version") - return :debian if @vm.channel.test("cat /proc/version | grep 'Debian'") - return :ubuntu if @vm.channel.test("cat /proc/version | grep 'Ubuntu'") - end + @vm.communicate.tap do |comm| + if comm.test("cat /etc/debian_version") == 0 + return :debian if comm.test("cat /proc/version | grep 'Debian'") == 0 + return :ubuntu if comm.test("cat /proc/version | grep 'Ubuntu'") == 0 + end - return :gentoo if @vm.channel.test("cat /etc/gentoo-release") - return :fedora if @vm.channel.test("grep 'Fedora release 16' /etc/redhat-release") - return :redhat if @vm.channel.test("cat /etc/redhat-release") - return :suse if @vm.channel.test("cat /etc/SuSE-release") - return :arch if @vm.channel.test("cat /etc/arch-release") + return :gentoo if comm.test("cat /etc/gentoo-release") == 0 + return :fedora if comm.test("grep 'Fedora release 16' /etc/redhat-release") == 0 + return :redhat if comm.test("cat /etc/redhat-release") == 0 + return :suse if comm.test("cat /etc/SuSE-release") == 0 + return :arch if comm.test("cat /etc/arch-release") == 0 + end # Can't detect the distro, assume vanilla linux nil end def halt - @vm.channel.sudo("shutdown -h now") + @vm.communicate.sudo("shutdown -h now") # Wait until the VM's state is actually powered off. If this doesn't # occur within a reasonable amount of time (15 seconds by default), diff --git a/plugins/providers/virtualbox/action/halt.rb b/plugins/providers/virtualbox/action/halt.rb index 5f339de8e..ed14d0ce0 100644 --- a/plugins/providers/virtualbox/action/halt.rb +++ b/plugins/providers/virtualbox/action/halt.rb @@ -17,9 +17,9 @@ module VagrantPlugins end # If we're not powered off now, then force it - if env[:machine].state != :poweroff + if env[:machine].provider.state != :poweroff env[:ui].info I18n.t("vagrant.actions.vm.halt.force") - env[:machine].driver.halt + env[:machine].provider.halt end # Sleep for a second to verify that the VM properly