Begin to make use of CLI from LXC::Container
This commit is contained in:
parent
811d9a4b29
commit
567ede7db6
2 changed files with 9 additions and 11 deletions
|
@ -1,11 +1,12 @@
|
||||||
# FIXME: Ruby 1.8 users dont have SecureRandom
|
# FIXME: Ruby 1.8 users dont have SecureRandom
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
|
|
||||||
|
require "vagrant-lxc/errors"
|
||||||
|
require "vagrant-lxc/container/cli"
|
||||||
|
|
||||||
require "vagrant/util/retryable"
|
require "vagrant/util/retryable"
|
||||||
require "vagrant/util/subprocess"
|
require "vagrant/util/subprocess"
|
||||||
|
|
||||||
require "vagrant-lxc/errors"
|
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
class Container
|
class Container
|
||||||
|
@ -21,13 +22,14 @@ module Vagrant
|
||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name, cli = CLI.new(name))
|
||||||
@name = name
|
@name = name
|
||||||
|
@cli = cli
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::lxc::container")
|
@logger = Log4r::Logger.new("vagrant::provider::lxc::container")
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate!
|
def validate!
|
||||||
raise NotFound if @name && ! lxc(:ls).split("\n").include?(@name)
|
raise NotFound if @name && ! @cli.list.include?(@name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_path
|
def base_path
|
||||||
|
|
|
@ -8,14 +8,10 @@ describe Vagrant::LXC::Container do
|
||||||
subject { described_class.new(name) }
|
subject { described_class.new(name) }
|
||||||
|
|
||||||
describe 'container name validation' do
|
describe 'container name validation' do
|
||||||
let(:unknown_container) { described_class.new('unknown') }
|
let(:unknown_container) { described_class.new('unknown', cli) }
|
||||||
let(:valid_container) { described_class.new('valid') }
|
let(:valid_container) { described_class.new('valid', cli) }
|
||||||
let(:new_container) { described_class.new(nil) }
|
let(:new_container) { described_class.new(nil) }
|
||||||
|
let(:cli) { fire_double('Vagrant::LXC::CLI', list: ['valid']) }
|
||||||
before do
|
|
||||||
unknown_container.stub(lxc: 'valid')
|
|
||||||
valid_container.stub(lxc: 'valid')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'raises a NotFound error if an unknown container name gets provided' do
|
it 'raises a NotFound error if an unknown container name gets provided' do
|
||||||
expect {
|
expect {
|
||||||
|
|
Loading…
Add table
Reference in a new issue