Hack in a fix for hosts that do not have lxc-shutdown around [GH-150]
This commit is contained in:
parent
5833e262aa
commit
2b062487bc
5 changed files with 27 additions and 3 deletions
|
@ -4,6 +4,10 @@ IMPROVEMENTS:
|
||||||
|
|
||||||
- Make `lxc-template` compatible with Ubuntu 13.10 [#150](https://github.com/fgrehm/vagrant-lxc/issues/150)
|
- Make `lxc-template` compatible with Ubuntu 13.10 [#150](https://github.com/fgrehm/vagrant-lxc/issues/150)
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
|
||||||
|
- Fix force halt for hosts that do not have `lxc-shutdown` around (like Ubuntu 13.10) [#150](https://github.com/fgrehm/vagrant-lxc/issues/150)
|
||||||
|
|
||||||
## [0.6.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.6.2...v0.6.3) (Oct 12, 2013)
|
## [0.6.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.6.2...v0.6.3) (Oct 12, 2013)
|
||||||
|
|
||||||
IMPROVEMENTS:
|
IMPROVEMENTS:
|
||||||
|
|
|
@ -84,7 +84,8 @@ module Vagrant
|
||||||
def forced_halt
|
def forced_halt
|
||||||
@logger.info('Shutting down container...')
|
@logger.info('Shutting down container...')
|
||||||
@cli.transition_to(:stopped) { |c| c.shutdown }
|
@cli.transition_to(:stopped) { |c| c.shutdown }
|
||||||
rescue CLI::TargetStateNotReached
|
# REFACTOR: Do not use exception to control the flow
|
||||||
|
rescue CLI::TargetStateNotReached, CLI::ShutdownNotSupported
|
||||||
@cli.transition_to(:stopped) { |c| c.stop }
|
@cli.transition_to(:stopped) { |c| c.stop }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ module Vagrant
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
|
||||||
class TransitionBlockNotProvided < RuntimeError; end
|
class TransitionBlockNotProvided < RuntimeError; end
|
||||||
|
class ShutdownNotSupported < RuntimeError; end
|
||||||
class TargetStateNotReached < RuntimeError
|
class TargetStateNotReached < RuntimeError
|
||||||
def initialize(target_state, state)
|
def initialize(target_state, state)
|
||||||
msg = "Target state '#{target_state}' not reached, currently on '#{state}'"
|
msg = "Target state '#{target_state}' not reached, currently on '#{state}'"
|
||||||
|
@ -72,7 +73,12 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def shutdown
|
def shutdown
|
||||||
run :shutdown, '--name', @name
|
if system('which lxc-shutdown > /dev/null')
|
||||||
|
run :shutdown, '--name', @name
|
||||||
|
else
|
||||||
|
# REFACTOR: Do not use exception to control the flow
|
||||||
|
raise ShutdownNotSupported
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach(*cmd)
|
def attach(*cmd)
|
||||||
|
|
|
@ -103,13 +103,19 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
subject { described_class.new(sudo_wrapper, name) }
|
subject { described_class.new(sudo_wrapper, name) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
subject.stub(system: true)
|
||||||
subject.stub(:run)
|
subject.stub(:run)
|
||||||
subject.shutdown
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'issues a lxc-shutdown with provided container name' do
|
it 'issues a lxc-shutdown with provided container name' do
|
||||||
|
subject.shutdown
|
||||||
subject.should have_received(:run).with(:shutdown, '--name', name)
|
subject.should have_received(:run).with(:shutdown, '--name', name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'raises a ShutdownNotSupported in case it is not supported' do
|
||||||
|
subject.stub(:system).with('which lxc-shutdown > /dev/null').and_return(false)
|
||||||
|
expect { subject.shutdown }.to raise_error(described_class::ShutdownNotSupported)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'state' do
|
describe 'state' do
|
||||||
|
|
|
@ -118,6 +118,13 @@ describe Vagrant::LXC::Driver do
|
||||||
cli.should_receive(:stop)
|
cli.should_receive(:stop)
|
||||||
subject.forced_halt
|
subject.forced_halt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'attempts to force the container to stop in case lxc-shutdown is not supported' do
|
||||||
|
cli.stub(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::ShutdownNotSupported)
|
||||||
|
cli.should_receive(:transition_to).with(:stopped).twice
|
||||||
|
cli.should_receive(:stop)
|
||||||
|
subject.forced_halt
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'state' do
|
describe 'state' do
|
||||||
|
|
Loading…
Reference in a new issue