Removing references to Vagrant::Env

This commit is contained in:
Mitchell Hashimoto 2010-03-19 21:15:45 -07:00
parent bafd15661d
commit 5db99c04d4
13 changed files with 65 additions and 47 deletions

View File

@ -51,7 +51,7 @@ module Vagrant
def with_tempfile
logger.info "Creating tempfile for storing box file..."
Tempfile.open(BASENAME, Env.tmp_path) do |tempfile|
Tempfile.open(BASENAME, @runner.env.tmp_path) do |tempfile|
yield tempfile
end
end

View File

@ -5,7 +5,7 @@ module Vagrant
def prepare
# If the dotfile is not a file, raise error
if File.exist?(@runner.env.dotfile_path) && !File.file?(@runner.env.dotfile_path)
raise ActionException.new(:dotfile_error)
raise ActionException.new(:dotfile_error, :env => @runner.env)
end
# Up is a "meta-action" so it really just queues up a bunch

View File

@ -12,7 +12,7 @@ module Vagrant
# begin using vagrant. The configuration file contains some documentation
# to get you started.
def init(default_box=nil)
rootfile_path = File.join(Dir.pwd, Env::ROOTFILE_NAME)
rootfile_path = File.join(Dir.pwd, Environment::ROOTFILE_NAME)
if File.exist?(rootfile_path)
error_and_exit(:rootfile_already_exists)
end
@ -20,7 +20,7 @@ module Vagrant
# Copy over the rootfile template into this directory
default_box ||= "base"
File.open(rootfile_path, 'w+') do |f|
f.write(TemplateRenderer.render(Env::ROOTFILE_NAME, :default_box => default_box))
f.write(TemplateRenderer.render(Environment::ROOTFILE_NAME, :default_box => default_box))
end
end

View File

@ -9,17 +9,20 @@ module Vagrant
@@config = nil
class << self
def reset!
def reset!(env=nil)
@@config = nil
proc_stack.clear
# Reset the configuration to the specified environment
config(env)
end
def configures(key, klass)
config.class.configures(key, klass)
end
def config
@@config ||= Config::Top.new
def config(env=nil)
@@config ||= Config::Top.new(env)
end
def run(&block)
@ -36,6 +39,8 @@ module Vagrant
class Config
class Base
attr_accessor :env
def [](key)
send(key)
end
@ -62,7 +67,7 @@ module Vagrant
attr_accessor :private_key_path
def private_key_path
File.expand_path(@private_key_path, Env.root_path)
File.expand_path(@private_key_path, env.root_path)
end
end
@ -108,11 +113,11 @@ module Vagrant
end
def shared_folder_uid
@shared_folder_uid || Vagrant.config.ssh.username
@shared_folder_uid || env.config.ssh.username
end
def shared_folder_gid
@shared_folder_gid || Vagrant.config.ssh.username
@shared_folder_gid || env.config.ssh.username
end
def customize(&block)
@ -155,12 +160,15 @@ module Vagrant
configures :vm, VMConfig
configures :vagrant, VagrantConfig
def initialize
def initialize(env=nil)
self.class.configures_list.each do |key, klass|
instance_variable_set("@#{key}".to_sym, klass.new)
config = klass.new
config.env = env
instance_variable_set("@#{key}".to_sym, config)
end
@loaded = false
@env = env
end
def loaded?

View File

@ -125,7 +125,7 @@ module Vagrant
load_paths << File.join(root_path, ROOTFILE_NAME) if root_path
# Clear out the old data
Config.reset!
Config.reset!(self)
# Load each of the config files in order
load_paths.each do |path|

View File

@ -28,7 +28,7 @@
\nvagrant box list"
:dotfile_error: "The dotfile which Vagrant uses to store the UUID of the project's
\nvirtual machine already exists and is not a file! The dotfile is
\ncurrently configured to be `<%= Vagrant::Env.dotfile_path %>`
\ncurrently configured to be `<%= env.dotfile_path %>`
\nTo change this value, please see `config.vagrant.dotfile_name`
@ -41,16 +41,16 @@
:environment_not_created: "The task you're trying to run requires that the vagrant environment
\nalready be created, but unfortunately this vagrant still appears to
\nhave no box! You can setup the environment by setting up your
\n<%= Vagrant::Env::ROOTFILE_NAME %> and running `vagrant up`"
\n<%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up`"
:package_include_file_doesnt_exist: "File specified to include: '<%= filename %>' does not exist!"
:package_requires_export: "Package must be used in conjunction with export."
:provisioner_invalid_class: "Provisioners must be an instance of Vagrant::Provisioners::Base"
:provisioner_unknown_type: "Unknown provisioner type: <%= provisioner %>"
:rootfile_already_exists: "It looks like this directory is already setup for vagrant! (A <%= Vagrant::Env::ROOTFILE_NAME %>
:rootfile_already_exists: "It looks like this directory is already setup for vagrant! (A <%= Vagrant::Environment::ROOTFILE_NAME %>
\nalready exists.)"
:rootfile_not_found: "A `<%= Vagrant::Env::ROOTFILE_NAME %>` was not found! This file is required for vagrant to run
:rootfile_not_found: "A `<%= Vagrant::Environment::ROOTFILE_NAME %>` was not found! This file is required for vagrant to run
\nsince it describes the expected environment that vagrant is supposed
\nto manage. Please create a `<%= Vagrant::Env::ROOTFILE_NAME %>` and place it in your project
\nto manage. Please create a `<%= Vagrant::Environment::ROOTFILE_NAME %>` and place it in your project
\nroot."
:ssh_bad_permissions: "The private key to connect to this box via SSH has invalid permissions
\nset on it. The permissions of the private key should be set to 0600, otherwise SSH will

View File

@ -20,7 +20,9 @@ require 'mocha'
class Test::Unit::TestCase
# Mocks an environment, setting it up with the given config.
def mock_environment
Vagrant::Config.reset!
environment = Vagrant::Environment.new
Vagrant::Config.reset!(environment)
Vagrant::Config.run do |config|
config.vagrant.dotfile_name = ".vagrant"
@ -66,7 +68,6 @@ class Test::Unit::TestCase
config = Vagrant::Config.execute!
environment = Vagrant::Environment.new
environment.instance_variable_set(:@config, config)
environment
end

View File

@ -8,7 +8,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
@runner.stubs(:temp_path=)
mock_config
Vagrant::Env.stubs(:tmp_path).returns("foo")
@runner.env.stubs(:tmp_path).returns("foo")
end
context "preparing" do
@ -81,7 +81,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
context "tempfile" do
should "create a tempfile in the vagrant tmp directory" do
Tempfile.expects(:open).with(Vagrant::Actions::Box::Download::BASENAME, Vagrant::Env.tmp_path).once
Tempfile.expects(:open).with(Vagrant::Actions::Box::Download::BASENAME, @runner.env.tmp_path).once
@action.with_tempfile
end

View File

@ -7,7 +7,7 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
@runner.stubs(:temp_path).returns("bar")
mock_config
Vagrant::Env.stubs(:boxes_path).returns("bar")
@runner.env.stubs(:boxes_path).returns("bar")
end
context "executing" do

View File

@ -2,12 +2,8 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
class CommandsTest < Test::Unit::TestCase
setup do
Vagrant::Env.stubs(:load!)
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
Vagrant::Env.stubs(:require_persisted_vm)
@env = mock_environment
@env.stubs(:vm).returns(@persisted_vm)
@ -20,7 +16,7 @@ class CommandsTest < Test::Unit::TestCase
@file = mock("file")
@file.stubs(:write)
File.stubs(:open).yields(@file)
@rootfile_path = File.join(Dir.pwd, Vagrant::Env::ROOTFILE_NAME)
@rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME)
Vagrant::Util::TemplateRenderer.stubs(:render)
end
@ -42,12 +38,12 @@ class CommandsTest < Test::Unit::TestCase
should "use the given base box if given" do
box = "zooo"
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Env::ROOTFILE_NAME, :default_box => box)
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box)
Vagrant::Commands.init(box)
end
should "use the default `base` if no box is given" do
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Env::ROOTFILE_NAME, :default_box => "base")
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base")
Vagrant::Commands.init
end
end

View File

@ -2,10 +2,14 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
class ConfigTest < Test::Unit::TestCase
context "the ssh config" do
setup do
@env = mock_environment
@env.stubs(:root_path).returns("foo")
end
should "expand any path when requesting the value" do
Vagrant::Env.stubs(:root_path).returns('foo')
File.stubs(:expand_path).with(Vagrant.config.ssh[:private_key_path], 'foo').returns('success')
assert Vagrant.config.ssh.private_key_path, 'success'
result = File.expand_path(@env.config.ssh[:private_key_path], @env.root_path)
assert_equal result, @env.config.ssh.private_key_path
end
end
@ -40,6 +44,12 @@ class ConfigTest < Test::Unit::TestCase
Vagrant::Config.reset!
assert Vagrant::Config.proc_stack.empty?
end
should "reload the config object based on the given environment" do
env = mock("env")
Vagrant::Config.expects(:config).with(env).once
Vagrant::Config.reset!(env)
end
end
context "accessing configuration" do
@ -144,21 +154,25 @@ class ConfigTest < Test::Unit::TestCase
end
should "initialize each configurer and set it to its key" do
env = mock('env')
5.times do |i|
key = "key#{i}"
klass = mock("klass#{i}")
instance = mock("instance#{i}")
instance.expects(:env=).with(env)
klass.expects(:new).returns(instance)
@configures_list << [key, klass]
end
Vagrant::Config::Top.new
Vagrant::Config::Top.new(env)
end
should "allow reading via methods" do
key = "my_foo_bar_key"
klass = mock("klass")
instance = mock("instance")
instance.stubs(:env=)
klass.expects(:new).returns(instance)
Vagrant::Config::Top.configures(key, klass)
@ -202,12 +216,9 @@ class ConfigTest < Test::Unit::TestCase
context "VM configuration" do
setup do
@config = Vagrant::Config::VMConfig.new
@username = "bob"
mock_config do |config|
config.ssh.username = @username
end
@env = mock_environment
@config = @env.config.vm
@env.config.ssh.username = @username
end
should "include the stacked proc runner module" do

View File

@ -14,7 +14,7 @@ class EnvironmentTest < Test::Unit::TestCase
should "not error and exit if everything is good" do
VirtualBox::Command.expects(:version).returns("3.1.4")
VirtualBox::Global.expects(:vboxconfig?).returns(true)
Vagrant::Env.expects(:error_and_exit).never
Vagrant::Environment.expects(:error_and_exit).never
Vagrant::Environment.check_virtualbox!
end
@ -194,10 +194,10 @@ class EnvironmentTest < Test::Unit::TestCase
should "should set the path for the rootfile" do
path = "/foo"
File.expects(:exist?).with("#{path}/#{Vagrant::Env::ROOTFILE_NAME}").returns(true)
File.expects(:exist?).with("#{path}/#{Vagrant::Environment::ROOTFILE_NAME}").returns(true)
assert Vagrant::Env.load_root_path!(Pathname.new(path))
assert_equal path, Vagrant::Env.root_path
assert @env.load_root_path!(Pathname.new(path))
assert_equal path, @env.root_path
end
end
@ -214,7 +214,7 @@ class EnvironmentTest < Test::Unit::TestCase
end
should "reset the configuration object" do
Vagrant::Config.expects(:reset!).once
Vagrant::Config.expects(:reset!).with(@env).once
@env.load_config!
end
@ -293,7 +293,7 @@ class EnvironmentTest < Test::Unit::TestCase
should "create each directory if it doesn't exist" do
create_seq = sequence("create_seq")
File.stubs(:directory?).returns(false)
Vagrant::Env::HOME_SUBDIRS.each do |subdir|
Vagrant::Environment::HOME_SUBDIRS.each do |subdir|
FileUtils.expects(:mkdir_p).with(File.join(@home_dir, subdir)).in_sequence(create_seq)
end

View File

@ -6,7 +6,9 @@ class VMTest < Test::Unit::TestCase
mock_config
@persisted_vm = mock("persisted_vm")
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
@env = mock_environment
@env.stubs(:vm).returns(@persisted_vm)
Net::SSH.stubs(:start)
end