chef 12.0.0.alpha.0-x86-mingw32 → 12.0.0.alpha.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -20,80 +20,60 @@ require 'spec_helper'
20
20
 
21
21
  describe Chef::Provider::Log::ChefLog do
22
22
 
23
- before(:each) do
24
- @log_str = "this is my test string to log"
25
- @node = Chef::Node.new
26
- @events = Chef::EventDispatch::Dispatcher.new
27
- @run_context = Chef::RunContext.new(@node, {}, @events)
28
- end
23
+ let(:log_str) { "this is my test string to log" }
24
+
25
+ let(:node) { Chef::Node.new }
26
+
27
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
28
+
29
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
30
+
31
+ let(:new_resource) { Chef::Resource::Log.new(log_str) }
32
+
33
+ let(:provider) { Chef::Provider::Log::ChefLog.new(new_resource, run_context) }
29
34
 
30
35
  it "should be registered with the default platform hash" do
31
- Chef::Platform.platforms[:default][:log].should_not be_nil
36
+ expect(Chef::Platform.platforms[:default][:log]).not_to be_nil
32
37
  end
33
38
 
34
39
  it "should write the string to the Chef::Log object at default level (info)" do
35
- @new_resource = Chef::Resource::Log.new(@log_str)
36
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
37
- Chef::Log.should_receive(:info).with(@log_str).and_return(true)
38
- @provider.action_write
40
+ expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
41
+ provider.run_action(:write)
39
42
  end
40
43
 
41
44
  it "should write the string to the Chef::Log object at debug level" do
42
- @new_resource = Chef::Resource::Log.new(@log_str)
43
- @new_resource.level :debug
44
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
45
- Chef::Log.should_receive(:debug).with(@log_str).and_return(true)
46
- @provider.action_write
45
+ new_resource.level :debug
46
+ expect(Chef::Log).to receive(:debug).with(log_str).and_return(true)
47
+ provider.run_action(:write)
47
48
  end
48
49
 
49
50
  it "should write the string to the Chef::Log object at info level" do
50
- @new_resource = Chef::Resource::Log.new(@log_str)
51
- @new_resource.level :info
52
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
53
- Chef::Log.should_receive(:info).with(@log_str).and_return(true)
54
- @provider.action_write
51
+ new_resource.level :info
52
+ expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
53
+ provider.run_action(:write)
55
54
  end
56
55
 
57
56
  it "should write the string to the Chef::Log object at warn level" do
58
- @new_resource = Chef::Resource::Log.new(@log_str)
59
- @new_resource.level :warn
60
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
61
- Chef::Log.should_receive(:warn).with(@log_str).and_return(true)
62
- @provider.action_write
57
+ new_resource.level :warn
58
+ expect(Chef::Log).to receive(:warn).with(log_str).and_return(true)
59
+ provider.run_action(:write)
63
60
  end
64
61
 
65
62
  it "should write the string to the Chef::Log object at error level" do
66
- @new_resource = Chef::Resource::Log.new(@log_str)
67
- @new_resource.level :error
68
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
69
- Chef::Log.should_receive(:error).with(@log_str).and_return(true)
70
- @provider.action_write
63
+ new_resource.level :error
64
+ expect(Chef::Log).to receive(:error).with(log_str).and_return(true)
65
+ provider.run_action(:write)
71
66
  end
72
67
 
73
68
  it "should write the string to the Chef::Log object at fatal level" do
74
- @new_resource = Chef::Resource::Log.new(@log_str)
75
- @new_resource.level :fatal
76
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
77
- Chef::Log.should_receive(:fatal).with(@log_str).and_return(true)
78
- @provider.action_write
79
- end
80
-
81
- it "should not update the resource if the message was not written to the log" do
82
- Chef::Log.level = :fatal
83
- @new_resource = Chef::Resource::Log.new(@log_str)
84
- @new_resource.level :info
85
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
86
- @provider.action_write
87
- @new_resource.updated.should be_false
69
+ new_resource.level :fatal
70
+ expect(Chef::Log).to receive(:fatal).with(log_str).and_return(true)
71
+ provider.run_action(:write)
88
72
  end
89
73
 
90
- it "should update the resource if the message has been written to the log" do
91
- Chef::Log.level = :debug
92
- @new_resource = Chef::Resource::Log.new(@log_str)
93
- @new_resource.level :info
94
- @provider = Chef::Provider::Log::ChefLog.new(@new_resource, @run_context)
95
- @provider.action_write
96
- @new_resource.updated.should be_true
74
+ it "should print the string in why-run mode" do
75
+ Chef::Config[:why_run] = true
76
+ expect(Chef::Log).to receive(:info).with(log_str).and_return(true)
77
+ provider.run_action(:write)
97
78
  end
98
-
99
79
  end
@@ -125,11 +125,17 @@ describe Chef::Provider::Mount::Mount do
125
125
  end
126
126
 
127
127
  it "should set mounted true if the mount point is found in the mounts list" do
128
- @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => '/dev/sdz1 on /tmp/foo'))
128
+ @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdz1 on /tmp/foo type ext3 (rw)\n"))
129
129
  @provider.load_current_resource()
130
130
  @provider.current_resource.mounted.should be_true
131
131
  end
132
132
 
133
+ it "should set mounted false if another mount point beginning with the same path is found in the mounts list" do
134
+ @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdz1 on /tmp/foobar type ext3 (rw)\n"))
135
+ @provider.load_current_resource()
136
+ @provider.current_resource.mounted.should be_false
137
+ end
138
+
133
139
  it "should set mounted true if the symlink target of the device is found in the mounts list" do
134
140
  # expand the target path to correct specs on Windows
135
141
  target = ::File.expand_path('/dev/mapper/target')
@@ -437,14 +443,17 @@ describe Chef::Provider::Mount::Mount do
437
443
  @current_resource.stub(:enabled).and_return(true)
438
444
  fstab_read = ["/dev/sdz1 /tmp/foo ext3 defaults 1 2\n",
439
445
  "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n",
440
- "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n"]
446
+ "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n",
447
+ "/dev/sdz1 /tmp/foobar ext3 defaults 1 2\n"]
441
448
 
442
449
  fstab_write = StringIO.new
443
450
  ::File.stub(:readlines).with("/etc/fstab").and_return(fstab_read)
444
451
  ::File.stub(:open).with("/etc/fstab", "w").and_yield(fstab_write)
445
452
 
446
453
  @provider.disable_fs
447
- fstab_write.string.should == "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n/dev/sdy1 /tmp/foo ext3 defaults 1 2\n"
454
+ fstab_write.string.should == "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n" +
455
+ "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n" +
456
+ "/dev/sdz1 /tmp/foobar ext3 defaults 1 2\n"
448
457
  end
449
458
 
450
459
  it "should not disable if enabled is false" do
@@ -30,54 +30,70 @@ describe Chef::Provider::Package::Ips do
30
30
  @current_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context)
31
31
  Chef::Resource::Package.stub(:new).and_return(@current_resource)
32
32
  @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
33
+ end
33
34
 
34
- @stdin = StringIO.new
35
- @stderr = StringIO.new
36
- @stdout =<<-PKG_STATUS
37
- Name: crypto/gnupg
38
- Summary: GNU Privacy Guard
39
- Description: A complete and free implementation of the OpenPGP Standard as
40
- defined by RFC4880.
41
- Category: Applications/System Utilities
42
- State: Not installed
43
- Publisher: solaris
44
- Version: 2.0.17
35
+ def local_output
36
+ stdin = StringIO.new
37
+ stdout = ''
38
+ stderr =<<-PKG_STATUS
39
+ pkg: info: no packages matching the following patterns you specified are
40
+ installed on the system. Try specifying -r to query remotely:
41
+
42
+ crypto/gnupg
43
+ PKG_STATUS
44
+ return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 1)
45
+ end
46
+
47
+ def remote_output
48
+
49
+ stdout = <<-PKG_STATUS
50
+ Name: security/sudo
51
+ Summary: sudo - authority delegation tool
52
+ State: Not Installed
53
+ Publisher: omnios
54
+ Version: 1.8.4.1 (1.8.4p1)
45
55
  Build Release: 5.11
46
- Branch: 0.175.0.0.0.2.537
47
- Packaging Date: October 19, 2011 09:14:50 AM
48
- Size: 8.07 MB
49
- FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
56
+ Branch: 0.151002
57
+ Packaging Date: April 1, 2012 05:55:52 PM
58
+ Size: 2.57 MB
59
+ FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
50
60
  PKG_STATUS
51
- @pid = 12345
52
- @shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
61
+ stdin = StringIO.new
62
+ stderr = ''
63
+ return OpenStruct.new(:stdout => stdout,:stdin => stdin,:stderr => stderr,:status => @status,:exitstatus => 0)
53
64
  end
54
65
 
55
66
  context "when loading current resource" do
56
67
  it "should create a current resource with the name of the new_resource" do
57
- @provider.should_receive(:shell_out!).and_return(@shell_out)
68
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
69
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
58
70
  Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
59
71
  @provider.load_current_resource
60
72
  end
61
73
 
62
74
  it "should set the current resources package name to the new resources package name" do
63
- @provider.should_receive(:shell_out!).and_return(@shell_out)
64
- @current_resource.should_receive(:package_name).with(@new_resource.package_name)
75
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
76
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
65
77
  @provider.load_current_resource
78
+ @current_resource.package_name.should == @new_resource.package_name
66
79
  end
67
80
 
68
81
  it "should run pkg info with the package name" do
69
- @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(@shell_out)
82
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
83
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
70
84
  @provider.load_current_resource
71
85
  end
72
86
 
73
87
  it "should set the installed version to nil on the current resource if package state is not installed" do
74
- @provider.should_receive(:shell_out!).and_return(@shell_out)
75
- @current_resource.should_receive(:version).with(nil).and_return(true)
88
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
89
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
76
90
  @provider.load_current_resource
91
+ @current_resource.version.should be_nil
77
92
  end
78
93
 
79
94
  it "should set the installed version if package has one" do
80
- @stdout.replace(<<-INSTALLED)
95
+ local = local_output
96
+ local.stdout = <<-INSTALLED
81
97
  Name: crypto/gnupg
82
98
  Summary: GNU Privacy Guard
83
99
  Description: A complete and free implementation of the OpenPGP Standard as
@@ -92,14 +108,15 @@ Packaging Date: October 19, 2011 09:14:50 AM
92
108
  Size: 8.07 MB
93
109
  FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
94
110
  INSTALLED
95
- @provider.should_receive(:shell_out!).and_return(@shell_out)
111
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local)
112
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
96
113
  @provider.load_current_resource
97
114
  @current_resource.version.should == "2.0.17"
98
- @provider.candidate_version.should eql("2.0.17")
99
115
  end
100
116
 
101
- it "should return the current resouce" do
102
- @provider.should_receive(:shell_out!).and_return(@shell_out)
117
+ it "should return the current resource" do
118
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
119
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output)
103
120
  @provider.load_current_resource.should eql(@current_resource)
104
121
  end
105
122
  end
@@ -121,8 +138,9 @@ INSTALLED
121
138
  @provider.install_package("crypto/gnupg", "2.0.17")
122
139
  end
123
140
 
124
- it "should not contain invalid characters for the version string" do
125
- @stdout.replace(<<-PKG_STATUS)
141
+ it "should not include the human-readable version in the candidate_version" do
142
+ remote = remote_output
143
+ remote.stdout = <<-PKG_STATUS
126
144
  Name: security/sudo
127
145
  Summary: sudo - authority delegation tool
128
146
  State: Not Installed
@@ -134,49 +152,64 @@ Packaging Date: April 1, 2012 05:55:52 PM
134
152
  Size: 2.57 MB
135
153
  FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
136
154
  PKG_STATUS
137
- @provider.should_receive(:run_command_with_systems_locale).with({
138
- :command => "pkg install -q security/sudo@1.8.4.1"
139
- })
140
- @provider.install_package("security/sudo", "1.8.4.1")
155
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output)
156
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote)
157
+ @provider.load_current_resource
158
+ @current_resource.version.should be_nil
159
+ @provider.candidate_version.should eql("1.8.4.1")
141
160
  end
142
161
 
143
- it "should not include the human-readable version in the candidate_version" do
144
- @stdout.replace(<<-PKG_STATUS)
145
- Name: security/sudo
146
- Summary: sudo - authority delegation tool
162
+ it "should not upgrade the package if it is already installed" do
163
+ local = local_output
164
+ local.stdout = <<-INSTALLED
165
+ Name: crypto/gnupg
166
+ Summary: GNU Privacy Guard
167
+ Description: A complete and free implementation of the OpenPGP Standard as
168
+ defined by RFC4880.
169
+ Category: Applications/System Utilities
170
+ State: Installed
171
+ Publisher: solaris
172
+ Version: 2.0.17
173
+ Build Release: 5.11
174
+ Branch: 0.175.0.0.0.2.537
175
+ Packaging Date: October 19, 2011 09:14:50 AM
176
+ Size: 8.07 MB
177
+ FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z
178
+ INSTALLED
179
+ remote = remote_output
180
+ remote.stdout = <<-REMOTE
181
+ Name: crypto/gnupg
182
+ Summary: GNU Privacy Guard
183
+ Description: A complete and free implementation of the OpenPGP Standard as
184
+ defined by RFC4880.
185
+ Category: Applications/System Utilities
147
186
  State: Not Installed
148
- Publisher: omnios
149
- Version: 1.8.4.1 (1.8.4p1)
187
+ Publisher: solaris
188
+ Version: 2.0.18
150
189
  Build Release: 5.11
151
- Branch: 0.151002
152
- Packaging Date: April 1, 2012 05:55:52 PM
153
- Size: 2.57 MB
154
- FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z
155
- PKG_STATUS
156
- @provider.should_receive(:shell_out!).and_return(@shell_out)
190
+ Branch: 0.175.0.0.0.2.537
191
+ Packaging Date: October 19, 2011 09:14:50 AM
192
+ Size: 8.07 MB
193
+ FMRI: pkg://solaris/crypto/gnupg@2.0.18,5.11-0.175.0.0.0.2.537:20111019T091450Z
194
+ REMOTE
195
+
196
+ @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local)
197
+ @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote)
157
198
  @provider.load_current_resource
158
- @current_resource.version.should be_nil
159
- @provider.candidate_version.should eql("1.8.4.1")
199
+ @provider.should_receive(:install_package).exactly(0).times
200
+ @provider.action_install
160
201
  end
161
202
 
162
- context "using the ips_package resource" do
203
+ context "when accept_license is true" do
163
204
  before do
164
- @new_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
165
- @current_resource = Chef::Resource::IpsPackage.new("crypto/gnupg", @run_context)
166
- @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context)
205
+ @new_resource.stub(:accept_license).and_return(true)
167
206
  end
168
207
 
169
- context "when accept_license is true" do
170
- before do
171
- @new_resource.stub(:accept_license).and_return(true)
172
- end
173
-
174
- it "should run pkg install with the --accept flag" do
175
- @provider.should_receive(:run_command_with_systems_locale).with({
176
- :command => "pkg install -q --accept crypto/gnupg@2.0.17"
177
- })
178
- @provider.install_package("crypto/gnupg", "2.0.17")
179
- end
208
+ it "should run pkg install with the --accept flag" do
209
+ @provider.should_receive(:run_command_with_systems_locale).with({
210
+ :command => "pkg install -q --accept crypto/gnupg@2.0.17"
211
+ })
212
+ @provider.install_package("crypto/gnupg", "2.0.17")
180
213
  end
181
214
  end
182
215
  end
@@ -59,7 +59,7 @@ PKG_STATUS
59
59
  end
60
60
 
61
61
  it "should run pkg info with the package name" do
62
- @provider.should_receive(:shell_out!).with("cave -L warning print-ids -m \"*/#{@new_resource.package_name.split('/').last}\" -f \"%c/%p %v %r\n\"").and_return(@shell_out)
62
+ @provider.should_receive(:shell_out!).with("cave -L warning print-ids -M none -m \"*/#{@new_resource.package_name.split('/').last}\" -f \"%c/%p %v %r\n\"").and_return(@shell_out)
63
63
  @provider.load_current_resource
64
64
  end
65
65
 
@@ -86,13 +86,13 @@ INSTALLED
86
86
 
87
87
  context "when installing a package" do
88
88
  it "should run pkg install with the package name and version" do
89
- @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"")
89
+ @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout})
90
90
  @provider.install_package("net/ntp", "4.2.6_p5-r2")
91
91
  end
92
92
 
93
93
 
94
94
  it "should run pkg install with the package name and version and options if specified" do
95
- @provider.should_receive(:shell_out!).with("cave -L warning resolve -x --preserve-world \"=net/ntp-4.2.6_p5-r2\"")
95
+ @provider.should_receive(:shell_out!).with("cave -L warning resolve -x --preserve-world \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout})
96
96
  @new_resource.stub(:options).and_return("--preserve-world")
97
97
  @provider.install_package("net/ntp", "4.2.6_p5-r2")
98
98
  end
@@ -102,7 +102,7 @@ INSTALLED
102
102
  sys-process/lsof 4.87 arbor
103
103
  sys-process/lsof 4.87 x86_64
104
104
  PKG_STATUS
105
- @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"")
105
+ @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"", {:timeout=>@new_resource.timeout})
106
106
  @provider.install_package("sys-process/lsof", "4.87")
107
107
  end
108
108
 
@@ -120,7 +120,7 @@ PKG_STATUS
120
120
 
121
121
  context "when upgrading a package" do
122
122
  it "should run pkg install with the package name and version" do
123
- @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"")
123
+ @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout})
124
124
  @provider.upgrade_package("net/ntp", "4.2.6_p5-r2")
125
125
  end
126
126
  end
@@ -80,6 +80,18 @@ describe Chef::Provider::Package::Rpm do
80
80
  @provider.stub(:popen4).and_return(status)
81
81
  lambda { @provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package)
82
82
  end
83
+
84
+ it "should not detect the package name as version when not installed" do
85
+ @status = double("Status", :exitstatus => -1)
86
+ @stdout = StringIO.new("package openssh-askpass is not installed")
87
+ @new_resource = Chef::Resource::Package.new("openssh-askpass")
88
+ @new_resource.source 'openssh-askpass'
89
+ @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context)
90
+ @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
91
+ @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(@status)
92
+ @provider.load_current_resource
93
+ @provider.current_resource.version.should be_nil
94
+ end
83
95
  end
84
96
 
85
97
  describe "after the current resource is loaded" do
@@ -146,25 +146,37 @@ describe Chef::Provider::Package::Zypper do
146
146
  end
147
147
 
148
148
  describe "remove_package" do
149
- it "should run zypper remove with the package name" do
150
- Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true)
151
- @provider.should_receive(:shell_out!).with(
152
- "zypper --non-interactive remove emacs=1.0")
153
- @provider.remove_package("emacs", "1.0")
149
+
150
+ context "when package version is not explicitly specified" do
151
+ it "should run zypper remove with the package name" do
152
+ Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true)
153
+ @provider.should_receive(:shell_out!).with(
154
+ "zypper --non-interactive remove emacs")
155
+ @provider.remove_package("emacs", nil)
156
+ end
154
157
  end
155
- it "should run zypper remove without gpg checks" do
156
- Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false)
157
- @provider.should_receive(:shell_out!).with(
158
+
159
+ context "when package version is explicitly specified" do
160
+ it "should run zypper remove with the package name" do
161
+ Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true)
162
+ @provider.should_receive(:shell_out!).with(
163
+ "zypper --non-interactive remove emacs=1.0")
164
+ @provider.remove_package("emacs", "1.0")
165
+ end
166
+ it "should run zypper remove without gpg checks" do
167
+ Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false)
168
+ @provider.should_receive(:shell_out!).with(
169
+ "zypper --non-interactive --no-gpg-checks remove emacs=1.0")
170
+ @provider.remove_package("emacs", "1.0")
171
+ end
172
+ it "should warn about gpg checks on zypper remove" do
173
+ Chef::Log.should_receive(:warn).with(
174
+ /All packages will be installed without gpg signature checks/)
175
+ @provider.should_receive(:shell_out!).with(
158
176
  "zypper --non-interactive --no-gpg-checks remove emacs=1.0")
159
- @provider.remove_package("emacs", "1.0")
160
- end
161
- it "should warn about gpg checks on zypper remove" do
162
- Chef::Log.should_receive(:warn).with(
163
- /All packages will be installed without gpg signature checks/)
164
- @provider.should_receive(:shell_out!).with(
165
- "zypper --non-interactive --no-gpg-checks remove emacs=1.0")
166
177
 
167
- @provider.remove_package("emacs", "1.0")
178
+ @provider.remove_package("emacs", "1.0")
179
+ end
168
180
  end
169
181
  end
170
182