driver: little cleanup after LXC 1.0+ requirement bump
The conditional `lxc-version` and `lxc-config` mechanisms aren't needed anymore. They were for pre-1.0 LXC versions.
This commit is contained in:
parent
aa777653f4
commit
2b08ae199f
4 changed files with 8 additions and 55 deletions
|
@ -17,8 +17,6 @@ module Vagrant
|
|||
class ContainerNotFound < StandardError; end
|
||||
|
||||
# Default root folder where container configs are stored
|
||||
DEFAULT_CONTAINERS_PATH = '/var/lib/lxc'
|
||||
|
||||
attr_reader :container_name,
|
||||
:customizations
|
||||
|
||||
|
@ -36,7 +34,7 @@ module Vagrant
|
|||
|
||||
# Root folder where container configs are stored
|
||||
def containers_path
|
||||
@containers_path ||= @cli.support_config_command? ? @cli.config('lxc.lxcpath') : DEFAULT_CONTAINERS_PATH
|
||||
@containers_path ||= @cli.config('lxc.lxcpath')
|
||||
end
|
||||
|
||||
def all_containers
|
||||
|
|
|
@ -29,7 +29,7 @@ module Vagrant
|
|||
|
||||
def version
|
||||
return @version if @version
|
||||
@version = support_version_command? ? run(:version) : run(:create, '--version')
|
||||
@version = run(:create, '--version')
|
||||
if @version =~ /(lxc version:\s+|)(.+)\s*$/
|
||||
@version = $2.downcase
|
||||
else
|
||||
|
@ -39,11 +39,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def config(param)
|
||||
if support_config_command?
|
||||
run(:config, param).gsub("\n", '')
|
||||
else
|
||||
raise Errors::CommandNotSupported, name: 'config', available_version: '> 1.x.x', version: version
|
||||
end
|
||||
end
|
||||
|
||||
def state
|
||||
|
@ -155,16 +151,6 @@ module Vagrant
|
|||
return @supports_attach
|
||||
end
|
||||
|
||||
def support_config_command?
|
||||
version[0].to_i >= 1
|
||||
end
|
||||
|
||||
def support_version_command?
|
||||
@sudo_wrapper.run('which', 'lxc-version').strip.chomp != ''
|
||||
rescue Vagrant::LXC::Errors::ExecuteError
|
||||
return false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run(command, *args)
|
||||
|
|
|
@ -30,16 +30,7 @@ describe Vagrant::LXC::Driver::CLI do
|
|||
|
||||
describe 'version' do
|
||||
before do
|
||||
allow(subject).to receive(:support_version_command?).and_return(true)
|
||||
allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
|
||||
end
|
||||
|
||||
describe 'lxc version before 1.x.x' do
|
||||
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
|
||||
|
||||
it 'parses the version from the output' do
|
||||
expect(subject.version).to eq('0.x.y-rc1')
|
||||
end
|
||||
allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
|
||||
end
|
||||
|
||||
describe 'lxc version after 1.x.x' do
|
||||
|
@ -53,24 +44,11 @@ describe Vagrant::LXC::Driver::CLI do
|
|||
|
||||
describe 'config' do
|
||||
before do
|
||||
allow(subject).to receive(:support_version_command?).and_return(support_version_command?)
|
||||
allow(subject).to receive(:run).with(:config, 'lxc.lxcpath').and_return(lxc_config_out)
|
||||
allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
|
||||
allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
|
||||
end
|
||||
|
||||
describe 'lxc version before 1.x.x' do
|
||||
let(:support_version_command?) { true }
|
||||
let(:lxc_config_out) { "/var/lib/lxc\n" }
|
||||
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
|
||||
|
||||
it 'not supported' do
|
||||
expect{subject.config('lxc.lxcpath')}.to raise_error(Vagrant::LXC::Errors::CommandNotSupported)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lxc version before after 1.x.x'do
|
||||
let(:support_version_command?) { false }
|
||||
describe 'lxc version after 1.x.x'do
|
||||
let(:lxc_config_out) { "/var/lib/lxc\n" }
|
||||
let(:lxc_version_out) { "1.0.0\n" }
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ describe Vagrant::LXC::Driver do
|
|||
describe 'start' do
|
||||
let(:customizations) { [['a', '1'], ['b', '2']] }
|
||||
let(:internal_customization) { ['internal', 'customization'] }
|
||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, start: true, support_config_command?: false) }
|
||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, start: true) }
|
||||
let(:sudo) { double(Vagrant::LXC::SudoWrapper) }
|
||||
|
||||
subject { described_class.new('name', sudo, cli) }
|
||||
|
@ -99,6 +99,7 @@ describe Vagrant::LXC::Driver do
|
|||
and_return('# CONFIGURATION')
|
||||
sudo.should_receive(:run).twice.with('cp', '-f', %r{/(run|tmp)/.*}, '/var/lib/lxc/name/config')
|
||||
sudo.should_receive(:run).twice.with('chown', 'root:root', '/var/lib/lxc/name/config')
|
||||
expect(cli).to receive(:config).with("lxc.lxcpath").and_return("/var/lib/lxc")
|
||||
|
||||
subject.customizations << internal_customization
|
||||
subject.start(customizations)
|
||||
|
@ -152,21 +153,11 @@ describe Vagrant::LXC::Driver do
|
|||
end
|
||||
|
||||
describe 'containers_path' do
|
||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, config: cli_config_value, support_config_command?: cli_support_config_command_value) }
|
||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, config: cli_config_value) }
|
||||
|
||||
subject { described_class.new('name', nil, cli) }
|
||||
|
||||
describe 'lxc version before 1.x.x' do
|
||||
let(:cli_support_config_command_value) { false }
|
||||
let(:cli_config_value) { '/var/lib/lxc' }
|
||||
|
||||
it 'delegates to cli' do
|
||||
expect(subject.containers_path).to eq(cli_config_value)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lxc version after 1.x.x' do
|
||||
let(:cli_support_config_command_value) { true }
|
||||
let(:cli_config_value) { '/etc/lxc' }
|
||||
|
||||
it 'delegates to cli' do
|
||||
|
|
Loading…
Reference in a new issue