chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -362,7 +362,7 @@ describe Chef::Provider::Deploy do
362
362
 
363
363
  it "skips the migration when resource.migrate => false but runs symlinks before migration" do
364
364
  @resource.migrate false
365
- expect(@provider).not_to receive :run_command
365
+ expect(@provider).not_to receive :shell_out!
366
366
  expect(@provider).to receive :run_symlinks_before_migrate
367
367
  @provider.migrate
368
368
  end
@@ -378,7 +378,7 @@ describe Chef::Provider::Deploy do
378
378
 
379
379
  allow(STDOUT).to receive(:tty?).and_return(true)
380
380
  allow(Chef::Log).to receive(:info?).and_return(true)
381
- expect(@provider).to receive(:run_command).with(:command => "migration_foo", :cwd => @expected_release_dir,
381
+ expect(@provider).to receive(:shell_out!).with("migration_foo",:cwd => @expected_release_dir,
382
382
  :user => "deployNinja", :group => "deployNinjas",
383
383
  :log_level => :info, :live_stream => STDOUT,
384
384
  :log_tag => "deploy[/my/deploy/dir]",
@@ -445,13 +445,13 @@ describe Chef::Provider::Deploy do
445
445
  end
446
446
 
447
447
  it "does nothing for restart if restart_command is empty" do
448
- expect(@provider).not_to receive(:run_command)
448
+ expect(@provider).not_to receive(:shell_out!)
449
449
  @provider.restart
450
450
  end
451
451
 
452
452
  it "runs the restart command in the current application dir when the resource has a restart_command" do
453
453
  @resource.restart_command "restartcmd"
454
- expect(@provider).to receive(:run_command).with(:command => "restartcmd", :cwd => "/my/deploy/dir/current", :log_tag => "deploy[/my/deploy/dir]", :log_level => :debug)
454
+ expect(@provider).to receive(:shell_out!).with("restartcmd", :cwd => "/my/deploy/dir/current", :log_tag => "deploy[/my/deploy/dir]", :log_level => :debug)
455
455
  @provider.restart
456
456
  end
457
457
 
@@ -509,7 +509,7 @@ describe Chef::Provider::Deploy do
509
509
  it "shouldn't give a no method error on migrate if the environment is nil" do
510
510
  allow(@provider).to receive(:enforce_ownership)
511
511
  allow(@provider).to receive(:run_symlinks_before_migrate)
512
- allow(@provider).to receive(:run_command)
512
+ allow(@provider).to receive(:shell_out!)
513
513
  @provider.migrate
514
514
 
515
515
  end
@@ -197,6 +197,41 @@ describe Chef::Provider::Directory do
197
197
  expect { directory.run_action(:create) }.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
198
198
  end
199
199
  end
200
+
201
+ describe "on OS X" do
202
+ before do
203
+ allow(node).to receive(:[]).with("platform").and_return('mac_os_x')
204
+ new_resource.path "/usr/bin/chef_test"
205
+ new_resource.recursive false
206
+ allow_any_instance_of(Chef::Provider::File).to receive(:do_selinux)
207
+ end
208
+
209
+ it "os x 10.10 can write to sip locations" do
210
+ allow(node).to receive(:[]).with("platform_version").and_return('10.10')
211
+ allow(Dir).to receive(:mkdir).and_return([true], [])
212
+ allow(::File).to receive(:directory?).and_return(true)
213
+ allow(Chef::FileAccessControl).to receive(:writable?).and_return(true)
214
+ directory.run_action(:create)
215
+ expect(new_resource).to be_updated
216
+ end
217
+
218
+ it "os x 10.11 cannot write to sip locations" do
219
+ allow(node).to receive(:[]).with("platform_version").and_return('10.11')
220
+ allow(::File).to receive(:directory?).and_return(true)
221
+ allow(Chef::FileAccessControl).to receive(:writable?).and_return(false)
222
+ expect {directory.run_action(:create) }.to raise_error(Chef::Exceptions::InsufficientPermissions)
223
+ end
224
+
225
+ it "os x 10.11 can write to sip exlcusions" do
226
+ new_resource.path "/usr/local/chef_test"
227
+ allow(node).to receive(:[]).with("platform_version").and_return('10.11')
228
+ allow(::File).to receive(:directory?).and_return(true)
229
+ allow(Dir).to receive(:mkdir).and_return([true], [])
230
+ allow(Chef::FileAccessControl).to receive(:writable?).and_return(false)
231
+ directory.run_action(:create)
232
+ expect(new_resource).to be_updated
233
+ end
234
+ end
200
235
  end
201
236
 
202
237
  describe "#run_action(:create)" do
@@ -50,30 +50,23 @@ describe Chef::Provider::DscResource do
50
50
  }
51
51
 
52
52
  context 'when RefreshMode is not set to Disabled' do
53
- let (:meta_configuration) { {'RefreshMode' => 'AnythingElse'}}
54
-
55
53
  it 'raises an exception' do
56
- expect(provider).to receive(:meta_configuration).and_return(
57
- meta_configuration)
54
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(false)
58
55
  expect { provider.run_action(:run) }.to raise_error(
59
56
  Chef::Exceptions::ProviderNotFound, /Disabled/)
60
57
  end
61
58
  end
62
59
 
63
60
  context 'when RefreshMode is set to Disabled' do
64
- let (:meta_configuration) { {'RefreshMode' => 'Disabled'}}
65
-
66
61
  it 'does not update the resource if it is up to date' do
67
- expect(provider).to receive(:meta_configuration).and_return(
68
- meta_configuration)
62
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
69
63
  expect(provider).to receive(:test_resource).and_return(true)
70
64
  provider.run_action(:run)
71
65
  expect(resource).not_to be_updated
72
66
  end
73
67
 
74
68
  it 'converges the resource if it is not up to date' do
75
- expect(provider).to receive(:meta_configuration).and_return(
76
- meta_configuration)
69
+ expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(true)
77
70
  expect(provider).to receive(:test_resource).and_return(false)
78
71
  expect(provider).to receive(:set_resource)
79
72
  provider.run_action(:run)
@@ -46,7 +46,7 @@ describe Chef::Provider::Ifconfig do
46
46
  allow(@provider).to receive(:shell_out).and_return(@status)
47
47
  @provider.load_current_resource
48
48
  end
49
- it "should track state of ifconfig failure." do
49
+ it "should track state of ifconfig failure" do
50
50
  expect(@provider.instance_variable_get("@status").exitstatus).not_to eq(0)
51
51
  end
52
52
  it "should thrown an exception when ifconfig fails" do
@@ -68,6 +68,16 @@ describe Chef::Provider::Ifconfig do
68
68
  expect(@new_resource).to be_updated
69
69
  end
70
70
 
71
+ it "should set the address to target if specified" do
72
+ allow(@provider).to receive(:load_current_resource)
73
+ @new_resource.target "172.16.32.2"
74
+ command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500"
75
+ expect(@provider).to receive(:run_command).with(:command => command)
76
+
77
+ @provider.run_action(:add)
78
+ expect(@new_resource).to be_updated
79
+ end
80
+
71
81
  it "should not add an interface if it already exists" do
72
82
  allow(@provider).to receive(:load_current_resource)
73
83
  expect(@provider).not_to receive(:run_command)
@@ -85,7 +95,7 @@ describe Chef::Provider::Ifconfig do
85
95
 
86
96
  describe Chef::Provider::Ifconfig, "action_enable" do
87
97
 
88
- it "should enable interface if does not exist" do
98
+ it "should enable interface if it does not exist" do
89
99
  allow(@provider).to receive(:load_current_resource)
90
100
  @current_resource.inet_addr nil
91
101
  command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500"
@@ -96,6 +106,16 @@ describe Chef::Provider::Ifconfig do
96
106
  expect(@new_resource).to be_updated
97
107
  end
98
108
 
109
+ it "should set the address to target if specified" do
110
+ allow(@provider).to receive(:load_current_resource)
111
+ @new_resource.target "172.16.32.2"
112
+ command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500"
113
+ expect(@provider).to receive(:run_command).with(:command => command)
114
+
115
+ @provider.run_action(:enable)
116
+ expect(@new_resource).to be_updated
117
+ end
118
+
99
119
  it "should not enable interface if it already exists" do
100
120
  allow(@provider).to receive(:load_current_resource)
101
121
  expect(@provider).not_to receive(:run_command)
@@ -126,9 +126,10 @@ ENABLED
126
126
  @provider.run_action(:mount)
127
127
  end
128
128
 
129
- it "should not mount resource if it is already mounted" do
129
+ it "should not mount resource if it is already mounted and the options have not changed" do
130
130
  stub_mounted_enabled(@provider, @mounted_output, "")
131
131
 
132
+ allow(@provider).to receive(:mount_options_unchanged?).and_return(true)
132
133
  expect(@provider).not_to receive(:mount_fs)
133
134
 
134
135
  @provider.run_action(:mount)
@@ -323,6 +323,12 @@ describe Chef::Provider::Mount::Mount do
323
323
  @provider.mount_fs()
324
324
  end
325
325
 
326
+ it "should not mount the filesystem if it is mounted and the options have not changed" do
327
+ allow(@current_resource).to receive(:mounted).and_return(true)
328
+ expect(@provider).to_not receive(:shell_out!)
329
+ @provider.mount_fs()
330
+ end
331
+
326
332
  end
327
333
 
328
334
  describe "umount_fs" do
@@ -111,6 +111,20 @@ describe Chef::Provider::Mount::Windows do
111
111
  allow(@current_resource).to receive(:mounted).and_return(true)
112
112
  @provider.mount_fs
113
113
  end
114
+
115
+ it "should remount the filesystem if it is mounted and the options have changed" do
116
+ expect(@vol).to receive(:add).with(:remote => @new_resource.device,
117
+ :username => @new_resource.username,
118
+ :domainname => @new_resource.domain,
119
+ :password => @new_resource.password)
120
+ @provider.mount_fs
121
+ end
122
+
123
+ it "should not mount the filesystem if it is mounted and the options have not changed" do
124
+ expect(@vol).to_not receive(:add)
125
+ allow(@current_resource).to receive(:mounted).and_return(true)
126
+ @provider.mount_fs
127
+ end
114
128
  end
115
129
 
116
130
  describe "when unmounting a file system" do
@@ -61,8 +61,19 @@ describe Chef::Provider::Mount do
61
61
  expect(new_resource).to be_updated_by_last_action
62
62
  end
63
63
 
64
- it "should not mount the filesystem if it is mounted" do
64
+ it "should remount the filesystem if it is mounted and the options have changed" do
65
65
  allow(current_resource).to receive(:mounted).and_return(true)
66
+ allow(provider).to receive(:mount_options_unchanged?).and_return(false)
67
+ expect(provider).to receive(:umount_fs).and_return(true)
68
+ expect(provider).to receive(:wait_until_unmounted)
69
+ expect(provider).to receive(:mount_fs).and_return(true)
70
+ provider.run_action(:mount)
71
+ expect(new_resource).to be_updated_by_last_action
72
+ end
73
+
74
+ it "should not mount the filesystem if it is mounted and the options have not changed" do
75
+ allow(current_resource).to receive(:mounted).and_return(true)
76
+ expect(provider).to receive(:mount_options_unchanged?).and_return(true)
66
77
  expect(provider).not_to receive(:mount_fs)
67
78
  provider.run_action(:mount)
68
79
  expect(new_resource).not_to be_updated_by_last_action
@@ -54,7 +54,6 @@ describe Chef::Provider::Package::Dpkg do
54
54
  allow(@provider).to receive(:shell_out).with("dpkg-deb -W #{@new_resource.source}", timeout: 900).and_return(@status)
55
55
  @provider.load_current_resource
56
56
  expect(@provider.current_resource.package_name).to eq("wget")
57
- expect(@new_resource.version).to eq(version)
58
57
  expect(@provider.candidate_version).to eq(version)
59
58
  end
60
59
 
@@ -83,6 +82,14 @@ describe Chef::Provider::Package::Dpkg do
83
82
  expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2")
84
83
  end
85
84
 
85
+ it "gets the source package version from dpkg-deb correctly when the package version has `~', `-', `+' or `.' characters" do
86
+ stdout = "b.a.r-pkg++1\t1.2.3+3141592-1ubuntu1~lucid"
87
+ status = double(:stdout => stdout, :exitstatus => 1)
88
+ allow(@provider).to receive(:shell_out).and_return(status)
89
+ @provider.load_current_resource
90
+ expect(@provider.candidate_version).to eq('1.2.3+3141592-1ubuntu1~lucid')
91
+ end
92
+
86
93
  it "should raise an exception if the source is not set but we are installing" do
87
94
  @new_resource = Chef::Resource::Package.new("wget")
88
95
  @provider.new_resource = @new_resource
@@ -256,6 +256,24 @@ describe Chef::Provider::Package::Rpm do
256
256
  end
257
257
  end
258
258
 
259
+ context "when the package name contains a plus symbol (chef#3671)" do
260
+
261
+ let(:package_name) { "chef-server-core" }
262
+
263
+ let(:package_source) { "/tmp/chef-server-core-12.2.0+20150713220422-1.el6.x86_64.rpm" }
264
+
265
+ let(:rpm_qp_stdout) { "chef-server-core 12.2.0+20150713220422-1.el6" }
266
+ let(:rpm_q_stdout) { "chef-server-core 12.2.0+20150713220422-1.el6" }
267
+
268
+ let(:rpm_qp_exitstatus) { 0 }
269
+ let(:rpm_q_exitstatus) { 0 }
270
+
271
+ it "should correctly determine the candidate version and installed version" do
272
+ expect(provider.current_resource.package_name).to eq("chef-server-core")
273
+ expect(provider.new_resource.version).to eq("12.2.0+20150713220422-1.el6")
274
+ end
275
+ end
276
+
259
277
  end
260
278
 
261
279
  context "when the source is given as an URI" do
@@ -413,4 +431,3 @@ describe Chef::Provider::Package::Rpm do
413
431
 
414
432
 
415
433
  end
416
-
@@ -369,6 +369,24 @@ describe Chef::Provider::Package::Rubygems do
369
369
  expect(provider.gem_env.gem_binary_location).to eq('/usr/weird/bin/gem')
370
370
  end
371
371
 
372
+ it "recognizes chef as omnibus" do
373
+ allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/chef/embedded/bin")
374
+ provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)
375
+ expect(provider.is_omnibus?).to be true
376
+ end
377
+
378
+ it "recognizes opscode as omnibus" do
379
+ allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/opscode/embedded/bin")
380
+ provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)
381
+ expect(provider.is_omnibus?).to be true
382
+ end
383
+
384
+ it "recognizes chefdk as omnibus" do
385
+ allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/chefdk/embedded/bin")
386
+ provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)
387
+ expect(provider.is_omnibus?).to be true
388
+ end
389
+
372
390
  it "searches for a gem binary when running on Omnibus on Unix" do
373
391
  platform_mock :unix do
374
392
  allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/chef/embedded/bin")
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@ describe Chef::Provider::Package::Yum do
24
24
  @node = Chef::Node.new
25
25
  @events = Chef::EventDispatch::Dispatcher.new
26
26
  @run_context = Chef::RunContext.new(@node, {}, @events)
27
- @new_resource = Chef::Resource::Package.new('cups')
27
+ @new_resource = Chef::Resource::YumPackage.new('cups')
28
28
  @status = double("Status", :exitstatus => 0)
29
29
  @yum_cache = double(
30
30
  'Chef::Provider::Yum::YumCache',
@@ -39,6 +39,7 @@ describe Chef::Provider::Package::Yum do
39
39
  :disable_extra_repo_control => true
40
40
  )
41
41
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
42
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
42
43
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
43
44
  @pid = double("PID")
44
45
  end
@@ -88,6 +89,46 @@ describe Chef::Provider::Package::Yum do
88
89
  end
89
90
  end
90
91
 
92
+ describe "yum_binary accessor" do
93
+ it "when yum-deprecated exists" do
94
+ expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true)
95
+ expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
96
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
97
+ expect(@provider.yum_binary).to eql("yum-deprecated")
98
+ end
99
+
100
+ it "when yum-deprecated does not exist" do
101
+ expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false)
102
+ expect(@yum_cache).to receive(:yum_binary=).with("yum")
103
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
104
+ expect(@provider.yum_binary).to eql("yum")
105
+ end
106
+
107
+ it "when the yum_binary is set on the resource" do
108
+ @new_resource.yum_binary "/usr/bin/yum-something"
109
+ expect(File).not_to receive(:exist?)
110
+ expect(@yum_cache).to receive(:yum_binary=).with("/usr/bin/yum-something")
111
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
112
+ expect(@provider.yum_binary).to eql("/usr/bin/yum-something")
113
+ end
114
+
115
+ it "when the new_resource is a vanilla package class and yum-deprecated exists" do
116
+ @new_resource = Chef::Resource::Package.new('cups')
117
+ expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true)
118
+ expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
119
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
120
+ expect(@provider.yum_binary).to eql("yum-deprecated")
121
+ end
122
+
123
+ it "when the new_resource is a vanilla package class and yum-deprecated does not exist" do
124
+ @new_resource = Chef::Resource::Package.new('cups')
125
+ expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false)
126
+ expect(@yum_cache).to receive(:yum_binary=).with("yum")
127
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
128
+ expect(@provider.yum_binary).to eql("yum")
129
+ end
130
+ end
131
+
91
132
  describe "when arch in package_name" do
92
133
  it "should set the arch if no existing package_name is found and new_package_name+new_arch is available" do
93
134
  @new_resource = Chef::Resource::YumPackage.new('testing.noarch')
@@ -109,6 +150,7 @@ describe Chef::Provider::Package::Yum do
109
150
  allow(@yum_cache).to receive(:package_available?).and_return(true)
110
151
  allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
111
152
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
153
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
112
154
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
113
155
  @provider.load_current_resource
114
156
  expect(@provider.new_resource.package_name).to eq("testing")
@@ -163,6 +205,7 @@ describe Chef::Provider::Package::Yum do
163
205
  allow(@yum_cache).to receive(:package_available?).and_return(true)
164
206
  allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
165
207
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
208
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
166
209
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
167
210
  # annoying side effect of the fun stub'ing above
168
211
  @provider.load_current_resource
@@ -194,6 +237,7 @@ describe Chef::Provider::Package::Yum do
194
237
  allow(@yum_cache).to receive(:package_available?).and_return(true)
195
238
  allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
196
239
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
240
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
197
241
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
198
242
  @provider.load_current_resource
199
243
  expect(@provider.new_resource.package_name).to eq("testing.beta3")
@@ -229,6 +273,7 @@ describe Chef::Provider::Package::Yum do
229
273
  allow(@yum_cache).to receive(:package_available?).and_return(true)
230
274
  allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
231
275
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
276
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
232
277
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
233
278
  @provider.load_current_resource
234
279
  expect(@provider.new_resource.package_name).to eq("testing.i386")
@@ -281,6 +326,7 @@ describe Chef::Provider::Package::Yum do
281
326
 
282
327
  before do
283
328
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
329
+ allow(yum_cache).to receive(:yum_binary=).with("yum")
284
330
  @pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
285
331
  expect(yum_cache).to receive(:packages_from_require).and_return([@pkg])
286
332
  end
@@ -352,6 +398,7 @@ describe Chef::Provider::Package::Yum do
352
398
  :disable_extra_repo_control => true
353
399
  )
354
400
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
401
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
355
402
  pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
356
403
  expect(@yum_cache).to receive(:packages_from_require).and_return([pkg])
357
404
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -373,6 +420,7 @@ describe Chef::Provider::Package::Yum do
373
420
  :disable_extra_repo_control => true
374
421
  )
375
422
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
423
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
376
424
  pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
377
425
  expect(@yum_cache).to receive(:packages_from_require).and_return([pkg])
378
426
  @new_resource = Chef::Resource::YumPackage.new('test-package = 2.0.1.el5')
@@ -395,6 +443,7 @@ describe Chef::Provider::Package::Yum do
395
443
  :disable_extra_repo_control => true
396
444
  )
397
445
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
446
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
398
447
 
399
448
  expect(@yum_cache).to receive(:packages_from_require).exactly(4).times.and_return([])
400
449
  expect(@yum_cache).to receive(:reload_provides).twice
@@ -419,6 +468,7 @@ describe Chef::Provider::Package::Yum do
419
468
  :disable_extra_repo_control => true
420
469
  )
421
470
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
471
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
422
472
  expect(@yum_cache).to receive(:packages_from_require).twice.and_return([])
423
473
  expect(@yum_cache).to receive(:reload_provides)
424
474
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -438,6 +488,7 @@ describe Chef::Provider::Package::Yum do
438
488
  :disable_extra_repo_control => true
439
489
  )
440
490
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
491
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
441
492
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
442
493
  expect(@yum_cache).to receive(:packages_from_require).once.and_return([])
443
494
  expect(@yum_cache).not_to receive(:reload_provides)
@@ -462,6 +513,7 @@ describe Chef::Provider::Package::Yum do
462
513
  :disable_extra_repo_control => true
463
514
  )
464
515
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
516
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
465
517
  expect(@yum_cache).to receive(:packages_from_require).twice.and_return([])
466
518
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
467
519
  @provider.load_current_resource
@@ -474,7 +526,7 @@ describe Chef::Provider::Package::Yum do
474
526
  @provider.load_current_resource
475
527
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
476
528
  expect(@provider).to receive(:yum_command).with(
477
- "yum -d0 -e0 -y install cups-1.2.4-11.19.el5"
529
+ "-d0 -e0 -y install cups-1.2.4-11.19.el5"
478
530
  )
479
531
  @provider.install_package("cups", "1.2.4-11.19.el5")
480
532
  end
@@ -482,7 +534,7 @@ describe Chef::Provider::Package::Yum do
482
534
  it "should run yum localinstall if given a path to an rpm" do
483
535
  allow(@new_resource).to receive(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm")
484
536
  expect(@provider).to receive(:yum_command).with(
485
- "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
537
+ "-d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
486
538
  )
487
539
  @provider.install_package("emacs", "21.4-20.el5")
488
540
  end
@@ -493,7 +545,7 @@ describe Chef::Provider::Package::Yum do
493
545
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
494
546
  expect(@new_resource.source).to eq("/tmp/emacs-21.4-20.el5.i386.rpm")
495
547
  expect(@provider).to receive(:yum_command).with(
496
- "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
548
+ "-d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
497
549
  )
498
550
  @provider.install_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5")
499
551
  end
@@ -503,7 +555,7 @@ describe Chef::Provider::Package::Yum do
503
555
  allow(@new_resource).to receive(:arch).and_return("i386")
504
556
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
505
557
  expect(@provider).to receive(:yum_command).with(
506
- "yum -d0 -e0 -y install cups-1.2.4-11.19.el5.i386"
558
+ "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386"
507
559
  )
508
560
  @provider.install_package("cups", "1.2.4-11.19.el5")
509
561
  end
@@ -514,7 +566,7 @@ describe Chef::Provider::Package::Yum do
514
566
  allow(@new_resource).to receive(:options).and_return("--disablerepo epmd")
515
567
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
516
568
  expect(@provider).to receive(:yum_command).with(
517
- "yum -d0 -e0 -y --disablerepo epmd install cups-11"
569
+ "-d0 -e0 -y --disablerepo epmd install cups-11"
518
570
  )
519
571
  @provider.install_package(@new_resource.name, @provider.candidate_version)
520
572
  end
@@ -531,6 +583,7 @@ describe Chef::Provider::Package::Yum do
531
583
  :disable_extra_repo_control => true
532
584
  )
533
585
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
586
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
534
587
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
535
588
  expect { @provider.install_package("lolcats", "0.99") }.to raise_error(Chef::Exceptions::Package, %r{Version .* not found})
536
589
  end
@@ -549,6 +602,7 @@ describe Chef::Provider::Package::Yum do
549
602
  :disable_extra_repo_control => true
550
603
  )
551
604
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
605
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
552
606
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
553
607
  @provider.load_current_resource
554
608
  expect { @provider.install_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package})
@@ -568,10 +622,11 @@ describe Chef::Provider::Package::Yum do
568
622
  :disable_extra_repo_control => true
569
623
  )
570
624
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
625
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
571
626
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
572
627
  @provider.load_current_resource
573
628
  expect(@provider).to receive(:yum_command).with(
574
- "yum -d0 -e0 -y install cups-1.2.4-11.15.el5"
629
+ "-d0 -e0 -y install cups-1.2.4-11.15.el5"
575
630
  )
576
631
  @provider.install_package("cups", "1.2.4-11.15.el5")
577
632
  end
@@ -591,10 +646,11 @@ describe Chef::Provider::Package::Yum do
591
646
  :disable_extra_repo_control => true
592
647
  )
593
648
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
649
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
594
650
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
595
651
  @provider.load_current_resource
596
652
  expect(@provider).to receive(:yum_command).with(
597
- "yum -d0 -e0 -y downgrade cups-1.2.4-11.15.el5"
653
+ "-d0 -e0 -y downgrade cups-1.2.4-11.15.el5"
598
654
  )
599
655
  @provider.install_package("cups", "1.2.4-11.15.el5")
600
656
  end
@@ -604,7 +660,7 @@ describe Chef::Provider::Package::Yum do
604
660
  @provider.load_current_resource
605
661
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
606
662
  expect(@provider).to receive(:yum_command).with(
607
- "yum -d0 -e0 -y install cups-1.2.4-11.15.el5"
663
+ "-d0 -e0 -y install cups-1.2.4-11.15.el5"
608
664
  )
609
665
  expect(@yum_cache).to receive(:reload).once
610
666
  @provider.install_package("cups", "1.2.4-11.15.el5")
@@ -615,7 +671,7 @@ describe Chef::Provider::Package::Yum do
615
671
  @provider.load_current_resource
616
672
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
617
673
  expect(@provider).to receive(:yum_command).with(
618
- "yum -d0 -e0 -y install cups-1.2.4-11.15.el5"
674
+ "-d0 -e0 -y install cups-1.2.4-11.15.el5"
619
675
  )
620
676
  expect(@yum_cache).not_to receive(:reload)
621
677
  @provider.install_package("cups", "1.2.4-11.15.el5")
@@ -628,7 +684,7 @@ describe Chef::Provider::Package::Yum do
628
684
  allow(@provider).to receive(:candidate_version).and_return('11')
629
685
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
630
686
  expect(@provider).to receive(:yum_command).with(
631
- "yum -d0 -e0 -y install cups-11"
687
+ "-d0 -e0 -y install cups-11"
632
688
  )
633
689
  @provider.upgrade_package(@new_resource.name, @provider.candidate_version)
634
690
  end
@@ -639,7 +695,7 @@ describe Chef::Provider::Package::Yum do
639
695
  allow(@provider).to receive(:candidate_version).and_return('11')
640
696
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
641
697
  expect(@provider).to receive(:yum_command).with(
642
- "yum -d0 -e0 -y install cups-11"
698
+ "-d0 -e0 -y install cups-11"
643
699
  )
644
700
  @provider.upgrade_package(@new_resource.name, @provider.candidate_version)
645
701
  end
@@ -657,6 +713,7 @@ describe Chef::Provider::Package::Yum do
657
713
  :disable_extra_repo_control => true
658
714
  )
659
715
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
716
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
660
717
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
661
718
  @provider.load_current_resource
662
719
  expect { @provider.upgrade_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package})
@@ -706,7 +763,7 @@ describe Chef::Provider::Package::Yum do
706
763
  describe "when removing a package" do
707
764
  it "should run yum remove with the package name" do
708
765
  expect(@provider).to receive(:yum_command).with(
709
- "yum -d0 -e0 -y remove emacs-1.0"
766
+ "-d0 -e0 -y remove emacs-1.0"
710
767
  )
711
768
  @provider.remove_package("emacs", "1.0")
712
769
  end
@@ -714,7 +771,7 @@ describe Chef::Provider::Package::Yum do
714
771
  it "should run yum remove with the package name and arch" do
715
772
  allow(@new_resource).to receive(:arch).and_return("x86_64")
716
773
  expect(@provider).to receive(:yum_command).with(
717
- "yum -d0 -e0 -y remove emacs-1.0.x86_64"
774
+ "-d0 -e0 -y remove emacs-1.0.x86_64"
718
775
  )
719
776
  @provider.remove_package("emacs", "1.0")
720
777
  end
@@ -723,7 +780,7 @@ describe Chef::Provider::Package::Yum do
723
780
  describe "when purging a package" do
724
781
  it "should run yum remove with the package name" do
725
782
  expect(@provider).to receive(:yum_command).with(
726
- "yum -d0 -e0 -y remove emacs-1.0"
783
+ "-d0 -e0 -y remove emacs-1.0"
727
784
  )
728
785
  @provider.purge_package("emacs", "1.0")
729
786
  end
@@ -737,7 +794,7 @@ describe Chef::Provider::Package::Yum do
737
794
  "yum -d0 -e0 -y install emacs-1.0",
738
795
  {:timeout => Chef::Config[:yum_timeout]}
739
796
  )
740
- @provider.yum_command("yum -d0 -e0 -y install emacs-1.0")
797
+ @provider.yum_command("-d0 -e0 -y install emacs-1.0")
741
798
  end
742
799
 
743
800
  it "should run yum once if it exits with a return code > 0 and no scriptlet failures" do
@@ -747,7 +804,7 @@ describe Chef::Provider::Package::Yum do
747
804
  "yum -d0 -e0 -y install emacs-1.0",
748
805
  {:timeout => Chef::Config[:yum_timeout]}
749
806
  )
