chef 10.14.4 → 10.16.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +182 -0
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +5 -5
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +5 -5
- data/distro/common/html/knife-cookbook-site.1.html +4 -4
- data/distro/common/html/knife-cookbook.1.html +8 -8
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +7 -7
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +6 -6
- data/distro/common/html/knife-ssh.1.html +4 -4
- data/distro/common/html/knife-status.1.html +5 -5
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +4 -4
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +1 -1
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +1 -1
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +1 -1
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/debian/etc/init.d/chef-client +1 -1
- data/distro/debian/etc/init.d/chef-expander +1 -1
- data/distro/debian/etc/init.d/chef-server +1 -1
- data/distro/debian/etc/init.d/chef-server-webui +1 -1
- data/distro/debian/etc/init.d/chef-solr +1 -1
- data/lib/chef/application/client.rb +3 -3
- data/lib/chef/client.rb +4 -1
- data/lib/chef/config.rb +2 -1
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -0
- data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -0
- data/lib/chef/knife/bootstrap/chef-full.erb +2 -1
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -0
- data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -0
- data/lib/chef/knife/configure.rb +19 -0
- data/lib/chef/knife/data_bag_from_file.rb +1 -1
- data/lib/chef/knife/environment_from_file.rb +41 -8
- data/lib/chef/knife/ssh.rb +5 -1
- data/lib/chef/provider/cookbook_file.rb +4 -4
- data/lib/chef/provider/directory.rb +3 -0
- data/lib/chef/provider/file.rb +49 -3
- data/lib/chef/provider/ifconfig.rb +1 -1
- data/lib/chef/provider/package.rb +2 -0
- data/lib/chef/provider/package/pacman.rb +10 -1
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/service.rb +22 -0
- data/lib/chef/provider/template.rb +9 -1
- data/lib/chef/resource.rb +1 -1
- data/lib/chef/resource/cookbook_file.rb +1 -0
- data/lib/chef/resource/cron.rb +5 -0
- data/lib/chef/resource/deploy.rb +6 -1
- data/lib/chef/resource/directory.rb +6 -0
- data/lib/chef/resource/env.rb +5 -0
- data/lib/chef/resource/erl_call.rb +3 -0
- data/lib/chef/resource/execute.rb +3 -0
- data/lib/chef/resource/file.rb +5 -5
- data/lib/chef/resource/group.rb +5 -0
- data/lib/chef/resource/http_request.rb +3 -0
- data/lib/chef/resource/ifconfig.rb +5 -0
- data/lib/chef/resource/link.rb +6 -1
- data/lib/chef/resource/log.rb +19 -16
- data/lib/chef/resource/mdadm.rb +5 -0
- data/lib/chef/resource/mount.rb +5 -0
- data/lib/chef/resource/ohai.rb +14 -0
- data/lib/chef/resource/package.rb +2 -1
- data/lib/chef/resource/remote_directory.rb +5 -0
- data/lib/chef/resource/route.rb +6 -1
- data/lib/chef/resource/ruby_block.rb +11 -0
- data/lib/chef/resource/scm.rb +4 -0
- data/lib/chef/resource/script.rb +3 -0
- data/lib/chef/resource/service.rb +5 -0
- data/lib/chef/resource/subversion.rb +2 -1
- data/lib/chef/resource/template.rb +1 -0
- data/lib/chef/resource/user.rb +4 -0
- data/lib/chef/resource_reporter.rb +71 -27
- data/lib/chef/rest.rb +8 -4
- data/lib/chef/run_list.rb +2 -2
- data/lib/chef/scan_access_control.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/spec/unit/client_spec.rb +6 -2
- data/spec/unit/knife/configure_spec.rb +121 -25
- data/spec/unit/knife/data_bag_from_file_spec.rb +5 -3
- data/spec/unit/knife/environment_from_file_spec.rb +23 -0
- data/spec/unit/provider/cookbook_file_spec.rb +3 -0
- data/spec/unit/provider/directory_spec.rb +16 -17
- data/spec/unit/provider/file_spec.rb +75 -0
- data/spec/unit/provider/ifconfig_spec.rb +2 -2
- data/spec/unit/provider/package/pacman_spec.rb +29 -0
- data/spec/unit/provider/package_spec.rb +4 -0
- data/spec/unit/provider/remote_directory_spec.rb +6 -1
- data/spec/unit/provider/remote_file_spec.rb +7 -0
- data/spec/unit/resource/cookbook_file_spec.rb +42 -1
- data/spec/unit/resource/cron_spec.rb +27 -0
- data/spec/unit/resource/deploy_spec.rb +27 -0
- data/spec/unit/resource/directory_spec.rb +20 -0
- data/spec/unit/resource/env_spec.rb +19 -0
- data/spec/unit/resource/erl_call_spec.rb +12 -0
- data/spec/unit/resource/execute_spec.rb +16 -0
- data/spec/unit/resource/group_spec.rb +17 -1
- data/spec/unit/resource/http_request_spec.rb +13 -0
- data/spec/unit/resource/ifconfig_spec.rb +46 -0
- data/spec/unit/resource/link_spec.rb +21 -0
- data/spec/unit/resource/log_spec.rb +10 -0
- data/spec/unit/resource/mdadm_spec.rb +22 -0
- data/spec/unit/resource/mount_spec.rb +20 -0
- data/spec/unit/resource/ohai_spec.rb +18 -0
- data/spec/unit/resource/package_spec.rb +3 -0
- data/spec/unit/resource/remote_directory_spec.rb +22 -0
- data/spec/unit/resource/remote_file_spec.rb +40 -0
- data/spec/unit/resource/route_spec.rb +19 -0
- data/spec/unit/resource/ruby_block_spec.rb +11 -0
- data/spec/unit/resource/scm_spec.rb +20 -0
- data/spec/unit/resource/script_spec.rb +14 -0
- data/spec/unit/resource/service_spec.rb +21 -0
- data/spec/unit/resource/user_spec.rb +21 -0
- data/spec/unit/resource_reporter_spec.rb +260 -134
- data/spec/unit/run_list_spec.rb +14 -0
- metadata +15 -10
@@ -1,5 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Tyler Cloke (<tyler@opscode.com>)
|
3
4
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
@@ -52,4 +53,17 @@ describe Chef::Resource::Script do
|
|
52
53
|
@resource.flags.should eql("-f")
|
53
54
|
end
|
54
55
|
|
56
|
+
describe "when it has interpreter and flags" do
|
57
|
+
before do
|
58
|
+
@resource.command("grep")
|
59
|
+
@resource.interpreter("gcc")
|
60
|
+
@resource.flags("-al")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the command as its identity" do
|
64
|
+
@resource.identity.should == "grep"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
55
69
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
|
+
# Author:: Tyler Cloke (<tyler@opscode.com>)
|
3
4
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
@@ -141,4 +142,24 @@ describe Chef::Resource::Service do
|
|
141
142
|
@resource.supports.should == support_hash
|
142
143
|
end
|
143
144
|
end
|
145
|
+
|
146
|
+
describe "when it has pattern and supports" do
|
147
|
+
before do
|
148
|
+
@resource.service_name("superfriend")
|
149
|
+
@resource.enabled(true)
|
150
|
+
@resource.running(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "describes its state" do
|
154
|
+
state = @resource.state
|
155
|
+
state[:enabled].should eql(true)
|
156
|
+
state[:running].should eql(false)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "returns the service name as its identity" do
|
160
|
+
@resource.identity.should == "superfriend"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
|
144
165
|
end
|
@@ -98,4 +98,25 @@ end
|
|
98
98
|
lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError)
|
99
99
|
end
|
100
100
|
end
|
101
|
+
|
102
|
+
describe "when it has uid, gid, and home" do
|
103
|
+
before do
|
104
|
+
@resource = Chef::Resource::User.new("root")
|
105
|
+
@resource.uid(123)
|
106
|
+
@resource.gid(456)
|
107
|
+
@resource.home("/usr/local/root/")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "describes its state" do
|
111
|
+
state = @resource.state
|
112
|
+
state[:uid].should == 123
|
113
|
+
state[:gid].should == 456
|
114
|
+
state[:home].should == "/usr/local/root/"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns the username as its identity" do
|
118
|
+
@resource.identity.should == "root"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
101
122
|
end
|
@@ -24,16 +24,19 @@ require 'chef/resource_reporter'
|
|
24
24
|
|
25
25
|
describe Chef::ResourceReporter do
|
26
26
|
before(:all) do
|
27
|
-
@reporting_toggle_default = Chef::Config[:
|
28
|
-
Chef::Config[:
|
27
|
+
@reporting_toggle_default = Chef::Config[:enable_reporting]
|
28
|
+
Chef::Config[:enable_reporting] = true
|
29
29
|
end
|
30
30
|
|
31
31
|
after(:all) do
|
32
|
-
Chef::Config[:
|
32
|
+
Chef::Config[:enable_reporting] = @reporting_toggle_default
|
33
33
|
end
|
34
34
|
|
35
35
|
before do
|
36
|
+
@node = Chef::Node.new
|
37
|
+
@node.name("spitfire")
|
36
38
|
@rest_client = mock("Chef::REST (mock)")
|
39
|
+
@rest_client.stub!(:post_rest).and_return(true)
|
37
40
|
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
|
38
41
|
@new_resource = Chef::Resource::File.new("/tmp/a-file.txt")
|
39
42
|
@new_resource.cookbook_name = "monkey"
|
@@ -57,7 +60,7 @@ describe Chef::ResourceReporter do
|
|
57
60
|
end
|
58
61
|
|
59
62
|
it "should have no error_descriptions" do
|
60
|
-
@resource_reporter.error_descriptions.should
|
63
|
+
@resource_reporter.error_descriptions.should eq({})
|
61
64
|
# @resource_reporter.error_descriptions.should be_empty
|
62
65
|
# @resource_reporter.should have(0).error_descriptions
|
63
66
|
end
|
@@ -65,6 +68,7 @@ describe Chef::ResourceReporter do
|
|
65
68
|
end
|
66
69
|
|
67
70
|
context "after the chef run completes" do
|
71
|
+
|
68
72
|
before do
|
69
73
|
end
|
70
74
|
|
@@ -74,113 +78,118 @@ describe Chef::ResourceReporter do
|
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
77
|
-
context "when chef fails
|
78
|
-
before do
|
79
|
-
@exception = Exception.new
|
80
|
-
@resource_reporter.run_failed(@exception)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets the run status to 'failure'" do
|
84
|
-
@resource_reporter.status.should == "failure"
|
85
|
-
end
|
86
|
-
|
87
|
-
it "keeps the exception data" do
|
88
|
-
@resource_reporter.exception.should == @exception
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when a resource fails before loading current state" do
|
81
|
+
context "when chef fails" do
|
94
82
|
before do
|
95
|
-
@
|
96
|
-
@
|
97
|
-
@
|
98
|
-
@resource_reporter.resource_failed(@new_resource, :create, @exception)
|
99
|
-
@resource_reporter.resource_completed(@new_resource)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "collects the resource as an updated resource" do
|
103
|
-
@resource_reporter.should have(1).updated_resources
|
104
|
-
end
|
105
|
-
|
106
|
-
it "collects the desired state of the resource" do
|
107
|
-
update_record = @resource_reporter.updated_resources.first
|
108
|
-
update_record.new_resource.should == @new_resource
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# TODO: make sure a resource that is skipped because of `not_if` doesn't
|
114
|
-
# leave us in a bad state.
|
83
|
+
@rest_client.stub!(:create_url).and_return("reports/nodes/spitfire/runs/ABC123");
|
84
|
+
@rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"});
|
85
|
+
@rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123"});
|
115
86
|
|
116
|
-
|
117
|
-
before do
|
118
|
-
@resource_reporter.resource_action_start(@new_resource, :create)
|
119
|
-
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
|
87
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
120
88
|
end
|
121
89
|
|
122
|
-
context "
|
90
|
+
context "before converging any resources" do
|
123
91
|
before do
|
124
|
-
@
|
92
|
+
@exception = Exception.new
|
93
|
+
@resource_reporter.run_failed(@exception)
|
125
94
|
end
|
126
|
-
|
127
|
-
it "
|
128
|
-
@resource_reporter.should
|
95
|
+
|
96
|
+
it "sets the run status to 'failure'" do
|
97
|
+
@resource_reporter.status.should == "failure"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "keeps the exception data" do
|
101
|
+
@resource_reporter.exception.should == @exception
|
129
102
|
end
|
130
103
|
end
|
131
104
|
|
132
|
-
context "
|
105
|
+
context "when a resource fails before loading current state" do
|
133
106
|
before do
|
134
|
-
@
|
135
|
-
@
|
136
|
-
@resource_reporter.
|
107
|
+
@exception = Exception.new
|
108
|
+
@exception.set_backtrace(caller)
|
109
|
+
@resource_reporter.resource_action_start(@new_resource, :create)
|
110
|
+
@resource_reporter.resource_failed(@new_resource, :create, @exception)
|
137
111
|
@resource_reporter.resource_completed(@new_resource)
|
138
112
|
end
|
139
113
|
|
140
|
-
it "collects the updated resource" do
|
114
|
+
it "collects the resource as an updated resource" do
|
141
115
|
@resource_reporter.should have(1).updated_resources
|
142
116
|
end
|
143
117
|
|
144
|
-
it "collects the
|
118
|
+
it "collects the desired state of the resource" do
|
145
119
|
update_record = @resource_reporter.updated_resources.first
|
120
|
+
update_record.new_resource.should == @new_resource
|
121
|
+
end
|
122
|
+
end
|
146
123
|
|
147
|
-
|
124
|
+
# TODO: make sure a resource that is skipped because of `not_if` doesn't
|
125
|
+
# leave us in a bad state.
|
126
|
+
|
127
|
+
context "once the a resource's current state is loaded" do
|
128
|
+
before do
|
129
|
+
@resource_reporter.resource_action_start(@new_resource, :create)
|
130
|
+
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
|
148
131
|
end
|
149
132
|
|
150
|
-
|
151
|
-
|
133
|
+
context "and the resource was not updated" do
|
134
|
+
before do
|
135
|
+
@resource_reporter.resource_up_to_date(@new_resource, :create)
|
136
|
+
end
|
152
137
|
|
153
|
-
|
138
|
+
it "has no updated resources" do
|
139
|
+
@resource_reporter.should have(0).updated_resources
|
140
|
+
end
|
154
141
|
end
|
155
142
|
|
156
|
-
context "and
|
143
|
+
context "and the resource was updated" do
|
157
144
|
before do
|
158
|
-
@
|
159
|
-
@
|
160
|
-
@
|
161
|
-
@resource_reporter.
|
162
|
-
@resource_reporter.resource_completed(@next_new_resource)
|
145
|
+
@new_resource.content("this is the old content")
|
146
|
+
@current_resource.content("this is the new hotness")
|
147
|
+
@resource_reporter.resource_updated(@new_resource, :create)
|
148
|
+
@resource_reporter.resource_completed(@new_resource)
|
163
149
|
end
|
164
150
|
|
165
|
-
it "collects the
|
166
|
-
|
167
|
-
|
151
|
+
it "collects the updated resource" do
|
152
|
+
@resource_reporter.should have(1).updated_resources
|
153
|
+
end
|
154
|
+
|
155
|
+
it "collects the old state of the resource" do
|
156
|
+
update_record = @resource_reporter.updated_resources.first
|
157
|
+
update_record.current_resource.should == @current_resource
|
158
|
+
end
|
159
|
+
|
160
|
+
it "collects the new state of the resource" do
|
161
|
+
update_record = @resource_reporter.updated_resources.first
|
162
|
+
update_record.new_resource.should == @new_resource
|
168
163
|
end
|
169
164
|
|
170
|
-
|
171
|
-
|
172
|
-
|
165
|
+
context "and a subsequent resource fails before loading current resource" do
|
166
|
+
before do
|
167
|
+
@next_new_resource = Chef::Resource::Service.new("apache2")
|
168
|
+
@exception = Exception.new
|
169
|
+
@exception.set_backtrace(caller)
|
170
|
+
@resource_reporter.resource_failed(@next_new_resource, :create, @exception)
|
171
|
+
@resource_reporter.resource_completed(@next_new_resource)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "collects the desired state of the failed resource" do
|
175
|
+
failed_resource_update = @resource_reporter.updated_resources.last
|
176
|
+
failed_resource_update.new_resource.should == @next_new_resource
|
177
|
+
end
|
178
|
+
|
179
|
+
it "does not have the current state of the failed resource" do
|
180
|
+
failed_resource_update = @resource_reporter.updated_resources.last
|
181
|
+
failed_resource_update.current_resource.should be_nil
|
182
|
+
end
|
173
183
|
end
|
174
184
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
@implementation_resource = Chef::Resource::CookbookFile.new("/preseed-file.txt")
|
185
|
+
|
186
|
+
# Some providers, such as RemoteDirectory and some LWRPs use other
|
187
|
+
# resources for their implementation. These should be hidden from reporting
|
188
|
+
# since we only care about the top-level resource and not the sub-resources
|
189
|
+
# used for implementation.
|
190
|
+
context "and a nested resource is updated" do
|
191
|
+
before do
|
192
|
+
@implementation_resource = Chef::Resource::CookbookFile.new("/preseed-file.txt")
|
184
193
|
@resource_reporter.resource_action_start(@implementation_resource , :create)
|
185
194
|
@resource_reporter.resource_current_state_loaded(@implementation_resource, :create, @implementation_resource)
|
186
195
|
@resource_reporter.resource_updated(@implementation_resource, :create)
|
@@ -189,54 +198,63 @@ describe Chef::ResourceReporter do
|
|
189
198
|
@resource_reporter.resource_completed(@new_resource)
|
190
199
|
end
|
191
200
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
context "and a nested resource runs but is not updated" do
|
198
|
-
before do
|
199
|
-
@implementation_resource = Chef::Resource::CookbookFile.new("/preseed-file.txt")
|
200
|
-
@resource_reporter.resource_action_start(@implementation_resource , :create)
|
201
|
-
@resource_reporter.resource_current_state_loaded(@implementation_resource, :create, @implementation_resource)
|
202
|
-
@resource_reporter.resource_up_to_date(@implementation_resource, :create)
|
203
|
-
@resource_reporter.resource_completed(@implementation_resource)
|
204
|
-
@resource_reporter.resource_updated(@new_resource, :create)
|
205
|
-
@resource_reporter.resource_completed(@new_resource)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "does not collect data about the nested resource" do
|
209
|
-
@resource_reporter.should have(1).updated_resources
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context "and the resource failed to converge" do
|
214
|
-
before do
|
215
|
-
@exception = Exception.new
|
216
|
-
@exception.set_backtrace(caller)
|
217
|
-
@resource_reporter.resource_failed(@new_resource, :create, @exception)
|
218
|
-
@resource_reporter.resource_completed(@new_resource)
|
201
|
+
it "does not collect data about the nested resource" do
|
202
|
+
@resource_reporter.should have(1).updated_resources
|
203
|
+
end
|
219
204
|
end
|
220
205
|
|
221
|
-
|
222
|
-
|
206
|
+
context "and a nested resource runs but is not updated" do
|
207
|
+
before do
|
208
|
+
@implementation_resource = Chef::Resource::CookbookFile.new("/preseed-file.txt")
|
209
|
+
@resource_reporter.resource_action_start(@implementation_resource , :create)
|
210
|
+
@resource_reporter.resource_current_state_loaded(@implementation_resource, :create, @implementation_resource)
|
211
|
+
@resource_reporter.resource_up_to_date(@implementation_resource, :create)
|
212
|
+
@resource_reporter.resource_completed(@implementation_resource)
|
213
|
+
@resource_reporter.resource_updated(@new_resource, :create)
|
214
|
+
@resource_reporter.resource_completed(@new_resource)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "does not collect data about the nested resource" do
|
218
|
+
@resource_reporter.should have(1).updated_resources
|
219
|
+
end
|
223
220
|
end
|
224
221
|
|
225
|
-
|
226
|
-
|
227
|
-
|
222
|
+
context "and the resource failed to converge" do
|
223
|
+
before do
|
224
|
+
@exception = Exception.new
|
225
|
+
@exception.set_backtrace(caller)
|
226
|
+
@resource_reporter.resource_failed(@new_resource, :create, @exception)
|
227
|
+
@resource_reporter.resource_completed(@new_resource)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "collects the resource as an updated resource" do
|
231
|
+
@resource_reporter.should have(1).updated_resources
|
232
|
+
end
|
233
|
+
|
234
|
+
it "collects the desired state of the resource" do
|
235
|
+
update_record = @resource_reporter.updated_resources.first
|
236
|
+
update_record.new_resource.should == @new_resource
|
237
|
+
end
|
238
|
+
|
239
|
+
it "collects the current state of the resource" do
|
240
|
+
update_record = @resource_reporter.updated_resources.first
|
241
|
+
update_record.current_resource.should == @current_resource
|
242
|
+
end
|
228
243
|
end
|
229
244
|
|
230
|
-
it "collects the current state of the resource" do
|
231
|
-
update_record = @resource_reporter.updated_resources.first
|
232
|
-
update_record.current_resource.should == @current_resource
|
233
|
-
end
|
234
245
|
end
|
235
|
-
|
236
246
|
end
|
237
247
|
|
238
248
|
describe "when generating a report for the server" do
|
239
249
|
|
250
|
+
before do
|
251
|
+
@rest_client.stub!(:create_url).and_return("reports/nodes/spitfire/runs/ABC123");
|
252
|
+
@rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"});
|
253
|
+
@rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123"});
|
254
|
+
|
255
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
256
|
+
end
|
257
|
+
|
240
258
|
context "for a successful client run" do
|
241
259
|
before do
|
242
260
|
# TODO: add inputs to generate expected output.
|
@@ -269,14 +287,11 @@ describe Chef::ResourceReporter do
|
|
269
287
|
# "status" : "success"
|
270
288
|
# "data" : ""
|
271
289
|
# }
|
272
|
-
|
273
|
-
@node = Chef::Node.new
|
274
|
-
@node.name("spitfire")
|
275
290
|
@resource_reporter.resource_action_start(@new_resource, :create)
|
276
291
|
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
|
277
292
|
@resource_reporter.resource_updated(@new_resource, :create)
|
278
293
|
@resource_reporter.resource_completed(@new_resource)
|
279
|
-
@report = @resource_reporter.
|
294
|
+
@report = @resource_reporter.prepare_run_data
|
280
295
|
@first_update_report = @report["resources"].first
|
281
296
|
end
|
282
297
|
|
@@ -349,22 +364,20 @@ describe Chef::ResourceReporter do
|
|
349
364
|
context "for an unsuccessful run" do
|
350
365
|
|
351
366
|
before do
|
352
|
-
|
353
|
-
@backtrace = "foo.rb:1 in `foo!'\nbar.rb:2 in `bar!\n'baz.rb:3 in `baz!'"
|
367
|
+
@backtrace = ["foo.rb:1 in `foo!'","bar.rb:2 in `bar!","'baz.rb:3 in `baz!'"]
|
354
368
|
@node = Chef::Node.new
|
355
369
|
@node.name("spitfire")
|
356
370
|
@exception = mock("ArgumentError")
|
357
371
|
@exception.stub!(:inspect).and_return("Net::HTTPServerException")
|
358
372
|
@exception.stub!(:message).and_return("Object not found")
|
359
373
|
@exception.stub!(:backtrace).and_return(@backtrace)
|
360
|
-
@resource_reporter.run_failed(@exception)
|
361
374
|
@resource_reporter.run_list_expand_failed(@node, @exception)
|
362
|
-
@
|
375
|
+
@resource_reporter.run_failed(@exception)
|
376
|
+
@report = @resource_reporter.prepare_run_data
|
363
377
|
end
|
364
378
|
|
365
379
|
it "includes the exception type in the event data" do
|
366
380
|
@report.should have_key("data")
|
367
|
-
@report["data"].should have_key("exception")
|
368
381
|
@report["data"]["exception"].should have_key("class")
|
369
382
|
@report["data"]["exception"]["class"].should == "Net::HTTPServerException"
|
370
383
|
end
|
@@ -376,7 +389,7 @@ describe Chef::ResourceReporter do
|
|
376
389
|
|
377
390
|
it "includes the exception trace in the event data" do
|
378
391
|
@report["data"]["exception"].should have_key("backtrace")
|
379
|
-
@report["data"]["exception"]["backtrace"].should == @backtrace
|
392
|
+
@report["data"]["exception"]["backtrace"].should == @backtrace.to_json
|
380
393
|
end
|
381
394
|
|
382
395
|
it "includes the error inspector output in the event data" do
|
@@ -384,15 +397,12 @@ describe Chef::ResourceReporter do
|
|
384
397
|
@report["data"]["exception"]["description"].should include({"title"=>"Error expanding the run_list:", "sections"=>[["Unexpected Error:", "RSpec::Mocks::Mock: Object not found"]]})
|
385
398
|
end
|
386
399
|
|
387
|
-
|
388
400
|
end
|
389
401
|
|
390
402
|
end
|
391
403
|
|
392
404
|
describe "when updating resource history on the server" do
|
393
405
|
before do
|
394
|
-
@node = Chef::Node.new
|
395
|
-
@node.name("spitfire")
|
396
406
|
end
|
397
407
|
|
398
408
|
context "when the server does not support storing resource history" do
|
@@ -417,6 +427,52 @@ describe Chef::ResourceReporter do
|
|
417
427
|
|
418
428
|
end
|
419
429
|
|
430
|
+
context "when the server returns a 500 to the client" do
|
431
|
+
before do
|
432
|
+
# 500 getting the run_id
|
433
|
+
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
|
434
|
+
@error = Net::HTTPServerException.new("500 message", @response)
|
435
|
+
@rest_client.should_receive(:post_rest).
|
436
|
+
with("reports/nodes/spitfire/runs", {:action => :begin}).
|
437
|
+
and_raise(@error)
|
438
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
439
|
+
end
|
440
|
+
|
441
|
+
it "assumes the feature is not enabled" do
|
442
|
+
@resource_reporter.reporting_enabled?.should be_false
|
443
|
+
end
|
444
|
+
|
445
|
+
it "does not send a resource report to the server" do
|
446
|
+
@rest_client.should_not_receive(:post_rest)
|
447
|
+
@resource_reporter.run_completed(@node)
|
448
|
+
end
|
449
|
+
|
450
|
+
end
|
451
|
+
|
452
|
+
context "when the server returns a 500 to the client and enable_reporting_url_fatals is true" do
|
453
|
+
before do
|
454
|
+
@enable_reporting_url_fatals = Chef::Config[:enable_reporting_url_fatals]
|
455
|
+
Chef::Config[:enable_reporting_url_fatals] = true
|
456
|
+
# 500 getting the run_id
|
457
|
+
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
|
458
|
+
@error = Net::HTTPServerException.new("500 message", @response)
|
459
|
+
@rest_client.should_receive(:post_rest).
|
460
|
+
with("reports/nodes/spitfire/runs", {:action => :begin}).
|
461
|
+
and_raise(@error)
|
462
|
+
end
|
463
|
+
|
464
|
+
after do
|
465
|
+
Chef::Config[:enable_reporting_url_fatals] = @enable_reporting_url_fatals
|
466
|
+
end
|
467
|
+
|
468
|
+
it "fails the run" do
|
469
|
+
lambda {
|
470
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
471
|
+
}.should raise_error(Net::HTTPServerException)
|
472
|
+
end
|
473
|
+
|
474
|
+
end
|
475
|
+
|
420
476
|
context "after creating the run history document" do
|
421
477
|
before do
|
422
478
|
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123"}
|
@@ -437,18 +493,88 @@ describe Chef::ResourceReporter do
|
|
437
493
|
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
|
438
494
|
@resource_reporter.resource_updated(@new_resource, :create)
|
439
495
|
|
440
|
-
@expected_data = @resource_reporter.
|
441
|
-
@expected_data["action"] = "end"
|
496
|
+
@expected_data = @resource_reporter.prepare_run_data
|
442
497
|
|
498
|
+
post_url = "https://chef_server/example_url"
|
443
499
|
response = {"result"=>"ok"}
|
444
500
|
|
501
|
+
@rest_client.should_receive(:create_url).
|
502
|
+
with("reports/nodes/spitfire/runs/ABC123").
|
503
|
+
ordered.
|
504
|
+
and_return(post_url)
|
505
|
+
@rest_client.should_receive(:raw_http_request).ordered do |method, url, headers, data|
|
506
|
+
method.should eq(:POST)
|
507
|
+
url.should eq(post_url)
|
508
|
+
headers.should eq({'Content-Encoding' => 'gzip'})
|
509
|
+
data_stream = Zlib::GzipReader.new(StringIO.new(data))
|
510
|
+
data = data_stream.read
|
511
|
+
data.should eq(@expected_data.to_json)
|
512
|
+
response
|
513
|
+
end
|
514
|
+
|
515
|
+
@resource_reporter.run_completed(@node)
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
context "after creating the run history document when summary_only is set to true" do
|
520
|
+
before do
|
521
|
+
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123", "summary_only"=>"true"}
|
445
522
|
@rest_client.should_receive(:post_rest).
|
446
|
-
with("reports/nodes/spitfire/runs
|
523
|
+
with("reports/nodes/spitfire/runs", {:action => :begin}).
|
447
524
|
and_return(response)
|
448
525
|
|
526
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
527
|
+
end
|
528
|
+
|
529
|
+
it "enables summary only reporting" do
|
530
|
+
@resource_reporter.summary_only.should == "true"
|
531
|
+
end
|
532
|
+
|
533
|
+
it "updates the run document with resource updates at the end of the run" do
|
534
|
+
# update some resources...
|
535
|
+
@resource_reporter.resource_action_start(@new_resource, :create)
|
536
|
+
@resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource)
|
537
|
+
@resource_reporter.resource_updated(@new_resource, :create)
|
538
|
+
|
539
|
+
post_url = "reports/nodes/spitfire/runs/ABC123"
|
540
|
+
response = {"result"=>"ok"}
|
541
|
+
|
542
|
+
@rest_client.should_receive(:post_rest).ordered do |url, data|
|
543
|
+
url.should eq(post_url)
|
544
|
+
data.should have_key("action")
|
545
|
+
data["action"].should == "end"
|
546
|
+
data.should have_key("status")
|
547
|
+
data.should have_key("resources")
|
548
|
+
data["resources"].should == []
|
549
|
+
data.should have_key("total_res_count")
|
550
|
+
data["total_res_count"].should == "1"
|
551
|
+
data.should have_key("data")
|
552
|
+
data["data"].should == {}
|
553
|
+
data.should have_key("updated_res_count")
|
554
|
+
data["updated_res_count"].should == "0"
|
555
|
+
data.should have_key("post_size")
|
556
|
+
response
|
557
|
+
end
|
558
|
+
|
449
559
|
@resource_reporter.run_completed(@node)
|
450
560
|
end
|
451
561
|
end
|
562
|
+
|
563
|
+
context "after creating the run history document when summary_only is set to false" do
|
564
|
+
before do
|
565
|
+
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123", "summary_only"=>"false"}
|
566
|
+
@rest_client.should_receive(:post_rest).
|
567
|
+
with("reports/nodes/spitfire/runs", {:action => :begin}).
|
568
|
+
and_return(response)
|
569
|
+
|
570
|
+
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
|
571
|
+
end
|
572
|
+
|
573
|
+
it "disables summary_only reporting" do
|
574
|
+
@resource_reporter.summary_only.should == "false"
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
452
578
|
end
|
453
579
|
|
454
580
|
end
|