lxc-start: check
This commit is contained in:
parent
8b8bfe739b
commit
e9a5385c02
2 changed files with 53 additions and 23 deletions
|
@ -22,13 +22,12 @@ module Vagrant
|
|||
def create
|
||||
# FIXME: Ruby 1.8 users dont have SecureRandom
|
||||
machine_id = SecureRandom.hex(6)
|
||||
log, status = lxc(:create, {'--template' => 'ubuntu-cloud', '--name' => machine_id}, {'-S' => '/home/vagrant/.ssh/id_rsa.pub'})
|
||||
log, status = lxc :create, '--template', 'ubuntu-cloud', '--name', machine_id, '--', '-S', '/home/vagrant/.ssh/id_rsa.pub'
|
||||
machine_id
|
||||
end
|
||||
|
||||
def start
|
||||
puts 'TODO: Start container'
|
||||
update!(:running)
|
||||
lxc :start, '-d', '--name', @machine.id
|
||||
end
|
||||
|
||||
def halt
|
||||
|
@ -40,19 +39,8 @@ module Vagrant
|
|||
File.delete(state_file_path) if state_file_path
|
||||
end
|
||||
|
||||
def state
|
||||
# TODO: Grab the real machine state here
|
||||
read_state_from_file
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lxc(command, params, extra = {})
|
||||
params = params.map { |opt, val| "#{opt}='#{val}'" }
|
||||
params << '--' if extra.any?
|
||||
# Handles extra options passed to templates when using lxc-create
|
||||
params << extra.map { |opt, val| "#{opt} #{val}" }
|
||||
execute('sudo', "lxc-#{command}", *params.flatten)
|
||||
def lxc(command, *args)
|
||||
execute('sudo', "lxc-#{command}", *args)
|
||||
end
|
||||
|
||||
def update!(state)
|
||||
|
|
|
@ -3,17 +3,38 @@ require 'unit_helper'
|
|||
require 'vagrant-lxc/container'
|
||||
|
||||
describe Vagrant::LXC::Container do
|
||||
# Default subject and machine for specs
|
||||
let(:machine) { fire_double('Vagrant::Machine') }
|
||||
|
||||
subject { described_class.new(machine) }
|
||||
|
||||
describe 'lxc commands execution' do
|
||||
let(:args) { @args }
|
||||
|
||||
before do
|
||||
subject.stub(:execute) { |*args| @args = args }
|
||||
subject.lxc :command, '--state', 'RUNNING'
|
||||
end
|
||||
|
||||
it 'prepends sudo for execution' do
|
||||
args[0].should == 'sudo'
|
||||
end
|
||||
|
||||
it 'uses the first argument as lxc command suffix' do
|
||||
args[1].should == 'lxc-command'
|
||||
end
|
||||
|
||||
it 'sends remaining arguments for execution' do
|
||||
args[2].should == '--state'
|
||||
args[3].should == 'RUNNING'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'create' do
|
||||
let(:last_command) { @last_command }
|
||||
let(:new_machine_id) { 'random-machine-id' }
|
||||
|
||||
before do
|
||||
Vagrant::Util::Subprocess.stub(:execute) do |*cmds|
|
||||
cmds.pop if cmds.last.is_a?(Hash)
|
||||
subject.stub(:lxc) do |*cmds|
|
||||
@last_command = cmds.join(' ')
|
||||
mock(exit_code: 0, stdout: '')
|
||||
end
|
||||
|
@ -21,10 +42,31 @@ describe Vagrant::LXC::Container do
|
|||
subject.create
|
||||
end
|
||||
|
||||
it 'runs lxc-create with the right arguments' do
|
||||
last_command.should include "--name='#{new_machine_id}'"
|
||||
last_command.should include "--template='ubuntu-cloud'"
|
||||
last_command.should =~ /\-\- \-S (\w|\/|\.)+\/id_rsa\.pub/
|
||||
it 'calls lxc-create with the right arguments' do
|
||||
last_command.should =~ /^create/
|
||||
last_command.should include "--name #{new_machine_id}"
|
||||
last_command.should include "--template ubuntu-cloud"
|
||||
last_command.should =~ /\-\- \-S (\w|\/|\.)+\/id_rsa\.pub$/
|
||||
end
|
||||
end
|
||||
|
||||
describe 'start' do
|
||||
let(:last_command) { @last_command }
|
||||
let(:machine_id) { 'random-machine-id' }
|
||||
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
|
||||
|
||||
before do
|
||||
subject.stub(:lxc) do |*cmds|
|
||||
@last_command = cmds.join(' ')
|
||||
mock(exit_code: 0, stdout: '')
|
||||
end
|
||||
subject.start
|
||||
end
|
||||
|
||||
it 'calls lxc-start with the right arguments' do
|
||||
last_command.should =~ /^start/
|
||||
last_command.should include "--name #{machine_id}"
|
||||
last_command.should include '-d'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue