Moved VM actions into the Actions::VM namespace.
This commit is contained in:
parent
f60b383b75
commit
35762a4308
|
@ -1,15 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Export < Base
|
|
||||||
def execute!(name=Vagrant.config.package.name, to=FileUtils.pwd)
|
|
||||||
folder = FileUtils.mkpath(File.join(to, name))
|
|
||||||
|
|
||||||
logger.info "Creating export directory: #{folder} ..."
|
|
||||||
ovf_path = File.join(folder, "#{name}.ovf")
|
|
||||||
|
|
||||||
logger.info "Exporting required VM files to directory: #{folder} ..."
|
|
||||||
@vm.export(ovf_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,30 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class ForwardPorts < Base
|
|
||||||
def execute!
|
|
||||||
clear
|
|
||||||
forward_ports
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear
|
|
||||||
logger.info "Deleting any previously set forwarded ports..."
|
|
||||||
@vm.vm.forwarded_ports.collect { |p| p.destroy(true) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def forward_ports
|
|
||||||
logger.info "Forwarding ports..."
|
|
||||||
|
|
||||||
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
|
||||||
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
|
||||||
port = VirtualBox::ForwardedPort.new
|
|
||||||
port.name = name
|
|
||||||
port.hostport = options[:hostport]
|
|
||||||
port.guestport = options[:guestport]
|
|
||||||
@vm.vm.forwarded_ports << port
|
|
||||||
end
|
|
||||||
|
|
||||||
@vm.vm.save(true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,22 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Import < Base
|
|
||||||
attr_accessor :ovf_file
|
|
||||||
#First arg should be the ovf_file location for import
|
|
||||||
def initialize(vm, *args)
|
|
||||||
super vm
|
|
||||||
@ovf_file = File.expand_path(args[0] || Vagrant.config[:vm][:base])
|
|
||||||
end
|
|
||||||
|
|
||||||
def execute!
|
|
||||||
@vm.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)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,51 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class MoveHardDrive < Base
|
|
||||||
def execute!
|
|
||||||
unless @vm.powered_off?
|
|
||||||
error_and_exit(<<-error)
|
|
||||||
The virtual machine must be powered off to move its disk.
|
|
||||||
error
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
destroy_drive_after { clone_and_attach }
|
|
||||||
end
|
|
||||||
|
|
||||||
def hard_drive
|
|
||||||
@hard_drive ||= find_hard_drive
|
|
||||||
end
|
|
||||||
|
|
||||||
# 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|
|
|
||||||
sc.devices.each do |d|
|
|
||||||
return d if d.image.is_a?(VirtualBox::HardDrive)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def clone_and_attach
|
|
||||||
logger.info "Cloning current VM Disk to new location (#{new_image_path})..."
|
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy_drive_after
|
|
||||||
old_image = hard_drive.image
|
|
||||||
|
|
||||||
yield
|
|
||||||
|
|
||||||
logger.info "Destroying old VM Disk (#{old_image.filename})..."
|
|
||||||
old_image.destroy(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the path to the new location for the hard drive
|
|
||||||
def new_image_path
|
|
||||||
File.join(Vagrant.config.vm.hd_location, hard_drive.image.filename)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,48 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Package < Base
|
|
||||||
attr_accessor :name, :to
|
|
||||||
|
|
||||||
def initialize(vm, *args)
|
|
||||||
super vm
|
|
||||||
@name = args[0]
|
|
||||||
@to = args[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def execute!
|
|
||||||
logger.info "Packaging VM into #{tar_path} ..."
|
|
||||||
compress
|
|
||||||
|
|
||||||
logger.info "Removing working directory ..."
|
|
||||||
clean
|
|
||||||
|
|
||||||
tar_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def clean
|
|
||||||
FileUtils.rm_r(working_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
def working_dir
|
|
||||||
FileUtils.mkpath(File.join(@to, @name))
|
|
||||||
end
|
|
||||||
|
|
||||||
def tar_path
|
|
||||||
"#{working_dir}#{Vagrant.config.package.extension}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def compress
|
|
||||||
Tar.open(tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU) do |tar|
|
|
||||||
begin
|
|
||||||
# Append tree will append the entire directory tree unless a relative folder reference is used
|
|
||||||
current_dir = FileUtils.pwd
|
|
||||||
FileUtils.cd(@to)
|
|
||||||
tar.append_tree(@name)
|
|
||||||
ensure
|
|
||||||
FileUtils.cd(current_dir)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,57 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Provision < Base
|
|
||||||
|
|
||||||
def execute!
|
|
||||||
chown_provisioning_folder
|
|
||||||
setup_json
|
|
||||||
setup_solo_config
|
|
||||||
run_chef_solo
|
|
||||||
end
|
|
||||||
|
|
||||||
def chown_provisioning_folder
|
|
||||||
logger.info "Setting permissions on provisioning folder..."
|
|
||||||
SSH.execute do |ssh|
|
|
||||||
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_json
|
|
||||||
logger.info "Generating JSON and uploading..."
|
|
||||||
|
|
||||||
json = { :project_directory => Vagrant.config.vm.project_directory }.merge(Vagrant.config.chef.json).to_json
|
|
||||||
|
|
||||||
SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_solo_config
|
|
||||||
solo_file = <<-solo
|
|
||||||
file_cache_path "#{Vagrant.config.chef.provisioning_path}"
|
|
||||||
cookbook_path "#{cookbooks_path}"
|
|
||||||
solo
|
|
||||||
|
|
||||||
logger.info "Uploading chef-solo configuration script..."
|
|
||||||
SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "solo.rb"))
|
|
||||||
end
|
|
||||||
|
|
||||||
def run_chef_solo
|
|
||||||
logger.info "Running chef recipes..."
|
|
||||||
SSH.execute do |ssh|
|
|
||||||
ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
|
|
||||||
# TODO: Very verbose. It would be easier to save the data and only show it during
|
|
||||||
# an error, or when verbosity level is set high
|
|
||||||
logger.info("#{stream}: #{data}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def cookbooks_path
|
|
||||||
File.join(Vagrant.config.chef.provisioning_path, "cookbooks")
|
|
||||||
end
|
|
||||||
|
|
||||||
def collect_shared_folders
|
|
||||||
["vagrant-provisioning", File.expand_path(Vagrant.config.chef.cookbooks_path, Env.root_path), cookbooks_path]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,14 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Reload < Base
|
|
||||||
def prepare
|
|
||||||
steps = [Stop, ForwardPorts, SharedFolders, Start]
|
|
||||||
steps << Provision if Vagrant.config.chef.enabled
|
|
||||||
|
|
||||||
steps.each do |action_klass|
|
|
||||||
@vm.add_action(action_klass)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,47 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class SharedFolders < Base
|
|
||||||
def shared_folders
|
|
||||||
shared_folders = @vm.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
|
|
||||||
# also verify that the host path exists, the name is valid,
|
|
||||||
# and that the guest path is valid.
|
|
||||||
shared_folders.collect do |folder|
|
|
||||||
if folder.is_a?(Array) && folder.length == 3
|
|
||||||
folder
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end.compact
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_boot
|
|
||||||
logger.info "Creating shared folders metadata..."
|
|
||||||
|
|
||||||
shared_folders.each do |name, hostpath, guestpath|
|
|
||||||
folder = VirtualBox::SharedFolder.new
|
|
||||||
folder.name = name
|
|
||||||
folder.hostpath = hostpath
|
|
||||||
@vm.vm.shared_folders << folder
|
|
||||||
end
|
|
||||||
|
|
||||||
@vm.vm.save(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_boot
|
|
||||||
logger.info "Mounting shared folders..."
|
|
||||||
|
|
||||||
Vagrant::SSH.execute do |ssh|
|
|
||||||
shared_folders.each do |name, hostpath, guestpath|
|
|
||||||
logger.info "-- #{name}: #{guestpath}"
|
|
||||||
ssh.exec!("sudo mkdir -p #{guestpath}")
|
|
||||||
ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}")
|
|
||||||
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{guestpath}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,43 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Start < Base
|
|
||||||
def execute!
|
|
||||||
@vm.invoke_around_callback(:boot) do
|
|
||||||
# Startup the VM
|
|
||||||
boot
|
|
||||||
|
|
||||||
# Wait for it to complete booting, or error if we could
|
|
||||||
# never detect it booted up successfully
|
|
||||||
if !wait_for_boot
|
|
||||||
error_and_exit(<<-error)
|
|
||||||
Failed to connect to VM! Failed to boot?
|
|
||||||
error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def boot
|
|
||||||
logger.info "Booting VM..."
|
|
||||||
@vm.vm.start(:headless, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
def wait_for_boot(sleeptime=5)
|
|
||||||
logger.info "Waiting for VM to boot..."
|
|
||||||
|
|
||||||
Vagrant.config[:ssh][:max_tries].to_i.times do |i|
|
|
||||||
logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
|
|
||||||
|
|
||||||
if Vagrant::SSH.up?
|
|
||||||
logger.info "VM booted and ready for use!"
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep sleeptime
|
|
||||||
end
|
|
||||||
|
|
||||||
logger.info "Failed to connect to VM! Failed to boot?"
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,10 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Stop < Base
|
|
||||||
def execute!
|
|
||||||
logger.info "Forcing shutdown of VM..."
|
|
||||||
@vm.vm.stop(true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,54 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Unpackage < Base
|
|
||||||
TAR_OPTIONS = [File::RDONLY, 0644, Tar::GNU]
|
|
||||||
attr_accessor :package_file_path
|
|
||||||
|
|
||||||
def initialize(vm, *args)
|
|
||||||
super vm
|
|
||||||
@package_file_path = args[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
def execute!
|
|
||||||
# Exit if folder of same name exists
|
|
||||||
# TODO provide a way for them to specify the directory name
|
|
||||||
error_and_exit(<<-error) if File.exists?(new_base_dir)
|
|
||||||
The directory `#{file_name_without_extension}` already exists under #{Vagrant.config[:vagrant][:home]}. Please
|
|
||||||
remove it, rename your packaged VM file, or (TODO) specifiy an
|
|
||||||
alternate directory
|
|
||||||
error
|
|
||||||
|
|
||||||
logger.info "Decompressing the packaged VM: #{package_file_path} to: #{working_dir}..."
|
|
||||||
decompress
|
|
||||||
|
|
||||||
logger.info "Moving decompressed files in: #{working_dir} to: #{new_base_dir} ..."
|
|
||||||
FileUtils.mv(working_dir, new_base_dir)
|
|
||||||
|
|
||||||
#Return the ovf file for importation
|
|
||||||
Dir["#{new_base_dir}/*.ovf"].first
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_base_dir
|
|
||||||
File.join(Vagrant.config.vagrant.home, file_name_without_extension)
|
|
||||||
end
|
|
||||||
|
|
||||||
def file_name_without_extension
|
|
||||||
File.basename(package_file_path, '.*')
|
|
||||||
end
|
|
||||||
|
|
||||||
def working_dir
|
|
||||||
package_file_path.chomp(File.extname(package_file_path))
|
|
||||||
end
|
|
||||||
|
|
||||||
def package_file_path
|
|
||||||
File.expand_path(@package_file_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def decompress
|
|
||||||
Tar.open(package_file_path, *TAR_OPTIONS) do |tar|
|
|
||||||
tar.extract_all
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,46 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Actions
|
|
||||||
class Up < Base
|
|
||||||
#First arg should be the ovf_file location for import
|
|
||||||
def initialize(vm, *args)
|
|
||||||
super vm
|
|
||||||
@ovf_file = args[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def collect_shared_folders
|
|
||||||
# The root shared folder for the project
|
|
||||||
["vagrant-root", Env.root_path, Vagrant.config.vm.project_directory]
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_import
|
|
||||||
persist
|
|
||||||
setup_mac_address
|
|
||||||
end
|
|
||||||
|
|
||||||
def persist
|
|
||||||
logger.info "Persisting the VM UUID (#{@vm.vm.uuid})..."
|
|
||||||
Env.persist_vm(@vm.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)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Export < Base
|
||||||
|
def execute!(name=Vagrant.config.package.name, to=FileUtils.pwd)
|
||||||
|
folder = FileUtils.mkpath(File.join(to, name))
|
||||||
|
|
||||||
|
logger.info "Creating export directory: #{folder} ..."
|
||||||
|
ovf_path = File.join(folder, "#{name}.ovf")
|
||||||
|
|
||||||
|
logger.info "Exporting required VM files to directory: #{folder} ..."
|
||||||
|
@vm.export(ovf_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,32 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class ForwardPorts < Base
|
||||||
|
def execute!
|
||||||
|
clear
|
||||||
|
forward_ports
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear
|
||||||
|
logger.info "Deleting any previously set forwarded ports..."
|
||||||
|
@vm.vm.forwarded_ports.collect { |p| p.destroy(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def forward_ports
|
||||||
|
logger.info "Forwarding ports..."
|
||||||
|
|
||||||
|
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
||||||
|
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
||||||
|
port = VirtualBox::ForwardedPort.new
|
||||||
|
port.name = name
|
||||||
|
port.hostport = options[:hostport]
|
||||||
|
port.guestport = options[:guestport]
|
||||||
|
@vm.vm.forwarded_ports << port
|
||||||
|
end
|
||||||
|
|
||||||
|
@vm.vm.save(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,24 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Import < Base
|
||||||
|
attr_accessor :ovf_file
|
||||||
|
#First arg should be the ovf_file location for import
|
||||||
|
def initialize(vm, *args)
|
||||||
|
super vm
|
||||||
|
@ovf_file = File.expand_path(args[0] || Vagrant.config[:vm][:base])
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute!
|
||||||
|
@vm.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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,53 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class MoveHardDrive < Base
|
||||||
|
def execute!
|
||||||
|
unless @vm.powered_off?
|
||||||
|
error_and_exit(<<-error)
|
||||||
|
The virtual machine must be powered off to move its disk.
|
||||||
|
error
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
destroy_drive_after { clone_and_attach }
|
||||||
|
end
|
||||||
|
|
||||||
|
def hard_drive
|
||||||
|
@hard_drive ||= find_hard_drive
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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|
|
||||||
|
sc.devices.each do |d|
|
||||||
|
return d if d.image.is_a?(VirtualBox::HardDrive)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clone_and_attach
|
||||||
|
logger.info "Cloning current VM Disk to new location (#{new_image_path})..."
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy_drive_after
|
||||||
|
old_image = hard_drive.image
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
logger.info "Destroying old VM Disk (#{old_image.filename})..."
|
||||||
|
old_image.destroy(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the path to the new location for the hard drive
|
||||||
|
def new_image_path
|
||||||
|
File.join(Vagrant.config.vm.hd_location, hard_drive.image.filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,50 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Package < Base
|
||||||
|
attr_accessor :name, :to
|
||||||
|
|
||||||
|
def initialize(vm, *args)
|
||||||
|
super vm
|
||||||
|
@name = args[0]
|
||||||
|
@to = args[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute!
|
||||||
|
logger.info "Packaging VM into #{tar_path} ..."
|
||||||
|
compress
|
||||||
|
|
||||||
|
logger.info "Removing working directory ..."
|
||||||
|
clean
|
||||||
|
|
||||||
|
tar_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean
|
||||||
|
FileUtils.rm_r(working_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
def working_dir
|
||||||
|
FileUtils.mkpath(File.join(@to, @name))
|
||||||
|
end
|
||||||
|
|
||||||
|
def tar_path
|
||||||
|
"#{working_dir}#{Vagrant.config.package.extension}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def compress
|
||||||
|
Tar.open(tar_path, File::CREAT | File::WRONLY, 0644, Tar::GNU) do |tar|
|
||||||
|
begin
|
||||||
|
# Append tree will append the entire directory tree unless a relative folder reference is used
|
||||||
|
current_dir = FileUtils.pwd
|
||||||
|
FileUtils.cd(@to)
|
||||||
|
tar.append_tree(@name)
|
||||||
|
ensure
|
||||||
|
FileUtils.cd(current_dir)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,58 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Provision < Base
|
||||||
|
def execute!
|
||||||
|
chown_provisioning_folder
|
||||||
|
setup_json
|
||||||
|
setup_solo_config
|
||||||
|
run_chef_solo
|
||||||
|
end
|
||||||
|
|
||||||
|
def chown_provisioning_folder
|
||||||
|
logger.info "Setting permissions on provisioning folder..."
|
||||||
|
SSH.execute do |ssh|
|
||||||
|
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_json
|
||||||
|
logger.info "Generating JSON and uploading..."
|
||||||
|
|
||||||
|
json = { :project_directory => Vagrant.config.vm.project_directory }.merge(Vagrant.config.chef.json).to_json
|
||||||
|
|
||||||
|
SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup_solo_config
|
||||||
|
solo_file = <<-solo
|
||||||
|
file_cache_path "#{Vagrant.config.chef.provisioning_path}"
|
||||||
|
cookbook_path "#{cookbooks_path}"
|
||||||
|
solo
|
||||||
|
|
||||||
|
logger.info "Uploading chef-solo configuration script..."
|
||||||
|
SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "solo.rb"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_chef_solo
|
||||||
|
logger.info "Running chef recipes..."
|
||||||
|
SSH.execute do |ssh|
|
||||||
|
ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
|
||||||
|
# TODO: Very verbose. It would be easier to save the data and only show it during
|
||||||
|
# an error, or when verbosity level is set high
|
||||||
|
logger.info("#{stream}: #{data}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cookbooks_path
|
||||||
|
File.join(Vagrant.config.chef.provisioning_path, "cookbooks")
|
||||||
|
end
|
||||||
|
|
||||||
|
def collect_shared_folders
|
||||||
|
["vagrant-provisioning", File.expand_path(Vagrant.config.chef.cookbooks_path, Env.root_path), cookbooks_path]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Reload < Base
|
||||||
|
def prepare
|
||||||
|
steps = [Stop, ForwardPorts, SharedFolders, Start]
|
||||||
|
steps << Provision if Vagrant.config.chef.enabled
|
||||||
|
|
||||||
|
steps.each do |action_klass|
|
||||||
|
@vm.add_action(action_klass)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,49 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class SharedFolders < Base
|
||||||
|
def shared_folders
|
||||||
|
shared_folders = @vm.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
|
||||||
|
# also verify that the host path exists, the name is valid,
|
||||||
|
# and that the guest path is valid.
|
||||||
|
shared_folders.collect do |folder|
|
||||||
|
if folder.is_a?(Array) && folder.length == 3
|
||||||
|
folder
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
def before_boot
|
||||||
|
logger.info "Creating shared folders metadata..."
|
||||||
|
|
||||||
|
shared_folders.each do |name, hostpath, guestpath|
|
||||||
|
folder = VirtualBox::SharedFolder.new
|
||||||
|
folder.name = name
|
||||||
|
folder.hostpath = hostpath
|
||||||
|
@vm.vm.shared_folders << folder
|
||||||
|
end
|
||||||
|
|
||||||
|
@vm.vm.save(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_boot
|
||||||
|
logger.info "Mounting shared folders..."
|
||||||
|
|
||||||
|
Vagrant::SSH.execute do |ssh|
|
||||||
|
shared_folders.each do |name, hostpath, guestpath|
|
||||||
|
logger.info "-- #{name}: #{guestpath}"
|
||||||
|
ssh.exec!("sudo mkdir -p #{guestpath}")
|
||||||
|
ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}")
|
||||||
|
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{guestpath}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,45 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Start < Base
|
||||||
|
def execute!
|
||||||
|
@vm.invoke_around_callback(:boot) do
|
||||||
|
# Startup the VM
|
||||||
|
boot
|
||||||
|
|
||||||
|
# Wait for it to complete booting, or error if we could
|
||||||
|
# never detect it booted up successfully
|
||||||
|
if !wait_for_boot
|
||||||
|
error_and_exit(<<-error)
|
||||||
|
Failed to connect to VM! Failed to boot?
|
||||||
|
error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def boot
|
||||||
|
logger.info "Booting VM..."
|
||||||
|
@vm.vm.start(:headless, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def wait_for_boot(sleeptime=5)
|
||||||
|
logger.info "Waiting for VM to boot..."
|
||||||
|
|
||||||
|
Vagrant.config[:ssh][:max_tries].to_i.times do |i|
|
||||||
|
logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
|
||||||
|
|
||||||
|
if Vagrant::SSH.up?
|
||||||
|
logger.info "VM booted and ready for use!"
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep sleeptime
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.info "Failed to connect to VM! Failed to boot?"
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Stop < Base
|
||||||
|
def execute!
|
||||||
|
logger.info "Forcing shutdown of VM..."
|
||||||
|
@vm.vm.stop(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,56 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Unpackage < Base
|
||||||
|
TAR_OPTIONS = [File::RDONLY, 0644, Tar::GNU]
|
||||||
|
attr_accessor :package_file_path
|
||||||
|
|
||||||
|
def initialize(vm, *args)
|
||||||
|
super vm
|
||||||
|
@package_file_path = args[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute!
|
||||||
|
# Exit if folder of same name exists
|
||||||
|
# TODO provide a way for them to specify the directory name
|
||||||
|
error_and_exit(<<-error) if File.exists?(new_base_dir)
|
||||||
|
The directory `#{file_name_without_extension}` already exists under #{Vagrant.config[:vagrant][:home]}. Please
|
||||||
|
remove it, rename your packaged VM file, or (TODO) specifiy an
|
||||||
|
alternate directory
|
||||||
|
error
|
||||||
|
|
||||||
|
logger.info "Decompressing the packaged VM: #{package_file_path} to: #{working_dir}..."
|
||||||
|
decompress
|
||||||
|
|
||||||
|
logger.info "Moving decompressed files in: #{working_dir} to: #{new_base_dir} ..."
|
||||||
|
FileUtils.mv(working_dir, new_base_dir)
|
||||||
|
|
||||||
|
#Return the ovf file for importation
|
||||||
|
Dir["#{new_base_dir}/*.ovf"].first
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_base_dir
|
||||||
|
File.join(Vagrant.config.vagrant.home, file_name_without_extension)
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_name_without_extension
|
||||||
|
File.basename(package_file_path, '.*')
|
||||||
|
end
|
||||||
|
|
||||||
|
def working_dir
|
||||||
|
package_file_path.chomp(File.extname(package_file_path))
|
||||||
|
end
|
||||||
|
|
||||||
|
def package_file_path
|
||||||
|
File.expand_path(@package_file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def decompress
|
||||||
|
Tar.open(package_file_path, *TAR_OPTIONS) do |tar|
|
||||||
|
tar.extract_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,48 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Up < Base
|
||||||
|
#First arg should be the ovf_file location for import
|
||||||
|
def initialize(vm, *args)
|
||||||
|
super vm
|
||||||
|
@ovf_file = args[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def collect_shared_folders
|
||||||
|
# The root shared folder for the project
|
||||||
|
["vagrant-root", Env.root_path, Vagrant.config.vm.project_directory]
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_import
|
||||||
|
persist
|
||||||
|
setup_mac_address
|
||||||
|
end
|
||||||
|
|
||||||
|
def persist
|
||||||
|
logger.info "Persisting the VM UUID (#{@vm.vm.uuid})..."
|
||||||
|
Env.persist_vm(@vm.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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -40,7 +40,7 @@ run `vagrant down` first.
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
|
|
||||||
VM.execute!(Actions::Up)
|
VM.execute!(Actions::VM::Up)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tear down a vagrant instance. This not only shuts down the instance
|
# Tear down a vagrant instance. This not only shuts down the instance
|
||||||
|
@ -63,7 +63,7 @@ error
|
||||||
def reload
|
def reload
|
||||||
Env.load!
|
Env.load!
|
||||||
Env.require_persisted_vm
|
Env.require_persisted_vm
|
||||||
Env.persisted_vm.execute!(Actions::Reload)
|
Env.persisted_vm.execute!(Actions::VM::Reload)
|
||||||
end
|
end
|
||||||
|
|
||||||
# SSH into the vagrant instance. This will setup an SSH connection into
|
# SSH into the vagrant instance. This will setup an SSH connection into
|
||||||
|
@ -120,8 +120,8 @@ The vagrant virtual environment you are trying to package must be powered off
|
||||||
error
|
error
|
||||||
# TODO allow directory specification
|
# TODO allow directory specification
|
||||||
act_on_vm do |vm|
|
act_on_vm do |vm|
|
||||||
vm.add_action(Actions::Export)
|
vm.add_action(Actions::VM::Export)
|
||||||
vm.add_action(Actions::Package, name || Vagrant.config[:package][:name], FileUtils.pwd)
|
vm.add_action(Actions::VM::Package, name || Vagrant.config[:package][:name], FileUtils.pwd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ error
|
||||||
Please specify a target package to unpack and import
|
Please specify a target package to unpack and import
|
||||||
error
|
error
|
||||||
|
|
||||||
VM.execute!(Actions::Up, VM.execute!(Actions::Unpackage, name))
|
VM.execute!(Actions::VM::Up, VM.execute!(Actions::VM::Unpackage, name))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Manages the `vagrant box` command, allowing the user to add
|
# Manages the `vagrant box` command, allowing the user to add
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
execute!(Actions::Stop) if @vm.running?
|
execute!(Actions::VM::Stop) if @vm.running?
|
||||||
|
|
||||||
logger.info "Destroying VM and associated drives..."
|
logger.info "Destroying VM and associated drives..."
|
||||||
@vm.destroy(:destroy_image => true)
|
@vm.destroy(:destroy_image => true)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class ExportActionTest < Test::Unit::TestCase
|
class ExportActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Export)
|
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Export)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class ForwardPortsActionTest < Test::Unit::TestCase
|
class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::ForwardPorts)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::ForwardPorts)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class ImportActionTest < Test::Unit::TestCase
|
class ImportActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @import = mock_action(Vagrant::Actions::Import)
|
@mock_vm, @vm, @import = mock_action(Vagrant::Actions::VM::Import)
|
||||||
|
|
||||||
VirtualBox::VM.stubs(:import)
|
VirtualBox::VM.stubs(:import)
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ class ImportActionTest < Test::Unit::TestCase
|
||||||
File.expand_path do |n|
|
File.expand_path do |n|
|
||||||
assert_equal n, Vagrant.config.vm.base
|
assert_equal n, Vagrant.config.vm.base
|
||||||
end
|
end
|
||||||
Vagrant::Actions::Import.new(@vm)
|
Vagrant::Actions::VM::Import.new(@vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expand the ovf path and assign it when passed as a parameter" do
|
should "expand the ovf path and assign it when passed as a parameter" do
|
||||||
|
@ -45,7 +45,7 @@ class ImportActionTest < Test::Unit::TestCase
|
||||||
File.expand_path do |n|
|
File.expand_path do |n|
|
||||||
assert_equal n, 'foo'
|
assert_equal n, 'foo'
|
||||||
end
|
end
|
||||||
Vagrant::Actions::Import.new(@vm, 'foo')
|
Vagrant::Actions::VM::Import.new(@vm, 'foo')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class MoveHardDriveActionTest < Test::Unit::TestCase
|
class MoveHardDriveActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::MoveHardDrive)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::MoveHardDrive)
|
||||||
@hd_location = "/foo"
|
@hd_location = "/foo"
|
||||||
mock_config do |config|
|
mock_config do |config|
|
||||||
File.expects(:directory?).with(@hd_location).returns(true)
|
File.expects(:directory?).with(@hd_location).returns(true)
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class PackageActionTest < Test::Unit::TestCase
|
class PackageActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Package)
|
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Package)
|
||||||
@action.to = '/foo/bar/baz'
|
@action.to = '/foo/bar/baz'
|
||||||
@action.name = 'bing'
|
@action.name = 'bing'
|
||||||
mock_config
|
mock_config
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class ProvisionActionTest < Test::Unit::TestCase
|
class ProvisionActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::Provision)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Provision)
|
||||||
|
|
||||||
Vagrant::SSH.stubs(:execute)
|
Vagrant::SSH.stubs(:execute)
|
||||||
Vagrant::SSH.stubs(:upload!)
|
Vagrant::SSH.stubs(:upload!)
|
|
@ -1,14 +1,14 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class ReloadActionTest < Test::Unit::TestCase
|
class ReloadActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::Reload)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Reload)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
context "sub-actions" do
|
context "sub-actions" do
|
||||||
setup do
|
setup do
|
||||||
@default_order = [Vagrant::Actions::Stop, Vagrant::Actions::ForwardPorts, Vagrant::Actions::SharedFolders, Vagrant::Actions::Start]
|
@default_order = [Vagrant::Actions::VM::Stop, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_action_expectations
|
def setup_action_expectations
|
||||||
|
@ -28,7 +28,7 @@ class ReloadActionTest < Test::Unit::TestCase
|
||||||
config.chef.enabled = true
|
config.chef.enabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@default_order.push(Vagrant::Actions::Provision)
|
@default_order.push(Vagrant::Actions::VM::Provision)
|
||||||
setup_action_expectations
|
setup_action_expectations
|
||||||
@action.prepare
|
@action.prepare
|
||||||
end
|
end
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class SharedFoldersActionTest < Test::Unit::TestCase
|
class SharedFoldersActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::SharedFolders)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class StartActionTest < Test::Unit::TestCase
|
class StartActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::Start)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
|
||||||
@mock_vm.stubs(:invoke_callback)
|
@mock_vm.stubs(:invoke_callback)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class StopActionTest < Test::Unit::TestCase
|
class StopActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::Stop)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Stop)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "force the VM to stop" do
|
should "force the VM to stop" do
|
|
@ -1,8 +1,8 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class UnpackageActionTest < Test::Unit::TestCase
|
class UnpackageActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Unpackage)
|
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Unpackage)
|
||||||
@expanded_path = File.join(FileUtils.pwd, 'foo.box')
|
@expanded_path = File.join(FileUtils.pwd, 'foo.box')
|
||||||
File.stubs(:expand_path).returns(@expanded_path)
|
File.stubs(:expand_path).returns(@expanded_path)
|
||||||
@action.package_file_path = 'foo.box'
|
@action.package_file_path = 'foo.box'
|
||||||
|
@ -27,7 +27,7 @@ class UnpackageActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call decompress with the defined options and the correct package path" do
|
should "call decompress with the defined options and the correct package path" do
|
||||||
Tar.expects(:open).with(@expanded_path, *Vagrant::Actions::Unpackage::TAR_OPTIONS)
|
Tar.expects(:open).with(@expanded_path, *Vagrant::Actions::VM::Unpackage::TAR_OPTIONS)
|
||||||
@action.decompress
|
@action.decompress
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
class UpActionTest < Test::Unit::TestCase
|
class UpActionTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::Up)
|
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
context "sub-actions" do
|
context "sub-actions" do
|
||||||
setup do
|
setup do
|
||||||
@default_order = [Vagrant::Actions::ForwardPorts, Vagrant::Actions::SharedFolders, Vagrant::Actions::Start]
|
@default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_action_expectations
|
def setup_action_expectations
|
||||||
default_seq = sequence("default_seq")
|
default_seq = sequence("default_seq")
|
||||||
@mock_vm.expects(:add_action).with(Vagrant::Actions::Import, nil).once.in_sequence(default_seq)
|
@mock_vm.expects(:add_action).with(Vagrant::Actions::VM::Import, nil).once.in_sequence(default_seq)
|
||||||
@default_order.each do |action|
|
@default_order.each do |action|
|
||||||
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||||
end
|
end
|
||||||
|
@ -29,7 +29,7 @@ class UpActionTest < Test::Unit::TestCase
|
||||||
config.chef.enabled = true
|
config.chef.enabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@default_order.push(Vagrant::Actions::Provision)
|
@default_order.push(Vagrant::Actions::VM::Provision)
|
||||||
setup_action_expectations
|
setup_action_expectations
|
||||||
@action.prepare
|
@action.prepare
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ class UpActionTest < Test::Unit::TestCase
|
||||||
config.vm.hd_location = "foo"
|
config.vm.hd_location = "foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
@default_order.insert(0, Vagrant::Actions::MoveHardDrive)
|
@default_order.insert(0, Vagrant::Actions::VM::MoveHardDrive)
|
||||||
setup_action_expectations
|
setup_action_expectations
|
||||||
@action.prepare
|
@action.prepare
|
||||||
end
|
end
|
|
@ -48,7 +48,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call the up action on VM" do
|
should "call the up action on VM" do
|
||||||
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::Up).once
|
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once
|
||||||
Vagrant::Commands.up
|
Vagrant::Commands.up
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -76,7 +76,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call the `reload` action on the VM" do
|
should "call the `reload` action on the VM" do
|
||||||
@persisted_vm.expects(:execute!).with(Vagrant::Actions::Reload).once
|
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
|
||||||
Vagrant::Commands.reload
|
Vagrant::Commands.reload
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,7 @@ class VMTest < Test::Unit::TestCase
|
||||||
should "stop the VM if its running" do
|
should "stop the VM if its running" do
|
||||||
@mock_vm.expects(:running?).returns(true)
|
@mock_vm.expects(:running?).returns(true)
|
||||||
@mock_vm.expects(:destroy).with(:destroy_image => true).once
|
@mock_vm.expects(:destroy).with(:destroy_image => true).once
|
||||||
@vm.expects(:execute!).with(Vagrant::Actions::Stop).once
|
@vm.expects(:execute!).with(Vagrant::Actions::VM::Stop).once
|
||||||
@vm.destroy
|
@vm.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue