From 2b08ae199feebdf4f483c71aa86d159553fe9b71 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 13 Jan 2018 20:34:41 -0500 Subject: [PATCH] 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. --- lib/vagrant-lxc/driver.rb | 4 +--- lib/vagrant-lxc/driver/cli.rb | 18 ++---------------- spec/unit/driver/cli_spec.rb | 26 ++------------------------ spec/unit/driver_spec.rb | 15 +++------------ 4 files changed, 8 insertions(+), 55 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index ce5191d3..5ab98d6d 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -17,8 +17,6 @@ class Driver 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 @@ def validate! # 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 diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 373c4588..98c414c6 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -29,7 +29,7 @@ def list 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 @@ def version 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 + run(:config, param).gsub("\n", '') end def state @@ -155,16 +151,6 @@ def supports_attach? 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) diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index ab0c2aa8..0d5aa61f 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -30,16 +30,7 @@ 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 '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" } diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index 9851acd2..7aae013b 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -89,7 +89,7 @@ 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 @@ 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 @@ 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