toft 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toft (0.0.11)
4
+ toft (0.0.12)
5
5
  net-ssh
6
6
 
7
7
  GEM
@@ -38,7 +38,7 @@ Scenario: Toft should not deal with empty cookbook and role path
38
38
  Then Running chef "recipe[test]" on node "n1" should succeed
39
39
  When I set the cookbook path to empty
40
40
  Then Running chef "recipe[test]" on node "n1" should fail
41
-
41
+
42
42
  Scenario: Run chef recipe with json attributes file
43
43
  Given I have a clean running node n1
44
44
  When I run "recipe[test::attribute]" on node "n1" and overwrite attributes with json file "attributes.json"
@@ -65,6 +65,14 @@ Scenario: Run chef recipe with data bags
65
65
  Then Node "n1" should have file or directory "/tmp/stub/bag2item1"
66
66
  Then Node "n1" should have file or directory "/tmp/stub/bag2item2"
67
67
 
68
+ Scenario: Toft should deal with multiple cookbook, roles and databag paths
69
+ Given I have a clean running node n1
70
+ When I add another cookbook "cookbooks2"
71
+ And I add another role dir "roles2"
72
+ And I add another databag dir "data_bags2"
73
+ Then Running chef "role[test2]" on node "n1" should succeed
74
+ And Node "n1" should have file or directory "/tmp/test2/bag3item3"
75
+
68
76
  Scenario: Run non-exist recipe
69
77
 
70
78
  Scenario: Run non-exist role
@@ -41,3 +41,15 @@ end
41
41
  When /^I run "([^"]*)" on node "([^"]*)" and overwrite attributes with json file "([^"]*)" and chef attributes:$/ do |run_list, node, json_file, table|
42
42
  find(node).run_chef run_list, {:json => CHEF_FIXTURE_PATH + '/attributes.json', :attributes => Toft::ChefAttributes.new(table)}
43
43
  end
44
+
45
+ When /^I add another cookbook "(.*?)"$/ do |cookbook_path|
46
+ Toft.cookbook_path = [CHEF_FIXTURE_PATH + '/cookbooks', CHEF_FIXTURE_PATH + "/#{cookbook_path}"]
47
+ end
48
+
49
+ When /^I add another role dir "(.*?)"$/ do |role_path|
50
+ Toft.role_path = [CHEF_FIXTURE_PATH + '/roles', CHEF_FIXTURE_PATH + "/#{role_path}"]
51
+ end
52
+
53
+ When /^I add another databag dir "(.*?)"$/ do |databag_path|
54
+ Toft.data_bag_path = [CHEF_FIXTURE_PATH + '/data_bags', CHEF_FIXTURE_PATH + "/#{databag_path}"]
55
+ end
@@ -22,5 +22,5 @@ Before do
22
22
  end
23
23
 
24
24
  at_exit do
25
- n1.destroy
25
+ # n1.destroy
26
26
  end
@@ -0,0 +1,5 @@
1
+ item = data_bag_item("bag3", "item3")
2
+ directory "/tmp/test2/#{item['value']}" do
3
+ action :create
4
+ recursive true
5
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "id": "item3",
3
+ "value": "bag3item3"
4
+ }
@@ -0,0 +1,3 @@
1
+ name 'test'
2
+ description 'Test!'
3
+ run_list "recipe[test2]"
@@ -0,0 +1,18 @@
1
+ require 'timeout'
2
+ require 'socket'
3
+
4
+ class Ping
5
+ def self.pingecho(host, timeout=5, service="echo")
6
+ begin
7
+ timeout(timeout) do
8
+ s = TCPSocket.new(host, service)
9
+ s.close
10
+ end
11
+ rescue Errno::ECONNREFUSED
12
+ return true
13
+ rescue Timeout::Error, StandardError
14
+ return false
15
+ end
16
+ return true
17
+ end
18
+ end
@@ -37,3 +37,9 @@ class String
37
37
  empty?
