From 6b705cbe42c3973243cb3ef2eba0960044f06b05 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 22 Feb 2010 16:35:22 -0800 Subject: [PATCH] Change `vm` attribute to be `runner` on action base to reflect what it now is. --- lib/vagrant/actions/base.rb | 6 +++--- lib/vagrant/actions/box/download.rb | 10 ++++++++++ lib/vagrant/actions/vm/export.rb | 2 +- lib/vagrant/actions/vm/forward_ports.rb | 6 +++--- lib/vagrant/actions/vm/import.rb | 4 ++-- lib/vagrant/actions/vm/move_hard_drive.rb | 6 +++--- lib/vagrant/actions/vm/reload.rb | 2 +- lib/vagrant/actions/vm/shared_folders.rb | 6 +++--- lib/vagrant/actions/vm/start.rb | 4 ++-- lib/vagrant/actions/vm/stop.rb | 2 +- lib/vagrant/actions/vm/up.rb | 12 ++++++------ test/vagrant/actions/base_test.rb | 4 ++-- test/vagrant/actions/box/download_test.rb | 8 ++++++++ 13 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 lib/vagrant/actions/box/download.rb create mode 100644 test/vagrant/actions/box/download_test.rb diff --git a/lib/vagrant/actions/base.rb b/lib/vagrant/actions/base.rb index e621cd8cc..e6bd4e995 100644 --- a/lib/vagrant/actions/base.rb +++ b/lib/vagrant/actions/base.rb @@ -5,7 +5,7 @@ module Vagrant # action should define any callbacks that it will call, or # attach itself to some callbacks on the VM object. class Base - attr_reader :vm + attr_reader :runner # Included so subclasses don't need to include it themselves. include Vagrant::Util @@ -17,8 +17,8 @@ module Vagrant # would be instance_evaling the vm instance to include a module so # additionally functionality could be defined on the vm which other # action `prepare` methods may rely on. - def initialize(vm, *args) - @vm = vm + def initialize(runner, *args) + @runner = runner end # This method is called once per action, allowing the action diff --git a/lib/vagrant/actions/box/download.rb b/lib/vagrant/actions/box/download.rb new file mode 100644 index 000000000..edb41a429 --- /dev/null +++ b/lib/vagrant/actions/box/download.rb @@ -0,0 +1,10 @@ +module Vagrant + module Actions + module Box + # An action which acts on a box by downloading the box file from + # the given URI into a temporary location. + class Download < Base + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant/actions/vm/export.rb b/lib/vagrant/actions/vm/export.rb index 493cd6e9d..1a1efaeb2 100644 --- a/lib/vagrant/actions/vm/export.rb +++ b/lib/vagrant/actions/vm/export.rb @@ -9,7 +9,7 @@ module Vagrant ovf_path = File.join(folder, "#{name}.ovf") logger.info "Exporting required VM files to directory: #{folder} ..." - @vm.export(ovf_path) + @runner.export(ovf_path) end end end diff --git a/lib/vagrant/actions/vm/forward_ports.rb b/lib/vagrant/actions/vm/forward_ports.rb index 232a5d587..ab8733662 100644 --- a/lib/vagrant/actions/vm/forward_ports.rb +++ b/lib/vagrant/actions/vm/forward_ports.rb @@ -9,7 +9,7 @@ module Vagrant def clear logger.info "Deleting any previously set forwarded ports..." - @vm.vm.forwarded_ports.collect { |p| p.destroy(true) } + @runner.vm.forwarded_ports.collect { |p| p.destroy(true) } end def forward_ports @@ -21,10 +21,10 @@ module Vagrant port.name = name port.hostport = options[:hostport] port.guestport = options[:guestport] - @vm.vm.forwarded_ports << port + @runner.vm.forwarded_ports << port end - @vm.vm.save(true) + @runner.vm.save(true) end end end diff --git a/lib/vagrant/actions/vm/import.rb b/lib/vagrant/actions/vm/import.rb index ea0d0d509..df9e2d459 100644 --- a/lib/vagrant/actions/vm/import.rb +++ b/lib/vagrant/actions/vm/import.rb @@ -10,11 +10,11 @@ module Vagrant end def execute! - @vm.invoke_around_callback(:import) do + @runner.invoke_around_callback(:import) do Busy.busy do logger.info "Importing base VM (#{@ovf_file})..." # Use the first argument passed to the action - @vm.vm = VirtualBox::VM.import(@ovf_file) + @runner.vm = VirtualBox::VM.import(@ovf_file) end end end diff --git a/lib/vagrant/actions/vm/move_hard_drive.rb b/lib/vagrant/actions/vm/move_hard_drive.rb index 16fa29e18..0d5b967d5 100644 --- a/lib/vagrant/actions/vm/move_hard_drive.rb +++ b/lib/vagrant/actions/vm/move_hard_drive.rb @@ -3,7 +3,7 @@ module Vagrant module VM class MoveHardDrive < Base def execute! - unless @vm.powered_off? + unless @runner.powered_off? error_and_exit(<<-error) The virtual machine must be powered off to move its disk. error @@ -19,7 +19,7 @@ error # TODO won't work if the first disk is not the boot disk or even if there are multiple disks def find_hard_drive - @vm.storage_controllers.each do |sc| + @runner.storage_controllers.each do |sc| sc.devices.each do |d| return d if d.image.is_a?(VirtualBox::HardDrive) end @@ -31,7 +31,7 @@ error hard_drive.image = hard_drive.image.clone(new_image_path, Vagrant.config.vm.disk_image_format, true) logger.info "Attaching new disk to VM ..." - @vm.vm.save + @runner.vm.save end def destroy_drive_after diff --git a/lib/vagrant/actions/vm/reload.rb b/lib/vagrant/actions/vm/reload.rb index e1516d178..8e6357a0f 100644 --- a/lib/vagrant/actions/vm/reload.rb +++ b/lib/vagrant/actions/vm/reload.rb @@ -7,7 +7,7 @@ module Vagrant steps << Provision if Vagrant.config.chef.enabled steps.each do |action_klass| - @vm.add_action(action_klass) + @runner.add_action(action_klass) end end end diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index 44fbd9db1..81c0db5a9 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -3,7 +3,7 @@ module Vagrant module VM class SharedFolders < Base def shared_folders - shared_folders = @vm.invoke_callback(:collect_shared_folders) + shared_folders = @runner.invoke_callback(:collect_shared_folders) # Basic filtering of shared folders. Basically only verifies that # the result is an array of 3 elements. In the future this should @@ -25,10 +25,10 @@ module Vagrant folder = VirtualBox::SharedFolder.new folder.name = name folder.hostpath = hostpath - @vm.vm.shared_folders << folder + @runner.vm.shared_folders << folder end - @vm.vm.save(true) + @runner.vm.save(true) end def after_boot diff --git a/lib/vagrant/actions/vm/start.rb b/lib/vagrant/actions/vm/start.rb index 7d564ecdb..681adc1d4 100644 --- a/lib/vagrant/actions/vm/start.rb +++ b/lib/vagrant/actions/vm/start.rb @@ -3,7 +3,7 @@ module Vagrant module VM class Start < Base def execute! - @vm.invoke_around_callback(:boot) do + @runner.invoke_around_callback(:boot) do # Startup the VM boot @@ -19,7 +19,7 @@ error def boot logger.info "Booting VM..." - @vm.vm.start(:headless, true) + @runner.vm.start(:headless, true) end def wait_for_boot(sleeptime=5) diff --git a/lib/vagrant/actions/vm/stop.rb b/lib/vagrant/actions/vm/stop.rb index 25c07d5ff..32e84efaa 100644 --- a/lib/vagrant/actions/vm/stop.rb +++ b/lib/vagrant/actions/vm/stop.rb @@ -4,7 +4,7 @@ module Vagrant class Stop < Base def execute! logger.info "Forcing shutdown of VM..." - @vm.vm.stop(true) + @runner.vm.stop(true) end end end diff --git a/lib/vagrant/actions/vm/up.rb b/lib/vagrant/actions/vm/up.rb index a97c630df..e6a69cc35 100644 --- a/lib/vagrant/actions/vm/up.rb +++ b/lib/vagrant/actions/vm/up.rb @@ -11,14 +11,14 @@ module Vagrant def prepare # Up is a "meta-action" so it really just queues up a bunch # of other actions in its place: - @vm.add_action(Import, @ovf_file) + @runner.add_action(Import, @ovf_file) steps = [ForwardPorts, SharedFolders, Start] steps << Provision if Vagrant.config.chef.enabled steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location steps.each do |action_klass| - @vm.add_action(action_klass) + @runner.add_action(action_klass) end end @@ -33,14 +33,14 @@ module Vagrant end def persist - logger.info "Persisting the VM UUID (#{@vm.vm.uuid})..." - Env.persist_vm(@vm.vm) + logger.info "Persisting the VM UUID (#{@runner.vm.uuid})..." + Env.persist_vm(@runner.vm) end def setup_mac_address logger.info "Matching MAC addresses..." - @vm.vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac] - @vm.vm.save(true) + @runner.vm.nics.first.macaddress = Vagrant.config[:vm][:base_mac] + @runner.vm.save(true) end end end diff --git a/test/vagrant/actions/base_test.rb b/test/vagrant/actions/base_test.rb index 996bc3e09..5404f9d92 100644 --- a/test/vagrant/actions/base_test.rb +++ b/test/vagrant/actions/base_test.rb @@ -11,8 +11,8 @@ class BaseActionTest < Test::Unit::TestCase @base = Vagrant::Actions::Base.new(@mock_vm) end - should "allow read-only access to the VM" do - assert_equal @mock_vm, @base.vm + should "allow read-only access to the runner" do + assert_equal @mock_vm, @base.runner end should "implement prepare which does nothing" do diff --git a/test/vagrant/actions/box/download_test.rb b/test/vagrant/actions/box/download_test.rb new file mode 100644 index 000000000..2fea16e29 --- /dev/null +++ b/test/vagrant/actions/box/download_test.rb @@ -0,0 +1,8 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') + +class DownloadBoxActionTest < Test::Unit::TestCase + setup do + @wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Box::Download) + mock_config + end +end