From aa2d3d58db74b36b197465a01cbb14b7d17dd1db Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 10 Feb 2010 12:05:36 -0800 Subject: [PATCH] Project directory and instance role added to provisioning JSON --- config/default.rb | 1 + lib/vagrant/provisioning.rb | 5 ++++- test/vagrant/provisioning_test.rb | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config/default.rb b/config/default.rb index 9efb75fd0..fc380eb12 100644 --- a/config/default.rb +++ b/config/default.rb @@ -16,6 +16,7 @@ Vagrant::Config.run do |config| config.chef.cookbooks_path = "cookbooks" config.chef.provisioning_path = "/tmp/vagrant-chef" config.chef.json = { + :instance_role => "vagrant", :recipes => ["vagrant_main"] } end \ No newline at end of file diff --git a/lib/vagrant/provisioning.rb b/lib/vagrant/provisioning.rb index 4d6d2468d..29d3a8a3d 100644 --- a/lib/vagrant/provisioning.rb +++ b/lib/vagrant/provisioning.rb @@ -26,7 +26,10 @@ module Vagrant def setup_json 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 def setup_solo_config diff --git a/test/vagrant/provisioning_test.rb b/test/vagrant/provisioning_test.rb index 46d5045ce..3c00adebc 100644 --- a/test/vagrant/provisioning_test.rb +++ b/test/vagrant/provisioning_test.rb @@ -36,13 +36,22 @@ class ProvisioningTest < Test::Unit::TestCase context "generating and uploading 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 end should "upload a StringIO to dna.json" do - Vagrant.config.chef.json.expects(:to_json).once.returns("foo") - StringIO.expects(:new).with("foo").returns("bar") + StringIO.expects(:new).with(anything).returns("bar") File.expects(:join).with(Vagrant.config.chef.provisioning_path, "dna.json").once.returns("baz") Vagrant::SSH.expects(:upload!).with("bar", "baz").once @prov.setup_json