core: Machine has reference to Vagrantfile

This commit is contained in:
Mitchell Hashimoto 2014-02-07 09:16:55 -08:00
parent 66f722ef68
commit 8e9ceeaf5c
5 changed files with 25 additions and 22 deletions

View File

@ -62,6 +62,11 @@ module Vagrant
# @return [UI] # @return [UI]
attr_reader :ui attr_reader :ui
# The Vagrantfile that this machine is attached to.
#
# @return [Vagrantfile]
attr_reader :vagrantfile
# Initialize a new machine. # Initialize a new machine.
# #
# @param [String] name Name of the virtual 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 [Box] box The box that is backing this virtual machine.
# @param [Environment] env The environment that this machine is a # @param [Environment] env The environment that this machine is a
# part of. # 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 = Log4r::Logger.new("vagrant::machine")
@logger.info("Initializing machine: #{name}") @logger.info("Initializing machine: #{name}")
@logger.info(" - Provider: #{provider_cls}") @logger.info(" - Provider: #{provider_cls}")
@ -88,6 +93,7 @@ module Vagrant
@config = config @config = config
@data_dir = data_dir @data_dir = data_dir
@env = env @env = env
@vagrantfile = vagrantfile
@guest = Guest.new( @guest = Guest.new(
self, self,
Vagrant.plugin("2").manager.guests, Vagrant.plugin("2").manager.guests,

View File

@ -73,7 +73,7 @@ module Vagrant
# Create the machine and cache it for future calls. This will also # Create the machine and cache it for future calls. This will also
# return the machine from this method. # return the machine from this method.
return Machine.new(name, provider, provider_cls, provider_config, 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 end
# Returns the configuration for a single machine. # Returns the configuration for a single machine.

View File

@ -61,7 +61,7 @@ module VagrantPlugins
:virtualbox, provider[0], nil, provider[1], :virtualbox, provider[0], nil, provider[1],
@env.vagrantfile.config, @env.vagrantfile.config,
nil, nil, nil, nil,
@env, true) @env, @env.vagrantfile, true)
@logger.debug("Packaging base VM: #{vm.name}") @logger.debug("Packaging base VM: #{vm.name}")
package_vm(vm, options) package_vm(vm, options)
end end

View File

@ -1,30 +1,25 @@
require_relative "../base" require_relative "../base"
describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds do
include_context "unit"
include_context "virtualbox" include_context "virtualbox"
let(:machine) { let(:iso_env) do
environment = Vagrant::Environment.new # We have to create a Vagrantfile so there is a root path
provider = :virtualbox env = isolated_environment
provider_cls, provider_options = Vagrant.plugin("2").manager.providers[provider] env.vagrantfile("")
provider_config = Vagrant.plugin("2").manager.provider_configs[provider] env.create_vagrant_env
end
Vagrant::Machine.new( let(:machine) do
'test_machine', iso_env.machine(iso_env.machine_names[0], :dummy).tap do |m|
provider, m.provider.stub(driver: driver)
provider_cls, end
provider_config, end
provider_options,
environment.vagrantfile.config,
Pathname('data_dir'),
double('box'),
environment
)
}
let(:env) {{ machine: machine }} let(:env) {{ machine: machine }}
let(:app) { lambda { |*args| }} let(:app) { lambda { |*args| }}
let(:driver) { env[:machine].provider.driver } let(:driver) { double("driver") }
subject { described_class.new(app, env) } subject { described_class.new(app, env) }

View File

@ -54,8 +54,9 @@ describe Vagrant::Vagrantfile do
let(:data_path) { Pathname.new(Dir.mktmpdir) } let(:data_path) { Pathname.new(Dir.mktmpdir) }
let(:env) { iso_env.create_vagrant_env } let(:env) { iso_env.create_vagrant_env }
let(:iso_env) { isolated_environment } 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 before do
@foo_config_cls = Class.new(Vagrant.plugin("2", "config")) 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(:name) { should eq(:default) }
its(:provider) { should be_kind_of(@provider_cls) } its(:provider) { should be_kind_of(@provider_cls) }
its(:provider_name) { should eq(:foo) } its(:provider_name) { should eq(:foo) }
its(:vagrantfile) { should equal(vagrantfile) }
it "has the proper box" do it "has the proper box" do
expect(subject.box.name).to eq("foo") expect(subject.box.name).to eq("foo")