Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Remove supports_attach? and call to /sbin/halt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Virgil Dupras committed Jul 24, 2018
1 parent 61c921a commit a1aa60d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 88 deletions.
4 changes: 0 additions & 4 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ def destroy
@cli.destroy
end

def supports_attach?
@cli.supports_attach?
end

def attach(*command)
@cli.attach(*command)
end
Expand Down
18 changes: 2 additions & 16 deletions lib/vagrant-lxc/driver/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ def start(options = [])
# 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
Expand Down Expand Up @@ -142,19 +141,6 @@ def transition_to(target_state, tries = 30, timeout = 1, &block)
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)
Expand Down
60 changes: 3 additions & 57 deletions spec/unit/driver/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,11 @@

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

Expand Down Expand Up @@ -231,33 +206,4 @@

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
11 changes: 0 additions & 11 deletions spec/unit/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@
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'] }
Expand Down

0 comments on commit a1aa60d

Please sign in to comment.