2013-03-01 20:45:13 -03:00
|
|
|
require 'unit_helper'
|
|
|
|
|
|
|
|
require 'vagrant-lxc/container'
|
|
|
|
|
|
|
|
describe Vagrant::LXC::Container do
|
2013-03-01 22:47:02 -03:00
|
|
|
# Default subject and machine for specs
|
2013-03-01 20:45:13 -03:00
|
|
|
let(:machine) { fire_double('Vagrant::Machine') }
|
|
|
|
subject { described_class.new(machine) }
|
|
|
|
|
2013-03-01 22:47:02 -03:00
|
|
|
describe 'lxc commands execution' do
|
|
|
|
let(:args) { @args }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.stub(:execute) { |*args| @args = args }
|
|
|
|
subject.lxc :command, '--state', 'RUNNING'
|
|
|
|
end
|
|
|
|
|
2013-03-01 23:08:17 -03:00
|
|
|
it 'prepends sudo' do
|
2013-03-01 22:47:02 -03:00
|
|
|
args[0].should == 'sudo'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the first argument as lxc command suffix' do
|
|
|
|
args[1].should == 'lxc-command'
|
|
|
|
end
|
|
|
|
|
2013-03-01 23:07:15 -03:00
|
|
|
it 'pass through remaining arguments' do
|
2013-03-01 22:47:02 -03:00
|
|
|
args[2].should == '--state'
|
|
|
|
args[3].should == 'RUNNING'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-01 23:07:15 -03:00
|
|
|
describe 'guard for container state' do
|
|
|
|
let(:machine_id) { 'random-machine-id' }
|
|
|
|
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
|
|
|
|
|
|
|
|
before do
|
2013-03-01 23:27:08 -03:00
|
|
|
subject.stub :lxc
|
2013-03-01 23:07:15 -03:00
|
|
|
subject.wait_until :running
|
|
|
|
end
|
|
|
|
|
2013-03-01 23:27:08 -03:00
|
|
|
it 'runs lxc-wait with the machine id and upcased state' do
|
|
|
|
subject.should have_received(:lxc).with(
|
|
|
|
:wait,
|
|
|
|
'--name', machine_id,
|
|
|
|
'--state', 'RUNNING'
|
|
|
|
)
|
2013-03-01 23:07:15 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'creation' do
|
2013-03-01 23:27:08 -03:00
|
|
|
let(:new_machine_id) { 'random-machine-id' }
|
2013-03-02 00:03:48 -03:00
|
|
|
let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s }
|
2013-03-01 20:45:13 -03:00
|
|
|
|
|
|
|
before do
|
2013-03-01 23:27:08 -03:00
|
|
|
subject.stub(:lxc)
|
2013-03-01 20:45:13 -03:00
|
|
|
SecureRandom.stub(hex: new_machine_id)
|
|
|
|
subject.create
|
|
|
|
end
|
|
|
|
|
2013-03-01 22:47:02 -03:00
|
|
|
it 'calls lxc-create with the right arguments' do
|
2013-03-01 23:27:08 -03:00
|
|
|
subject.should have_received(:lxc).with(
|
|
|
|
:create,
|
|
|
|
'--template', 'ubuntu-cloud',
|
|
|
|
'--name', new_machine_id,
|
|
|
|
'--',
|
|
|
|
'-S', public_key_path
|
|
|
|
)
|
2013-03-01 22:47:02 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'start' do
|
2013-03-01 23:08:17 -03:00
|
|
|
let(:machine_id) { 'random-machine-id' }
|
|
|
|
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
|
2013-03-01 22:47:02 -03:00
|
|
|
|
|
|
|
before do
|
2013-03-01 23:08:17 -03:00
|
|
|
subject.stub(lxc: true, wait_until: true)
|
2013-03-01 22:47:02 -03:00
|
|
|
subject.start
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls lxc-start with the right arguments' do
|
2013-03-01 23:27:08 -03:00
|
|
|
subject.should have_received(:lxc).with(
|
|
|
|
:start,
|
|
|
|
'-d',
|
|
|
|
'--name', machine.id
|
|
|
|
)
|
2013-03-01 23:08:17 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'waits for container state to be RUNNING' do
|
|
|
|
subject.should have_received(:wait_until).with(:running)
|
2013-03-01 20:45:13 -03:00
|
|
|
end
|
|
|
|
end
|
2013-03-02 00:05:10 -03:00
|
|
|
|
|
|
|
describe 'state' do
|
|
|
|
let(:machine_id) { 'random-machine-id' }
|
|
|
|
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.stub(lxc: "state: STOPPED\npid: 2")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls lxc-info with the right arguments' do
|
|
|
|
subject.state
|
|
|
|
subject.should have_received(:lxc).with(
|
|
|
|
:info,
|
|
|
|
'--name', machine_id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'maps the output of lxc-info status out to a symbol' do
|
|
|
|
subject.state.should == :stopped
|
|
|
|
end
|
|
|
|
end
|
2013-03-01 20:45:13 -03:00
|
|
|
end
|