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
  #
@@ -22,6 +23,8 @@ class Chef
22
23
  class Resource
23
24
  class HttpRequest < Chef::Resource
24
25
 
26
+ identity_attr :url
27
+
25
28
  def initialize(name, run_context=nil)
26
29
  super
27
30
  @resource_name = :http_request
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Jason K. Jackson (jasonjackson@gmail.com)
3
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2009 Jason K. Jackson
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -22,6 +23,10 @@ class Chef
22
23
  class Resource
23
24
  class Ifconfig < Chef::Resource
24
25
 
26
+ identity_attr :device
27
+
28
+ state_attrs :inet_addr, :mask
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :ifconfig
@@ -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
  #
@@ -24,7 +25,11 @@ class Chef
24
25
  class Link < Chef::Resource
25
26
  include Chef::Mixin::Securable
26
27
 
27
- provides :link, :on_platform => :all
28
+ provides :link, :on_platform => :all
29
+
30
+ identity_attr :target_file
31
+
32
+ state_attrs :to, :owner, :group
28
33
 
29
34
  def initialize(name, run_context=nil)
30
35
  super
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Cary Penniman (<cary@rightscale.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
  #
@@ -17,22 +18,24 @@
17
18
  #
18
19
  class Chef
19
20
  class Resource
20
-
21
- # Sends a string from a recipe to a log provider
22
- #
23
- # log "some string to log" do
24
- # level :info # (default) also supports :warn, :debug, and :error
25
- # end
26
- #
27
- # === Example
28
- # log "your string to log"
29
- #
30
- # or
31
- #
32
- # log "a debug string" { level :debug }
33
- #
34
21
  class Log < Chef::Resource
35
-
22
+
23
+ identity_attr :name
24
+
25
+ # Sends a string from a recipe to a log provider
26
+ #
27
+ # log "some string to log" do
28
+ # level :info # (default) also supports :warn, :debug, and :error
29
+ # end
30
+ #
31
+ # === Example
32
+ # log "your string to log"
33
+ #
34
+ # or
35
+ #
36
+ # log "a debug string" { level :debug }
37
+ #
38
+
36
39
  # Initialize log resource with a name as the string to log
37
40
  #
38
41
  # === Parameters
@@ -54,7 +57,7 @@ class Chef
54
57
  :equal_to => [ :debug, :info, :warn, :error, :fatal ]
55
58
  )
56
59
  end
57
-
60
+
58
61
  end
59
62
  end
60
63
  end
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Joe Williams (<joe@joetify.com>)
3
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2009 Joe Williams
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -22,6 +23,10 @@ class Chef
22
23
  class Resource
23
24
  class Mdadm < Chef::Resource
24
25
 
26
+ identity_attr :raid_device
27
+
28
+ state_attrs :devices, :level, :chunk
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :mdadm
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2009 Opscode, Inc
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -22,6 +23,10 @@ class Chef
22
23
  class Resource
23
24
  class Mount < Chef::Resource
24
25
 
26
+ identity_attr :device
27
+
28
+ state_attrs :mount_point, :device_type, :fstype
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :mount
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Michael Leinartas (<mleinartas@gmail.com>)
3
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2010 Michael Leinartas
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -20,9 +21,14 @@ class Chef
20
21
  class Resource
21
22
  class Ohai < Chef::Resource
22
23
 
24
+ identity_attr :name
25
+
26
+ state_attrs :plugin
27
+
23
28
  def initialize(name, run_context=nil)
24
29
  super
25
30
  @resource_name = :ohai
31
+ @name = name
26
32
  @allowed_actions.push(:reload)
27
33
  @action = :reload
28
34
  @plugin = nil
@@ -35,6 +41,14 @@ class Chef
35
41
  :kind_of => [ String ]
36
42
  )
37
43
  end
44
+
45
+ def name(arg=nil)
46
+ set_or_return(
47
+ :name,
48
+ arg,
49
+ :kind_of => [ String ]
50
+ )
51
+ end
38
52
  end
39
53
  end
40
54
  end
@@ -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
  #
@@ -24,7 +25,7 @@ class Chef
24
25
 
25
26
  identity_attr :package_name
26
27
 
27
- state_attrs :version
28
+ state_attrs :version, :options
28
29
 
29
30
  def initialize(name, run_context=nil)
30
31
  super
@@ -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
  #
@@ -27,6 +28,10 @@ class Chef
27
28
 
28
29
  provides :remote_directory, :on_platforms => :all
29
30
 
31
+ identity_attr :path
32
+
33
+ state_attrs :files_owner, :files_group, :files_mode
34
+
30
35
  def initialize(name, run_context=nil)
31
36
  super
32
37
  @resource_name = :remote_directory
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -21,7 +22,11 @@ require 'chef/resource'
21
22
  class Chef
22
23
  class Resource
23
24
  class Route < Chef::Resource
24
-
25
+
26
+ identity_attr :target
27
+
28
+ state_attrs :netmask, :gateway
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :route
@@ -21,11 +21,14 @@ class Chef
21
21
  class Resource
22
22
  class RubyBlock < Chef::Resource
23
23
 
24
+ identity_attr :block_name
25
+
24
26
  def initialize(name, run_context=nil)
25
27
  super
26
28
  @resource_name = :ruby_block
27
29
  @action = "create"
28
30
  @allowed_actions.push(:create)
31
+ @block_name = name
29
32
  end
30
33
 
31
34
  def block(&block)
@@ -35,6 +38,14 @@ class Chef
35
38
  @block
36
39
  end
37
40
  end
41
+
42
+ def block_name(arg=nil)
43
+ set_or_return(
44
+ :block_name,
45
+ arg,
46
+ :kind_of => String
47
+ )
48
+ end
38
49
  end
39
50
  end
40
51
  end
@@ -23,6 +23,10 @@ class Chef
23
23
  class Resource
24
24
  class Scm < Chef::Resource
25
25
 
26
+ identity_attr :destination
27
+
28
+ state_attrs :revision
29
+
26
30
  def initialize(name, run_context=nil)
27
31
  super
28
32
  @destination = name
@@ -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
  #
@@ -22,6 +23,8 @@ class Chef
22
23
  class Resource
23
24
  class Script < Chef::Resource::Execute
24
25
 
26
+ identity_attr :command
27
+
25
28
  def initialize(name, run_context=nil)
26
29
  super
27
30
  @resource_name = :script
@@ -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
  #
@@ -22,6 +23,10 @@ class Chef
22
23
  class Resource
23
24
  class Service < Chef::Resource
24
25
 
26
+ identity_attr :service_name
27
+
28
+ state_attrs :enabled, :running
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :service
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Daniel DeLeo (<dan@kallistec.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
  #
@@ -21,7 +22,7 @@ require "chef/resource/scm"
21
22
  class Chef
22
23
  class Resource
23
24
  class Subversion < Chef::Resource::Scm
24
-
25
+
25
26
  def initialize(name, run_context=nil)
26
27
  super
27
28
  @svn_arguments = '--no-auth-cache'
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Author:: Seth Chisamore (<schisamo@opscode.com>)
4
+ # Author:: Tyler Cloke (<tyler@opscode.com>)
4
5
  # Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
5
6
  # License:: Apache License, Version 2.0
6
7
  #
@@ -21,6 +21,10 @@ require 'chef/resource'
21
21
  class Chef
22
22
  class Resource
23
23
  class User < Chef::Resource
24
+
25
+ identity_attr :username
26
+
27
+ state_attrs :uid, :gid, :home
24
28
 
25
29
  def initialize(name, run_context=nil)
26
30
  super
@@ -58,6 +58,7 @@ class Chef
58
58
  as_hash["duration"] = (elapsed_time * 1000).to_i.to_s
59
59
  as_hash["delta"] = new_resource.diff if new_resource.respond_to?("diff")
60
60
  as_hash["delta"] = "" if as_hash["delta"].nil?
61
+
61
62
  # TODO: rename as "action"
62
63
  as_hash["result"] = action.to_s
63
64
  if success?
@@ -84,12 +85,13 @@ class Chef
84
85
  attr_reader :exception
85
86
  attr_reader :run_id
86
87
  attr_reader :error_descriptions
88
+ attr_reader :summary_only
87
89
 
88
90
  def initialize(rest_client)
89
- if Chef::Config[:disable_reporting]
90
- @reporting_enabled = false
91
- else
91
+ if Chef::Config[:enable_reporting] && !Chef::Config[:why_run]
92
92
  @reporting_enabled = true
93
+ else
94
+ @reporting_enabled = false
93
95
  end
94
96
  @updated_resources = []
95
97
  @total_res_count = 0
@@ -99,22 +101,31 @@ class Chef
99
101
  @run_id = nil
100
102
  @rest_client = rest_client
101
103
  @node = nil
102
- @error_descriptions = nil
104
+ @error_descriptions = {}
105
+ @summary_only = true
103
106
  end
104
107
 
105
108
  def node_load_completed(node, expanded_run_list_with_versions, config)
106
109
  @node = node
107
-
108
110
  if reporting_enabled?
109
111
  begin
110
- resource_history_url = "reports/nodes/#{@node.name}/runs"
112
+ resource_history_url = "reports/nodes/#{node.name}/runs"
111
113
  server_response = @rest_client.post_rest(resource_history_url, {:action => :begin})
112
114
  run_uri = URI.parse(server_response["uri"])
113
115
  @run_id = ::File.basename(run_uri.path)
114
116
  Chef::Log.info("Chef server generated run history id: #{@run_id}")
115
- rescue Net::HTTPServerException => e
116
- raise unless e.response.code.to_s == "404"
117
- Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
117
+ @summary_only = server_response["summary_only"]
118
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
119
+ if !e.response || e.response.code.to_s != 404
120
+ if Chef::Config[:enable_reporting_url_fatals]
121
+ Chef::Log.error("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
122
+ raise
123
+ else
124
+ Chef::Log.info("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
125
+ end
126
+ else
127
+ Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
128
+ end
118
129
  @reporting_enabled = false
119
130
  end
120
131
  end
@@ -159,42 +170,69 @@ class Chef
159
170
  end
160
171
 
161
172
  def run_completed(node)
162
- if reporting_enabled?
163
- resource_history_url = "reports/nodes/#{@node.name}/runs/#{run_id}"
164
- run_data = report(node)
165
- run_data["action"] = "end"
166
- Chef::Log.info("Sending resource update report (run-id: #{run_id})")
167
- Chef::Log.debug run_data.inspect
168
- @rest_client.post_rest(resource_history_url, run_data)
169
- else
170
- Chef::Log.debug("Server doesn't support resource history, skipping resource report.")
171
- end
173
+ @status = "success"
174
+ post_reporting_data
172
175
  end
173
176
 
174
177
  def run_failed(exception)
175
178
  @exception = exception
176
179
  @status = "failure"
180
+ post_reporting_data
177
181
  end
178
182
 
179
- def report(node)
183
+ def post_reporting_data
184
+ if reporting_enabled?
185
+ run_data = prepare_run_data
186
+ resource_history_url = "reports/nodes/#{@node.name}/runs/#{@run_id}"
187
+ Chef::Log.info("Sending resource update report (run-id: #{@run_id})")
188
+ Chef::Log.debug run_data.inspect
189
+ compressed_data = encode_gzip(run_data.to_json)
190
+ #if summary only is enabled send the uncompressed run_data excluding the run_data["resources"] and some additional metrics.
191
+ if @summary_only
192
+ run_data = report_summary(run_data, compressed_data)
193
+ Chef::Log.info("run_data_summary: #{run_data}")
194
+ @rest_client.post_rest(resource_history_url, run_data)
195
+ else
196
+ Chef::Log.debug("Sending Compressed Run Data...")
197
+ # Since we're posting compressed data we can not directly call
198
+ # post_rest which expects JSON
199
+ reporting_url = @rest_client.create_url(resource_history_url)
200
+ @rest_client.raw_http_request(:POST, reporting_url, {'Content-Encoding' => 'gzip'}, compressed_data)
201
+ end
202
+ else
203
+ Chef::Log.debug("Server doesn't support resource history, skipping resource report.")
204
+ end
205
+ end
206
+
207
+ def prepare_run_data
180
208
  run_data = {}
209
+ run_data["action"] = "end"
181
210
  run_data["resources"] = updated_resources.map do |resource_record|
182
211
  resource_record.for_json
183
212
  end
184
- run_data["status"] = status
185
- run_data["run_list"] = node.run_list.to_json
213
+ run_data["status"] = @status
214
+ run_data["run_list"] = @node.run_list.to_json
186
215
  run_data["total_res_count"] = @total_res_count.to_s
187
216
  run_data["data"] = {}
217
+
188
218
  if exception
189
- run_data["data"]["exception"] = {}
190
- run_data["data"]["exception"]["class"] = exception.inspect
191
- run_data["data"]["exception"]["message"] = exception.message
192
- run_data["data"]["exception"]["backtrace"] = exception.backtrace
193
- run_data["data"]["exception"]["description"] = @error_descriptions
219
+ exception_data = {}
220
+ exception_data["class"] = exception.inspect
221
+ exception_data["message"] = exception.message
222
+ exception_data["backtrace"] = exception.backtrace.to_json
223
+ exception_data["description"] = @error_descriptions
224
+ run_data["data"]["exception"] = exception_data
194
225
  end
195
226
  run_data
196
227
  end
197
228
 
229
+ def report_summary(run_data, compressed_data)
230
+ run_data["updated_res_count"] = updated_resources.count.to_s
231
+ run_data["post_size"] = compressed_data.bytesize.to_s
232
+ run_data["resources"] = []
233
+ run_data
234
+ end
235
+
198
236
  def run_list_expand_failed(node, exception)
199
237
  description = Formatters::ErrorMapper.run_list_expand_failed(node, exception)
200
238
  @error_descriptions = description.for_json
@@ -224,5 +262,11 @@ class Chef
224
262
  @pending_update && @pending_update.new_resource != new_resource
225
263
  end
226
264
 
265
+ def encode_gzip(data)
266
+ "".tap do |out|
267
+ Zlib::GzipWriter.wrap(StringIO.new(out)){|gz| gz << data }
268
+ end
269
+ end
270
+
227
271
  end
228
272
  end