Removed unpackage VM action (since its part of box now)
This commit is contained in:
parent
5b68f3dd10
commit
10e67e85f0
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
begin
|
||||
require File.expand_path('../../.bundle/environment', __FILE__)
|
||||
rescue LoadError
|
||||
# Fallback on rubygems
|
||||
require "rubygems"
|
||||
end
|
||||
|
||||
require 'git-style-binary/command'
|
||||
|
||||
# Get library
|
||||
libdir = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
$:.unshift(libdir) unless $:.include?(libdir)
|
||||
require 'vagrant'
|
||||
|
||||
GitStyleBinary.command do
|
||||
short_desc "unpackage a vagrant environment"
|
||||
banner <<-EOS
|
||||
Usage: #{command.full_name} #{all_options_string}
|
||||
|
||||
Unpackage a vagrant environment
|
||||
|
||||
EOS
|
||||
run do |command|
|
||||
Vagrant::Commands.unpackage(command.argv[0])
|
||||
end
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
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
|
|
@ -2,18 +2,10 @@ 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:
|
||||
@runner.add_action(Import, @ovf_file)
|
||||
|
||||
steps = [ForwardPorts, SharedFolders, Start]
|
||||
steps = [Import, ForwardPorts, SharedFolders, Start]
|
||||
steps << Provision if Vagrant.config.chef.enabled
|
||||
steps.insert(0, MoveHardDrive) if Vagrant.config.vm.hd_location
|
||||
|
||||
|
|
|
@ -125,15 +125,6 @@ error
|
|||
end
|
||||
end
|
||||
|
||||
def unpackage(name)
|
||||
Env.load!
|
||||
error_and_exit(<<-error) unless name
|
||||
Please specify a target package to unpack and import
|
||||
error
|
||||
|
||||
VM.execute!(Actions::VM::Up, VM.execute!(Actions::VM::Unpackage, name))
|
||||
end
|
||||
|
||||
# Manages the `vagrant box` command, allowing the user to add
|
||||
# and remove boxes. This single command, given an array, determines
|
||||
# which action to take and calls the respective action method
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class UnpackageActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Unpackage)
|
||||
@expanded_path = File.join(FileUtils.pwd, 'foo.box')
|
||||
File.stubs(:expand_path).returns(@expanded_path)
|
||||
@action.package_file_path = 'foo.box'
|
||||
mock_config
|
||||
end
|
||||
|
||||
# TODO test actual decompression
|
||||
should "call decompress with the path to the file and the directory to decompress to" do
|
||||
new_base_dir = File.join Vagrant.config[:vagrant][:home], 'foo'
|
||||
FileUtils.expects(:mv).with(@action.working_dir, new_base_dir).once
|
||||
Dir.expects(:[]).returns(File.join new_base_dir, 'something.ovf')
|
||||
@action.expects(:decompress)
|
||||
@action.execute!
|
||||
end
|
||||
|
||||
should "return the full package file path without extension for the working directory" do
|
||||
assert_equal @action.working_dir, @action.package_file_path.gsub(/\.box/, '')
|
||||
end
|
||||
|
||||
should "return base name without extension" do
|
||||
assert_equal @action.file_name_without_extension, 'foo'
|
||||
end
|
||||
|
||||
should "call decompress with the defined options and the correct package path" do
|
||||
Tar.expects(:open).with(@expanded_path, *Vagrant::Actions::VM::Unpackage::TAR_OPTIONS)
|
||||
@action.decompress
|
||||
end
|
||||
|
||||
should "return a new base dir under the home dir with the same name as the file without the extension" do
|
||||
assert_equal @action.new_base_dir, File.join(Vagrant.config.vagrant.home, 'foo')
|
||||
end
|
||||
end
|
|
@ -8,12 +8,11 @@ class UpActionTest < Test::Unit::TestCase
|
|||
|
||||
context "sub-actions" do
|
||||
setup do
|
||||
@default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
|
||||
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
|
||||
end
|
||||
|
||||
def setup_action_expectations
|
||||
default_seq = sequence("default_seq")
|
||||
@mock_vm.expects(:add_action).with(Vagrant::Actions::VM::Import, nil).once.in_sequence(default_seq)
|
||||
@default_order.each do |action|
|
||||
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue