chef 12.0.0.alpha.0 → 12.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -46,6 +46,7 @@ class Chef
46
46
  def remove_user
47
47
  command = [ "userdel" ]
48
48
  command << "-r" if managing_home_dir?
49
+ command << "-f" if new_resource.force
49
50
  command << new_resource.username
50
51
  shell_out!(*command)
51
52
  end
@@ -91,6 +91,7 @@ require 'chef/provider/user/pw'
91
91
  require 'chef/provider/user/useradd'
92
92
  require 'chef/provider/user/windows'
93
93
  require 'chef/provider/user/solaris'
94
+ require 'chef/provider/user/aix'
94
95
 
95
96
  require 'chef/provider/group/aix'
96
97
  require 'chef/provider/group/dscl'
@@ -134,7 +134,6 @@ F
134
134
 
135
135
  extend Chef::Mixin::ConvertToClassName
136
136
 
137
-
138
137
  if Module.method(:const_defined?).arity == 1
139
138
  def self.strict_const_defined?(const)
140
139
  const_defined?(const)
@@ -277,7 +276,6 @@ F
277
276
  end
278
277
  end
279
278
 
280
-
281
279
  def updated=(true_or_false)
282
280
  Chef::Log.warn("Chef::Resource#updated=(true|false) is deprecated. Please call #updated_by_last_action(true|false) instead.")
283
281
  Chef::Log.warn("Called from:")
@@ -544,7 +542,7 @@ F
544
542
  # Serialize this object as a hash
545
543
  def to_json(*a)
546
544
  results = as_json
547
- results.to_json(*a)
545
+ Chef::JSONCompat.to_json(results, *a)
548
546
  end
549
547
 
550
548
  def to_hash
@@ -662,6 +660,9 @@ F
662
660
  end
663
661
  ensure
664
662
  @elapsed_time = Time.now - start_time
663
+ # Reporting endpoint doesn't accept a negative resource duration so set it to 0.
664
+ # A negative value can occur when a resource changes the system time backwards
665
+ @elapsed_time = 0 if @elapsed_time < 0
665
666
  events.resource_completed(self)
666
667
  end
667
668
  end
@@ -31,17 +31,26 @@ class Chef
31
31
 
32
32
  provides :package, :on_platforms => ["freebsd"]
33
33
 
34
+ attr_accessor :created_as_type
34
35
 
35
36
  def initialize(name, run_context=nil)
36
37
  super
37
38
  @resource_name = :freebsd_package
39
+ @created_as_type = "freebsd_package"
38
40
  end
39
41
 
40
42
  def after_created
41
43
  assign_provider
42
44
  end
43
45
 
44
-
46
+ # This resource can be invoked with multiple names package & freebsd_package.
47
+ # We override the to_s method to ensure the key in resource collection
48
+ # matches the type resource is declared as using created_as_type. This
49
+ # logic can be removed once Chef does this for all resource in Chef 12:
50
+ # https://github.com/opscode/chef/issues/1817
51
+ def to_s
52
+ "#{created_as_type}[#{name}]"
53
+ end
45
54
 
46
55
  private
47
56
 
@@ -68,4 +77,3 @@ class Chef
68
77
  end
69
78
  end
70
79
  end
71
-
@@ -27,6 +27,7 @@ class Chef
27
27
  @resource_name = :paludis_package
28
28
  @provider = Chef::Provider::Package::Paludis
29
29
  @allowed_actions = [ :install, :remove, :upgrade ]
30
+ @timeout = 3600
30
31
  end
31
32
  end
32
33
  end
@@ -40,6 +40,7 @@ class Chef
40
40
  @allowed_actions.push(:checkout, :export, :sync, :diff, :log)
41
41
  @action = [:sync]
42
42
  @checkout_branch = "deploy"
43
+ @environment = nil
43
44
  end
44
45
 
45
46
  def destination(arg=nil)
@@ -172,6 +173,15 @@ class Chef
172
173
  )
173
174
  end
174
175
 
176
+ def environment(arg=nil)
177
+ set_or_return(
178
+ :environment,
179
+ arg,
180
+ :kind_of => [ Hash ]
181
+ )
182
+ end
183
+
184
+ alias :env :environment
175
185
  end
176
186
  end
177
187
  end
@@ -38,12 +38,15 @@ class Chef
38
38
  @password = nil
39
39
  @system = false
40
40
  @manage_home = false
41
+ @force = false
41
42
  @non_unique = false
42
43
  @action = :create
43
44
  @supports = {
44
45
  :manage_home => false,
45
46
  :non_unique => false
46
47
  }
48
+ @iterations = 27855
49
+ @salt = nil
47
50
  @allowed_actions.push(:create, :remove, :modify, :manage, :lock, :unlock)
48
51
  end
49
52
 
@@ -105,6 +108,22 @@ class Chef
105
108
  )
106
109
  end
107
110
 
111
+ def salt(arg=nil)
112
+ set_or_return(
113
+ :salt,
114
+ arg,
115
+ :kind_of => [ String ]
116
+ )
117
+ end
118
+
119
+ def iterations(arg=nil)
120
+ set_or_return(
121
+ :iterations,
122
+ arg,
123
+ :kind_of => [ Integer ]
124
+ )
125
+ end
126
+
108
127
  def system(arg=nil)
109
128
  set_or_return(
110
129
  :system,
@@ -121,6 +140,14 @@ class Chef
121
140
  )
122
141
  end
123
142
 
143
+ def force(arg=nil)
144
+ set_or_return(
145
+ :force,
146
+ arg,
147
+ :kind_of => [ TrueClass, FalseClass ]
148
+ )
149
+ end
150
+
124
151
  def non_unique(arg=nil)
