NFS cleanup on BSD host
This commit is contained in:
parent
fe430ff006
commit
dc5a1be320
|
@ -0,0 +1,20 @@
|
||||||
|
require File.join(File.dirname(__FILE__), 'nfs_helpers')
|
||||||
|
|
||||||
|
module Vagrant
|
||||||
|
class Action
|
||||||
|
module VM
|
||||||
|
class ClearNFSExports
|
||||||
|
include NFSHelpers
|
||||||
|
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
clear_nfs_exports(env)
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,5 @@
|
||||||
|
require File.join(File.dirname(__FILE__), 'nfs_helpers')
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Action
|
class Action
|
||||||
module VM
|
module VM
|
||||||
|
@ -15,6 +17,7 @@ module Vagrant
|
||||||
#
|
#
|
||||||
class NFS
|
class NFS
|
||||||
include ExceptionCatcher
|
include ExceptionCatcher
|
||||||
|
include NFSHelpers
|
||||||
|
|
||||||
def initialize(app,env)
|
def initialize(app,env)
|
||||||
@app = app
|
@app = app
|
||||||
|
@ -27,7 +30,12 @@ module Vagrant
|
||||||
@env = env
|
@env = env
|
||||||
|
|
||||||
extract_folders
|
extract_folders
|
||||||
export_folders if !folders.empty?
|
|
||||||
|
if !folders.empty?
|
||||||
|
export_folders
|
||||||
|
clear_nfs_exports(env)
|
||||||
|
end
|
||||||
|
|
||||||
return if env.error?
|
return if env.error?
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
module Vagrant
|
||||||
|
class Action
|
||||||
|
module VM
|
||||||
|
module NFSHelpers
|
||||||
|
def clear_nfs_exports(env)
|
||||||
|
env["host"].nfs_cleanup if env["host"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -67,6 +67,10 @@ module Vagrant
|
||||||
# @param [Hash] folders Shared folders to sync.
|
# @param [Hash] folders Shared folders to sync.
|
||||||
def nfs_export(ip, folders)
|
def nfs_export(ip, folders)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Cleans up the exports for the current VM.
|
||||||
|
def nfs_cleanup
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,16 @@ module Vagrant
|
||||||
# is not starting
|
# is not starting
|
||||||
system("sudo nfsd restart")
|
system("sudo nfsd restart")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nfs_cleanup
|
||||||
|
system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")
|
||||||
|
|
||||||
|
if $?.to_i == 0
|
||||||
|
# Use sed to just strip out the block of code which was inserted
|
||||||
|
# by Vagrant
|
||||||
|
system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -i bak /etc/exports")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class ClearNFSExportsActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Vagrant::Action::VM::ClearNFSExports
|
||||||
|
@app, @env = mock_action_data
|
||||||
|
@env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env))
|
||||||
|
|
||||||
|
@instance = @klass.new(@app, @env)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "include the NFS helpers module" do
|
||||||
|
assert @klass.included_modules.include?(Vagrant::Action::VM::NFSHelpers)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "clear NFS exports then continue chain" do
|
||||||
|
seq = sequence("seq")
|
||||||
|
@instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
|
||||||
|
@app.expects(:call).with(@env).in_sequence(seq)
|
||||||
|
@instance.call(@env)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,23 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class NFSHelpersVMActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Class.new
|
||||||
|
@klass.send(:include, Vagrant::Action::VM::NFSHelpers)
|
||||||
|
@app, @env = mock_action_data
|
||||||
|
|
||||||
|
@instance = @klass.new
|
||||||
|
end
|
||||||
|
|
||||||
|
should "clear NFS exports for the environment if the host exists" do
|
||||||
|
@host = mock("host")
|
||||||
|
@env.env.stubs(:host).returns(@host)
|
||||||
|
@host.expects(:nfs_cleanup).once
|
||||||
|
|
||||||
|
@instance.clear_nfs_exports(@env)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not do anything if host is nil" do
|
||||||
|
assert_nothing_raised { @instance.clear_nfs_exports(@env) }
|
||||||
|
end
|
||||||
|
end
|
|
@ -46,6 +46,7 @@ class NFSVMActionTest < Test::Unit::TestCase
|
||||||
seq = sequence('seq')
|
seq = sequence('seq')
|
||||||
@instance.expects(:extract_folders).in_sequence(seq)
|
@instance.expects(:extract_folders).in_sequence(seq)
|
||||||
@instance.expects(:export_folders).in_sequence(seq)
|
@instance.expects(:export_folders).in_sequence(seq)
|
||||||
|
@instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq)
|
||||||
@app.expects(:call).with(@env).in_sequence(seq)
|
@app.expects(:call).with(@env).in_sequence(seq)
|
||||||
@instance.expects(:mount_folders).in_sequence(seq)
|
@instance.expects(:mount_folders).in_sequence(seq)
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
|
@ -57,6 +58,7 @@ class NFSVMActionTest < Test::Unit::TestCase
|
||||||
seq = sequence('seq')
|
seq = sequence('seq')
|
||||||
@instance.expects(:extract_folders).in_sequence(seq)
|
@instance.expects(:extract_folders).in_sequence(seq)
|
||||||
@instance.expects(:export_folders).never
|
@instance.expects(:export_folders).never
|
||||||
|
@instance.expects(:clear_nfs_exports).never
|
||||||
@app.expects(:call).with(@env).in_sequence(seq)
|
@app.expects(:call).with(@env).in_sequence(seq)
|
||||||
@instance.expects(:mount_folders).never
|
@instance.expects(:mount_folders).never
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
|
@ -68,6 +70,7 @@ class NFSVMActionTest < Test::Unit::TestCase
|
||||||
seq = sequence('seq')
|
seq = sequence('seq')
|
||||||
@instance.expects(:extract_folders).in_sequence(seq)
|
@instance.expects(:extract_folders).in_sequence(seq)
|
||||||
@instance.expects(:export_folders).in_sequence(seq)
|
@instance.expects(:export_folders).in_sequence(seq)
|
||||||
|
@instance.expects(:clear_nfs_exports).in_sequence(seq)
|
||||||
@app.expects(:call).never
|
@app.expects(:call).never
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,8 @@ class BSDHostTest < Test::Unit::TestCase
|
||||||
@klass = Vagrant::Hosts::BSD
|
@klass = Vagrant::Hosts::BSD
|
||||||
@env = mock_environment
|
@env = mock_environment
|
||||||
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
||||||
|
@env.logger.stubs(:info)
|
||||||
|
|
||||||
@instance = @klass.new(@env)
|
@instance = @klass.new(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,4 +55,8 @@ class BSDHostTest < Test::Unit::TestCase
|
||||||
@instance.nfs_export(@ip, @folders)
|
@instance.nfs_export(@ip, @folders)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "nfs cleanup" do
|
||||||
|
# TODO: How to test all the system calls?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue