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.
Files changed (147) hide show
  1. data/distro/common/html/chef-client.8.html +4 -4
  2. data/distro/common/html/chef-expander.8.html +4 -4
  3. data/distro/common/html/chef-expanderctl.8.html +4 -4
  4. data/distro/common/html/chef-server-webui.8.html +4 -4
  5. data/distro/common/html/chef-server.8.html +182 -0
  6. data/distro/common/html/chef-solo.8.html +4 -4
  7. data/distro/common/html/chef-solr.8.html +4 -4
  8. data/distro/common/html/knife-bootstrap.1.html +5 -5
  9. data/distro/common/html/knife-client.1.html +4 -4
  10. data/distro/common/html/knife-configure.1.html +5 -5
  11. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  12. data/distro/common/html/knife-cookbook.1.html +8 -8
  13. data/distro/common/html/knife-data-bag.1.html +4 -4
  14. data/distro/common/html/knife-environment.1.html +7 -7
  15. data/distro/common/html/knife-exec.1.html +4 -4
  16. data/distro/common/html/knife-index.1.html +4 -4
  17. data/distro/common/html/knife-node.1.html +5 -5
  18. data/distro/common/html/knife-role.1.html +4 -4
  19. data/distro/common/html/knife-search.1.html +6 -6
  20. data/distro/common/html/knife-ssh.1.html +4 -4
  21. data/distro/common/html/knife-status.1.html +5 -5
  22. data/distro/common/html/knife-tag.1.html +4 -4
  23. data/distro/common/html/knife.1.html +4 -4
  24. data/distro/common/html/shef.1.html +4 -4
  25. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  26. data/distro/common/man/man1/knife-client.1 +1 -1
  27. data/distro/common/man/man1/knife-configure.1 +1 -1
  28. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  30. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  31. data/distro/common/man/man1/knife-environment.1 +1 -1
  32. data/distro/common/man/man1/knife-exec.1 +1 -1
  33. data/distro/common/man/man1/knife-index.1 +1 -1
  34. data/distro/common/man/man1/knife-node.1 +1 -1
  35. data/distro/common/man/man1/knife-role.1 +1 -1
  36. data/distro/common/man/man1/knife-search.1 +1 -1
  37. data/distro/common/man/man1/knife-ssh.1 +1 -1
  38. data/distro/common/man/man1/knife-status.1 +1 -1
  39. data/distro/common/man/man1/knife-tag.1 +1 -1
  40. data/distro/common/man/man1/knife.1 +1 -1
  41. data/distro/common/man/man1/shef.1 +1 -1
  42. data/distro/common/man/man8/chef-client.8 +1 -1
  43. data/distro/common/man/man8/chef-expander.8 +1 -1
  44. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  45. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  46. data/distro/common/man/man8/chef-server.8 +1 -1
  47. data/distro/common/man/man8/chef-solo.8 +1 -1
  48. data/distro/common/man/man8/chef-solr.8 +1 -1
  49. data/distro/debian/etc/init.d/chef-client +1 -1
  50. data/distro/debian/etc/init.d/chef-expander +1 -1
  51. data/distro/debian/etc/init.d/chef-server +1 -1
  52. data/distro/debian/etc/init.d/chef-server-webui +1 -1
  53. data/distro/debian/etc/init.d/chef-solr +1 -1
  54. data/lib/chef/application/client.rb +3 -3
  55. data/lib/chef/client.rb +4 -1
  56. data/lib/chef/config.rb +2 -1
  57. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -0
  58. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -0
  59. data/lib/chef/knife/bootstrap/chef-full.erb +2 -1
  60. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -0
  61. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -0
  62. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -0
  63. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -0
  64. data/lib/chef/knife/configure.rb +19 -0
  65. data/lib/chef/knife/data_bag_from_file.rb +1 -1
  66. data/lib/chef/knife/environment_from_file.rb +41 -8
  67. data/lib/chef/knife/ssh.rb +5 -1
  68. data/lib/chef/provider/cookbook_file.rb +4 -4
  69. data/lib/chef/provider/directory.rb +3 -0
  70. data/lib/chef/provider/file.rb +49 -3
  71. data/lib/chef/provider/ifconfig.rb +1 -1
  72. data/lib/chef/provider/package.rb +2 -0
  73. data/lib/chef/provider/package/pacman.rb +10 -1
  74. data/lib/chef/provider/remote_file.rb +1 -1
  75. data/lib/chef/provider/service.rb +22 -0
  76. data/lib/chef/provider/template.rb +9 -1
  77. data/lib/chef/resource.rb +1 -1
  78. data/lib/chef/resource/cookbook_file.rb +1 -0
  79. data/lib/chef/resource/cron.rb +5 -0
  80. data/lib/chef/resource/deploy.rb +6 -1
  81. data/lib/chef/resource/directory.rb +6 -0
  82. data/lib/chef/resource/env.rb +5 -0
  83. data/lib/chef/resource/erl_call.rb +3 -0
  84. data/lib/chef/resource/execute.rb +3 -0
  85. data/lib/chef/resource/file.rb +5 -5
  86. data/lib/chef/resource/group.rb +5 -0
  87. data/lib/chef/resource/http_request.rb +3 -0
  88. data/lib/chef/resource/ifconfig.rb +5 -0
  89. data/lib/chef/resource/link.rb +6 -1
  90. data/lib/chef/resource/log.rb +19 -16
  91. data/lib/chef/resource/mdadm.rb +5 -0
  92. data/lib/chef/resource/mount.rb +5 -0
  93. data/lib/chef/resource/ohai.rb +14 -0
  94. data/lib/chef/resource/package.rb +2 -1
  95. data/lib/chef/resource/remote_directory.rb +5 -0
  96. data/lib/chef/resource/route.rb +6 -1
  97. data/lib/chef/resource/ruby_block.rb +11 -0
  98. data/lib/chef/resource/scm.rb +4 -0
  99. data/lib/chef/resource/script.rb +3 -0
  100. data/lib/chef/resource/service.rb +5 -0
  101. data/lib/chef/resource/subversion.rb +2 -1
  102. data/lib/chef/resource/template.rb +1 -0
  103. data/lib/chef/resource/user.rb +4 -0
  104. data/lib/chef/resource_reporter.rb +71 -27
  105. data/lib/chef/rest.rb +8 -4
  106. data/lib/chef/run_list.rb +2 -2
  107. data/lib/chef/scan_access_control.rb +1 -1
  108. data/lib/chef/version.rb +1 -1
  109. data/spec/unit/client_spec.rb +6 -2
  110. data/spec/unit/knife/configure_spec.rb +121 -25
  111. data/spec/unit/knife/data_bag_from_file_spec.rb +5 -3
  112. data/spec/unit/knife/environment_from_file_spec.rb +23 -0
  113. data/spec/unit/provider/cookbook_file_spec.rb +3 -0
  114. data/spec/unit/provider/directory_spec.rb +16 -17
  115. data/spec/unit/provider/file_spec.rb +75 -0
  116. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  117. data/spec/unit/provider/package/pacman_spec.rb +29 -0
  118. data/spec/unit/provider/package_spec.rb +4 -0
  119. data/spec/unit/provider/remote_directory_spec.rb +6 -1
  120. data/spec/unit/provider/remote_file_spec.rb +7 -0
  121. data/spec/unit/resource/cookbook_file_spec.rb +42 -1
  122. data/spec/unit/resource/cron_spec.rb +27 -0
  123. data/spec/unit/resource/deploy_spec.rb +27 -0
  124. data/spec/unit/resource/directory_spec.rb +20 -0
  125. data/spec/unit/resource/env_spec.rb +19 -0
  126. data/spec/unit/resource/erl_call_spec.rb +12 -0
  127. data/spec/unit/resource/execute_spec.rb +16 -0
  128. data/spec/unit/resource/group_spec.rb +17 -1
  129. data/spec/unit/resource/http_request_spec.rb +13 -0
  130. data/spec/unit/resource/ifconfig_spec.rb +46 -0
  131. data/spec/unit/resource/link_spec.rb +21 -0
  132. data/spec/unit/resource/log_spec.rb +10 -0
  133. data/spec/unit/resource/mdadm_spec.rb +22 -0
  134. data/spec/unit/resource/mount_spec.rb +20 -0
  135. data/spec/unit/resource/ohai_spec.rb +18 -0
  136. data/spec/unit/resource/package_spec.rb +3 -0
  137. data/spec/unit/resource/remote_directory_spec.rb +22 -0
  138. data/spec/unit/resource/remote_file_spec.rb +40 -0
  139. data/spec/unit/resource/route_spec.rb +19 -0
  140. data/spec/unit/resource/ruby_block_spec.rb +11 -0
  141. data/spec/unit/resource/scm_spec.rb +20 -0
  142. data/spec/unit/resource/script_spec.rb +14 -0
  143. data/spec/unit/resource/service_spec.rb +21 -0
  144. data/spec/unit/resource/user_spec.rb +21 -0
  145. data/spec/unit/resource_reporter_spec.rb +260 -134
  146. data/spec/unit/run_list_spec.rb +14 -0
  147. 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[:disable_reporting]
28
- Chef::Config[:disable_reporting] = false
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[:disable_reporting] = @reporting_toggle_default
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 be_nil
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 before converging any resources" do
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
- @exception = Exception.new
96
- @exception.set_backtrace(caller)
97
- @resource_reporter.resource_action_start(@new_resource, :create)
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
- context "once the a resource's current state is loaded" do
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 "and the resource was not updated" do
90
+ context "before converging any resources" do
123
91
  before do
124
- @resource_reporter.resource_up_to_date(@new_resource, :create)
92
+ @exception = Exception.new
93
+ @resource_reporter.run_failed(@exception)
125
94
  end
126
-
127
- it "has no updated resources" do
128
- @resource_reporter.should have(0).updated_resources
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 "and the resource was updated" do
105
+ context "when a resource fails before loading current state" do
133
106
  before do
134
- @new_resource.content("this is the old content")
135
- @current_resource.content("this is the new hotness")
136
- @resource_reporter.resource_updated(@new_resource, :create)
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 old state of the resource" do
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
- update_record.current_resource.should == @current_resource
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
- it "collects the new state of the resource" do
151
- update_record = @resource_reporter.updated_resources.first
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
- update_record.new_resource.should == @new_resource
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 a subsequent resource fails before loading current resource" do
143
+ context "and the resource was updated" do
157
144
  before do
