toft 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/features/chef.feature +9 -1
- data/features/step_definitions/chef.rb +12 -0
- data/features/support/env.rb +1 -1
- data/fixtures/chef/cookbooks2/test2/recipes/default.rb +5 -0
- data/fixtures/chef/data_bags2/bag3/item3.json +4 -0
- data/fixtures/chef/roles2/test2.rb +3 -0
- data/lib/ping.rb +18 -0
- data/lib/toft.rb +6 -0
- data/lib/toft/chef/chef_runner.rb +10 -3
- data/lib/toft/version.rb +1 -1
- data/spec/toft/chef/chef_runner_spec.rb +7 -0
- metadata +8 -4
data/Gemfile.lock
CHANGED
data/features/chef.feature
CHANGED
@@ -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
|
data/features/support/env.rb
CHANGED
data/lib/ping.rb
ADDED
@@ -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
|
data/lib/toft.rb
CHANGED
@@ -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
|
-
|
46
|
-
|
47
|
-
|
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?
|
data/lib/toft/version.rb
CHANGED
@@ -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:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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
|