chef 10.34.6-x86-mingw32 → 11.6.2-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (777) hide show
  1. checksums.yaml +5 -13
  2. data/CONTRIBUTING.md +155 -0
  3. data/README.md +89 -0
  4. data/Rakefile +18 -1
  5. data/bin/chef-apply +25 -0
  6. data/bin/chef-service-manager +37 -0
  7. data/bin/chef-shell +34 -0
  8. data/bin/shef +6 -5
  9. data/distro/common/html/chef-client.8.html +4 -4
  10. data/distro/common/html/chef-expander.8.html +4 -4
  11. data/distro/common/html/chef-expanderctl.8.html +4 -4
  12. data/distro/common/html/chef-server-webui.8.html +4 -4
  13. data/distro/common/html/chef-server.8.html +4 -4
  14. data/distro/common/html/{shef.1.html → chef-shell.1.html} +49 -46
  15. data/distro/common/html/chef-solo.8.html +4 -4
  16. data/distro/common/html/chef-solr.8.html +5 -5
  17. data/distro/common/html/knife-bootstrap.1.html +4 -4
  18. data/distro/common/html/knife-client.1.html +4 -4
  19. data/distro/common/html/knife-configure.1.html +4 -4
  20. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  21. data/distro/common/html/knife-cookbook.1.html +4 -4
  22. data/distro/common/html/knife-data-bag.1.html +4 -4
  23. data/distro/common/html/knife-environment.1.html +4 -4
  24. data/distro/common/html/knife-exec.1.html +9 -9
  25. data/distro/common/html/knife-index.1.html +4 -4
  26. data/distro/common/html/knife-node.1.html +4 -4
  27. data/distro/common/html/knife-role.1.html +4 -4
  28. data/distro/common/html/knife-search.1.html +4 -4
  29. data/distro/common/html/knife-ssh.1.html +4 -4
  30. data/distro/common/html/knife-status.1.html +4 -4
  31. data/distro/common/html/knife-tag.1.html +4 -4
  32. data/distro/common/html/knife.1.html +8 -13
  33. data/distro/common/man/man1/{shef.1 → chef-shell.1} +21 -57
  34. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  35. data/distro/common/man/man1/knife-client.1 +0 -99
  36. data/distro/common/man/man1/knife-configure.1 +1 -1
  37. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  38. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  39. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  40. data/distro/common/man/man1/knife-environment.1 +0 -168
  41. data/distro/common/man/man1/knife-exec.1 +4 -7
  42. data/distro/common/man/man1/knife-index.1 +1 -1
  43. data/distro/common/man/man1/knife-node.1 +1 -1
  44. data/distro/common/man/man1/knife-role.1 +1 -1
  45. data/distro/common/man/man1/knife-search.1 +1 -1
  46. data/distro/common/man/man1/knife-ssh.1 +1 -1
  47. data/distro/common/man/man1/knife-status.1 +1 -1
  48. data/distro/common/man/man1/knife-tag.1 +1 -1
  49. data/distro/common/man/man1/knife.1 +3 -6
  50. data/distro/common/man/man8/chef-client.8 +1 -1
  51. data/distro/common/man/man8/chef-expander.8 +1 -1
  52. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  53. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  54. data/distro/common/man/man8/chef-server.8 +1 -1
  55. data/distro/common/man/man8/chef-solo.8 +1 -1
  56. data/distro/common/man/man8/chef-solr.8 +1 -1
  57. data/distro/common/markdown/man1/{shef.mkd → chef-shell.mkd} +49 -43
  58. data/distro/common/markdown/man1/knife-exec.mkd +11 -6
  59. data/distro/common/markdown/man1/knife.mkd +4 -9
  60. data/distro/debian/etc/default/chef-client +0 -1
  61. data/distro/debian/etc/init.d/chef-client +6 -4
  62. data/distro/windows/service_manager.rb +2 -146
  63. data/lib/chef.rb +3 -6
  64. data/lib/chef/api_client.rb +20 -130
  65. data/lib/chef/api_client/registration.rb +126 -0
  66. data/lib/chef/application.rb +68 -18
  67. data/lib/chef/application/apply.rb +162 -0
  68. data/lib/chef/application/client.rb +37 -22
  69. data/lib/chef/application/knife.rb +2 -4
  70. data/lib/chef/application/solo.rb +27 -13
  71. data/lib/chef/application/windows_service.rb +114 -54
  72. data/lib/chef/application/windows_service_manager.rb +179 -0
  73. data/lib/chef/applications.rb +1 -0
  74. data/lib/chef/chef_fs.rb +9 -0
  75. data/lib/chef/chef_fs/chef_fs_data_store.rb +371 -0
  76. data/lib/chef/chef_fs/command_line.rb +284 -0
  77. data/lib/chef/chef_fs/config.rb +205 -0
  78. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +26 -0
  79. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +38 -0
  80. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +29 -0
  81. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +38 -0
  82. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +56 -0
  83. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +128 -0
  84. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +40 -0
  85. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +51 -0
  86. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +36 -0
  87. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +40 -0
  88. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +27 -0
  89. data/lib/chef/chef_fs/file_pattern.rb +312 -0
  90. data/lib/chef/chef_fs/file_system.rb +426 -0
  91. data/lib/chef/chef_fs/file_system/acl_dir.rb +64 -0
  92. data/lib/chef/chef_fs/file_system/acl_entry.rb +58 -0
  93. data/lib/chef/chef_fs/file_system/acls_dir.rb +68 -0
  94. data/lib/chef/chef_fs/file_system/already_exists_error.rb +31 -0
  95. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +47 -0
  96. data/lib/chef/chef_fs/file_system/base_fs_object.rb +180 -0
  97. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +85 -0
  98. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +71 -0
  99. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +55 -0
  100. data/lib/chef/chef_fs/file_system/chef_repository_file_system_data_bags_dir.rb +36 -0
  101. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +60 -0
  102. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +121 -0
  103. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +110 -0
  104. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +223 -0
  105. data/lib/chef/chef_fs/file_system/cookbook_file.rb +85 -0
  106. data/lib/chef/chef_fs/file_system/cookbook_frozen_error.rb +31 -0
  107. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +54 -0
  108. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +41 -0
  109. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +149 -0
  110. data/lib/chef/chef_fs/file_system/data_bag_dir.rb +69 -0
  111. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +72 -0
  112. data/lib/chef/chef_fs/file_system/default_environment_cannot_be_modified_error.rb +36 -0
  113. data/lib/chef/chef_fs/file_system/environments_dir.rb +60 -0
  114. data/lib/chef/chef_fs/file_system/file_system_entry.rb +90 -0
  115. data/lib/chef/chef_fs/file_system/file_system_error.rb +33 -0
  116. data/lib/chef/chef_fs/file_system/file_system_root_dir.rb +31 -0
  117. data/lib/chef/chef_fs/file_system/memory_dir.rb +52 -0
  118. data/lib/chef/chef_fs/file_system/memory_file.rb +17 -0
  119. data/lib/chef/chef_fs/file_system/memory_root.rb +21 -0
  120. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +48 -0
  121. data/lib/chef/chef_fs/file_system/must_delete_recursively_error.rb +31 -0
  122. data/lib/chef/chef_fs/file_system/nodes_dir.rb +55 -0
  123. data/lib/chef/chef_fs/file_system/nonexistent_fs_object.rb +36 -0
  124. data/lib/chef/chef_fs/file_system/not_found_error.rb +31 -0
  125. data/lib/chef/chef_fs/file_system/operation_failed_error.rb +34 -0
  126. data/lib/chef/chef_fs/file_system/operation_not_allowed_error.rb +48 -0
  127. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +113 -0
  128. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +177 -0
  129. data/lib/chef/chef_fs/knife.rb +116 -0
  130. data/lib/chef/chef_fs/parallelizer.rb +129 -0
  131. data/lib/chef/chef_fs/path_utils.rb +90 -0
  132. data/lib/chef/chef_fs/raw_request.rb +79 -0
  133. data/lib/chef/client.rb +111 -34
  134. data/lib/chef/config.rb +111 -102
  135. data/lib/chef/cookbook/chefignore.rb +2 -1
  136. data/lib/chef/cookbook/metadata.rb +0 -2
  137. data/lib/chef/cookbook/syntax_check.rb +76 -14
  138. data/lib/chef/cookbook_loader.rb +39 -26
  139. data/lib/chef/cookbook_uploader.rb +16 -9
  140. data/lib/chef/cookbook_version.rb +2 -410
  141. data/lib/chef/daemon.rb +24 -19
  142. data/lib/chef/data_bag.rb +20 -104
  143. data/lib/chef/data_bag_item.rb +2 -65
  144. data/lib/chef/deprecation/mixin/template.rb +49 -0
  145. data/lib/chef/deprecation/provider/cookbook_file.rb +55 -0
  146. data/lib/chef/deprecation/provider/file.rb +197 -0
  147. data/lib/chef/deprecation/provider/remote_file.rb +86 -0
  148. data/lib/chef/deprecation/provider/template.rb +63 -0
  149. data/lib/chef/deprecation/warnings.rb +38 -0
  150. data/lib/chef/digester.rb +73 -0
  151. data/lib/chef/dsl.rb +6 -0
  152. data/lib/chef/dsl/data_query.rb +71 -0
  153. data/lib/chef/dsl/include_attribute.rb +63 -0
  154. data/lib/chef/dsl/include_recipe.rb +45 -0
  155. data/lib/chef/dsl/platform_introspection.rb +218 -0
  156. data/lib/chef/dsl/recipe.rb +87 -0
  157. data/lib/chef/dsl/registry_helper.rb +59 -0
  158. data/lib/chef/encrypted_data_bag_item.rb +171 -24
  159. data/lib/chef/environment.rb +39 -179
  160. data/lib/chef/event_dispatch/base.rb +3 -0
  161. data/lib/chef/exceptions.rb +107 -8
  162. data/lib/chef/file_access_control/unix.rb +64 -7
  163. data/lib/chef/file_access_control/windows.rb +22 -11
  164. data/lib/chef/file_content_management/content_base.rb +56 -0
  165. data/lib/chef/file_content_management/deploy.rb +38 -0
  166. data/lib/chef/file_content_management/deploy/cp.rb +48 -0
  167. data/lib/chef/file_content_management/deploy/mv_unix.rb +77 -0
  168. data/lib/chef/file_content_management/deploy/mv_windows.rb +95 -0
  169. data/lib/chef/file_content_management/tempfile.rb +61 -0
  170. data/lib/chef/formatters/base.rb +4 -1
  171. data/lib/chef/formatters/doc.rb +1 -1
  172. data/lib/chef/formatters/error_descriptor.rb +5 -4
  173. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +23 -3
  174. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +8 -0
  175. data/lib/chef/json_compat.rb +15 -14
  176. data/lib/chef/knife.rb +99 -41
  177. data/lib/chef/knife/bootstrap.rb +46 -2
  178. data/lib/chef/knife/bootstrap/archlinux-gems.erb +1 -1
  179. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  180. data/lib/chef/knife/bootstrap/chef-full.erb +1 -1
  181. data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
  182. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -1
  183. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +1 -1
  184. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +1 -1
  185. data/lib/chef/knife/client_show.rb +2 -5
  186. data/lib/chef/knife/configure.rb +19 -17
  187. data/lib/chef/knife/cookbook_create.rb +6 -5
  188. data/lib/chef/knife/cookbook_download.rb +13 -5
  189. data/lib/chef/knife/cookbook_metadata.rb +1 -0
  190. data/lib/chef/knife/cookbook_site_share.rb +1 -0
  191. data/lib/chef/knife/cookbook_test.rb +4 -2
  192. data/lib/chef/knife/cookbook_upload.rb +4 -4
  193. data/lib/chef/knife/core/bootstrap_context.rb +11 -5
  194. data/lib/chef/knife/core/generic_presenter.rb +42 -13
  195. data/lib/chef/knife/core/node_editor.rb +36 -16
  196. data/lib/chef/knife/core/node_presenter.rb +1 -1
  197. data/lib/chef/knife/core/subcommand_loader.rb +43 -12
  198. data/lib/chef/knife/core/text_formatter.rb +23 -37
  199. data/lib/chef/knife/core/ui.rb +34 -13
  200. data/lib/chef/knife/delete.rb +106 -0
  201. data/lib/chef/knife/deps.rb +139 -0
  202. data/lib/chef/knife/diff.rb +63 -0
  203. data/lib/chef/knife/download.rb +63 -0
  204. data/lib/chef/knife/edit.rb +76 -0
  205. data/lib/chef/knife/environment_show.rb +2 -0
  206. data/lib/chef/knife/exec.rb +5 -5
  207. data/lib/chef/knife/help_topics.rb +1 -1
  208. data/lib/chef/knife/index_rebuild.rb +91 -7
  209. data/lib/chef/knife/list.rb +153 -0
  210. data/lib/chef/knife/node_run_list_set.rb +66 -0
  211. data/lib/chef/knife/node_show.rb +1 -7
  212. data/lib/chef/knife/raw.rb +64 -0
  213. data/lib/chef/knife/role_show.rb +2 -4
  214. data/lib/chef/knife/search.rb +45 -28
  215. data/lib/chef/knife/show.rb +55 -0
  216. data/lib/chef/knife/ssh.rb +14 -2
  217. data/lib/chef/knife/upload.rb +69 -0
  218. data/lib/chef/knife/user_create.rb +93 -0
  219. data/lib/chef/knife/user_delete.rb +46 -0
  220. data/lib/chef/knife/user_edit.rb +53 -0
  221. data/lib/chef/{provider/whyrun_safe_ruby_block.rb → knife/user_list.rb} +21 -9
  222. data/lib/chef/knife/user_reregister.rb +59 -0
  223. data/lib/chef/knife/user_show.rb +49 -0
  224. data/lib/chef/knife/xargs.rb +265 -0
  225. data/lib/chef/log.rb +2 -2
  226. data/lib/chef/mixin/checksum.rb +3 -3
  227. data/lib/chef/mixin/deep_merge.rb +78 -194
  228. data/lib/chef/mixin/deprecation.rb +35 -0
  229. data/lib/chef/mixin/file_class.rb +0 -9
  230. data/lib/chef/mixin/language.rb +22 -223
  231. data/lib/chef/mixin/language_include_attribute.rb +10 -36
  232. data/lib/chef/mixin/language_include_recipe.rb +7 -33
  233. data/lib/chef/mixin/params_validate.rb +0 -3
  234. data/lib/chef/mixin/recipe_definition_dsl_core.rb +10 -61
  235. data/lib/chef/mixin/securable.rb +32 -7
  236. data/lib/chef/mixin/template.rb +156 -26
  237. data/lib/chef/mixin/windows_architecture_helper.rb +91 -0
  238. data/lib/chef/mixins.rb +1 -5
  239. data/{spec/unit/monkey_patches/uri_spec.rb → lib/chef/monkey_patches/file.rb} +6 -14
  240. data/lib/chef/monkey_patches/net-ssh-multi.rb +140 -0
  241. data/lib/chef/monkey_patches/net_http.rb +0 -34
  242. data/lib/chef/monkey_patches/securerandom.rb +44 -0
  243. data/lib/chef/monologger.rb +93 -0
  244. data/lib/chef/node.rb +139 -308
  245. data/lib/chef/node/attribute.rb +367 -473
  246. data/lib/chef/node/attribute_collections.rb +206 -0
  247. data/lib/chef/node/immutable_collections.rb +186 -0
  248. data/lib/chef/platform.rb +4 -496
  249. data/lib/chef/platform/provider_mapping.rb +529 -0
  250. data/lib/chef/{mixin/check_helper.rb → platform/query_helpers.rb} +20 -9
  251. data/lib/chef/provider.rb +14 -58
  252. data/lib/chef/provider/batch.rb +35 -0
  253. data/lib/chef/provider/breakpoint.rb +6 -6
  254. data/lib/chef/provider/cookbook_file.rb +11 -80
  255. data/lib/chef/provider/cookbook_file/content.rb +49 -0
  256. data/lib/chef/provider/deploy.rb +26 -21
  257. data/lib/chef/provider/deploy/revision.rb +27 -0
  258. data/lib/chef/provider/directory.rb +12 -18
  259. data/lib/chef/provider/execute.rb +22 -5
  260. data/lib/chef/provider/file.rb +297 -248
  261. data/lib/chef/provider/file/content.rb +39 -0
  262. data/lib/chef/provider/git.rb +76 -43
  263. data/lib/chef/provider/group.rb +31 -51
  264. data/lib/chef/provider/group/dscl.rb +13 -53
  265. data/lib/chef/provider/group/gpasswd.rb +19 -14
  266. data/lib/chef/provider/group/groupadd.rb +1 -41
  267. data/lib/chef/provider/group/groupmod.rb +36 -46
  268. data/lib/chef/provider/group/pw.rb +16 -59
  269. data/lib/chef/provider/group/suse.rb +13 -16
  270. data/lib/chef/provider/group/usermod.rb +18 -40
  271. data/lib/chef/provider/group/windows.rb +6 -13
  272. data/lib/chef/provider/http_request.rb +25 -42
  273. data/lib/chef/provider/ifconfig.rb +25 -35
  274. data/lib/chef/provider/ifconfig/debian.rb +71 -0
  275. data/lib/chef/provider/ifconfig/redhat.rb +47 -0
  276. data/lib/chef/provider/link.rb +12 -3
  277. data/lib/chef/provider/lwrp_base.rb +150 -0
  278. data/lib/chef/provider/mount.rb +1 -1
  279. data/lib/chef/provider/mount/mount.rb +8 -3
  280. data/lib/chef/provider/mount/windows.rb +4 -1
  281. data/lib/chef/provider/package/rpm.rb +2 -2
  282. data/lib/chef/provider/package/rubygems.rb +4 -1
  283. data/lib/chef/provider/package/smartos.rb +47 -36
  284. data/lib/chef/provider/package/zypper.rb +45 -55
  285. data/lib/chef/provider/powershell_script.rb +77 -0
  286. data/lib/chef/provider/registry_key.rb +156 -0
  287. data/lib/chef/provider/remote_directory.rb +6 -5
  288. data/lib/chef/provider/remote_file.rb +13 -100
  289. data/lib/chef/provider/remote_file/cache_control_data.rb +165 -0
  290. data/lib/chef/provider/remote_file/content.rb +75 -0
  291. data/lib/chef/provider/remote_file/fetcher.rb +43 -0
  292. data/lib/chef/provider/remote_file/ftp.rb +183 -0
  293. data/lib/chef/provider/remote_file/http.rb +124 -0
  294. data/lib/chef/provider/remote_file/local_file.rb +47 -0
  295. data/lib/chef/provider/route.rb +6 -2
  296. data/lib/chef/provider/ruby_block.rb +5 -2
  297. data/lib/chef/provider/script.rb +14 -2
  298. data/lib/chef/provider/service.rb +15 -0
  299. data/lib/chef/provider/service/init.rb +9 -7
  300. data/lib/chef/provider/service/macosx.rb +29 -81
  301. data/lib/chef/provider/service/simple.rb +1 -1
  302. data/lib/chef/provider/service/solaris.rb +6 -5
  303. data/lib/chef/provider/template.rb +16 -81
  304. data/lib/chef/provider/template/content.rb +61 -0
  305. data/lib/chef/provider/template_finder.rb +61 -0
  306. data/lib/chef/provider/user.rb +0 -1
  307. data/lib/chef/provider/user/dscl.rb +175 -568
  308. data/lib/chef/provider/user/useradd.rb +50 -54
  309. data/lib/chef/provider/windows_script.rb +73 -0
  310. data/lib/chef/providers.rb +18 -1
  311. data/lib/chef/recipe.rb +14 -8
  312. data/lib/chef/resource.rb +52 -146
  313. data/lib/chef/resource/{whyrun_safe_ruby_block.rb → batch.rb} +10 -10
  314. data/lib/chef/resource/conditional.rb +4 -0
  315. data/lib/chef/resource/conditional_action_not_nothing.rb +48 -0
  316. data/lib/chef/resource/file.rb +31 -3
  317. data/lib/chef/resource/group.rb +1 -11
  318. data/lib/chef/resource/http_request.rb +2 -1
  319. data/lib/chef/resource/link.rb +17 -0
  320. data/lib/chef/resource/lwrp_base.rb +132 -0
  321. data/lib/chef/resource/mount.rb +39 -13
  322. data/lib/chef/resource/powershell_script.rb +31 -0
  323. data/lib/chef/resource/registry_key.rb +86 -0
  324. data/lib/chef/resource/remote_directory.rb +6 -5
  325. data/lib/chef/resource/remote_file.rb +62 -25
  326. data/lib/chef/resource/route.rb +1 -1
  327. data/lib/chef/resource/ruby_block.rb +2 -2
  328. data/lib/chef/resource/service.rb +14 -0
  329. data/lib/chef/resource/template.rb +145 -0
  330. data/lib/chef/resource/user.rb +0 -18
  331. data/lib/chef/resource/windows_script.rb +62 -0
  332. data/lib/chef/resource_collection.rb +69 -31
  333. data/lib/chef/resource_reporter.rb +81 -52
  334. data/lib/chef/resources.rb +4 -1
  335. data/lib/chef/rest.rb +55 -127
  336. data/lib/chef/rest/auth_credentials.rb +4 -20
  337. data/lib/chef/rest/rest_request.rb +7 -8
  338. data/lib/chef/role.rb +1 -97
  339. data/lib/chef/run_context.rb +108 -130
  340. data/lib/chef/run_context/cookbook_compiler.rb +280 -0
  341. data/lib/chef/run_list.rb +0 -2
  342. data/lib/chef/run_list/run_list_expansion.rb +1 -16
  343. data/lib/chef/run_lock.rb +96 -0
  344. data/lib/chef/runner.rb +28 -6
  345. data/lib/chef/sandbox.rb +15 -148
  346. data/lib/chef/scan_access_control.rb +8 -5
  347. data/lib/chef/search/query.rb +2 -2
  348. data/lib/chef/shef/ext.rb +3 -575
  349. data/lib/chef/{shef.rb → shell.rb} +35 -40
  350. data/lib/chef/shell/ext.rb +593 -0
  351. data/lib/chef/{shef → shell}/model_wrapper.rb +3 -3
  352. data/lib/chef/{shef/shef_rest.rb → shell/shell_rest.rb} +4 -4
  353. data/lib/chef/{shef/shef_session.rb → shell/shell_session.rb} +15 -13
  354. data/lib/chef/shell_out.rb +7 -0
  355. data/lib/chef/user.rb +182 -0
  356. data/lib/chef/util/backup.rb +84 -0
  357. data/lib/chef/util/diff.rb +145 -0
  358. data/lib/chef/util/file_edit.rb +1 -1
  359. data/lib/chef/util/selinux.rb +100 -0
  360. data/lib/chef/util/windows/net_group.rb +1 -5
  361. data/lib/chef/util/windows/net_user.rb +14 -1
  362. data/lib/chef/util/windows/volume.rb +2 -2
  363. data/lib/chef/version.rb +1 -1
  364. data/lib/chef/version/platform.rb +42 -0
  365. data/lib/chef/version_class.rb +1 -1
  366. data/lib/chef/version_constraint.rb +6 -5
  367. data/lib/chef/{index_queue.rb → version_constraint/platform.rb} +11 -14
  368. data/lib/chef/win32/api/file.rb +8 -2
  369. data/lib/chef/win32/api/security.rb +45 -1
  370. data/lib/chef/win32/registry.rb +382 -0
  371. data/lib/chef/win32/security.rb +19 -0
  372. data/lib/chef/win32/version.rb +25 -8
  373. data/spec/data/apt/chef-integration-test-1.0/debian/changelog +5 -0
  374. data/spec/data/apt/chef-integration-test-1.0/debian/compat +1 -0
  375. data/spec/data/apt/chef-integration-test-1.0/debian/control +13 -0
  376. data/spec/data/apt/chef-integration-test-1.0/debian/copyright +34 -0
  377. data/spec/data/apt/chef-integration-test-1.0/debian/files +1 -0
  378. data/spec/data/apt/chef-integration-test-1.0/debian/rules +13 -0
  379. data/spec/data/apt/chef-integration-test-1.0/debian/source/format +1 -0
  380. data/spec/data/apt/chef-integration-test-1.1/debian/changelog +11 -0
  381. data/spec/data/apt/chef-integration-test-1.1/debian/compat +1 -0
  382. data/spec/data/apt/chef-integration-test-1.1/debian/control +13 -0
  383. data/spec/data/apt/chef-integration-test-1.1/debian/copyright +34 -0
  384. data/spec/data/apt/chef-integration-test-1.1/debian/files +1 -0
  385. data/spec/data/apt/chef-integration-test-1.1/debian/rules +13 -0
  386. data/spec/data/apt/chef-integration-test-1.1/debian/source/format +1 -0
  387. data/spec/data/apt/chef-integration-test_1.0-1_amd64.changes +22 -0
  388. data/spec/data/apt/chef-integration-test_1.0-1_amd64.deb +0 -0
  389. data/spec/data/apt/chef-integration-test_1.0.orig.tar.gz +0 -0
  390. data/spec/data/apt/chef-integration-test_1.1-1_amd64.changes +22 -0
  391. data/spec/data/apt/chef-integration-test_1.1-1_amd64.deb +0 -0
  392. data/spec/data/apt/chef-integration-test_1.1.orig.tar.gz +0 -0
  393. data/spec/data/apt/var/www/apt/conf/distributions +7 -0
  394. data/spec/data/apt/var/www/apt/conf/incoming +4 -0
  395. data/spec/data/apt/var/www/apt/conf/pulls +3 -0
  396. data/spec/data/apt/var/www/apt/db/checksums.db +0 -0
  397. data/spec/data/apt/var/www/apt/db/contents.cache.db +0 -0
  398. data/spec/data/apt/var/www/apt/db/packages.db +0 -0
  399. data/spec/data/apt/var/www/apt/db/references.db +0 -0
  400. data/spec/data/apt/var/www/apt/db/release.caches.db +0 -0
  401. data/spec/data/apt/var/www/apt/db/version +4 -0
  402. data/spec/data/apt/var/www/apt/dists/sid/Release +19 -0
  403. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Packages +16 -0
  404. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Packages.gz +0 -0
  405. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Release +5 -0
  406. data/spec/data/apt/var/www/apt/dists/sid/main/binary-i386/Packages +0 -0
  407. data/spec/data/apt/var/www/apt/pool/main/c/chef-integration-test/chef-integration-test_1.0-1_amd64.deb +0 -0
  408. data/spec/data/apt/var/www/apt/pool/main/c/chef-integration-test/chef-integration-test_1.1-1_amd64.deb +0 -0
  409. data/spec/data/bootstrap/encrypted_data_bag_secret +1 -0
  410. data/spec/data/bootstrap/secret.erb +9 -0
  411. data/spec/data/cookbooks/ignorken/recipes/default.rb +1 -0
  412. data/spec/data/cookbooks/ignorken/recipes/ignoreme.rb +2 -0
  413. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  414. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  415. data/spec/data/cookbooks/openldap/templates/default/all_windows_line_endings.erb +4 -0
  416. data/spec/data/cookbooks/openldap/templates/default/helper_test.erb +1 -0
  417. data/spec/data/cookbooks/openldap/templates/default/helpers_via_partial_test.erb +1 -0
  418. data/spec/data/cookbooks/openldap/templates/default/no_windows_line_endings.erb +4 -0
  419. data/spec/data/cookbooks/openldap/templates/default/some_windows_line_endings.erb +4 -0
  420. data/spec/data/cookbooks/preseed/files/default/preseed-file.seed +1 -0
  421. data/spec/data/cookbooks/preseed/templates/default/preseed-template.seed +1 -0
  422. data/spec/data/file-providers-method-snapshot-chef-11-4.json +127 -0
  423. data/spec/data/git_bundles/example-repo.gitbundle +0 -0
  424. data/spec/data/knife_subcommand/test_yourself.rb +8 -0
  425. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  426. data/spec/data/nodes/default.rb +3 -3
  427. data/spec/data/nodes/test.example.com.rb +3 -3
  428. data/spec/data/nodes/test.rb +3 -3
  429. data/spec/data/null_config.rb +1 -0
  430. data/spec/data/partial_one.erb +1 -0
  431. data/spec/data/remote_file/nyan_cat.png.gz +0 -0
  432. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  433. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  434. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  435. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  436. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  437. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  438. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  439. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  440. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  441. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  442. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  443. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  444. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  445. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  446. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  447. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  448. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  449. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  450. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  451. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  452. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  453. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  454. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  455. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  456. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  457. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  458. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  459. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  460. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  461. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  462. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  463. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  464. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  465. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  466. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  467. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  468. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  469. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  470. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  471. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  472. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  473. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  474. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  475. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  476. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  477. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  478. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  479. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  480. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  481. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  482. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  483. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  484. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  485. data/spec/data/shef-config.rb +10 -0
  486. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  487. data/spec/functional/file_content_management/deploy_strategies_spec.rb +238 -0
  488. data/spec/functional/knife/cookbook_delete_spec.rb +1 -1
  489. data/spec/functional/knife/exec_spec.rb +3 -3
  490. data/spec/functional/knife/smoke_test.rb +34 -0
  491. data/spec/functional/knife/ssh_spec.rb +5 -1
  492. data/spec/functional/provider/remote_file/cache_control_data_spec.rb +101 -0
  493. data/spec/functional/resource/batch_spec.rb +64 -0
  494. data/spec/functional/resource/cookbook_file_spec.rb +15 -9
  495. data/spec/functional/resource/deploy_revision_spec.rb +180 -0
  496. data/spec/functional/resource/directory_spec.rb +5 -1
  497. data/spec/functional/resource/file_spec.rb +71 -21
  498. data/spec/functional/resource/git_spec.rb +259 -0
  499. data/spec/functional/resource/link_spec.rb +424 -388
  500. data/spec/functional/resource/package_spec.rb +297 -0
  501. data/spec/functional/resource/powershell_spec.rb +188 -0
  502. data/spec/functional/resource/registry_spec.rb +576 -0
  503. data/spec/functional/resource/remote_directory_spec.rb +143 -37
  504. data/spec/functional/resource/remote_file_spec.rb +99 -13
  505. data/spec/functional/resource/template_spec.rb +180 -3
  506. data/spec/functional/resource/user_spec.rb +547 -0
  507. data/spec/functional/run_lock_spec.rb +243 -0
  508. data/spec/functional/shell_spec.rb +102 -0
  509. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  510. data/spec/functional/win32/security_spec.rb +37 -0
  511. data/spec/functional/win32/service_manager_spec.rb +269 -0
  512. data/spec/functional/win32/versions_spec.rb +78 -0
  513. data/spec/integration/knife/chef_repo_path_spec.rb +805 -0
  514. data/spec/integration/knife/chef_repository_file_system_spec.rb +276 -0
  515. data/spec/integration/knife/chefignore_spec.rb +271 -0
  516. data/spec/integration/knife/delete_spec.rb +944 -0
  517. data/spec/integration/knife/deps_spec.rb +648 -0
  518. data/spec/integration/knife/diff_spec.rb +536 -0
  519. data/spec/integration/knife/download_spec.rb +962 -0
  520. data/spec/integration/knife/list_spec.rb +633 -0
  521. data/spec/integration/knife/raw_spec.rb +166 -0
  522. data/spec/integration/knife/redirection_spec.rb +57 -0
  523. data/spec/integration/knife/show_spec.rb +158 -0
  524. data/spec/integration/knife/upload_spec.rb +1060 -0
  525. data/spec/integration/solo/solo_spec.rb +41 -0
  526. data/spec/spec_helper.rb +49 -13
  527. data/spec/stress/win32/security_spec.rb +1 -1
  528. data/spec/support/chef_helpers.rb +33 -3
  529. data/spec/support/lib/chef/resource/cat.rb +3 -5
  530. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  531. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  532. data/spec/support/platform_helpers.rb +46 -13
  533. data/spec/support/platforms/win32/spec_service.rb +59 -0
  534. data/spec/support/shared/functional/diff_disabled.rb +10 -0
  535. data/spec/support/shared/functional/directory_resource.rb +129 -38
  536. data/spec/support/shared/functional/file_resource.rb +837 -71
  537. data/spec/support/shared/functional/securable_resource.rb +189 -58
  538. data/spec/support/shared/functional/securable_resource_with_reporting.rb +385 -0
  539. data/spec/support/shared/integration/integration_helper.rb +166 -0
  540. data/spec/support/shared/integration/knife_support.rb +171 -0
  541. data/spec/support/shared/unit/execute_resource.rb +125 -0
  542. data/spec/support/shared/unit/file_system_support.rb +70 -0
  543. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  544. data/spec/support/shared/unit/provider/file.rb +609 -0
  545. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +407 -0
  546. data/spec/support/shared/unit/script_resource.rb +52 -0
  547. data/spec/support/shared/unit/windows_script_resource.rb +48 -0
  548. data/spec/tiny_server.rb +13 -11
  549. data/spec/unit/api_client/registration_spec.rb +172 -0
  550. data/spec/unit/api_client_spec.rb +78 -156
  551. data/spec/unit/application/apply.rb +84 -0
  552. data/spec/unit/application/client_spec.rb +16 -14
  553. data/spec/unit/application/knife_spec.rb +17 -0
  554. data/spec/unit/application/solo_spec.rb +1 -1
  555. data/spec/unit/application_spec.rb +113 -3
  556. data/spec/unit/checksum/storage/filesystem_spec.rb +1 -1
  557. data/spec/unit/chef_fs/diff_spec.rb +328 -0
  558. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  559. data/spec/unit/chef_fs/file_system_spec.rb +135 -0
  560. data/spec/unit/client_spec.rb +195 -23
  561. data/spec/unit/config_spec.rb +102 -51
  562. data/spec/unit/cookbook/syntax_check_spec.rb +75 -111
  563. data/spec/unit/cookbook_loader_spec.rb +154 -91
  564. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  565. data/spec/unit/cookbook_spec.rb +3 -20
  566. data/spec/unit/cookbook_version_spec.rb +23 -122
  567. data/spec/unit/daemon_spec.rb +24 -19
  568. data/spec/unit/data_bag_spec.rb +13 -4
  569. data/spec/unit/deprecation_spec.rb +86 -0
  570. data/spec/unit/digester_spec.rb +50 -0
  571. data/spec/unit/dsl/data_query_spec.rb +66 -0
  572. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  573. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  574. data/spec/unit/encrypted_data_bag_item_spec.rb +197 -157
  575. data/spec/unit/environment_spec.rb +94 -126
  576. data/spec/unit/exceptions_spec.rb +8 -4
  577. data/spec/unit/file_access_control_spec.rb +21 -1
  578. data/spec/unit/file_content_management/deploy/cp_spec.rb +46 -0
  579. data/spec/unit/file_content_management/deploy/mv_unix_spec.rb +103 -0
  580. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +179 -0
  581. data/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +38 -2
  582. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +6 -5
  583. data/spec/unit/json_compat_spec.rb +8 -0
  584. data/spec/unit/knife/bootstrap_spec.rb +130 -29
  585. data/spec/unit/knife/configure_spec.rb +64 -45
  586. data/spec/unit/knife/cookbook_download_spec.rb +24 -3
  587. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  588. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  589. data/spec/unit/knife/cookbook_upload_spec.rb +39 -0
  590. data/spec/unit/knife/core/bootstrap_context_spec.rb +79 -62
  591. data/spec/unit/knife/core/subcommand_loader_spec.rb +20 -0
  592. data/spec/unit/knife/core/ui_spec.rb +196 -124
  593. data/spec/unit/knife/data_bag_create_spec.rb +9 -0
  594. data/spec/unit/knife/data_bag_edit_spec.rb +1 -4
  595. data/spec/unit/knife/data_bag_from_file_spec.rb +4 -6
  596. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  597. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  598. data/spec/unit/knife/knife_help.rb +7 -7
  599. data/spec/unit/knife/node_edit_spec.rb +6 -33
  600. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  601. data/spec/unit/knife/node_run_list_set_spec.rb +140 -0
  602. data/spec/unit/knife/ssh_spec.rb +12 -15
  603. data/spec/unit/knife/status_spec.rb +2 -2
  604. data/spec/unit/knife/user_create_spec.rb +86 -0
  605. data/spec/unit/knife/user_delete_spec.rb +39 -0
  606. data/spec/unit/knife/user_edit_spec.rb +42 -0
  607. data/spec/unit/knife/user_list_spec.rb +32 -0
  608. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  609. data/spec/unit/knife/user_show_spec.rb +41 -0
  610. data/spec/unit/knife_spec.rb +74 -0
  611. data/spec/unit/lwrp_spec.rb +102 -60
  612. data/spec/unit/mixin/checksum_spec.rb +2 -2
  613. data/spec/unit/mixin/deep_merge_spec.rb +130 -791
  614. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  615. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +7 -1
  616. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  617. data/spec/unit/mixin/securable_spec.rb +5 -3
  618. data/spec/unit/mixin/template_spec.rb +145 -14
  619. data/spec/unit/mixin/windows_architecture_helper_spec.rb +83 -0
  620. data/spec/unit/node/attribute_spec.rb +273 -173
  621. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  622. data/spec/unit/node_spec.rb +418 -370
  623. data/spec/unit/platform_spec.rb +21 -8
  624. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  625. data/spec/unit/provider/cookbook_file/content_spec.rb +40 -0
  626. data/spec/unit/provider/cookbook_file_spec.rb +26 -187
  627. data/spec/unit/provider/cron/solaris_spec.rb +1 -1
  628. data/spec/unit/provider/deploy/revision_spec.rb +19 -11
  629. data/spec/unit/provider/deploy_spec.rb +2 -2
  630. data/spec/unit/provider/directory_spec.rb +99 -67
  631. data/spec/unit/provider/env_spec.rb +2 -2
  632. data/spec/unit/provider/execute_spec.rb +27 -1
  633. data/spec/unit/provider/file/content_spec.rb +101 -0
  634. data/spec/unit/provider/file_spec.rb +25 -475
  635. data/spec/unit/provider/git_spec.rb +224 -28
  636. data/spec/unit/provider/group/dscl_spec.rb +0 -36
  637. data/spec/unit/provider/group/gpasswd_spec.rb +9 -16
  638. data/spec/unit/provider/group/groupadd_spec.rb +4 -3
  639. data/spec/unit/provider/group/groupmod_spec.rb +1 -0
  640. data/spec/unit/provider/group/pw_spec.rb +15 -12
  641. data/spec/unit/provider/group/usermod_spec.rb +9 -22
  642. data/spec/unit/provider/group/windows_spec.rb +8 -0
  643. data/spec/unit/provider/group_spec.rb +6 -28
  644. data/spec/unit/provider/http_request_spec.rb +28 -69
  645. data/spec/unit/provider/ifconfig/debian_spec.rb +89 -0
  646. data/spec/unit/provider/ifconfig/redhat_spec.rb +71 -0
  647. data/spec/unit/provider/ifconfig_spec.rb +0 -33
  648. data/spec/unit/provider/mount/mount_spec.rb +33 -2
  649. data/spec/unit/provider/mount/windows_spec.rb +4 -1
  650. data/spec/unit/provider/mount_spec.rb +16 -6
  651. data/spec/unit/provider/ohai_spec.rb +4 -4
  652. data/spec/unit/provider/package/apt_spec.rb +0 -1
  653. data/spec/unit/provider/package/ips_spec.rb +0 -1
  654. data/spec/unit/provider/package/rpm_spec.rb +0 -12
  655. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  656. data/spec/unit/provider/package/smartos_spec.rb +3 -2
  657. data/spec/unit/provider/package/zypper_spec.rb +84 -22
  658. data/spec/unit/provider/package_spec.rb +7 -9
  659. data/spec/unit/provider/powershell_spec.rb +38 -0
  660. data/spec/unit/provider/registry_key_spec.rb +269 -0
  661. data/spec/unit/provider/remote_directory_spec.rb +7 -7
  662. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +211 -0
  663. data/spec/unit/provider/remote_file/content_spec.rb +230 -0
  664. data/spec/unit/provider/remote_file/fetcher_spec.rb +75 -0
  665. data/spec/unit/provider/remote_file/ftp_spec.rb +224 -0
  666. data/spec/unit/provider/remote_file/http_spec.rb +319 -0
  667. data/spec/unit/provider/remote_file/local_file_spec.rb +60 -0
  668. data/spec/unit/provider/remote_file_spec.rb +33 -259
  669. data/spec/unit/provider/route_spec.rb +29 -12
  670. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  671. data/spec/unit/provider/service/arch_service_spec.rb +5 -5
  672. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  673. data/spec/unit/provider/service/freebsd_service_spec.rb +5 -5
  674. data/spec/unit/provider/service/init_service_spec.rb +27 -4
  675. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  676. data/spec/unit/provider/service/invokercd_service_spec.rb +4 -4
  677. data/spec/unit/provider/service/macosx_spec.rb +176 -207
  678. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  679. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  680. data/spec/unit/provider/service/solaris_smf_service_spec.rb +21 -18
  681. data/spec/unit/provider/service/systemd_service_spec.rb +2 -2
  682. data/spec/unit/provider/service/upstart_service_spec.rb +11 -11
  683. data/spec/unit/provider/service_spec.rb +3 -3
  684. data/spec/unit/provider/subversion_spec.rb +1 -1
  685. data/spec/unit/provider/template/content_spec.rb +78 -0
  686. data/spec/unit/provider/template_spec.rb +52 -160
  687. data/spec/unit/provider/user/dscl_spec.rb +285 -681
  688. data/spec/unit/provider/user/solaris_spec.rb +39 -373
  689. data/spec/unit/provider/user/useradd_spec.rb +12 -379
  690. data/spec/unit/provider/user_spec.rb +1 -1
  691. data/spec/unit/recipe_spec.rb +10 -8
  692. data/spec/unit/registry_helper_spec.rb +376 -0
  693. data/spec/unit/resource/batch_spec.rb +48 -0
  694. data/spec/unit/resource/conditional_action_not_nothing_spec.rb +45 -0
  695. data/spec/unit/resource/execute_spec.rb +3 -101
  696. data/spec/unit/resource/file_spec.rb +0 -5
  697. data/spec/unit/resource/group_spec.rb +9 -0
  698. data/spec/unit/resource/ifconfig_spec.rb +60 -1
  699. data/spec/unit/resource/link_spec.rb +1 -0
  700. data/spec/unit/resource/mount_spec.rb +37 -11
  701. data/spec/unit/resource/powershell_spec.rb +48 -0
  702. data/spec/unit/resource/registry_key_spec.rb +171 -0
  703. data/spec/unit/resource/remote_file_spec.rb +63 -25
  704. data/spec/unit/resource/route_spec.rb +1 -1
  705. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  706. data/spec/unit/resource/script_spec.rb +13 -36
  707. data/spec/unit/resource/service_spec.rb +11 -0
  708. data/spec/unit/resource/template_spec.rb +111 -8
  709. data/spec/unit/resource/user_spec.rb +7 -0
  710. data/spec/unit/resource_collection_spec.rb +61 -32
  711. data/spec/unit/resource_reporter_spec.rb +115 -102
  712. data/spec/unit/resource_spec.rb +197 -5
  713. data/spec/unit/rest/auth_credentials_spec.rb +4 -21
  714. data/spec/unit/rest_spec.rb +134 -284
  715. data/spec/unit/run_context/cookbook_compiler_spec.rb +190 -0
  716. data/spec/unit/run_context_spec.rb +18 -4
  717. data/spec/unit/run_list_spec.rb +0 -209
  718. data/spec/unit/run_lock_spec.rb +37 -0
  719. data/spec/unit/runner_spec.rb +102 -3
  720. data/spec/unit/scan_access_control_spec.rb +8 -6
  721. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  722. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  723. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +16 -58
  724. data/spec/unit/shell_out_spec.rb +18 -0
  725. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  726. data/spec/unit/user_spec.rb +255 -0
  727. data/spec/unit/util/backup_spec.rb +149 -0
  728. data/spec/unit/util/diff_spec.rb +596 -0
  729. data/spec/unit/util/selinux_spec.rb +172 -0
  730. data/spec/unit/version/platform_spec.rb +61 -0
  731. data/spec/unit/version_constraint/platform_spec.rb +46 -0
  732. data/spec/unit/version_constraint_spec.rb +5 -0
  733. metadata +493 -264
  734. data/README.rdoc +0 -177
  735. data/distro/common/html/knife-recipe.1.html +0 -92
  736. data/lib/chef/certificate.rb +0 -161
  737. data/lib/chef/checksum.rb +0 -167
  738. data/lib/chef/checksum_cache.rb +0 -190
  739. data/lib/chef/cookbook_version_selector.rb +0 -168
  740. data/lib/chef/couchdb.rb +0 -246
  741. data/lib/chef/index_queue/amqp_client.rb +0 -116
  742. data/lib/chef/index_queue/consumer.rb +0 -76
  743. data/lib/chef/index_queue/indexable.rb +0 -109
  744. data/lib/chef/knife/bootstrap/ubuntu12.10-gems.erb +0 -60
  745. data/lib/chef/monkey_patches/dir.rb +0 -36
  746. data/lib/chef/monkey_patches/moneta.rb +0 -50
  747. data/lib/chef/monkey_patches/uri.rb +0 -70
  748. data/lib/chef/openid_registration.rb +0 -187
  749. data/lib/chef/solr_query.rb +0 -187
  750. data/lib/chef/solr_query/lucene.treetop +0 -150
  751. data/lib/chef/solr_query/lucene_nodes.rb +0 -285
  752. data/lib/chef/solr_query/query_transform.rb +0 -65
  753. data/lib/chef/solr_query/solr_http_request.rb +0 -132
  754. data/lib/chef/webui_user.rb +0 -231
  755. data/spec/data/mac_users/10.7-8.plist.xml +0 -559
  756. data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
  757. data/spec/data/mac_users/10.7.plist.xml +0 -559
  758. data/spec/data/mac_users/10.7.shadow.xml +0 -11
  759. data/spec/data/mac_users/10.8.plist.xml +0 -559
  760. data/spec/data/mac_users/10.8.shadow.xml +0 -21
  761. data/spec/data/mac_users/10.9.plist.xml +0 -560
  762. data/spec/data/mac_users/10.9.shadow.xml +0 -21
  763. data/spec/functional/resource/base.rb +0 -40
  764. data/spec/functional/resource/group_spec.rb +0 -343
  765. data/spec/functional/resource/user/dscl_spec.rb +0 -199
  766. data/spec/unit/certificate_spec.rb +0 -76
  767. data/spec/unit/checksum_cache_spec.rb +0 -209
  768. data/spec/unit/checksum_spec.rb +0 -94
  769. data/spec/unit/couchdb_spec.rb +0 -274
  770. data/spec/unit/index_queue_spec.rb +0 -391
  771. data/spec/unit/mixin/language_spec.rb +0 -305
  772. data/spec/unit/openid_registration_spec.rb +0 -153
  773. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +0 -47
  774. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  775. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  776. data/spec/unit/solr_query_spec.rb +0 -203
  777. data/spec/unit/webui_user_spec.rb +0 -238
@@ -0,0 +1,139 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, 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 'spec_helper'
20
+ require "chef/node/immutable_collections"
21
+
22
+ describe Chef::Node::ImmutableMash do
23
+ before do
24
+ @data_in = {:top => {:second_level => "some value"},
25
+ "top_level_2" => %w[array of values],
26
+ :top_level_3 => [{:hash_array => 1, :hash_array_b => 2}],
27
+ :top_level_4 => {:level2 => {:key => "value"}}
28
+ }
29
+ @immutable_mash = Chef::Node::ImmutableMash.new(@data_in)
30
+ end
31
+
32
+ it "element references like regular hash" do
33
+ @immutable_mash[:top][:second_level].should == "some value"
34
+ end
35
+
36
+ it "elelment references like a regular Mash" do
37
+ @immutable_mash[:top_level_2].should == %w[array of values]
38
+ end
39
+
40
+ it "converts Hash-like inputs into ImmutableMash's" do
41
+ @immutable_mash[:top].should be_a(Chef::Node::ImmutableMash)
42
+ end
43
+
44
+ it "converts array inputs into ImmutableArray's" do
45
+ @immutable_mash[:top_level_2].should be_a(Chef::Node::ImmutableArray)
46
+ end
47
+
48
+ it "converts arrays of hashes to ImmutableArray's of ImmutableMashes" do
49
+ @immutable_mash[:top_level_3].first.should be_a(Chef::Node::ImmutableMash)
50
+ end
51
+
52
+ it "converts nested hashes to ImmutableMashes" do
53
+ @immutable_mash[:top_level_4].should be_a(Chef::Node::ImmutableMash)
54
+ @immutable_mash[:top_level_4][:level2].should be_a(Chef::Node::ImmutableMash)
55
+ end
56
+
57
+
58
+ [
59
+ :[]=,
60
+ :clear,
61
+ :default=,
62
+ :default_proc=,
63
+ :delete,
64
+ :delete_if,
65
+ :keep_if,
66
+ :merge!,
67
+ :update,
68
+ :reject!,
69
+ :replace,
70
+ :select!,
71
+ :shift
72
+ ].each do |mutator|
73
+ it "doesn't allow mutation via `#{mutator}'" do
74
+ lambda { @immutable_mash.send(mutator) }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
75
+ end
76
+ end
77
+
78
+ it "returns a mutable version of itself when duped" do
79
+ mutable = @immutable_mash.dup
80
+ mutable[:new_key] = :value
81
+ mutable[:new_key].should == :value
82
+ end
83
+
84
+ end
85
+
86
+ describe Chef::Node::ImmutableArray do
87
+
88
+ before do
89
+ @immutable_array = Chef::Node::ImmutableArray.new(%w[foo bar baz])
90
+ end
91
+
92
+ ##
93
+ # Note: other behaviors, such as immutibilizing input data, are tested along
94
+ # with ImmutableMash, above
95
+ ###
96
+
97
+ [
98
+ :<<,
99
+ :[]=,
100
+ :clear,
101
+ :collect!,
102
+ :compact!,
103
+ :default=,
104
+ :default_proc=,
105
+ :delete,
106
+ :delete_at,
107
+ :delete_if,
108
+ :fill,
109
+ :flatten!,
110
+ :insert,
111
+ :keep_if,
112
+ :map!,
113
+ :merge!,
114
+ :pop,
115
+ :push,
116
+ :update,
117
+ :reject!,
118
+ :reverse!,
119
+ :replace,
120
+ :select!,
121
+ :shift,
122
+ :slice!,
123
+ :sort!,
124
+ :sort_by!,
125
+ :uniq!,
126
+ :unshift
127
+ ].each do |mutator|
128
+ it "does not allow mutation via `#{mutator}" do
129
+ lambda { @immutable_array.send(mutator)}.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
130
+ end
131
+ end
132
+
133
+ it "returns a mutable version of itself when duped" do
134
+ mutable = @immutable_array.dup
135
+ mutable[0] = :value
136
+ mutable[0].should == :value
137
+ end
138
+ end
139
+
@@ -20,10 +20,11 @@ require 'spec_helper'
20
20
  require 'ostruct'
21
21
 
22
22
  describe Chef::Node do
23
- before(:each) do
24
- Chef::Config.node_path(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes")))
25
- @node = Chef::Node.new()
26
- end
23
+
24
+ let(:node) { Chef::Node.new() }
25
+ let(:platform_introspector) { node }
26
+
27
+ it_behaves_like "a platform introspector"
27
28
 
28
29
  it "creates a node and assigns it a name" do
29
30
  node = Chef::Node.build('solo-node')
@@ -34,41 +35,45 @@ describe Chef::Node do
34
35
  lambda{Chef::Node.build('solo node')}.should raise_error(Chef::Exceptions::ValidationFailed)
35
36
  end
36
37
 
38
+ it "should be sortable" do
39
+ n1 = Chef::Node.build('alpha')
40
+ n2 = Chef::Node.build('beta')
41
+ n3 = Chef::Node.build('omega')
42
+ [n3, n1, n2].sort.should == [n1, n2, n3]
43
+ end
44
+
37
45
  describe "when the node does not exist on the server" do
38
46
  before do
39
47
  response = OpenStruct.new(:code => '404')
40
48
  exception = Net::HTTPServerException.new("404 not found", response)
41
49
  Chef::Node.stub!(:load).and_raise(exception)
42
- @node.name("created-node")
50
+ node.name("created-node")
43
51
  end
44
52
 
45
53
  it "creates a new node for find_or_create" do
46
- Chef::Node.stub!(:new).and_return(@node)
47
- @node.should_receive(:create).and_return(@node)
54
+ Chef::Node.stub!(:new).and_return(node)
55
+ node.should_receive(:create).and_return(node)
48
56
  node = Chef::Node.find_or_create("created-node")
49
57
  node.name.should == 'created-node'
50
- node.should equal(@node)
58
+ node.should equal(node)
51
59
  end
52
60
  end
53
61
 
54
62
  describe "when the node exists on the server" do
55
63
  before do
56
- @node.name('existing-node')
57
- Chef::Node.stub!(:load).and_return(@node)
64
+ node.name('existing-node')
65
+ Chef::Node.stub!(:load).and_return(node)
58
66
  end
59
67
 
60
68
  it "loads the node via the REST API for find_or_create" do
61
- Chef::Node.find_or_create('existing-node').should equal(@node)
69
+ Chef::Node.find_or_create('existing-node').should equal(node)
62
70
  end
63
71
  end
64
72
 
65
73
  describe "run_state" do
66
- it "should have a template_cache hash" do
67
- @node.run_state[:template_cache].should be_a_kind_of(Hash)
68
- end
69
-
70
- it "should have a seen_recipes hash" do
71
- @node.run_state[:seen_recipes].should be_a_kind_of(Hash)
74
+ it "is an empty hash" do
75
+ node.run_state.should respond_to(:keys)
76
+ node.run_state.should be_empty
72
77
  end
73
78
  end
74
79
 
@@ -81,180 +86,225 @@ describe Chef::Node do
81
86
 
82
87
  describe "name" do
83
88
  it "should allow you to set a name with name(something)" do
84
- lambda { @node.name("latte") }.should_not raise_error
89
+ lambda { node.name("latte") }.should_not raise_error
85
90
  end
86
91
 
87
92
  it "should return the name with name()" do
88
- @node.name("latte")
89
- @node.name.should eql("latte")
93
+ node.name("latte")
94
+ node.name.should eql("latte")
90
95
  end
91
96
 
92
97
  it "should always have a string for name" do
93
- lambda { @node.name(Hash.new) }.should raise_error(ArgumentError)
98
+ lambda { node.name(Hash.new) }.should raise_error(ArgumentError)
94
99
  end
95
100
 
96
101
  it "cannot be blank" do
97
- lambda { @node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed)
102
+ lambda { node.name("")}.should raise_error(Chef::Exceptions::ValidationFailed)
98
103
  end
99
104
 
100
105
  it "should not accept name doesn't match /^[\-[:alnum:]_:.]+$/" do
101
- lambda { @node.name("space in it")}.should raise_error(Chef::Exceptions::ValidationFailed)
106
+ lambda { node.name("space in it")}.should raise_error(Chef::Exceptions::ValidationFailed)
102
107
  end
103
108
  end
104
109
 
105
110
  describe "chef_environment" do
106
111
  it "should set an environment with chef_environment(something)" do
107
- lambda { @node.chef_environment("latte") }.should_not raise_error
112
+ lambda { node.chef_environment("latte") }.should_not raise_error
108
113
  end
109
114
 
110
115
  it "should return the chef_environment with chef_environment()" do
111
- @node.chef_environment("latte")
112
- @node.chef_environment.should == "latte"
116
+ node.chef_environment("latte")
117
+ node.chef_environment.should == "latte"
113
118
  end
114
119
 
115
120
  it "should disallow non-strings" do
116
- lambda { @node.chef_environment(Hash.new) }.should raise_error(ArgumentError)
117
- lambda { @node.chef_environment(42) }.should raise_error(ArgumentError)
121
+ lambda { node.chef_environment(Hash.new) }.should raise_error(ArgumentError)
122
+ lambda { node.chef_environment(42) }.should raise_error(ArgumentError)
118
123
  end
119
124
 
120
125
  it "cannot be blank" do
121
- lambda { @node.chef_environment("")}.should raise_error(Chef::Exceptions::ValidationFailed)
126
+ lambda { node.chef_environment("")}.should raise_error(Chef::Exceptions::ValidationFailed)
122
127
  end
123
128
  end
124
129
 
125
130
  describe "attributes" do
126
- it "should be loaded from the node's cookbooks" do
127
- @cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
128
- @node.cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new(@cookbook_repo))
129
- @node.load_attributes
130
- @node.ldap_server.should eql("ops1prod")
131
- @node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
132
- @node.ldap_replication_password.should eql("forsure")
133
- @node.smokey.should eql("robinson")
134
- end
135
-
136
131
  it "should have attributes" do
137
- @node.attribute.should be_a_kind_of(Hash)
132
+ node.attribute.should be_a_kind_of(Hash)
138
133
  end
139
134
 
140
135
  it "should allow attributes to be accessed by name or symbol directly on node[]" do
141
- @node.attribute["locust"] = "something"
142
- @node[:locust].should eql("something")
143
- @node["locust"].should eql("something")
136
+ node.default["locust"] = "something"
137
+ node[:locust].should eql("something")
138
+ node["locust"].should eql("something")
144
139
  end
145
140
 
146
141
  it "should return nil if it cannot find an attribute with node[]" do
147
- @node["secret"].should eql(nil)
142
+ node["secret"].should eql(nil)
148
143
  end
149
144
 
150
- it "should allow you to set an attribute via node[]=" do
151
- @node["secret"] = "shush"
152
- @node["secret"].should eql("shush")
145
+ it "does not allow you to set an attribute via node[]=" do
146
+ lambda { node["secret"] = "shush" }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
153
147
  end
154
148
 
155
149
  it "should allow you to query whether an attribute exists with attribute?" do
156
- @node.attribute["locust"] = "something"
157
- @node.attribute?("locust").should eql(true)
158
- @node.attribute?("no dice").should eql(false)
150
+ node.default["locust"] = "something"
151
+ node.attribute?("locust").should eql(true)
152
+ node.attribute?("no dice").should eql(false)
159
153
  end
160
154
 
161
155
  it "should let you go deep with attribute?" do
162
- @node.set["battles"]["people"]["wonkey"] = true
163
- @node["battles"]["people"].attribute?("wonkey").should == true
164
- @node["battles"]["people"].attribute?("snozzberry").should == false
156
+ node.set["battles"]["people"]["wonkey"] = true
157
+ node["battles"]["people"].attribute?("wonkey").should == true
158
+ node["battles"]["people"].attribute?("snozzberry").should == false
165
159
  end
166
160
 
167
- it "should allow you to set an attribute via method_missing" do
168
- @node.sunshine "is bright"
169
- @node.attribute[:sunshine].should eql("is bright")
161
+ it "does not allow you to set an attribute via method_missing" do
162
+ lambda { node.sunshine = "is bright"}.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
170
163
  end
171
164
 
172
165
  it "should allow you get get an attribute via method_missing" do
173
- @node.sunshine "is bright"
174
- @node.sunshine.should eql("is bright")
166
+ node.default.sunshine = "is bright"
167
+ node.sunshine.should eql("is bright")
175
168
  end
176
169
 
177
170
  describe "normal attributes" do
178
171
  it "should allow you to set an attribute with set, without pre-declaring a hash" do
179
- @node.set[:snoopy][:is_a_puppy] = true
180
- @node[:snoopy][:is_a_puppy].should == true
172
+ node.set[:snoopy][:is_a_puppy] = true
173
+ node[:snoopy][:is_a_puppy].should == true
181
174
  end
182
175
 
183
176
  it "should allow you to set an attribute with set_unless" do
184
- @node.set_unless[:snoopy][:is_a_puppy] = false
185
- @node[:snoopy][:is_a_puppy].should == false
177
+ node.set_unless[:snoopy][:is_a_puppy] = false
178
+ node[:snoopy][:is_a_puppy].should == false
186
179
  end
187
180
 
188
181
  it "should not allow you to set an attribute with set_unless if it already exists" do
189
- @node.set[:snoopy][:is_a_puppy] = true
190
- @node.set_unless[:snoopy][:is_a_puppy] = false
191
- @node[:snoopy][:is_a_puppy].should == true
182
+ node.set[:snoopy][:is_a_puppy] = true
183
+ node.set_unless[:snoopy][:is_a_puppy] = false
184
+ node[:snoopy][:is_a_puppy].should == true
185
+ end
186
+
187
+ it "should allow you to set a value after a set_unless" do
188
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
189
+ node.set_unless[:snoopy][:is_a_puppy] = false
190
+ node.set[:snoopy][:is_a_puppy] = true
191
+ node[:snoopy][:is_a_puppy].should == true
192
+ end
193
+
194
+ it "should let you set a value after a 'dangling' set_unless" do
195
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
196
+ node.set[:snoopy][:is_a_puppy] = "what"
197
+ node.set_unless[:snoopy][:is_a_puppy]
198
+ node.set[:snoopy][:is_a_puppy] = true
199
+ node[:snoopy][:is_a_puppy].should == true
192
200
  end
193
201
 
194
202
  it "auto-vivifies attributes created via method syntax" do
195
- @node.set.fuu.bahrr.baz = "qux"
196
- @node.fuu.bahrr.baz.should == "qux"
203
+ node.set.fuu.bahrr.baz = "qux"
204
+ node.fuu.bahrr.baz.should == "qux"
197
205
  end
198
206
 
199
207
  end
200
208
 
201
209
  describe "default attributes" do
202
210
  it "should be set with default, without pre-declaring a hash" do
203
- @node.default[:snoopy][:is_a_puppy] = true
204
- @node[:snoopy][:is_a_puppy].should == true
211
+ node.default[:snoopy][:is_a_puppy] = true
212
+ node[:snoopy][:is_a_puppy].should == true
205
213
  end
206
214
 
207
215
  it "should allow you to set with default_unless without pre-declaring a hash" do
208
- @node.default_unless[:snoopy][:is_a_puppy] = false
209
- @node[:snoopy][:is_a_puppy].should == false
216
+ node.default_unless[:snoopy][:is_a_puppy] = false
217
+ node[:snoopy][:is_a_puppy].should == false
210
218
  end
211
219
 
212
220
  it "should not allow you to set an attribute with default_unless if it already exists" do
213
- @node.default[:snoopy][:is_a_puppy] = true
214
- @node.default_unless[:snoopy][:is_a_puppy] = false
215
- @node[:snoopy][:is_a_puppy].should == true
221
+ node.default[:snoopy][:is_a_puppy] = true
222
+ node.default_unless[:snoopy][:is_a_puppy] = false
223
+ node[:snoopy][:is_a_puppy].should == true
224
+ end
225
+
226
+ it "should allow you to set a value after a default_unless" do
227
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
228
+ node.default_unless[:snoopy][:is_a_puppy] = false
229
+ node.default[:snoopy][:is_a_puppy] = true
230
+ node[:snoopy][:is_a_puppy].should == true
231
+ end
232
+
233
+ it "should allow you to set a value after a 'dangling' default_unless" do
234
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
235
+ node.default[:snoopy][:is_a_puppy] = "what"
236
+ node.default_unless[:snoopy][:is_a_puppy]
237
+ node.default[:snoopy][:is_a_puppy] = true
238
+ node[:snoopy][:is_a_puppy].should == true
216
239
  end
217
240
 
218
241
  it "auto-vivifies attributes created via method syntax" do
219
- @node.default.fuu.bahrr.baz = "qux"
220
- @node.fuu.bahrr.baz.should == "qux"
242
+ node.default.fuu.bahrr.baz = "qux"
243
+ node.fuu.bahrr.baz.should == "qux"
244
+ end
245
+
246
+ it "accesses force defaults via default!" do
247
+ node.default![:foo] = "wet bar"
248
+ node.default[:foo] = "bar"
249
+ node[:foo].should == "wet bar"
221
250
  end
222
251
 
223
252
  end
224
253
 
225
254
  describe "override attributes" do
226
255
  it "should be set with override, without pre-declaring a hash" do
227
- @node.override[:snoopy][:is_a_puppy] = true
228
- @node[:snoopy][:is_a_puppy].should == true
256
+ node.override[:snoopy][:is_a_puppy] = true
257
+ node[:snoopy][:is_a_puppy].should == true
229
258
  end
230
259
 
231
260
  it "should allow you to set with override_unless without pre-declaring a hash" do
232
- @node.override_unless[:snoopy][:is_a_puppy] = false
233
- @node[:snoopy][:is_a_puppy].should == false
261
+ node.override_unless[:snoopy][:is_a_puppy] = false
262
+ node[:snoopy][:is_a_puppy].should == false
234
263
  end
235
264
 
236
265
  it "should not allow you to set an attribute with override_unless if it already exists" do
237
- @node.override[:snoopy][:is_a_puppy] = true
238
- @node.override_unless[:snoopy][:is_a_puppy] = false
239
- @node[:snoopy][:is_a_puppy].should == true
266
+ node.override[:snoopy][:is_a_puppy] = true
267
+ node.override_unless[:snoopy][:is_a_puppy] = false
268
+ node[:snoopy][:is_a_puppy].should == true
269
+ end
270
+
271
+ it "should allow you to set a value after an override_unless" do
272
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
273
+ node.override_unless[:snoopy][:is_a_puppy] = false
274
+ node.override[:snoopy][:is_a_puppy] = true
275
+ node[:snoopy][:is_a_puppy].should == true
276
+ end
277
+
278
+ it "should allow you to set a value after a 'dangling' override_unless" do
279
+ # this tests for set_unless_present state bleeding between statements CHEF-3806
280
+ node.override_unless[:snoopy][:is_a_puppy] = "what"
281
+ node.override_unless[:snoopy][:is_a_puppy]
282
+ node.override[:snoopy][:is_a_puppy] = true
283
+ node[:snoopy][:is_a_puppy].should == true
240
284
  end
241
285
 
242
286
  it "auto-vivifies attributes created via method syntax" do
243
- @node.override.fuu.bahrr.baz = "qux"
244
- @node.fuu.bahrr.baz.should == "qux"
287
+ node.override.fuu.bahrr.baz = "qux"
288
+ node.fuu.bahrr.baz.should == "qux"
289
+ end
290
+
291
+ it "sets force_overrides via override!" do
292
+ node.override![:foo] = "wet bar"
293
+ node.override[:foo] = "bar"
294
+ node[:foo].should == "wet bar"
245
295
  end
246
296
 
247
297
  end
248
298
 
249
299
  it "should raise an ArgumentError if you ask for an attribute that doesn't exist via method_missing" do
250
- lambda { @node.sunshine }.should raise_error(ArgumentError)
300
+ lambda { node.sunshine }.should raise_error(NoMethodError)
251
301
  end
252
302
 
253
303
  it "should allow you to iterate over attributes with each_attribute" do
254
- @node.sunshine "is bright"
255
- @node.canada "is a nice place"
304
+ node.default.sunshine = "is bright"
305
+ node.default.canada = "is a nice place"
256
306
  seen_attributes = Hash.new
257
- @node.each_attribute do |a,v|
307
+ node.each_attribute do |a,v|
258
308
  seen_attributes[a] = v
259
309
  end
260
310
  seen_attributes.should have_key("sunshine")
@@ -272,62 +322,62 @@ describe Chef::Node do
272
322
 
273
323
  it "consumes the run list portion of a collection of attributes and returns the remainder" do
274
324
  attrs = {"run_list" => [ "role[base]", "recipe[chef::server]" ], "foo" => "bar"}
275
- @node.consume_run_list(attrs).should == {"foo" => "bar"}
276
- @node.run_list.should == [ "role[base]", "recipe[chef::server]" ]
325
+ node.consume_run_list(attrs).should == {"foo" => "bar"}
326
+ node.run_list.should == [ "role[base]", "recipe[chef::server]" ]
277
327
  end
278
328
 
279
329
  it "should overwrites the run list with the run list it consumes" do
280
- @node.consume_run_list "recipes" => [ "one", "two" ]
281
- @node.consume_run_list "recipes" => [ "three" ]
282
- @node.run_list.should == [ "three" ]
330
+ node.consume_run_list "recipes" => [ "one", "two" ]
331
+ node.consume_run_list "recipes" => [ "three" ]
332
+ node.run_list.should == [ "three" ]
283
333
  end
284
334
 
285
335
  it "should not add duplicate recipes from the json attributes" do
286
- @node.run_list << "one"
287
- @node.consume_run_list "recipes" => [ "one", "two", "three" ]
288
- @node.run_list.should == [ "one", "two", "three" ]
336
+ node.run_list << "one"
337
+ node.consume_run_list "recipes" => [ "one", "two", "three" ]
338
+ node.run_list.should == [ "one", "two", "three" ]
289
339
  end
290
340
 
291
341
  it "doesn't change the run list if no run_list is specified in the json" do
292
- @node.run_list << "role[database]"
293
- @node.consume_run_list "foo" => "bar"
294
- @node.run_list.should == ["role[database]"]
342
+ node.run_list << "role[database]"
343
+ node.consume_run_list "foo" => "bar"
344
+ node.run_list.should == ["role[database]"]
295
345
  end
296
346
 
297
347
  it "raises an exception if you provide both recipe and run_list attributes, since this is ambiguous" do
298
- lambda { @node.consume_run_list "recipes" => "stuff", "run_list" => "other_stuff" }.should raise_error(Chef::Exceptions::AmbiguousRunlistSpecification)
348
+ lambda { node.consume_run_list "recipes" => "stuff", "run_list" => "other_stuff" }.should raise_error(Chef::Exceptions::AmbiguousRunlistSpecification)
299
349
  end
300
350
 
301
351
  it "should add json attributes to the node" do
302
- @node.consume_external_attrs(@ohai_data, {"one" => "two", "three" => "four"})
303
- @node.one.should eql("two")
304
- @node.three.should eql("four")
352
+ node.consume_external_attrs(@ohai_data, {"one" => "two", "three" => "four"})
353
+ node.one.should eql("two")
354
+ node.three.should eql("four")
305
355
  end
306
356
 
307
357
  it "should set the tags attribute to an empty array if it is not already defined" do
308
- @node.consume_external_attrs(@ohai_data, {})
309
- @node.tags.should eql([])
358
+ node.consume_external_attrs(@ohai_data, {})
359
+ node.tags.should eql([])
310
360
  end
311
361
 
312
362
  it "should not set the tags attribute to an empty array if it is already defined" do
313
- @node[:tags] = [ "radiohead" ]
314
- @node.consume_external_attrs(@ohai_data, {})
315
- @node.tags.should eql([ "radiohead" ])
363
+ node.normal[:tags] = [ "radiohead" ]
364
+ node.consume_external_attrs(@ohai_data, {})
365
+ node.tags.should eql([ "radiohead" ])
316
366
  end
317
367
 
318
368
  it "deep merges attributes instead of overwriting them" do
319
- @node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
320
- @node.one.to_hash.should == {"two" => {"three" => "four"}}
321
- @node.consume_external_attrs(@ohai_data, "one" => {"abc" => "123"})
322
- @node.consume_external_attrs(@ohai_data, "one" => {"two" => {"foo" => "bar"}})
323
- @node.one.to_hash.should == {"two" => {"three" => "four", "foo" => "bar"}, "abc" => "123"}
369
+ node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
370
+ node.one.to_hash.should == {"two" => {"three" => "four"}}
371
+ node.consume_external_attrs(@ohai_data, "one" => {"abc" => "123"})
372
+ node.consume_external_attrs(@ohai_data, "one" => {"two" => {"foo" => "bar"}})
373
+ node.one.to_hash.should == {"two" => {"three" => "four", "foo" => "bar"}, "abc" => "123"}
324
374
  end
325
375
 
326
376
  it "gives attributes from JSON priority when deep merging" do
327
- @node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
328
- @node.one.to_hash.should == {"two" => {"three" => "four"}}
329
- @node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "forty-two"}})
330
- @node.one.to_hash.should == {"two" => {"three" => "forty-two"}}
377
+ node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "four"}})
378
+ node.one.to_hash.should == {"two" => {"three" => "four"}}
379
+ node.consume_external_attrs(@ohai_data, "one" => {"two" => {"three" => "forty-two"}})
380
+ node.one.to_hash.should == {"two" => {"three" => "forty-two"}}
331
381
  end
332
382
 
333
383
  end
@@ -338,161 +388,249 @@ describe Chef::Node do
338
388
  end
339
389
 
340
390
  it "sets its platform according to platform detection" do
341
- @node.consume_external_attrs(@ohai_data, {})
342
- @node.automatic_attrs[:platform].should == 'foobuntu'
343
- @node.automatic_attrs[:platform_version].should == '23.42'
391
+ node.consume_external_attrs(@ohai_data, {})
392
+ node.automatic_attrs[:platform].should == 'foobuntu'
393
+ node.automatic_attrs[:platform_version].should == '23.42'
344
394
  end
345
395
 
346
396
  it "consumes the run list from provided json attributes" do
347
- @node.consume_external_attrs(@ohai_data, {"run_list" => ['recipe[unicorn]']})
348
- @node.run_list.should == ['recipe[unicorn]']
397
+ node.consume_external_attrs(@ohai_data, {"run_list" => ['recipe[unicorn]']})
398
+ node.run_list.should == ['recipe[unicorn]']
349
399
  end
350
400
 
351
401
  it "saves non-runlist json attrs for later" do
352
402
  expansion = Chef::RunList::RunListExpansion.new('_default', [])
353
- @node.run_list.stub!(:expand).and_return(expansion)
354
- @node.consume_external_attrs(@ohai_data, {"foo" => "bar"})
355
- @node.expand!
356
- @node.normal_attrs.should == {"foo" => "bar", "tags" => []}
403
+ node.run_list.stub!(:expand).and_return(expansion)
404
+ node.consume_external_attrs(@ohai_data, {"foo" => "bar"})
405
+ node.expand!
406
+ node.normal_attrs.should == {"foo" => "bar", "tags" => []}
357
407
  end
358
408
 
359
409
  end
360
410
 
361
411
  describe "when expanding its run list and merging attributes" do
362
412
  before do
363
- @expansion = Chef::RunList::RunListExpansion.new("_default", [])
364
- @node.run_list.stub!(:expand).and_return(@expansion)
413
+ @environment = Chef::Environment.new.tap do |e|
414
+ e.name('rspec_env')
415
+ e.default_attributes("env default key" => "env default value")
416
+ e.override_attributes("env override key" => "env override value")
417
+ end
418
+ Chef::Environment.should_receive(:load).with("rspec_env").and_return(@environment)
419
+ @expansion = Chef::RunList::RunListExpansion.new("rspec_env", [])
420
+ node.chef_environment("rspec_env")
421
+ node.run_list.stub!(:expand).and_return(@expansion)
365
422
  end
366
423
 
367
424
  it "sets the 'recipes' automatic attribute to the recipes in the expanded run_list" do
368
425
  @expansion.recipes << 'recipe[chef::client]' << 'recipe[nginx::default]'
369
- @node.expand!
370
- @node.automatic_attrs[:recipes].should == ['recipe[chef::client]', 'recipe[nginx::default]']
426
+ node.expand!
427
+ node.automatic_attrs[:recipes].should == ['recipe[chef::client]', 'recipe[nginx::default]']
371
428
  end
372
429
 
373
430
  it "sets the 'roles' automatic attribute to the expanded role list" do
374
431
  @expansion.instance_variable_set(:@applied_roles, {'arf' => nil, 'countersnark' => nil})
375
- @node.expand!
376
- @node.automatic_attrs[:roles].sort.should == ['arf', 'countersnark']
432
+ node.expand!
433
+ node.automatic_attrs[:roles].sort.should == ['arf', 'countersnark']
434
+ end
435
+
436
+ it "applies default attributes from the environment as environment defaults" do
437
+ node.expand!
438
+ node.attributes.env_default["env default key"].should == "env default value"
439
+ end
440
+
441
+ it "applies override attributes from the environment as env overrides" do
442
+ node.expand!
443
+ node.attributes.env_override["env override key"].should == "env override value"
444
+ end
445
+
446
+ it "applies default attributes from roles as role defaults" do
447
+ @expansion.default_attrs["role default key"] = "role default value"
448
+ node.expand!
449
+ node.attributes.role_default["role default key"].should == "role default value"
377
450
  end
378
451
 
452
+ it "applies override attributes from roles as role overrides" do
453
+ @expansion.override_attrs["role override key"] = "role override value"
454
+ node.expand!
455
+ node.attributes.role_override["role override key"].should == "role override value"
456
+ end
379
457
  end
380
458
 
381
- # TODO: timh, cw: 2010-5-19: Node.recipe? deprecated. See node.rb
382
- # describe "recipes" do
383
- # it "should have a RunList of recipes that should be applied" do
384
- # @node.recipes.should be_a_kind_of(Chef::RunList)
385
- # end
386
- #
387
- # it "should allow you to query whether or not it has a recipe applied with recipe?" do
388
- # @node.recipes << "sunrise"
389
- # @node.recipe?("sunrise").should eql(true)
390
- # @node.recipe?("not at home").should eql(false)
391
- # end
392
- #
393
- # it "should allow you to query whether or not a recipe has been applied, even if it was included" do
394
- # @node.run_state[:seen_recipes]["snakes"] = true
395
- # @node.recipe?("snakes").should eql(true)
396
- # end
397
- #
398
- # it "should return false if a recipe has not been seen" do
399
- # @node.recipe?("snakes").should eql(false)
400
- # end
401
- #
402
- # it "should allow you to set recipes with arguments" do
403
- # @node.recipes "one", "two"
404
- # @node.recipe?("one").should eql(true)
405
- # @node.recipe?("two").should eql(true)
406
- # end
407
- # end
459
+ describe "when querying for recipes in the run list" do
460
+ context "when a recipe is in the top level run list" do
461
+ before do
462
+ node.run_list << "recipe[nginx::module]"
463
+ end
464
+
465
+ it "finds the recipe" do
466
+ node.recipe?("nginx::module").should be_true
467
+ end
468
+
469
+ it "does not find a recipe not in the run list" do
470
+ node.recipe?("nginx::other_module").should be_false
471
+ end
472
+ end
473
+ context "when a recipe is in the expanded run list only" do
474
+ before do
475
+ node.run_list << "role[base]"
476
+ node.automatic_attrs[:recipes] = [ "nginx::module" ]
477
+ end
478
+
479
+ it "finds a recipe in the expanded run list" do
480
+ node.recipe?("nginx::module").should be_true
481
+ end
482
+
483
+ it "does not find a recipe that's not in the run list" do
484
+ node.recipe?("nginx::other_module").should be_false
485
+ end
486
+ end
487
+ end
488
+
489
+ describe "when clearing computed state at the beginning of a run" do
490
+ before do
491
+ node.default[:foo] = "default"
492
+ node.normal[:foo] = "normal"
493
+ node.override[:foo] = "override"
494
+ node.reset_defaults_and_overrides
495
+ end
496
+
497
+ it "removes default attributes" do
498
+ node.default.should be_empty
499
+ end
500
+
501
+ it "removes override attributes" do
502
+ node.override.should be_empty
503
+ end
504
+
505
+ it "leaves normal level attributes untouched" do
506
+ node[:foo].should == "normal"
507
+ end
508
+
509
+ end
510
+
511
+ describe "when merging environment attributes" do
512
+ before do
513
+ node.chef_environment = "rspec"
514
+ @expansion = Chef::RunList::RunListExpansion.new("rspec", [])
515
+ @expansion.default_attrs.replace({:default => "from role", :d_role => "role only"})
516
+ @expansion.override_attrs.replace({:override => "from role", :o_role => "role only"})
517
+
518
+
519
+ @environment = Chef::Environment.new
520
+ @environment.default_attributes = {:default => "from env", :d_env => "env only" }
521
+ @environment.override_attributes = {:override => "from env", :o_env => "env only"}
522
+ Chef::Environment.stub!(:load).and_return(@environment)
523
+ node.apply_expansion_attributes(@expansion)
524
+ end
525
+
526
+ it "does not nuke role-only default attrs" do
527
+ node[:d_role].should == "role only"
528
+ end
529
+
530
+ it "does not nuke role-only override attrs" do
531
+ node[:o_role].should == "role only"
532
+ end
533
+
534
+ it "does not nuke env-only default attrs" do
535
+ node[:o_env].should == "env only"
536
+ end
537
+
538
+ it "does not nuke role-only override attrs" do
539
+ node[:o_env].should == "env only"
540
+ end
541
+
542
+ it "gives role defaults precedence over env defaults" do
543
+ node[:default].should == "from role"
544
+ end
545
+
546
+ it "gives env overrides precedence over role overrides" do
547
+ node[:override].should == "from env"
548
+ end
549
+ end
550
+
551
+ describe "when evaluating attributes files" do
552
+ before do
553
+ @cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks"))
554
+ @cookbook_loader = Chef::CookbookLoader.new(@cookbook_repo)
555
+ @cookbook_loader.load_cookbooks
556
+
557
+ @cookbook_collection = Chef::CookbookCollection.new(@cookbook_loader.cookbooks_by_name)
558
+
559
+ @events = Chef::EventDispatch::Dispatcher.new
560
+ @run_context = Chef::RunContext.new(node, @cookbook_collection, @events)
561
+
562
+ node.include_attribute("openldap::default")
563
+ node.include_attribute("openldap::smokey")
564
+ end
565
+
566
+ it "sets attributes from the files" do
567
+ node.ldap_server.should eql("ops1prod")
568
+ node.ldap_basedn.should eql("dc=hjksolutions,dc=com")
569
+ node.ldap_replication_password.should eql("forsure")
570
+ node.smokey.should eql("robinson")
571
+ end
572
+
573
+ it "gives a sensible error when attempting to load a missing attributes file" do
574
+ lambda { node.include_attribute("nope-this::doesnt-exist") }.should raise_error(Chef::Exceptions::CookbookNotFound)
575
+ end
576
+ end
408
577
 
409
578
  describe "roles" do
410
579
  it "should allow you to query whether or not it has a recipe applied with role?" do
411
- @node.run_list << "role[sunrise]"
412
- @node.role?("sunrise").should eql(true)
413
- @node.role?("not at home").should eql(false)
580
+ node.run_list << "role[sunrise]"
581
+ node.role?("sunrise").should eql(true)
582
+ node.role?("not at home").should eql(false)
414
583
  end
415
584
 
416
585
  it "should allow you to set roles with arguments" do
417
- @node.run_list << "role[one]"
418
- @node.run_list << "role[two]"
419
- @node.role?("one").should eql(true)
420
- @node.role?("two").should eql(true)
586
+ node.run_list << "role[one]"
587
+ node.run_list << "role[two]"
588
+ node.role?("one").should eql(true)
589
+ node.role?("two").should eql(true)
421
590
  end
422
591
  end
423
592
 
424
593
  describe "run_list" do
425
594
  it "should have a Chef::RunList of recipes and roles that should be applied" do
426
- @node.run_list.should be_a_kind_of(Chef::RunList)
595
+ node.run_list.should be_a_kind_of(Chef::RunList)
427
596
  end
428
597
 
429
598
  it "should allow you to query the run list with arguments" do
430
- @node.run_list "recipe[baz]"
431
- @node.run_list?("recipe[baz]").should eql(true)
599
+ node.run_list "recipe[baz]"
600
+ node.run_list?("recipe[baz]").should eql(true)
432
601
  end
433
602
 
434
603
  it "should allow you to set the run list with arguments" do
435
- @node.run_list "recipe[baz]", "role[foo]"
436
- @node.run_list?("recipe[baz]").should eql(true)
437
- @node.run_list?("role[foo]").should eql(true)
604
+ node.run_list "recipe[baz]", "role[foo]"
605
+ node.run_list?("recipe[baz]").should eql(true)
606
+ node.run_list?("role[foo]").should eql(true)
438
607
  end
439
608
  end
440
609
 
441
610
  describe "from file" do
442
611
  it "should load a node from a ruby file" do
443
- @node.from_file(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes", "test.rb")))
444
- @node.name.should eql("test.example.com-short")
445
- @node.sunshine.should eql("in")
446
- @node.something.should eql("else")
447
- @node.recipes.should == ["operations-master", "operations-monitoring"]
612
+ node.from_file(File.expand_path(File.join(CHEF_SPEC_DATA, "nodes", "test.rb")))
613
+ node.name.should eql("test.example.com-short")
614
+ node.sunshine.should eql("in")
615
+ node.something.should eql("else")
616
+ node.run_list.should == ["operations-master", "operations-monitoring"]
448
617
  end
449
618
 
450
619
  it "should raise an exception if the file cannot be found or read" do
451
- lambda { @node.from_file("/tmp/monkeydiving") }.should raise_error(IOError)
452
- end
453
- end
454
-
455
- describe "find_file" do
456
- it "should load a node from a file by fqdn" do
457
- @node.find_file("test.example.com")
458
- @node.name.should == "test.example.com"
459
- @node.chef_environment.should == "dev"
460
- end
461
-
462
- it "should load a node from a file by hostname" do
463
- File.stub!(:exists?).and_return(true)
464
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
465
- @node.find_file("test.example.com")
466
- @node.name.should == "test.example.com-short"
467
- end
468
-
469
- it "should load a node from the default file" do
470
- File.stub!(:exists?).and_return(true)
471
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
472
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false)
473
- @node.find_file("test.example.com")
474
- @node.name.should == "test.example.com-default"
475
- end
476
-
477
- it "should raise an ArgumentError if it cannot find any node file at all" do
478
- File.stub!(:exists?).and_return(true)
479
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false)
480
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false)
481
- File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "default.rb")).and_return(false)
482
- lambda { @node.find_file("test.example.com") }.should raise_error(ArgumentError)
620
+ lambda { node.from_file("/tmp/monkeydiving") }.should raise_error(IOError)
483
621
  end
484
622
  end
485
623
 
486
624
  describe "update_from!" do
487
625
  before(:each) do
488
- @node.name("orig")
489
- @node.chef_environment("dev")
490
- @node.default_attrs = { "one" => { "two" => "three", "four" => "five", "eight" => "nine" } }
491
- @node.override_attrs = { "one" => { "two" => "three", "four" => "six" } }
492
- @node.normal_attrs = { "one" => { "two" => "seven" } }
493
- @node.run_list << "role[marxist]"
494
- @node.run_list << "role[leninist]"
495
- @node.run_list << "recipe[stalinist]"
626
+ node.name("orig")
627
+ node.chef_environment("dev")
628
+ node.default_attrs = { "one" => { "two" => "three", "four" => "five", "eight" => "nine" } }
629
+ node.override_attrs = { "one" => { "two" => "three", "four" => "six" } }
630
+ node.normal_attrs = { "one" => { "two" => "seven" } }
631
+ node.run_list << "role[marxist]"
632
+ node.run_list << "role[leninist]"
633
+ node.run_list << "recipe[stalinist]"
496
634
 
497
635
  @example = Chef::Node.new()
498
636
  @example.name("newname")
@@ -506,31 +644,31 @@ describe Chef::Node do
506
644
  end
507
645
 
508
646
  it "allows update of everything except name" do
509
- @node.update_from!(@example)
510
- @node.name.should == "orig"
511
- @node.chef_environment.should == @example.chef_environment
512
- @node.default_attrs.should == @example.default_attrs
513
- @node.override_attrs.should == @example.override_attrs
514
- @node.normal_attrs.should == @example.normal_attrs
515
- @node.run_list.should == @example.run_list
647
+ node.update_from!(@example)
648
+ node.name.should == "orig"
649
+ node.chef_environment.should == @example.chef_environment
650
+ node.default_attrs.should == @example.default_attrs
651
+ node.override_attrs.should == @example.override_attrs
652
+ node.normal_attrs.should == @example.normal_attrs
653
+ node.run_list.should == @example.run_list
516
654
  end
517
655
 
518
656
  it "should not update the name of the node" do
519
- @node.should_not_receive(:name).with(@example.name)
520
- @node.update_from!(@example)
657
+ node.should_not_receive(:name).with(@example.name)
658
+ node.update_from!(@example)
521
659
  end
522
660
  end
523
661
 
524
662
  describe "to_hash" do
525
663
  it "should serialize itself as a hash" do
526
- @node.chef_environment("dev")
527
- @node.default_attrs = { "one" => { "two" => "three", "four" => "five", "eight" => "nine" } }
528
- @node.override_attrs = { "one" => { "two" => "three", "four" => "six" } }
529
- @node.normal_attrs = { "one" => { "two" => "seven" } }
530
- @node.run_list << "role[marxist]"
531
- @node.run_list << "role[leninist]"
532
- @node.run_list << "recipe[stalinist]"
533
- h = @node.to_hash
664
+ node.chef_environment("dev")
665
+ node.default_attrs = { "one" => { "two" => "three", "four" => "five", "eight" => "nine" } }
666
+ node.override_attrs = { "one" => { "two" => "three", "four" => "six" } }
667
+ node.normal_attrs = { "one" => { "two" => "seven" } }
668
+ node.run_list << "role[marxist]"
669
+ node.run_list << "role[leninist]"
670
+ node.run_list << "recipe[stalinist]"
671
+ h = node.to_hash
534
672
  h["one"]["two"].should == "three"
535
673
  h["one"]["four"].should == "six"
536
674
  h["one"]["eight"].should == "nine"
@@ -543,10 +681,10 @@ describe Chef::Node do
543
681
  end
544
682
  end
545
683
 
546
- describe "json" do
684
+ describe "converting to or from json" do
547
685
  it "should serialize itself as json", :json => true do
548
- @node.find_file("test.example.com")
549
- json = Chef::JSONCompat.to_json(@node)
686
+ node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
687
+ json = Chef::JSONCompat.to_json(node)
550
688
  json.should =~ /json_class/
551
689
  json.should =~ /name/
552
690
  json.should =~ /chef_environment/
@@ -556,33 +694,50 @@ describe Chef::Node do
556
694
  json.should =~ /run_list/
557
695
  end
558
696
 
559
- it 'should serialze valid json with a run list', :json => true do
697
+ it 'should serialize valid json with a run list', :json => true do
560
698
  #This test came about because activesupport mucks with Chef json serialization
561
699
  #Test should pass with and without Activesupport
562
- @node.run_list << {"type" => "role", "name" => 'Cthulu'}
563
- @node.run_list << {"type" => "role", "name" => 'Hastur'}
564
- json = Chef::JSONCompat.to_json(@node)
700
+ node.run_list << {"type" => "role", "name" => 'Cthulu'}
701
+ node.run_list << {"type" => "role", "name" => 'Hastur'}
702
+ json = Chef::JSONCompat.to_json(node)
565
703
  json.should =~ /\"run_list\":\[\"role\[Cthulu\]\",\"role\[Hastur\]\"\]/
566
704
  end
567
705
 
706
+ it "merges the override components into a combined override object" do
707
+ node.attributes.role_override["role override"] = "role override"
708
+ node.attributes.env_override["env override"] = "env override"
709
+ node_for_json = node.for_json
710
+ node_for_json["override"]["role override"].should == "role override"
711
+ node_for_json["override"]["env override"].should == "env override"
712
+ end
713
+
714
+ it "merges the default components into a combined default object" do
715
+ node.attributes.role_default["role default"] = "role default"
716
+ node.attributes.env_default["env default"] = "env default"
717
+ node_for_json = node.for_json
718
+ node_for_json["default"]["role default"].should == "role default"
719
+ node_for_json["default"]["env default"].should == "env default"
720
+ end
721
+
722
+
568
723
  it "should deserialize itself from json", :json => true do
569
- @node.find_file("test.example.com")
570
- json = Chef::JSONCompat.to_json(@node)
724
+ node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
725
+ json = Chef::JSONCompat.to_json(node)
571
726
  serialized_node = Chef::JSONCompat.from_json(json)
572
727
  serialized_node.should be_a_kind_of(Chef::Node)
573
- serialized_node.name.should eql(@node.name)
574
- serialized_node.chef_environment.should eql(@node.chef_environment)
575
- @node.each_attribute do |k,v|
728
+ serialized_node.name.should eql(node.name)
729
+ serialized_node.chef_environment.should eql(node.chef_environment)
730
+ node.each_attribute do |k,v|
576
731
  serialized_node[k].should eql(v)
577
732
  end
578
- serialized_node.run_list.should == @node.run_list
733
+ serialized_node.run_list.should == node.run_list
579
734
  end
580
735
  end
581
736
 
582
737
  describe "to_s" do
583
738
  it "should turn into a string like node[name]" do
584
- @node.name("airplane")
585
- @node.to_s.should eql("node[airplane]")
739
+ node.name("airplane")
740
+ node.to_s.should eql("node[airplane]")
586
741
  end
587
742
  end
588
743
 
@@ -621,31 +776,31 @@ describe Chef::Node do
621
776
  describe "destroy" do
622
777
  it "should destroy a node" do
623
778
  @rest.should_receive(:delete_rest).with("nodes/monkey").and_return("foo")
624
- @node.name("monkey")
625
- @node.destroy
779
+ node.name("monkey")
780
+ node.destroy
626
781
  end
627
782
  end
628
783
 
629
784
  describe "save" do
630
785
  it "should update a node if it already exists" do
631
- @node.name("monkey")
632
- @rest.should_receive(:put_rest).with("nodes/monkey", @node).and_return("foo")
633
- @node.save
786
+ node.name("monkey")
787
+ @rest.should_receive(:put_rest).with("nodes/monkey", node).and_return("foo")
788
+ node.save
634
789
  end
635
790
 
636
791
  it "should not try and create if it can update" do
637
- @node.name("monkey")
638
- @rest.should_receive(:put_rest).with("nodes/monkey", @node).and_return("foo")
792
+ node.name("monkey")
793
+ @rest.should_receive(:put_rest).with("nodes/monkey", node).and_return("foo")
639
794
  @rest.should_not_receive(:post_rest)
640
- @node.save
795
+ node.save
641
796
  end
642
797
 
643
798
  it "should create if it cannot update" do
644
- @node.name("monkey")
799
+ node.name("monkey")
645
800
  exception = mock("404 error", :code => "404")
646
801
  @rest.should_receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
647
- @rest.should_receive(:post_rest).with("nodes", @node)
648
- @node.save
802
+ @rest.should_receive(:post_rest).with("nodes", node)
803
+ node.save
649
804
  end
650
805
 
651
806
  describe "when whyrun mode is enabled" do
@@ -656,120 +811,13 @@ describe Chef::Node do
656
811
  Chef::Config[:why_run] = false
657
812
  end
658
813
  it "should not save" do
659
- @node.name("monkey")
814
+ node.name("monkey")
660
815
  @rest.should_not_receive(:put_rest)
661
816
  @rest.should_not_receive(:post_rest)
662
- @node.save
817
+ node.save
663
818
  end
664
819
  end
665
820
  end
666
821
  end
667
822
 
668
- describe "acting as a CouchDB-backed model" do
669
- before(:each) do
670
- @couchdb = Chef::CouchDB.new
671
- @mock_couch = mock('couch mock')
672
- end
673
-
674
- describe "list" do
675
- before(:each) do
676
- @mock_couch.stub!(:list).and_return(
677
- { "rows" => [ { "value" => "a", "key" => "avenue" } ] }
678
- )
679
- Chef::CouchDB.stub!(:new).and_return(@mock_couch)
680
- end
681
-
682
- it "should retrieve a list of nodes from CouchDB" do
683
- Chef::Node.cdb_list.should eql(["avenue"])
684
- end
685
-
686
- it "should return just the ids if inflate is false" do
687
- Chef::Node.cdb_list(false).should eql(["avenue"])
688
- end
689
-
690
- it "should return the full objects if inflate is true" do
691
- Chef::Node.cdb_list(true).should eql(["a"])
692
- end
693
- end
694
-
695
- describe "when loading a given node" do
696
- it "should load a node from couchdb by name" do
697
- @couchdb.should_receive(:load).with("node", "coffee").and_return(true)
698
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
699
- Chef::Node.cdb_load("coffee")
700
- end
701
- end
702
-
703
- describe "when destroying a Node" do
704
- it "should delete this node from couchdb" do
705
- @couchdb.should_receive(:delete).with("node", "bob", 1).and_return(true)
706
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
707
- node = Chef::Node.new
708
- node.name "bob"
709
- node.couchdb_rev = 1
710
- node.cdb_destroy
711
- end
712
- end
713
-
714
- describe "when saving a Node" do
715
- before(:each) do
716
- @couchdb.stub!(:store).and_return({ "rev" => 33 })
717
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
718
- @node = Chef::Node.new
719
- @node.name "bob"
720
- @node.couchdb_rev = 1
721
- end
722
-
723
- it "should save the node to couchdb" do
724
- @couchdb.should_receive(:store).with("node", "bob", @node).and_return({ "rev" => 33 })
725
- @node.cdb_save
726
- end
727
-
728
- it "should store the new couchdb_rev" do
729
- @node.cdb_save
730
- @node.couchdb_rev.should eql(33)
731
- end
732
- end
733
-
734
- describe "create_design_document" do
735
- it "should create our design document" do
736
- @couchdb.should_receive(:create_design_document).with("nodes", Chef::Node::DESIGN_DOCUMENT)
737
- Chef::CouchDB.stub!(:new).and_return(@couchdb)
738
- Chef::Node.create_design_document
739
- end
740
- end
741
-
742
- end
743
-
744
- describe "regression test for CHEF-4631" do
745
- before(:each) do
746
- @node.stub!(:chef_environment).and_return("_default")
747
- end
748
-
749
- it "array values in the role default attributes should be concatanated to the nodes default attributes" do
750
- @node.default_attrs = {"foo" => {"bar" => ["1", "2"]}}
751
- expansion = mock("Expansion", :default_attrs => { "foo" => {"bar" => ["3", "2"]}}, :override_attrs => { })
752
- @node.apply_expansion_attributes(expansion)
753
- @node["foo"]["bar"].should == ["1", "2", "3", "2"]
754
- @node["foo"].to_hash["bar"].should == ["1", "2", "3", "2"]
755
- end
756
-
757
- it "array values in the role override attributes should override the nodes default attributes" do
758
- @node.default_attrs = {"foo" => {"bar" => ["1", "2"]}}
759
- expansion = mock("Expansion", :default_attrs => { "foo" => {"bar" => ["3", "2"]}}, :override_attrs => { "foo" => {"bar" => ["5"] } })
760
- @node.apply_expansion_attributes(expansion)
761
- @node["foo"]["bar"].should == ["5"]
762
- @node["foo"].to_hash["bar"].should == ["5"]
763
- end
764
-
765
- it "array values in the role override attributes should merge with the nodes override attributes" do
766
- @node.default_attrs = {"foo" => {"bar" => ["1", "2"]}}
767
- @node.override_attrs = {"foo" => {"bar" => ["5", "0"]}}
768
- expansion = mock("Expansion", :default_attrs => { "foo" => {"bar" => ["3", "2"]}}, :override_attrs => { "foo" => {"bar" => ["5"] } })
769
- @node.apply_expansion_attributes(expansion)
770
- @node["foo"]["bar"].should == ["5", "0", "5"]
771
- @node["foo"].to_hash["bar"].should == ["5", "0", "5"]
772
- end
773
- end
774
-
775
823
  end