From f1623a9136f0f2aabdee512c7a4110b958efe9a9 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 1 Mar 2013 23:07:15 -0300 Subject: [PATCH] lxc-wait: check --- lib/vagrant-lxc/container.rb | 4 ++++ spec/unit/container_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index be9ff21..a97ea8a 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -39,6 +39,10 @@ module Vagrant File.delete(state_file_path) if state_file_path end + def wait_until(state) + lxc :wait, '--name', @machine.id, '--state', state.to_s.upcase + end + def lxc(command, *args) execute('sudo', "lxc-#{command}", *args) end diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index 1be33ec..8a99eff 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -23,13 +23,35 @@ describe Vagrant::LXC::Container do args[1].should == 'lxc-command' end - it 'sends remaining arguments for execution' do + it 'pass through remaining arguments' do args[2].should == '--state' args[3].should == 'RUNNING' end end - describe 'create' do + describe 'guard for container state' 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.wait_until :running + end + + it 'runs lxc-wait with the machine id' do + last_command.should include "--name #{machine_id}" + end + + it 'runs lxc-wait with upcased state' do + last_command.should include "--state RUNNING" + end + end + + describe 'creation' do let(:last_command) { @last_command } let(:new_machine_id) { 'random-machine-id' }