125
152
  set_or_return(
126
153
  :non_unique,
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Bryan McLellan <btm@loftninjas.org>
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/resource/service'
20
+
21
+ class Chef
22
+ class Resource
23
+ class WindowsService < Chef::Resource::Service
24
+
25
+ # Until #1773 is resolved, you need to manually specify the windows_service resource
26
+ # to use action :configure_startup and attribute startup_type
27
+
28
+ # provides :service, :on_platforms => ["windows"]
29
+
30
+ identity_attr :service_name
31
+
32
+ state_attrs :enabled, :running
33
+
34
+ def initialize(name, run_context=nil)
35
+ super
36
+ @resource_name = :windows_service
37
+ @provider = Chef::Provider::Service::Windows
38
+ @allowed_actions.push(:configure_startup)
39
+ @startup_type = :automatic
40
+ end
41
+
42
+ def startup_type(arg=nil)
43
+ # Set-Service arguments are automatic and manual
44
+ # Win32::Service returns 'auto start' or 'demand start' respectively, which the provider currently uses
45
+ set_or_return(
46
+ :startup_type,
47
+ arg,
48
+ :equal_to => [ :automatic, :manual, :disabled ]
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
@@ -67,24 +67,33 @@ class Chef
67
67
  alias_method :push, :<<
68
68
 
69
69
  def insert(resource)
70
- is_chef_resource(resource)
71
70
  if @insert_after_idx
72
71
  # in the middle of executing a run, so any resources inserted now should
73
72
  # be placed after the most recent addition done by the currently executing
74
73
  # resource
75
- @resources.insert(@insert_after_idx + 1, resource)
76
- # update name -> location mappings and register new resource
77
- @resources_by_name.each_key do |key|
78
- @resources_by_name[key] += 1 if @resources_by_name[key] > @insert_after_idx
79
- end
80
- @resources_by_name[resource.to_s] = @insert_after_idx + 1
74
+ insert_at(@insert_after_idx + 1, resource)
81
75
  @insert_after_idx += 1
82
76
  else
77
+ is_chef_resource(resource)
83
78
  @resources << resource
84
79
  @resources_by_name[resource.to_s] = @resources.length - 1
85
80
  end
86
81
  end
87
82
 
83
+ def insert_at(insert_at_index, *resources)
84
+ resources.each do |resource|
85
+ is_chef_resource(resource)
86
+ end
87
+ @resources.insert(insert_at_index, *resources)
88
+ # update name -> location mappings and register new resource
89
+ @resources_by_name.each_key do |key|
90
+ @resources_by_name[key] += resources.size if @resources_by_name[key] >= insert_at_index
91
+ end
92
+ resources.each_with_index do |resource, i|
93
+ @resources_by_name[resource.to_s] = insert_at_index + i
94
+ end
95
+ end
96
+
88
97
  def each
89
98
  @resources.each do |resource|
90
99
  yield resource
@@ -158,7 +167,6 @@ class Chef
158
167
  # compat.
159
168
  alias_method :resources, :find
160
169
 
161
-
162
170
  # Returns true if +query_object+ is a valid string for looking up a
163
171
  # resource, or raises InvalidResourceSpecification if not.
164
172
  # === Arguments
@@ -189,16 +197,19 @@ class Chef
189
197
  end
190
198
 
191
199
  # Serialize this object as a hash
192
- def to_json(*a)
200
+ def to_hash
193
201
  instance_vars = Hash.new
194
202
  self.instance_variables.each do |iv|
195
203
  instance_vars[iv] = self.instance_variable_get(iv)
196
204
  end
197
- results = {
205
+ {
198
206
  'json_class' => self.class.name,
199
207
  'instance_vars' => instance_vars
200
208
  }
201
- results.to_json(*a)
209
+ end
210
+
211
+ def to_json(*a)
212
+ Chef::JSONCompat.to_json(to_hash, *a)
202
213
  end
203
214
 
204
215
  def self.json_create(o)
@@ -247,7 +258,7 @@ class Chef
247
258
 
248
259
  def is_chef_resource(arg)
249
260
  unless arg.kind_of?(Chef::Resource)
250
- raise ArgumentError, "Members must be Chef::Resource's"
261
+ raise ArgumentError, "Cannot insert a #{arg.class} into a resource collection: must be a subclass of Chef::Resource"
251
262
  end
252
263
  true
253
264
  end
@@ -230,18 +230,18 @@ class Chef
230
230
  resource_history_url = "reports/nodes/#{node_name}/runs/#{run_id}"
231
231
  Chef::Log.info("Sending resource update report (run-id: #{run_id})")
232
232
  Chef::Log.debug run_data.inspect
233
- compressed_data = encode_gzip(run_data.to_json)
233
+ compressed_data = encode_gzip(Chef::JSONCompat.to_json(run_data))
234
+ Chef::Log.debug("Sending compressed run data...")
235
+ # Since we're posting compressed data we can not directly call post_rest which expects JSON
236
+ reporting_url = @rest_client.create_url(resource_history_url)
234
237
  begin
235
- Chef::Log.debug("Sending compressed run data...")
236
- # Since we're posting compressed data we can not directly call post_rest which expects JSON
237
- reporting_url = @rest_client.create_url(resource_history_url)
238
238
  @rest_client.raw_http_request(:POST, reporting_url, headers({'Content-Encoding' => 'gzip'}), compressed_data)
239
- rescue Net::HTTPServerException => e
240
- if e.response.code.to_s == "400"
239
+ rescue StandardError => e
240
+ if e.respond_to? :response
241
241
  Chef::FileCache.store("failed-reporting-data.json", Chef::JSONCompat.to_json_pretty(run_data), 0640)
242
- Chef::Log.error("Failed to post reporting data to server (HTTP 400), saving to #{Chef::FileCache.load("failed-reporting-data.json", false)}")
242
+ Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code}), saving to #{Chef::FileCache.load("failed-reporting-data.json", false)}")
243
243
  else
244
- Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code.to_s})")
244
+ Chef::Log.error("Failed to post reporting data to server (#{e})")
245
245
  end
246
246
  end
247
247
  else
@@ -273,7 +273,7 @@ class Chef
273
273
  resource_record.for_json
274
274
  end
275
275
  run_data["status"] = @status
276
- run_data["run_list"] = @run_status.node.run_list.to_json
276
+ run_data["run_list"] = Chef::JSONCompat.to_json(@run_status.node.run_list)
277
277
  run_data["total_res_count"] = @total_res_count.to_s
278
278
  run_data["data"] = {}
279
279
  run_data["start_time"] = start_time.to_s
@@ -283,7 +283,7 @@ class Chef
283
283
  exception_data = {}
284
284
  exception_data["class"] = exception.inspect
285
285
  exception_data["message"] = exception.message
286
- exception_data["backtrace"] = exception.backtrace.to_json
286
+ exception_data["backtrace"] = Chef::JSONCompat.to_json(exception.backtrace)
287
287
  exception_data["description"] = @error_descriptions
