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.
This commit is contained in:
parent
61c921ac6f
commit
a1aa60ded5
4 changed files with 5 additions and 88 deletions
|
@ -122,10 +122,6 @@ module Vagrant
|
||||||
@cli.destroy
|
@cli.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_attach?
|
|
||||||
@cli.supports_attach?
|
|
||||||
end
|
|
||||||
|
|
||||||
def attach(*command)
|
def attach(*command)
|
||||||
@cli.attach(*command)
|
@cli.attach(*command)
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,7 +89,6 @@ module Vagrant
|
||||||
# Man Page:
|
# Man Page:
|
||||||
# 2 The specified container exists but was not running.
|
# 2 The specified container exists but was not running.
|
||||||
def stop
|
def stop
|
||||||
attach '/sbin/halt' if supports_attach?
|
|
||||||
begin
|
begin
|
||||||
run :stop, '--name', @name
|
run :stop, '--name', @name
|
||||||
rescue LXC::Errors::ExecuteError => e
|
rescue LXC::Errors::ExecuteError => e
|
||||||
|
@ -142,19 +141,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def run(command, *args)
|
def run(command, *args)
|
||||||
|
|
|
@ -134,39 +134,14 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(subject).to receive(:run)
|
allow(subject).to receive(:run)
|
||||||
end
|
|
||||||
|
|
||||||
context 'lxc-attach is supported' do
|
|
||||||
before do
|
|
||||||
subject.stub(attach: true, supports_attach?: true)
|
|
||||||
subject.stop
|
subject.stop
|
||||||
end
|
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
|
it 'issues a lxc-stop with provided container name' do
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
||||||
end
|
end
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'state' do
|
describe 'state' do
|
||||||
let(:name) { 'a-container' }
|
let(:name) { 'a-container' }
|
||||||
subject { described_class.new(sudo_wrapper, name) }
|
subject { described_class.new(sudo_wrapper, name) }
|
||||||
|
@ -231,33 +206,4 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
skip 'waits for the expected container state'
|
skip 'waits for the expected container state'
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -75,17 +75,6 @@ describe Vagrant::LXC::Driver do
|
||||||
end
|
end
|
||||||
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
|
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'] }
|
||||||
|
|
Loading…
Reference in a new issue