Rename Container to Driver

This commit is contained in:
Fabio Rehm 2013-04-05 02:17:19 -03:00
parent 4ebc691bda
commit 082f7dc5d3
8 changed files with 31 additions and 30 deletions

View file

@ -1,14 +1,14 @@
require 'securerandom'
require "vagrant-lxc/errors"
require "vagrant-lxc/container/cli"
require "vagrant/util/retryable"
require "vagrant/util/subprocess"
require "vagrant-lxc/errors"
require "vagrant-lxc/driver/cli"
module Vagrant
module LXC
class Container
class Driver
# Root folder where containers are stored
CONTAINERS_PATH = '/var/lib/lxc'
@ -17,7 +17,7 @@ module Vagrant
# This is raised if the container can't be found when initializing it with
# a name.
class NotFound < StandardError; end
class ContainerNotFound < StandardError; end
attr_reader :name
@ -28,7 +28,7 @@ module Vagrant
end
def validate!
raise NotFound if @name && ! @cli.list.include?(@name)
raise ContainerNotFound if @name && ! @cli.list.include?(@name)
end
def base_path

View file

@ -5,7 +5,7 @@ require "vagrant-lxc/errors"
module Vagrant
module LXC
class Container
class Driver
class CLI
attr_accessor :name

View file

@ -1,3 +1,5 @@
require 'vagrant/errors'
module Vagrant
module LXC
module Errors

View file

@ -1,7 +1,7 @@
require "log4r"
require "vagrant-lxc/action"
require "vagrant-lxc/container"
require "vagrant-lxc/driver"
require "vagrant-lxc/machine_state"
module Vagrant
@ -23,9 +23,9 @@ module Vagrant
begin
@logger.debug("Instantiating the container for: #{id.inspect}")
@container = Container.new(id)
@container = Driver.new(id)
@container.validate!
rescue Container::NotFound
rescue Driver::ContainerNotFound
# The container doesn't exist, so we probably have a stale
# ID. Just clear the id out of the machine and reload it.
@logger.debug("Container not found! Clearing saved machine ID and reloading.")

View file

@ -7,7 +7,7 @@ describe Vagrant::LXC::Action::CompressRootFS do
let(:env) { {machine: machine, ui: stub(info: true)} }
let(:machine) { fire_double('Vagrant::Machine', provider: provider) }
let(:provider) { fire_double('Vagrant::LXC::Provider', container: container) }
let(:container) { fire_double('Vagrant::LXC::Container', compress_rootfs: compressed_rootfs_path) }
let(:container) { fire_double('Vagrant::LXC::Driver', compress_rootfs: compressed_rootfs_path) }
let(:compressed_rootfs_path) { '/path/to/rootfs.tar.gz' }
subject { described_class.new(app, env) }

View file

@ -11,7 +11,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
let(:host_port) { 8080 }
let(:guest_port) { 80 }
let(:provider) { fire_double('Vagrant::LXC::Provider', container: container) }
let(:container) { fire_double('Vagrant::LXC::Container', assigned_ip: container_ip) }
let(:container) { fire_double('Vagrant::LXC::Driver', assigned_ip: container_ip) }
let(:container_ip) { '10.0.1.234' }
let(:pid) { 'a-pid' }

View file

@ -1,9 +1,8 @@
require 'unit_helper'
require 'vagrant'
require 'vagrant-lxc/container/cli'
require 'vagrant-lxc/driver/cli'
describe Vagrant::LXC::Container::CLI do
describe Vagrant::LXC::Driver::CLI do
describe 'list' do
let(:lxc_ls_out) { "dup-container\na-container dup-container" }
let(:exec_args) { @exec_args }

View file

@ -1,9 +1,9 @@
require 'unit_helper'
require 'vagrant'
require 'vagrant-lxc/container'
require 'vagrant-lxc/driver'
describe Vagrant::LXC::Container do
describe Vagrant::LXC::Driver do
let(:name) { nil }
subject { described_class.new(name) }
@ -11,24 +11,24 @@ describe Vagrant::LXC::Container do
let(:unknown_container) { described_class.new('unknown', cli) }
let(:valid_container) { described_class.new('valid', cli) }
let(:new_container) { described_class.new(nil) }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', list: ['valid']) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', list: ['valid']) }
it 'raises a NotFound error if an unknown container name gets provided' do
it 'raises a ContainerNotFound error if an unknown container name gets provided' do
expect {
unknown_container.validate!
}.to raise_error(Vagrant::LXC::Container::NotFound)
}.to raise_error(Vagrant::LXC::Driver::ContainerNotFound)
end
it 'does not raise a NotFound error if a valid container name gets provided' do
it 'does not raise a ContainerNotFound error if a valid container name gets provided' do
expect {
valid_container.validate!
}.to_not raise_error(Vagrant::LXC::Container::NotFound)
}.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound)
end
it 'does not raise a NotFound error if nil is provider as name' do
it 'does not raise a ContainerNotFound error if nil is provider as name' do
expect {
new_container.validate!
}.to_not raise_error(Vagrant::LXC::Container::NotFound)
}.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound)
end
end
@ -39,7 +39,7 @@ describe Vagrant::LXC::Container do
let(:rootfs_tarball) { '/path/to/cache/rootfs.tar.gz' }
let(:target_rootfs) { '/path/to/rootfs' }
let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', :create => true, :name= => true) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :create => true, :name= => true) }
subject { described_class.new(name, cli) }
@ -62,7 +62,7 @@ describe Vagrant::LXC::Container do
describe 'destruction' do
let(:name) { 'container-name' }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', destroy: true) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', destroy: true) }
subject { described_class.new(name, cli) }
@ -76,7 +76,7 @@ describe Vagrant::LXC::Container do
describe 'start' do
let(:config) { mock(:config, start_opts: ['a=1', 'b=2']) }
let(:name) { 'container-name' }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', start: true) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) }
subject { described_class.new(name, cli) }
@ -97,7 +97,7 @@ describe Vagrant::LXC::Container do
describe 'halt' do
let(:name) { 'container-name' }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', shutdown: true) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', shutdown: true) }
subject { described_class.new(name, cli) }
@ -119,7 +119,7 @@ describe Vagrant::LXC::Container do
describe 'state' do
let(:name) { 'random-container-name' }
let(:cli_state) { :something }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', state: cli_state) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', state: cli_state) }
subject { described_class.new(name, cli) }
@ -133,7 +133,7 @@ describe Vagrant::LXC::Container do
let(:ip) { "10.0.3.109" }
let(:ifconfig_output) { File.read('spec/fixtures/sample-ifconfig-output') }
let(:name) { 'random-container-name' }
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', :attach => ifconfig_output) }
let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :attach => ifconfig_output) }
subject { described_class.new(name, cli) }