Project directory and instance role added to provisioning JSON

This commit is contained in:
Mitchell Hashimoto 2010-02-10 12:05:36 -08:00
parent ba77944d67
commit aa2d3d58db
3 changed files with 17 additions and 4 deletions

View File

@ -16,6 +16,7 @@ Vagrant::Config.run do |config|
config.chef.cookbooks_path = "cookbooks" config.chef.cookbooks_path = "cookbooks"
config.chef.provisioning_path = "/tmp/vagrant-chef" config.chef.provisioning_path = "/tmp/vagrant-chef"
config.chef.json = { config.chef.json = {
:instance_role => "vagrant",
:recipes => ["vagrant_main"] :recipes => ["vagrant_main"]
} }
end end

View File

@ -26,7 +26,10 @@ module Vagrant
def setup_json def setup_json
logger.info "Generating JSON and uploading..." logger.info "Generating JSON and uploading..."
SSH.upload!(StringIO.new(Vagrant.config.chef.json.to_json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
json = { :project_directory => Vagrant.config.vm.project_directory }.merge(Vagrant.config.chef.json).to_json
SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json"))
end end
def setup_solo_config def setup_solo_config

View File

@ -36,13 +36,22 @@ class ProvisioningTest < Test::Unit::TestCase
context "generating and uploading json" do context "generating and uploading json" do
should "convert the JSON config to JSON" do should "convert the JSON config to JSON" do
Vagrant.config.chef.json.expects(:to_json).once.returns("foo") Hash.any_instance.expects(:to_json).once.returns("foo")
@prov.setup_json
end
should "add the project directory to the JSON" do
Vagrant::SSH.expects(:upload!).with do |json, path|
data = JSON.parse(json.read)
assert_equal Vagrant.config.vm.project_directory, data["project_directory"]
true
end
@prov.setup_json @prov.setup_json
end end
should "upload a StringIO to dna.json" do should "upload a StringIO to dna.json" do
Vagrant.config.chef.json.expects(:to_json).once.returns("foo") StringIO.expects(:new).with(anything).returns("bar")
StringIO.expects(:new).with("foo").returns("bar")
File.expects(:join).with(Vagrant.config.chef.provisioning_path, "dna.json").once.returns("baz") File.expects(:join).with(Vagrant.config.chef.provisioning_path, "dna.json").once.returns("baz")
Vagrant::SSH.expects(:upload!).with("bar", "baz").once Vagrant::SSH.expects(:upload!).with("bar", "baz").once
@prov.setup_json @prov.setup_json