288
288
  run_data["data"]["exception"] = exception_data
289
289
  end
@@ -64,6 +64,7 @@ require 'chef/resource/ruby_block'
64
64
  require 'chef/resource/scm'
65
65
  require 'chef/resource/script'
66
66
  require 'chef/resource/service'
67
+ require 'chef/resource/windows_service'
67
68
  require 'chef/resource/subversion'
68
69
  require 'chef/resource/smartos_package'
69
70
  require 'chef/resource/template'
@@ -143,7 +143,7 @@ class Chef
143
143
 
144
144
  # Serialize this object as a hash
145
145
  def to_json(*a)
146
- to_hash.to_json(*a)
146
+ Chef::JSONCompat.to_json(to_hash, *a)
147
147
  end
148
148
 
149
149
  def update_from!(o)
@@ -236,8 +236,8 @@ class Chef
236
236
  paths = Array(Chef::Config[:role_path])
237
237
  paths.each do |path|
238
238
  roles_files = Dir.glob(File.join(path, "**", "**"))
239
- js_files = roles_files.select { |file| file.match /#{name}\.json$/ }
240
- rb_files = roles_files.select { |file| file.match /#{name}\.rb$/ }
239
+ js_files = roles_files.select { |file| file.match /\/#{name}\.json$/ }
240
+ rb_files = roles_files.select { |file| file.match /\/#{name}\.rb$/ }
241
241
  if js_files.count > 1 or rb_files.count > 1
242
242
  raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}"
243
243
  end
@@ -85,8 +85,12 @@ class Chef
85
85
  @run_list_items.join(", ")
86
86
  end
87
87
 
88
- def to_json(*args)
89
- to_a.map { |item| item.to_s}.to_json(*args)
88
+ def for_json
89
+ to_a.map { |item| item.to_s }
90
+ end
91
+
92
+ def to_json(*a)
93
+ Chef::JSONCompat.to_json(for_json, *a)
90
94
  end
91
95
 
92
96
  def empty?
@@ -158,6 +162,5 @@ class Chef
158
162
  end
159
163
  end
160
164
 
161
-
162
165
  end
163
166
  end
@@ -73,7 +73,7 @@ class Chef
73
73
  end
74
74
 
75
75
  def to_json(*a)
76
- to_hash.to_json(*a)
76
+ Chef::JSONCompat.to_json(to_hash, *a)
77
77
  end
78
78
 
79
79
  def destroy
@@ -82,7 +82,7 @@ class Chef
82
82
  end
83
83
  end
84
84
  end
85
-
85
+
86
86
  # produces a unified-output-format diff with 3 lines of context
87
87
  # ChefFS uses udiff() directly
88
88
  def udiff(old_file, new_file)
@@ -185,4 +185,3 @@ class Chef
185
185
  end
186
186
  end
187
187
  end
188
-
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '12.0.0.alpha.0'
20
+ VERSION = '12.0.0.alpha.1'
21
21
  end
22
22
 
23
23
  #
@@ -24,7 +24,7 @@ class Chef
24
24
  PATTERN = /^(#{OPS.join('|')}) *([0-9].*)$/
25
25
  VERSION_CLASS = Chef::Version
26
26
 
27
- attr_reader :op, :version, :raw_version
27
+ attr_reader :op, :version
28
28
 
29
29
  def initialize(constraint_spec=DEFAULT_CONSTRAINT)
30
30
  case constraint_spec
@@ -50,11 +50,11 @@ class Chef
50
50
  end
51
51
 
52
52
  def inspect
53
- "(#{@op} #{@version})"
53
+ "(#{to_s})"
54
54
  end
55
55
 
56
56
  def to_s
57
- "#{@op} #{@version}"
57
+ "#{@op} #{@raw_version}"
58
58
  end
59
59
 
60
60
  def eql?(o)
@@ -106,7 +106,7 @@ class Chef
106
106
  @op = $1
107
107
  @raw_version = $2
108
108
  @version = self.class::VERSION_CLASS.new(@raw_version)
109
- if raw_version.split('.').size <= 2
109
+ if @raw_version.split('.').size <= 2
110
110
  @missing_patch_level = true
111
111
  end
112
112
  else