Permalink
Browse files

Merge pull request #10 from cbuben/data_bag_support

Add data bag support.
  • Loading branch information...
2 parents 2b202af + e269d79 commit 6252cf43b347eab115aa728f572165247862bc7e @exceedhl committed May 16, 2012
View
8 features/chef.feature
@@ -57,6 +57,14 @@ Scenario: Attributes table should override attributes in json file
Then Node "n1" should have file or directory "/tmp/stub/two_two"
Then Node "n1" should have file or directory "/tmp/stub/three"
+Scenario: Run chef recipe with data bags
+ Given I have a clean running node n1
+ When I run "recipe[test::data_bag]" on node "n1"
+ Then Node "n1" should have file or directory "/tmp/stub/bag1item1"
+ Then Node "n1" should have file or directory "/tmp/stub/bag1item2"
+ Then Node "n1" should have file or directory "/tmp/stub/bag2item1"
+ Then Node "n1" should have file or directory "/tmp/stub/bag2item2"
+
Scenario: Run non-exist recipe
Scenario: Run non-exist role
View
1 features/support/env.rb
@@ -15,6 +15,7 @@
Before do
Toft.cookbook_path = CHEF_FIXTURE_PATH + '/cookbooks'
Toft.role_path = CHEF_FIXTURE_PATH + '/roles'
+ Toft.data_bag_path = CHEF_FIXTURE_PATH + '/data_bags'
Toft.manifest_path = PUPPET_FIXTURE_PATH
@n1 = n1
View
9 fixtures/chef/cookbooks/test/recipes/data_bag.rb
@@ -0,0 +1,9 @@
+%w{bag1 bag2}.each do |bag_name|
+ %w{item1 item2}.each do |item_name|
+ item = data_bag_item(bag_name, item_name)
+ directory "/tmp/stub/#{item['value']}" do
+ action :create
+ recursive true
+ end
+ end
+end
View
4 fixtures/chef/data_bags/bag1/item1.json
@@ -0,0 +1,4 @@
+{
+ "id": "item1",
+ "value": "bag1item1"
+}
View
4 fixtures/chef/data_bags/bag1/item2.json
@@ -0,0 +1,4 @@
+{
+ "id": "item2",
+ "value": "bag1item2"
+}
View
4 fixtures/chef/data_bags/bag2/item1.json
@@ -0,0 +1,4 @@
+{
+ "id": "item1",
+ "value": "bag2item1"
+}
View
4 fixtures/chef/data_bags/bag2/item2.json
@@ -0,0 +1,4 @@
+{
+ "id": "item2",
+ "value": "bag2item2"
+}
View
2 lib/toft.rb
@@ -9,7 +9,7 @@ module Toft
DOMAIN = "foo"
class << self
- attr_accessor :manifest_path, :cookbook_path, :role_path
+ attr_accessor :manifest_path, :cookbook_path, :role_path, :data_bag_path
end
def create_node(hostname, options = {})
View
9 lib/toft/chef/chef_runner.rb
@@ -9,6 +9,7 @@ class ChefRunner
DEST_CHEF_TMP = "/tmp/toft-chef-tmp"
DEST_COOKBOOK_PATH = "#{DEST_CHEF_TMP}/cookbooks"
DEST_ROLE_PATH = "#{DEST_CHEF_TMP}/roles"
+ DEST_DATA_BAG_PATH = "#{DEST_CHEF_TMP}/data_bags"
DEST_CHEF_SOLO_PATH = "#{DEST_CHEF_TMP}/solo.rb"
DEST_CHEF_JSON_PATH = "#{DEST_CHEF_TMP}/solo.json"
@@ -43,19 +44,25 @@ def copy_chef_material
mkdir_p "#{@root_dir}#{DEST_CHEF_TMP}"
cp_r Toft.cookbook_path, "#{@root_dir}#{DEST_COOKBOOK_PATH}"
cp_r Toft.role_path, "#{@root_dir}#{DEST_ROLE_PATH}" unless roles_missing?
+ cp_r Toft.data_bag_path, "#{@root_dir}#{DEST_DATA_BAG_PATH}" unless data_bags_missing?
end
def roles_missing?
Toft.role_path.blank?
end
+ def data_bags_missing?
+ Toft.data_bag_path.blank?
+ end
+
def generate_solo_rb
mkdir_p "#{@root_dir}/tmp/chef-file-cache"
solo = <<-EOF
file_cache_path "/tmp/chef-file-cache"
cookbook_path ["#{DEST_COOKBOOK_PATH}"]
EOF
solo += "role_path [\"#{DEST_ROLE_PATH}\"]" unless roles_missing?
+ solo += "\ndata_bag_path \"#{DEST_DATA_BAG_PATH}\"" unless data_bags_missing?
File.open("#{@root_dir}#{DEST_CHEF_SOLO_PATH}", 'w') do |f|
f.write(solo);
@@ -75,4 +82,4 @@ def cmd(cmd)
end
end
end
-end
+end

0 comments on commit 6252cf4

Please sign in to comment.