38
38
  end
39
39
  end
40
+
41
+ class Array
42
+ def blank?
43
+ empty?
44
+ end
45
+ end
@@ -42,9 +42,16 @@ module Toft
42
42
  raise ArgumentError, "Toft.cookbook_path can not be empty!" if Toft.cookbook_path.blank?
43
43
  rm_rf "#{@root_dir}#{DEST_CHEF_TMP}"
44
44
  mkdir_p "#{@root_dir}#{DEST_CHEF_TMP}"
45
- cp_r Toft.cookbook_path, "#{@root_dir}#{DEST_COOKBOOK_PATH}"
46
- cp_r Toft.role_path, "#{@root_dir}#{DEST_ROLE_PATH}" unless roles_missing?
47
- cp_r Toft.data_bag_path, "#{@root_dir}#{DEST_DATA_BAG_PATH}" unless data_bags_missing?
45
+ copy_resources Toft.cookbook_path, "#{@root_dir}#{DEST_COOKBOOK_PATH}"
46
+ copy_resources Toft.role_path, "#{@root_dir}#{DEST_ROLE_PATH}" unless roles_missing?
47
+ copy_resources Toft.data_bag_path, "#{@root_dir}#{DEST_DATA_BAG_PATH}" unless data_bags_missing?
48
+ end
49
+
50
+ def copy_resources(src_dir, dest_dir)
51
+ src_dir = [src_dir] if src_dir.is_a? String
52
+ src_dir.each do |dir|
53
+ cp_r dir + "/.", dest_dir
54
+ end
48
55
  end
49
56
 
50
57
  def roles_missing?
@@ -1,3 +1,3 @@
1
1
  module Toft
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -31,4 +31,11 @@ describe "ChefRunner" do
31
31
  lambda { cf.run "run list" }.should raise_error RuntimeError
32
32
  end
33
33
 
34
+ it "should throw exception if data bags not exist" do
35
+ Toft.cookbook_path = "#{PROJECT_ROOT}/fixtures/chef/cookbookse"
36
+ Toft.data_bag_path = "non-exist-data-bags"
37
+ cf = Toft::Chef::ChefRunner.new "#{PROJECT_ROOT}/tmp"
38
+ lambda { cf.run "run list" }.should raise_error RuntimeError
39
+ end
40
+
34
41
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toft
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Huang Liang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-04 00:00:00 Z
18
+ date: 2012-06-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -134,11 +134,14 @@ files:
134
134
  - fixtures/chef/cookbooks/test/recipes/data_bag.rb
135
135
  - fixtures/chef/cookbooks/test/recipes/default.rb
136
136
  - fixtures/chef/cookbooks/test/recipes/role.rb
137
+ - fixtures/chef/cookbooks2/test2/recipes/default.rb
137
138
  - fixtures/chef/data_bags/bag1/item1.json
138
139
  - fixtures/chef/data_bags/bag1/item2.json
139
140
  - fixtures/chef/data_bags/bag2/item1.json
140
141
  - fixtures/chef/data_bags/bag2/item2.json
142
+ - fixtures/chef/data_bags2/bag3/item3.json
141
143
  - fixtures/chef/roles/test.rb
144
+ - fixtures/chef/roles2/test2.rb
142
145
  - fixtures/puppet/conf/fileserver.conf
143
146
  - fixtures/puppet/conf/puppet.conf
144
147
  - fixtures/puppet/conf/puppet_exec.conf
@@ -156,6 +159,7 @@ files:
156
159
  - fixtures/puppet/manifests/test_service.pp
157
160
  - fixtures/puppet/manifests/test_template.pp
158
161
  - fixtures/puppet/modules/test_module/manifests/init.pp
162
+ - lib/ping.rb
159
163
  - lib/toft.rb
160
164
  - lib/toft/chef/chef_attributes.rb
161
165
  - lib/toft/chef/chef_runner.rb