Merge pull request #7725 from chrisroberts/fix/package-machine-dir
Machine data directory for base box package
This commit is contained in:
commit
5e44e308a5
|
@ -56,14 +56,20 @@ module VagrantPlugins
|
||||||
# better in the future. We just hardcode this to keep VirtualBox working
|
# better in the future. We just hardcode this to keep VirtualBox working
|
||||||
# for now.
|
# for now.
|
||||||
provider = Vagrant.plugin("2").manager.providers[:virtualbox]
|
provider = Vagrant.plugin("2").manager.providers[:virtualbox]
|
||||||
vm = Vagrant::Machine.new(
|
tmp_data_directory = File.join(@env.tmp_path, SecureRandom.uuid)
|
||||||
options[:base],
|
FileUtils.mkdir_p(tmp_data_directory)
|
||||||
:virtualbox, provider[0], nil, provider[1],
|
begin
|
||||||
@env.vagrantfile.config,
|
vm = Vagrant::Machine.new(
|
||||||
nil, nil,
|
options[:base],
|
||||||
@env, @env.vagrantfile, true)
|
:virtualbox, provider[0], nil, provider[1],
|
||||||
@logger.debug("Packaging base VM: #{vm.name}")
|
@env.vagrantfile.config,
|
||||||
package_vm(vm, options)
|
Pathname.new(tmp_data_directory), nil,
|
||||||
|
@env, @env.vagrantfile, true)
|
||||||
|
@logger.debug("Packaging base VM: #{vm.name}")
|
||||||
|
package_vm(vm, options)
|
||||||
|
ensure
|
||||||
|
FileUtils.rm_rf(tmp_data_directory)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def package_target(name, options)
|
def package_target(name, options)
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
require_relative "../../../base"
|
||||||
|
require_relative "../../../../../plugins/commands/package/command"
|
||||||
|
|
||||||
|
RSpec::Matchers.define :a_machine_named do |name|
|
||||||
|
match{ |actual| actual.name.to_s == name.to_s }
|
||||||
|
end
|
||||||
|
|
||||||
|
RSpec::Matchers.define :an_existing_directory do
|
||||||
|
match{ |actual| File.directory?(actual) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe VagrantPlugins::CommandPackage::Command do
|
||||||
|
include_context "unit"
|
||||||
|
|
||||||
|
let(:argv) { [] }
|
||||||
|
let(:iso_env) do
|
||||||
|
# We have to create a Vagrantfile so there is a root path
|
||||||
|
env = isolated_environment
|
||||||
|
env.vagrantfile("")
|
||||||
|
env.create_vagrant_env
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:package_command) { described_class.new(argv, iso_env) }
|
||||||
|
|
||||||
|
let(:action_runner) { double("action_runner") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
iso_env.stub(action_runner: action_runner)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#execute" do
|
||||||
|
|
||||||
|
context "with no arguments" do
|
||||||
|
|
||||||
|
it "packages default machine" do
|
||||||
|
expect(package_command).to receive(:package_vm).with(a_machine_named('default'), {})
|
||||||
|
package_command.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with single argument" do
|
||||||
|
context "set to default" do
|
||||||
|
|
||||||
|
let(:argv){ ['default'] }
|
||||||
|
|
||||||
|
it "packages default machine" do
|
||||||
|
expect(package_command).to receive(:package_vm).with(a_machine_named('default'), {})
|
||||||
|
package_command.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "set to undefined vm" do
|
||||||
|
|
||||||
|
let(:argv){ ['undefined'] }
|
||||||
|
|
||||||
|
it "raises machine not found error" do
|
||||||
|
expect{ package_command.execute }.to raise_error(Vagrant::Errors::MachineNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with multiple arguments" do
|
||||||
|
|
||||||
|
let(:argv){ ['default', 'undefined'] }
|
||||||
|
|
||||||
|
it "ignores the extra arguments" do
|
||||||
|
expect(package_command).to receive(:package_vm).with(a_machine_named('default'), {})
|
||||||
|
package_command.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with --base option" do
|
||||||
|
context "and no option value" do
|
||||||
|
|
||||||
|
let(:argv){ ['--base'] }
|
||||||
|
|
||||||
|
it "shows help" do
|
||||||
|
expect{ package_command.execute }.to raise_error(Vagrant::Errors::CLIInvalidOptions)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and option value" do
|
||||||
|
|
||||||
|
let(:argv){ ['--base', 'machine-id'] }
|
||||||
|
|
||||||
|
it "packages vm defined within virtualbox" do
|
||||||
|
expect(package_command).to receive(:package_base).with(:base => 'machine-id')
|
||||||
|
package_command.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
it "provides a machine data directory" do
|
||||||
|
expect(Vagrant::Machine).to receive(:new).with(
|
||||||
|
'machine-id', :virtualbox, anything, nil, anything, anything, an_existing_directory,
|
||||||
|
anything, anything, anything, anything).and_return(double("vm", name: "machine-id"))
|
||||||
|
allow(package_command).to receive(:package_vm)
|
||||||
|
package_command.execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue