core: Machine has reference to Vagrantfile
This commit is contained in:
parent
66f722ef68
commit
8e9ceeaf5c
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue