Store shared folders customizations on a local array instead of messing up with provider configs
This commit is contained in:
parent
7187556b6a
commit
a700d88783
3 changed files with 43 additions and 17 deletions
|
@ -60,8 +60,7 @@ module Vagrant
|
||||||
@env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
@env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
||||||
:guest_path => data[:guestpath]))
|
:guest_path => data[:guestpath]))
|
||||||
end
|
end
|
||||||
config = @env[:machine].provider_config
|
@env[:machine].provider.driver.share_folders(folders)
|
||||||
@env[:machine].provider.driver.share_folders(folders, config)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,12 +14,14 @@ module Vagrant
|
||||||
# a name.
|
# a name.
|
||||||
class ContainerNotFound < StandardError; end
|
class ContainerNotFound < StandardError; end
|
||||||
|
|
||||||
attr_reader :container_name
|
attr_reader :container_name,
|
||||||
|
:customizations
|
||||||
|
|
||||||
def initialize(container_name, cli = CLI.new(container_name))
|
def initialize(container_name, cli = CLI.new(container_name))
|
||||||
@container_name = container_name
|
@container_name = container_name
|
||||||
@cli = cli
|
@cli = cli
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::lxc::driver")
|
@logger = Log4r::Logger.new("vagrant::provider::lxc::driver")
|
||||||
|
@customizations = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate!
|
def validate!
|
||||||
|
@ -43,20 +45,19 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def share_folders(folders, config)
|
def share_folders(folders)
|
||||||
folders.each do |folder|
|
folders.each do |folder|
|
||||||
guestpath = rootfs_path.join(folder[:guestpath].gsub(/^\//, ''))
|
guestpath = rootfs_path.join(folder[:guestpath].gsub(/^\//, ''))
|
||||||
unless guestpath.directory?
|
unless guestpath.directory?
|
||||||
begin
|
begin
|
||||||
|
@logger.debug("Guest path doesn't exist, creating: #{guestpath}")
|
||||||
system "sudo mkdir -p #{guestpath.to_s}"
|
system "sudo mkdir -p #{guestpath.to_s}"
|
||||||
rescue Errno::EACCES
|
rescue Errno::EACCES
|
||||||
raise Vagrant::Errors::SharedFolderCreateFailed,
|
raise Vagrant::Errors::SharedFolderCreateFailed, :path => guestpath.to_s
|
||||||
:path => guestpath.to_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Move outside
|
@customizations << ['mount.entry', "#{folder[:hostpath]} #{guestpath} none bind 0 0"]
|
||||||
config.customize 'mount.entry', "#{folder[:hostpath]} #{guestpath} none bind 0 0"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ module Vagrant
|
||||||
if ENV['LXC_START_LOG_FILE']
|
if ENV['LXC_START_LOG_FILE']
|
||||||
extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG']
|
extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG']
|
||||||
end
|
end
|
||||||
|
customizations = customizations + @customizations
|
||||||
|
|
||||||
@cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) }
|
@cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,24 +70,24 @@ describe Vagrant::LXC::Driver do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'start' do
|
describe 'start' do
|
||||||
let(:name) { 'container-name' }
|
let(:customizations) { [['a', '1'], ['b', '2']] }
|
||||||
let(:customizations) { [['a', '1'], ['b', '2']] }
|
let(:internal_customization) { ['internal', 'customization'] }
|
||||||
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) }
|
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) }
|
||||||
|
|
||||||
subject { described_class.new(name, cli) }
|
subject { described_class.new('name', cli) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
cli.stub(:transition_to).and_yield(cli)
|
cli.stub(:transition_to).and_yield(cli)
|
||||||
|
subject.customizations << internal_customization
|
||||||
|
subject.start(customizations)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'starts container with configured lxc settings' do
|
it 'starts container with configured customizations' do
|
||||||
cli.should_receive(:start).with(customizations, nil)
|
cli.should have_received(:start).with(customizations + [internal_customization], nil)
|
||||||
subject.start(customizations)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'expects a transition to running state to take place' do
|
it 'expects a transition to running state to take place' do
|
||||||
cli.should_receive(:transition_to).with(:running)
|
cli.should have_received(:transition_to).with(:running)
|
||||||
subject.start(customizations)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,4 +149,29 @@ describe Vagrant::LXC::Driver do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'folder sharing' do
|
||||||
|
let(:shared_folder) { {guestpath: '/vagrant', hostpath: '/path/to/host/dir'} }
|
||||||
|
let(:folders) { [shared_folder] }
|
||||||
|
let(:rootfs_path) { Pathname('/path/to/rootfs') }
|
||||||
|
let(:expected_guest_path) { "#{rootfs_path}/vagrant" }
|
||||||
|
|
||||||
|
subject { described_class.new('container-name') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
subject.stub(rootfs_path: rootfs_path, system: true)
|
||||||
|
subject.share_folders(folders)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates guest folder under container's rootfs" do
|
||||||
|
subject.should have_received(:system).with("sudo mkdir -p #{expected_guest_path}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'adds a mount.entry to its local customizations' do
|
||||||
|
subject.customizations.should include [
|
||||||
|
'mount.entry',
|
||||||
|
"#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue