From 082f7dc5d3e0db0a3809dd080a511bf9aa763fbc Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 5 Apr 2013 02:17:19 -0300 Subject: [PATCH] Rename Container to Driver --- lib/vagrant-lxc/{container.rb => driver.rb} | 12 ++++---- lib/vagrant-lxc/{container => driver}/cli.rb | 2 +- lib/vagrant-lxc/errors.rb | 2 ++ lib/vagrant-lxc/provider.rb | 6 ++-- spec/unit/action/compress_rootfs_spec.rb | 2 +- spec/unit/action/forward_ports_spec.rb | 2 +- spec/unit/{container => driver}/cli_spec.rb | 5 ++-- .../{container_spec.rb => driver_spec.rb} | 30 +++++++++---------- 8 files changed, 31 insertions(+), 30 deletions(-) rename lib/vagrant-lxc/{container.rb => driver.rb} (95%) rename lib/vagrant-lxc/{container => driver}/cli.rb (99%) rename spec/unit/{container => driver}/cli_spec.rb (98%) rename spec/unit/{container_spec.rb => driver_spec.rb} (76%) diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/driver.rb similarity index 95% rename from lib/vagrant-lxc/container.rb rename to lib/vagrant-lxc/driver.rb index 9c31626..58e4102 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/driver.rb @@ -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 diff --git a/lib/vagrant-lxc/container/cli.rb b/lib/vagrant-lxc/driver/cli.rb similarity index 99% rename from lib/vagrant-lxc/container/cli.rb rename to lib/vagrant-lxc/driver/cli.rb index 57a3deb..519d44a 100644 --- a/lib/vagrant-lxc/container/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -5,7 +5,7 @@ require "vagrant-lxc/errors" module Vagrant module LXC - class Container + class Driver class CLI attr_accessor :name diff --git a/lib/vagrant-lxc/errors.rb b/lib/vagrant-lxc/errors.rb index f94b831..a9cda95 100644 --- a/lib/vagrant-lxc/errors.rb +++ b/lib/vagrant-lxc/errors.rb @@ -1,3 +1,5 @@ +require 'vagrant/errors' + module Vagrant module LXC module Errors diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index f977688..b3f9699 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -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.") diff --git a/spec/unit/action/compress_rootfs_spec.rb b/spec/unit/action/compress_rootfs_spec.rb index 17d854e..5ccd0ad 100644 --- a/spec/unit/action/compress_rootfs_spec.rb +++ b/spec/unit/action/compress_rootfs_spec.rb @@ -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) } diff --git a/spec/unit/action/forward_ports_spec.rb b/spec/unit/action/forward_ports_spec.rb index 0b24296..6a813db 100644 --- a/spec/unit/action/forward_ports_spec.rb +++ b/spec/unit/action/forward_ports_spec.rb @@ -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' } diff --git a/spec/unit/container/cli_spec.rb b/spec/unit/driver/cli_spec.rb similarity index 98% rename from spec/unit/container/cli_spec.rb rename to spec/unit/driver/cli_spec.rb index 14f9b83..35e77d5 100644 --- a/spec/unit/container/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -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 } diff --git a/spec/unit/container_spec.rb b/spec/unit/driver_spec.rb similarity index 76% rename from spec/unit/container_spec.rb rename to spec/unit/driver_spec.rb index b8a0939..4f63236 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/driver_spec.rb @@ -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) }