From a1aa60ded5e31c3a0b0698815b54dbdf0a166721 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 24 Jul 2018 11:15:20 -0400 Subject: [PATCH] Remove supports_attach? and call to /sbin/halt Hosts without support for lxc-attach are ancien and can always use old versions of vagrant-lxc. To be able to move forward more easily, we should be able to assume a functional `lxc-attach`. As for `/sbin/halt`, I'm really not sure it's needed anymore. Let's see if its removal causes problems. --- lib/vagrant-lxc/driver.rb | 4 --- lib/vagrant-lxc/driver/cli.rb | 18 ++--------- spec/unit/driver/cli_spec.rb | 60 ++--------------------------------- spec/unit/driver_spec.rb | 11 ------- 4 files changed, 5 insertions(+), 88 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 1c1a024..01d54fe 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -122,10 +122,6 @@ module Vagrant @cli.destroy end - def supports_attach? - @cli.supports_attach? - end - def attach(*command) @cli.attach(*command) end diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 9832d9e..26b7582 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -89,14 +89,13 @@ module Vagrant # Man Page: # 2 The specified container exists but was not running. def stop - attach '/sbin/halt' if supports_attach? begin run :stop, '--name', @name rescue LXC::Errors::ExecuteError => e if e.exitcode == 2 - @logger.debug "Machine already stopped, lxc-stop returned 2" + @logger.debug "Machine already stopped, lxc-stop returned 2" else - raise e + raise e end end end @@ -142,19 +141,6 @@ module Vagrant end end - def supports_attach? - unless defined?(@supports_attach) - begin - @supports_attach = true - run(:attach, '--name', @name, '--', '/bin/true') - rescue LXC::Errors::ExecuteError - @supports_attach = false - end - end - - return @supports_attach - end - private def run(command, *args) diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index 0d5aa61..1a1cf88 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -134,36 +134,11 @@ describe Vagrant::LXC::Driver::CLI do before do allow(subject).to receive(:run) + subject.stop end - context 'lxc-attach is supported' do - before do - subject.stub(attach: true, supports_attach?: true) - subject.stop - end - - it 'runs a /sbin/halt within the container' do - expect(subject).to have_received(:attach).with('/sbin/halt') - end - - it 'issues a lxc-stop with provided container name' do - expect(subject).to have_received(:run).with(:stop, '--name', name) - end - end - - context 'lxc-attach is not supported' do - before do - subject.stub(attach: false, supports_attach?: false) - subject.stop - end - - it 'runs a /sbin/halt within the container' do - expect(subject).to_not have_received(:attach) - end - - it 'issues a lxc-stop with provided container name' do - expect(subject).to have_received(:run).with(:stop, '--name', name) - end + it 'issues a lxc-stop with provided container name' do + expect(subject).to have_received(:run).with(:stop, '--name', name) end end @@ -231,33 +206,4 @@ describe Vagrant::LXC::Driver::CLI do skip 'waits for the expected container state' end - - describe 'check for whether lxc-attach is supported' do - let(:name) { 'a-running-container' } - subject { described_class.new(sudo_wrapper, name) } - - context 'lxc-attach is present on system' do - before { subject.stub(run: true) } - - it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do - expect(subject.supports_attach?).to be_truthy - expect(subject).to have_received(:run).with( - :attach, '--name', name, '--', '/bin/true' - ) - end - end - - context 'lxc-attach is not present on system' do - before do - allow(subject).to receive(:run).and_raise(Vagrant::LXC::Errors::ExecuteError.new('msg')) - end - - it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do - expect(subject.supports_attach?).to be_falsy - expect(subject).to have_received(:run).with( - :attach, '--name', name, '--', '/bin/true' - ) - end - end - end end diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index 1d78e64..ea8efb6 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -75,17 +75,6 @@ describe Vagrant::LXC::Driver do end end - describe 'supports_attach?' do - let(:cli) { double(Vagrant::LXC::Driver::CLI, supports_attach?: true) } - - subject { described_class.new('name', nil, cli) } - - it 'delegates to cli object' do - expect(subject.supports_attach?).to be_truthy - expect(cli).to have_received(:supports_attach?) - end - end - describe 'start' do let(:customizations) { [['a', '1'], ['b', '2']] } let(:internal_customization) { ['internal', 'customization'] }