750
- expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
807
+ expect { @provider.yum_command("-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
751
808
  end
752
809
 
753
810
  it "should run yum once if it exits with a return code of 1 and %pre scriptlet failures" do
@@ -759,7 +816,7 @@ describe Chef::Provider::Package::Yum do
759
816
  {:timeout => Chef::Config[:yum_timeout]}
760
817
  )
761
818
  # will still raise an exception, can't stub out the subsequent call
762
- expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
819
+ expect { @provider.yum_command("-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
763
820
  end
764
821
 
765
822
  it "should run yum twice if it exits with a return code of 1 and %post scriptlet failures" do
@@ -771,7 +828,20 @@ describe Chef::Provider::Package::Yum do
771
828
  {:timeout => Chef::Config[:yum_timeout]}
772
829
  )
773
830
  # will still raise an exception, can't stub out the subsequent call
774
- expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
831
+ expect { @provider.yum_command("-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
832
+ end
833
+
834
+ it "should pass the yum_binary to the command if its specified" do
835
+ @new_resource.yum_binary "yum-deprecated"
836
+ expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
837
+ @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
838
+ @status = double("Status", :exitstatus => 0, :stdout => "", :stderr => "")
839
+ allow(@provider).to receive(:shell_out).and_return(@status)
840
+ expect(@provider).to receive(:shell_out).once.with(
841
+ "yum-deprecated -d0 -e0 -y install emacs-1.0",
842
+ {:timeout => Chef::Config[:yum_timeout]}
843
+ )
844
+ @provider.yum_command("-d0 -e0 -y install emacs-1.0")
775
845
  end
776
846
  end
777
847
  end
@@ -1737,6 +1807,7 @@ EOF
1737
1807
  Chef::Provider::Package::Yum::YumCache.reset_instance
1738
1808
  @yc = Chef::Provider::Package::Yum::YumCache.instance
1739
1809
  # load valid data
1810
+ @yc.yum_binary = "yum"
1740
1811
  allow(@yc).to receive(:shell_out!).and_return(@status)
1741
1812
  allow_any_instance_of(described_class).to receive(:which).with("yum").and_return("/usr/bin/yum")
1742
1813
  allow(::File).to receive(:open).with("/usr/bin/yum", "r") do |&block|
@@ -2053,6 +2124,8 @@ describe "Chef::Provider::Package::Yum - Multi" do
2053
2124
  :disable_extra_repo_control => true
2054
2125
  )
2055
2126
  allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
2127
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
2128
+ allow(@yum_cache).to receive(:yum_binary=).with("yum")
2056
2129
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
2057
2130
  @pid = double("PID")
2058
2131
  end
@@ -2134,7 +2207,7 @@ describe "Chef::Provider::Package::Yum - Multi" do
2134
2207
  allow(@yum_cache).to receive(:installed_version).with('cups', nil).and_return('1.2.4-11.18.el5')
2135
2208
  allow(@yum_cache).to receive(:installed_version).with('vim', nil).and_return('0.9')
2136
2209
  expect(@provider).to receive(:yum_command).with(
2137
- "yum -d0 -e0 -y install cups-1.2.4-11.19.el5 vim-1.0"
2210
+ "-d0 -e0 -y install cups-1.2.4-11.19.el5 vim-1.0"
2138
2211
  )
2139
2212
  @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", '1.0'])
2140
2213
  end
@@ -2144,7 +2217,7 @@ describe "Chef::Provider::Package::Yum - Multi" do
2144
2217
  allow(@new_resource).to receive(:arch).and_return("i386")
2145
2218
  allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
2146
2219
  expect(@provider).to receive(:yum_command).with(
2147
- "yum -d0 -e0 -y install cups-1.2.4-11.19.el5.i386 vim-1.0.i386"
2220
+ "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386 vim-1.0.i386"
2148
2221
  )
2149
2222
  @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"])
2150
2223
  end
@@ -2155,7 +2228,7 @@ describe "Chef::Provider::Package::Yum - Multi" do
2155
2228
  allow(@yum_cache).to receive(:installed_version).with('cups', nil).and_return('1.2.4-11.18.el5')
2156
2229
  allow(@yum_cache).to receive(:installed_version).with('vim', nil).and_return('0.9')
2157
2230
  expect(@provider).to receive(:yum_command).with(
2158
- "yum -d0 -e0 -y --disablerepo epmd install cups-1.2.4-11.19.el5 vim-1.0"
2231
+ "-d0 -e0 -y --disablerepo epmd install cups-1.2.4-11.19.el5 vim-1.0"
2159
2232
  )
2160
2233
  allow(@new_resource).to receive(:options).and_return("--disablerepo epmd")
2161
2234
  @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", '1.0'])
@@ -2181,7 +2254,7 @@ describe "Chef::Provider::Package::Yum - Multi" do
2181
2254
 
2182
2255
  @provider.load_current_resource
2183
2256
  expect(@provider).to receive(:yum_command).with(
2184
- "yum -d0 -e0 -y install cups-1.2.4-11.19.el5.x86_64 vim-1.0"
2257
+ "-d0 -e0 -y install cups-1.2.4-11.19.el5.x86_64 vim-1.0"
2185
2258
  )
2186
2259
  @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", '1.0'])
2187
2260
  end