diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index dcfbd821f..e0728aafb 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -62,6 +62,11 @@ module Vagrant # @return [UI] attr_reader :ui + # The Vagrantfile that this machine is attached to. + # + # @return [Vagrantfile] + attr_reader :vagrantfile + # Initialize a new machine. # # @param [String] name Name of the virtual machine. @@ -77,7 +82,7 @@ module Vagrant # @param [Box] box The box that is backing this virtual machine. # @param [Environment] env The environment that this machine is a # part of. - def initialize(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, base=false) + def initialize(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, env, vagrantfile, base=false) @logger = Log4r::Logger.new("vagrant::machine") @logger.info("Initializing machine: #{name}") @logger.info(" - Provider: #{provider_cls}") @@ -88,6 +93,7 @@ module Vagrant @config = config @data_dir = data_dir @env = env + @vagrantfile = vagrantfile @guest = Guest.new( self, Vagrant.plugin("2").manager.guests, diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index af4d0fa9a..fde3769cf 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -73,7 +73,7 @@ module Vagrant # Create the machine and cache it for future calls. This will also # return the machine from this method. return Machine.new(name, provider, provider_cls, provider_config, - provider_options, config, data_path, box, env) + provider_options, config, data_path, box, env, self) end # Returns the configuration for a single machine. diff --git a/plugins/commands/package/command.rb b/plugins/commands/package/command.rb index 36e3f8cca..92541be60 100644 --- a/plugins/commands/package/command.rb +++ b/plugins/commands/package/command.rb @@ -61,7 +61,7 @@ module VagrantPlugins :virtualbox, provider[0], nil, provider[1], @env.vagrantfile.config, nil, nil, - @env, true) + @env, @env.vagrantfile, true) @logger.debug("Packaging base VM: #{vm.name}") package_vm(vm, options) end diff --git a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb index bd617381b..23a2328a6 100644 --- a/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb +++ b/test/unit/plugins/providers/virtualbox/action/prepare_nfs_valid_ids_test.rb @@ -1,30 +1,25 @@ require_relative "../base" describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do + include_context "unit" include_context "virtualbox" - let(:machine) { - environment = Vagrant::Environment.new - provider = :virtualbox - provider_cls, provider_options = Vagrant.plugin("2").manager.providers[provider] - provider_config = Vagrant.plugin("2").manager.provider_configs[provider] + 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 - Vagrant::Machine.new( - 'test_machine', - provider, - provider_cls, - provider_config, - provider_options, - environment.vagrantfile.config, - Pathname('data_dir'), - double('box'), - environment - ) - } + let(:machine) do + iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m| + m.provider.stub(driver: driver) + end + end let(:env) {{ machine: machine }} let(:app) { lambda { |*args| }} - let(:driver) { env[:machine].provider.driver } + let(:driver) { double("driver") } subject { described_class.new(app, env) } diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index 1f727afce..7fbaa085e 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -54,8 +54,9 @@ describe Vagrant::Vagrantfile do let(:data_path) { Pathname.new(Dir.mktmpdir) } let(:env) { iso_env.create_vagrant_env } let(:iso_env) { isolated_environment } + let(:vagrantfile) { described_class.new(loader, keys) } - subject { super().machine(:default, :foo, boxes, data_path, env) } + subject { vagrantfile.machine(:default, :foo, boxes, data_path, env) } before do @foo_config_cls = Class.new(Vagrant.plugin("2", "config")) do @@ -83,6 +84,7 @@ describe Vagrant::Vagrantfile do its(:name) { should eq(:default) } its(:provider) { should be_kind_of(@provider_cls) } its(:provider_name) { should eq(:foo) } + its(:vagrantfile) { should equal(vagrantfile) } it "has the proper box" do expect(subject.box.name).to eq("foo")