core: Allow options to be passed down into SF cleanup
This commit is contained in:
parent
deb6ba07b2
commit
2c65d247da
|
@ -26,6 +26,20 @@ module Vagrant
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This finds the options in the env that are set for a given
|
||||||
|
# synced folder type.
|
||||||
|
def impl_opts(name, env)
|
||||||
|
{}.tap do |result|
|
||||||
|
env.each do |k, v|
|
||||||
|
if k.to_s.start_with?("#{name}_")
|
||||||
|
k = k.dup if !k.is_a?(Symbol)
|
||||||
|
v = v.dup if !v.is_a?(Symbol)
|
||||||
|
result[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This returns the available synced folder implementations. This
|
# This returns the available synced folder implementations. This
|
||||||
# is a separate method so that it can be easily stubbed by tests.
|
# is a separate method so that it can be easily stubbed by tests.
|
||||||
def plugins
|
def plugins
|
||||||
|
|
|
@ -21,7 +21,8 @@ module Vagrant
|
||||||
# Go through each folder and do cleanup
|
# Go through each folder and do cleanup
|
||||||
folders.each_key do |impl_name|
|
folders.each_key do |impl_name|
|
||||||
@logger.info("Invoking synced folder cleanup for: #{impl_name}")
|
@logger.info("Invoking synced folder cleanup for: #{impl_name}")
|
||||||
plugins[impl_name.to_sym][0].new.cleanup(env[:machine])
|
plugins[impl_name.to_sym][0].new.cleanup(
|
||||||
|
env[:machine], impl_opts(impl_name, env))
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -73,20 +73,6 @@ module Vagrant
|
||||||
plugins[impl_name.to_sym][0].new.enable(env[:machine], fs, impl_opts(impl_name, env))
|
plugins[impl_name.to_sym][0].new.enable(env[:machine], fs, impl_opts(impl_name, env))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This finds the options in the env that are set for a given
|
|
||||||
# synced folder type.
|
|
||||||
def impl_opts(name, env)
|
|
||||||
{}.tap do |result|
|
|
||||||
env.each do |k, v|
|
|
||||||
if k.to_s.start_with?("#{name}_")
|
|
||||||
k = k.dup if !k.is_a?(Symbol)
|
|
||||||
v = v.dup if !v.is_a?(Symbol)
|
|
||||||
result[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,10 +27,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is called after destroying the machine during a
|
# This is called after destroying the machine during a
|
||||||
# `vagrant destroy`.
|
# `vagrant destroy` and also prior to syncing folders during
|
||||||
|
# a `vagrant up`.
|
||||||
#
|
#
|
||||||
# No return value.
|
# No return value.
|
||||||
def cleanup(machine)
|
#
|
||||||
|
# @param [Machine] machine
|
||||||
|
# @param [Hash] opts
|
||||||
|
def cleanup(machine, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,7 +61,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup(machine)
|
def cleanup(machine, opts)
|
||||||
driver(machine).clear_shared_folders if machine.id && machine.id != ""
|
driver(machine).clear_shared_folders if machine.id && machine.id != ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ module VagrantPlugins
|
||||||
:mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders)
|
:mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup(machine)
|
def cleanup(machine, opts)
|
||||||
# Get the ID of all active machines.
|
# Get the ID of all active machines.
|
||||||
ids = machine.env.active_machines.map do |name, provider|
|
ids = machine.env.active_machines.map do |name, provider|
|
||||||
machine.env.machine(name, provider).id
|
machine.env.machine(name, provider).id
|
||||||
|
|
|
@ -38,6 +38,21 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "impl_opts" do
|
||||||
|
it "should return only relevant keys" do
|
||||||
|
env = {
|
||||||
|
:foo_bar => "baz",
|
||||||
|
:bar_bar => "nope",
|
||||||
|
:foo_baz => "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
result = subject.impl_opts("foo", env)
|
||||||
|
result.length.should == 2
|
||||||
|
result[:foo_bar].should == "baz"
|
||||||
|
result[:foo_baz].should == "bar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "synced_folders" do
|
describe "synced_folders" do
|
||||||
let(:folders) { {} }
|
let(:folders) { {} }
|
||||||
let(:plugins) { {} }
|
let(:plugins) { {} }
|
||||||
|
|
|
@ -38,7 +38,7 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
|
||||||
class_variable_get(:@@clean)
|
class_variable_get(:@@clean)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup(machine)
|
def cleanup(machine, opts)
|
||||||
self.class.class_variable_set(:@@clean, true)
|
self.class.class_variable_set(:@@clean, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -75,7 +75,10 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
|
||||||
}
|
}
|
||||||
|
|
||||||
expect_any_instance_of(tracker).to receive(:cleanup).
|
expect_any_instance_of(tracker).to receive(:cleanup).
|
||||||
with(env[:machine])
|
with(env[:machine], { tracker_foo: :bar })
|
||||||
|
|
||||||
|
# Test that the impl-specific opts are passed through
|
||||||
|
env[:tracker_foo] = :bar
|
||||||
|
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
end
|
end
|
||||||
|
|
|
@ -113,19 +113,4 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
||||||
actual["root"][:foo].should == "bar"
|
actual["root"][:foo].should == "bar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "impl_opts" do
|
|
||||||
it "should return only relevant keys" do
|
|
||||||
env = {
|
|
||||||
:foo_bar => "baz",
|
|
||||||
:bar_bar => "nope",
|
|
||||||
:foo_baz => "bar",
|
|
||||||
}
|
|
||||||
|
|
||||||
result = subject.impl_opts("foo", env)
|
|
||||||
result.length.should == 2
|
|
||||||
result[:foo_bar].should == "baz"
|
|
||||||
result[:foo_baz].should == "bar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue