From 274f7c7b8a34130e3e90016c8be4114f28be498e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Mar 2013 23:12:26 -0300 Subject: [PATCH] Provide --cache-path to lxc templates on creation --- lib/vagrant-lxc/action/handle_box_metadata.rb | 2 +- lib/vagrant-lxc/container.rb | 10 +++++++++- spec/unit/action/handle_box_metadata_spec.rb | 4 ++-- spec/unit/container_spec.rb | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index f6784c8..a67c14e 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -23,7 +23,7 @@ module Vagrant metadata.merge!( 'template-name' => "vagrant-#{box.name}-#{template_name}", - 'tar-cache' => box.directory.join(metadata['tar-cache']).to_s, + 'lxc-cache-path' => box.directory.to_s, 'after-create-script' => after_create ) diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index f3ec3c7..a42a7f3 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -37,7 +37,15 @@ module Vagrant public_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s # TODO: Handle errors - lxc :create, '--template', metadata['template-name'], '--name', @name, '--', '-S', public_key, '-T', metadata['tar-cache'] + lxc :create, + # lxc-create options + '--template', metadata['template-name'], + '--name', @name, + '--', + # Template options + '-S', public_key, + '--cache-path', metadata['lxc-cache-path'], + '-T', metadata['tar-cache'] @name end diff --git a/spec/unit/action/handle_box_metadata_spec.rb b/spec/unit/action/handle_box_metadata_spec.rb index afb2ec7..9953ad6 100644 --- a/spec/unit/action/handle_box_metadata_spec.rb +++ b/spec/unit/action/handle_box_metadata_spec.rb @@ -19,8 +19,8 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do subject.call(env) end - it 'prepends box directory to tar-cache' do - metadata['tar-cache'].should == "#{box.directory.to_s}/#{tar_cache}" + it 'sets box directory as lxc-cache-path' do + metadata['lxc-cache-path'].should == box.directory.to_s end it 'prepends box directory to after-create-script' do diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index 3ea90da..72cf496 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -79,12 +79,13 @@ describe Vagrant::LXC::Container do let(:name) { 'random-container-name' } let(:template_name) { 'template-name' } let(:tar_cache_path) { '/path/to/tar/cache' } + let(:lxc_cache) { '/path/to/cache' } let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s } before do subject.stub(lxc: true) SecureRandom.stub(hex: name) - subject.create 'template-name' => template_name, 'tar-cache' => tar_cache_path + subject.create 'template-name' => template_name, 'tar-cache' => tar_cache_path, 'lxc-cache-path' => lxc_cache end it 'calls lxc-create with the right arguments' do @@ -94,6 +95,7 @@ describe Vagrant::LXC::Container do '--name', name, '--', '-S', public_key_path, + '--cache-path', lxc_cache, '-T', tar_cache_path ) end