Merge branch 'feature/chef_solo_databags' into develop
This commit is contained in:
commit
b71890bcfd
|
@ -7,6 +7,7 @@ module Vagrant
|
||||||
class Config < Chef::Config
|
class Config < Chef::Config
|
||||||
attr_accessor :cookbooks_path
|
attr_accessor :cookbooks_path
|
||||||
attr_accessor :roles_path
|
attr_accessor :roles_path
|
||||||
|
attr_accessor :data_bags_path
|
||||||
attr_accessor :recipe_url
|
attr_accessor :recipe_url
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -14,6 +15,7 @@ module Vagrant
|
||||||
|
|
||||||
@cookbooks_path = ["cookbooks", [:vm, "cookbooks"]]
|
@cookbooks_path = ["cookbooks", [:vm, "cookbooks"]]
|
||||||
@roles_path = []
|
@roles_path = []
|
||||||
|
@data_bags_path = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate(errors)
|
def validate(errors)
|
||||||
|
@ -27,6 +29,7 @@ module Vagrant
|
||||||
def prepare
|
def prepare
|
||||||
share_cookbook_folders
|
share_cookbook_folders
|
||||||
share_role_folders
|
share_role_folders
|
||||||
|
share_data_bags_folders
|
||||||
end
|
end
|
||||||
|
|
||||||
def provision!
|
def provision!
|
||||||
|
@ -49,6 +52,12 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def share_data_bags_folders
|
||||||
|
host_data_bag_paths.each_with_index do |data_bag, i|
|
||||||
|
env.config.vm.share_folder("v-csdb-#{i}", data_bag_path(i), data_bag)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup_solo_config
|
def setup_solo_config
|
||||||
setup_config("chef_solo_solo", "solo.rb", {
|
setup_config("chef_solo_solo", "solo.rb", {
|
||||||
:node_name => config.node_name,
|
:node_name => config.node_name,
|
||||||
|
@ -56,6 +65,7 @@ module Vagrant
|
||||||
:cookbooks_path => cookbooks_path,
|
:cookbooks_path => cookbooks_path,
|
||||||
:recipe_url => config.recipe_url,
|
:recipe_url => config.recipe_url,
|
||||||
:roles_path => roles_path,
|
:roles_path => roles_path,
|
||||||
|
:data_bags_path => data_bags_path,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,6 +132,10 @@ module Vagrant
|
||||||
host_folder_paths(config.roles_path)
|
host_folder_paths(config.roles_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def host_data_bag_paths
|
||||||
|
host_folder_paths(config.data_bags_path)
|
||||||
|
end
|
||||||
|
|
||||||
def cookbook_path(i)
|
def cookbook_path(i)
|
||||||
folder_path("cookbooks", i)
|
folder_path("cookbooks", i)
|
||||||
end
|
end
|
||||||
|
@ -130,6 +144,10 @@ module Vagrant
|
||||||
folder_path("roles", i)
|
folder_path("roles", i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_bag_path(i)
|
||||||
|
folder_path("data_bags", i)
|
||||||
|
end
|
||||||
|
|
||||||
def cookbooks_path
|
def cookbooks_path
|
||||||
folders_path(config.cookbooks_path, "cookbooks").to_json
|
folders_path(config.cookbooks_path, "cookbooks").to_json
|
||||||
end
|
end
|
||||||
|
@ -137,6 +155,10 @@ module Vagrant
|
||||||
def roles_path
|
def roles_path
|
||||||
folders_path(config.roles_path, "roles").to_json
|
folders_path(config.roles_path, "roles").to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_bags_path
|
||||||
|
folders_path(config.data_bags_path, "data_bags").to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,10 @@ cookbook_path <%= cookbooks_path %>
|
||||||
role_path <%= roles_path %>
|
role_path <%= roles_path %>
|
||||||
log_level <%= log_level.inspect %>
|
log_level <%= log_level.inspect %>
|
||||||
|
|
||||||
|
<% if data_bags_path %>
|
||||||
|
data_bag_path <%= data_bags_path %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if recipe_url -%>
|
<% if recipe_url -%>
|
||||||
recipe_url "<%= recipe_url %>"
|
recipe_url "<%= recipe_url %>"
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
|
@ -42,6 +42,11 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||||
@action.expects(:share_role_folders).once
|
@action.expects(:share_role_folders).once
|
||||||
@action.prepare
|
@action.prepare
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "share data bag folders" do
|
||||||
|
@action.expects(:share_data_bags_folders).once
|
||||||
|
@action.prepare
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "provisioning" do
|
context "provisioning" do
|
||||||
|
@ -87,6 +92,22 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "sharing data bag folders" do
|
||||||
|
setup do
|
||||||
|
@host_data_bag_paths = ["foo", "bar"]
|
||||||
|
@action.stubs(:host_data_bag_paths).returns(@host_data_bag_paths)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "share each data bag folder" do
|
||||||
|
share_seq = sequence("share_seq")
|
||||||
|
@host_data_bag_paths.each_with_index do |data_bag, i|
|
||||||
|
@env.config.vm.expects(:share_folder).with("v-csdb-#{i}", @action.data_bag_path(i), data_bag).in_sequence(share_seq)
|
||||||
|
end
|
||||||
|
|
||||||
|
@action.share_data_bags_folders
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "host folder paths" do
|
context "host folder paths" do
|
||||||
should "ignore VM paths" do
|
should "ignore VM paths" do
|
||||||
assert @action.host_folder_paths([:vm, "foo"]).empty?
|
assert @action.host_folder_paths([:vm, "foo"]).empty?
|
||||||
|
@ -125,6 +146,15 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "host data bags paths" do
|
||||||
|
should "get folders path for configured data bag path" do
|
||||||
|
result = mock("result")
|
||||||
|
@config.stubs(:data_bags_path).returns("foo")
|
||||||
|
@action.expects(:host_folder_paths).with(@config.data_bags_path).returns(result)
|
||||||
|
assert_equal result, @action.host_data_bag_paths
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "folder path" do
|
context "folder path" do
|
||||||
should "return a proper path to a single folder" do
|
should "return a proper path to a single folder" do
|
||||||
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
||||||
|
@ -179,6 +209,19 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "data bags path" do
|
||||||
|
should "return a proper path to a single data bag" do
|
||||||
|
expected = File.join(@config.provisioning_path, "data_bags-5")
|
||||||
|
assert_equal expected, @action.data_bag_path(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "properly call folders path and return result" do
|
||||||
|
result = [:a, :b, :c]
|
||||||
|
@action.expects(:folders_path).with(@config.data_bags_path, "data_bags").once.returns(result)
|
||||||
|
assert_equal result.to_json, @action.data_bags_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "generating and uploading chef solo configuration file" do
|
context "generating and uploading chef solo configuration file" do
|
||||||
setup do
|
setup do
|
||||||
@vm.ssh.stubs(:upload!)
|
@vm.ssh.stubs(:upload!)
|
||||||
|
@ -192,7 +235,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||||
:provisioning_path => @config.provisioning_path,
|
:provisioning_path => @config.provisioning_path,
|
||||||
:cookbooks_path => @action.cookbooks_path,
|
:cookbooks_path => @action.cookbooks_path,
|
||||||
:recipe_url => @config.recipe_url,
|
:recipe_url => @config.recipe_url,
|
||||||
:roles_path => @action.roles_path
|
:roles_path => @action.roles_path,
|
||||||
|
:data_bags_path => @action.data_bags_path
|
||||||
})
|
})
|
||||||
|
|
||||||
@action.setup_solo_config
|
@action.setup_solo_config
|
||||||
|
|
Loading…
Reference in New Issue