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:
Virgil Dupras 2018-01-13 20:34:41 -05:00
parent aa777653f4
commit 2b08ae199f
4 changed files with 8 additions and 55 deletions

View file

@ -17,8 +17,6 @@ module Vagrant
class ContainerNotFound < StandardError; end class ContainerNotFound < StandardError; end
# Default root folder where container configs are stored # Default root folder where container configs are stored
DEFAULT_CONTAINERS_PATH = '/var/lib/lxc'
attr_reader :container_name, attr_reader :container_name,
:customizations :customizations
@ -36,7 +34,7 @@ module Vagrant
# Root folder where container configs are stored # Root folder where container configs are stored
def containers_path def containers_path
@containers_path ||= @cli.support_config_command? ? @cli.config('lxc.lxcpath') : DEFAULT_CONTAINERS_PATH @containers_path ||= @cli.config('lxc.lxcpath')
end end
def all_containers def all_containers

View file

@ -29,7 +29,7 @@ module Vagrant
def version def version
return @version if @version return @version if @version
@version = support_version_command? ? run(:version) : run(:create, '--version') @version = run(:create, '--version')
if @version =~ /(lxc version:\s+|)(.+)\s*$/ if @version =~ /(lxc version:\s+|)(.+)\s*$/
@version = $2.downcase @version = $2.downcase
else else
@ -39,11 +39,7 @@ module Vagrant
end end
def config(param) def config(param)
if support_config_command? run(:config, param).gsub("\n", '')
run(:config, param).gsub("\n", '')
else
raise Errors::CommandNotSupported, name: 'config', available_version: '> 1.x.x', version: version
end
end end
def state def state
@ -155,16 +151,6 @@ module Vagrant
return @supports_attach return @supports_attach
end 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 private
def run(command, *args) def run(command, *args)

View file

@ -30,16 +30,7 @@ describe Vagrant::LXC::Driver::CLI do
describe 'version' do describe 'version' do
before do before do
allow(subject).to receive(:support_version_command?).and_return(true) allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
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
end end
describe 'lxc version after 1.x.x' do describe 'lxc version after 1.x.x' do
@ -53,24 +44,11 @@ describe Vagrant::LXC::Driver::CLI do
describe 'config' do describe 'config' do
before 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(: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) allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
end end
describe 'lxc version before 1.x.x' do describe 'lxc version after 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 }
let(:lxc_config_out) { "/var/lib/lxc\n" } let(:lxc_config_out) { "/var/lib/lxc\n" }
let(:lxc_version_out) { "1.0.0\n" } let(:lxc_version_out) { "1.0.0\n" }

View file

@ -89,7 +89,7 @@ describe Vagrant::LXC::Driver do
describe 'start' do describe 'start' do
let(:customizations) { [['a', '1'], ['b', '2']] } let(:customizations) { [['a', '1'], ['b', '2']] }
let(:internal_customization) { ['internal', 'customization'] } 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) } let(:sudo) { double(Vagrant::LXC::SudoWrapper) }
subject { described_class.new('name', sudo, cli) } subject { described_class.new('name', sudo, cli) }
@ -99,6 +99,7 @@ describe Vagrant::LXC::Driver do
and_return('# CONFIGURATION') 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('cp', '-f', %r{/(run|tmp)/.*}, '/var/lib/lxc/name/config')
sudo.should_receive(:run).twice.with('chown', 'root:root', '/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.customizations << internal_customization
subject.start(customizations) subject.start(customizations)
@ -152,21 +153,11 @@ describe Vagrant::LXC::Driver do
end end
describe 'containers_path' do 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) } 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 describe 'lxc version after 1.x.x' do
let(:cli_support_config_command_value) { true }
let(:cli_config_value) { '/etc/lxc' } let(:cli_config_value) { '/etc/lxc' }
it 'delegates to cli' do it 'delegates to cli' do