158
- @next_new_resource = Chef::Resource::Service.new("apache2")
159
- @exception = Exception.new
160
- @exception.set_backtrace(caller)
161
- @resource_reporter.resource_failed(@next_new_resource, :create, @exception)
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 desired state of the failed resource" do
166
- failed_resource_update = @resource_reporter.updated_resources.last
167
- failed_resource_update.new_resource.should == @next_new_resource
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
- it "does not have the current state of the failed resource" do
171
- failed_resource_update = @resource_reporter.updated_resources.last
172
- failed_resource_update.current_resource.should be_nil
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
- end
176
-
177
- # Some providers, such as RemoteDirectory and some LWRPs use other
178
- # resources for their implementation. These should be hidden from reporting
179
- # since we only care about the top-level resource and not the sub-resources
180
- # used for implementation.
181
- context "and a nested resource is updated" do
182
- before do
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
- it "does not collect data about the nested resource" do
193
- @resource_reporter.should have(1).updated_resources
194
- end
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
- it "collects the resource as an updated resource" do
222
- @resource_reporter.should have(1).updated_resources
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
- it "collects the desired state of the resource" do
226
- update_record = @resource_reporter.updated_resources.first
227
- update_record.new_resource.should == @new_resource
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.report(@node)
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
- @report = @resource_reporter.report(@node)
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.report(@node)
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/ABC123", @expected_data).
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