chef 11.14.0.alpha.4 → 11.14.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CONTRIBUTING.md +0 -4
  2. data/README.md +1 -1
  3. data/distro/common/man/man1/chef-shell.1 +4 -4
  4. data/distro/common/man/man1/knife-bootstrap.1 +14 -11
  5. data/distro/common/man/man1/knife-client.1 +14 -11
  6. data/distro/common/man/man1/knife-configure.1 +7 -7
  7. data/distro/common/man/man1/knife-cookbook-site.1 +23 -23
  8. data/distro/common/man/man1/knife-cookbook.1 +23 -23
  9. data/distro/common/man/man1/knife-data-bag.1 +13 -13
  10. data/distro/common/man/man1/knife-delete.1 +9 -9
  11. data/distro/common/man/man1/knife-deps.1 +9 -9
  12. data/distro/common/man/man1/knife-diff.1 +10 -10
  13. data/distro/common/man/man1/knife-download.1 +9 -9
  14. data/distro/common/man/man1/knife-edit.1 +7 -7
  15. data/distro/common/man/man1/knife-environment.1 +10 -10
  16. data/distro/common/man/man1/knife-exec.1 +7 -7
  17. data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
  18. data/distro/common/man/man1/knife-list.1 +12 -12
  19. data/distro/common/man/man1/knife-node.1 +12 -9
  20. data/distro/common/man/man1/knife-raw.1 +7 -7
  21. data/distro/common/man/man1/knife-recipe-list.1 +1 -1
  22. data/distro/common/man/man1/knife-role.1 +8 -8
  23. data/distro/common/man/man1/knife-search.1 +9 -9
  24. data/distro/common/man/man1/knife-serve.1 +109 -0
  25. data/distro/common/man/man1/knife-show.1 +8 -8
  26. data/distro/common/man/man1/knife-ssh.1 +9 -9
  27. data/distro/common/man/man1/knife-ssl-check.1 +9 -9
  28. data/distro/common/man/man1/knife-ssl-fetch.1 +10 -10
  29. data/distro/common/man/man1/knife-status.1 +9 -9
  30. data/distro/common/man/man1/knife-tag.1 +7 -7
  31. data/distro/common/man/man1/knife-upload.1 +10 -10
  32. data/distro/common/man/man1/knife-user.1 +9 -9
  33. data/distro/common/man/man1/knife-xargs.1 +7 -7
  34. data/distro/common/man/man1/knife.1 +118 -14
  35. data/distro/common/man/man8/chef-client.8 +13 -10
  36. data/distro/common/man/man8/chef-solo.8 +13 -14
  37. data/distro/common/markdown/man1/knife.mkd +1 -1
  38. data/lib/chef/application/knife.rb +1 -1
  39. data/lib/chef/application/windows_service.rb +0 -1
  40. data/lib/chef/chef_fs/file_system.rb +6 -2
  41. data/lib/chef/config.rb +3 -2
  42. data/lib/chef/config_fetcher.rb +1 -1
  43. data/lib/chef/cookbook/metadata.rb +20 -14
  44. data/lib/chef/cookbook/synchronizer.rb +24 -13
  45. data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
  46. data/lib/chef/encrypted_data_bag_item/encryptor.rb +2 -2
  47. data/lib/chef/exceptions.rb +1 -0
  48. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  49. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +1 -1
  50. data/lib/chef/http.rb +6 -1
  51. data/lib/chef/http/http_request.rb +9 -1
  52. data/lib/chef/http/simple.rb +2 -1
  53. data/lib/chef/json_compat.rb +5 -16
  54. data/lib/chef/knife/bootstrap.rb +2 -0
  55. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  56. data/lib/chef/knife/core/object_loader.rb +3 -1
  57. data/lib/chef/knife/ssh.rb +14 -7
  58. data/lib/chef/mixin/convert_to_class_name.rb +1 -0
  59. data/lib/chef/mixin/windows_architecture_helper.rb +24 -4
  60. data/lib/chef/platform/provider_mapping.rb +13 -0
  61. data/lib/chef/provider/env/windows.rb +3 -6
  62. data/lib/chef/provider/git.rb +1 -2
  63. data/lib/chef/provider/log.rb +15 -1
  64. data/lib/chef/provider/package/apt.rb +3 -3
  65. data/lib/chef/provider/package/dpkg.rb +35 -16
  66. data/lib/chef/provider/package/paludis.rb +91 -0
  67. data/lib/chef/provider/package/rpm.rb +3 -2
  68. data/lib/chef/provider/package/yum-dump.py +6 -6
  69. data/lib/chef/provider/package/yum.rb +2 -0
  70. data/lib/chef/provider/registry_key.rb +4 -5
  71. data/lib/chef/provider/remote_file/cache_control_data.rb +1 -1
  72. data/lib/chef/provider/service/solaris.rb +1 -1
  73. data/lib/chef/provider/service/upstart.rb +2 -1
  74. data/lib/chef/provider/service/windows.rb +37 -9
  75. data/lib/chef/provider/user/pw.rb +1 -1
  76. data/lib/chef/provider/user/useradd.rb +1 -1
  77. data/lib/chef/provider/windows_script.rb +2 -1
  78. data/lib/chef/providers.rb +1 -0
  79. data/lib/chef/resource.rb +10 -0
  80. data/lib/chef/resource/file.rb +0 -9
  81. data/lib/chef/resource/package.rb +14 -4
  82. data/lib/chef/resource/paludis_package.rb +33 -0
  83. data/lib/chef/resource/registry_key.rb +62 -3
  84. data/lib/chef/resource/service.rb +21 -4
  85. data/lib/chef/resource_reporter.rb +10 -0
  86. data/lib/chef/resources.rb +1 -0
  87. data/lib/chef/role.rb +14 -10
  88. data/lib/chef/shell.rb +8 -0
  89. data/lib/chef/shell/shell_session.rb +3 -3
  90. data/lib/chef/user.rb +12 -11
  91. data/lib/chef/util/selinux.rb +1 -1
  92. data/lib/chef/version.rb +1 -1
  93. data/lib/chef/version_constraint.rb +6 -5
  94. data/lib/chef/win32/api/process.rb +1 -0
  95. data/lib/chef/win32/api/system.rb +14 -0
  96. data/lib/chef/win32/error.rb +1 -1
  97. data/lib/chef/win32/security.rb +5 -5
  98. data/lib/chef/win32/version.rb +6 -2
  99. data/spec/data/trusted_certs/opscode.pem +57 -35
  100. data/spec/functional/application_spec.rb +2 -2
  101. data/spec/functional/resource/mount_spec.rb +3 -1
  102. data/spec/functional/shell_spec.rb +10 -0
  103. data/spec/functional/tiny_server_spec.rb +2 -2
  104. data/spec/support/chef_helpers.rb +1 -1
  105. data/spec/support/shared/functional/securable_resource.rb +11 -2
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +13 -2
  107. data/spec/tiny_server.rb +1 -1
  108. data/spec/unit/config_spec.rb +5 -0
  109. data/spec/unit/cookbook/metadata_spec.rb +24 -0
  110. data/spec/unit/environment_spec.rb +6 -0
  111. data/spec/unit/http/http_request_spec.rb +91 -0
  112. data/spec/unit/http_spec.rb +23 -0
  113. data/spec/unit/knife/bootstrap_spec.rb +2 -2
  114. data/spec/unit/knife/ssh_spec.rb +7 -13
  115. data/spec/unit/knife_spec.rb +1 -1
  116. data/spec/unit/mixin/convert_to_class_name_spec.rb +4 -0
  117. data/spec/unit/provider/git_spec.rb +2 -2
  118. data/spec/unit/provider/log_spec.rb +18 -0
  119. data/spec/unit/provider/mount/solaris_spec.rb +3 -1
  120. data/spec/unit/provider/package/apt_spec.rb +85 -40
  121. data/spec/unit/provider/package/dpkg_spec.rb +24 -48
  122. data/spec/unit/provider/package/paludis_spec.rb +135 -0
  123. data/spec/unit/provider/package/rpm_spec.rb +40 -32
  124. data/spec/unit/provider/package/yum_spec.rb +11 -4
  125. data/spec/unit/provider/registry_key_spec.rb +67 -53
  126. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +10 -1
  127. data/spec/unit/provider/service/solaris_smf_service_spec.rb +23 -2
  128. data/spec/unit/provider/service/upstart_service_spec.rb +7 -0
  129. data/spec/unit/provider/service/windows_spec.rb +72 -0
  130. data/spec/unit/provider/user/pw_spec.rb +21 -4
  131. data/spec/unit/provider/user/useradd_spec.rb +10 -0
  132. data/spec/unit/resource/package_spec.rb +26 -18
  133. data/spec/unit/resource/registry_key_spec.rb +28 -0
  134. data/spec/unit/resource/service_spec.rb +14 -0
  135. data/spec/unit/resource_reporter_spec.rb +37 -12
  136. data/spec/unit/resource_spec.rb +41 -6
  137. data/spec/unit/rest_spec.rb +2 -2
  138. data/spec/unit/role_spec.rb +46 -28
  139. data/spec/unit/shell/shell_session_spec.rb +42 -2
  140. data/spec/unit/shell_spec.rb +1 -1
  141. data/spec/unit/user_spec.rb +12 -0
  142. data/spec/unit/util/selinux_spec.rb +4 -4
  143. data/spec/unit/version_constraint_spec.rb +14 -2
  144. metadata +195 -161
  145. checksums.yaml +0 -7
@@ -78,4 +78,22 @@ describe Chef::Provider::Log::ChefLog do
78
78
  @provider.action_write
79
79
  end
80
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
88
+ end
89
+
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
97
+ end
98
+
81
99
  end
@@ -19,7 +19,9 @@
19
19
  require 'spec_helper'
20
20
  require 'ostruct'
21
21
 
22
- describe Chef::Provider::Mount::Solaris do
22
+ # Do not run these tests on windows because some path handling
23
+ # code is not implemented to handle windows paths.
24
+ describe Chef::Provider::Mount::Solaris, :unix_only do
23
25
  let(:node) { Chef::Node.new }
24
26
 
25
27
  let(:events) { Chef::EventDispatch::Dispatcher.new }
@@ -39,12 +39,16 @@ irssi:
39
39
  PKG_STATUS
40
40
  @stderr = ""
41
41
  @shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
42
+ @timeout = 900
42
43
  end
43
44
 
44
45
  describe "when loading current resource" do
45
46
 
46
47
  it "should create a current resource with the name of the new_resource" do
47
- @provider.should_receive(:shell_out!).with("apt-cache policy #{@new_resource.package_name}").and_return(@shell_out)
48
+ @provider.should_receive(:shell_out!).with(
49
+ "apt-cache policy #{@new_resource.package_name}",
50
+ :timeout => @timeout
51
+ ).and_return(@shell_out)
48
52
  @provider.load_current_resource
49
53
 
50
54
  current_resource = @provider.current_resource
@@ -84,7 +88,10 @@ libmysqlclient15-dev:
84
88
  Version table:
85
89
  VPKG_STDOUT
86
90
  virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0)
87
- @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient15-dev").and_return(virtual_package)
91
+ @provider.should_receive(:shell_out!).with(
92
+ "apt-cache policy libmysqlclient15-dev",
93
+ :timeout => @timeout
94
+ ).and_return(virtual_package)
88
95
  showpkg_out =<<-SHOWPKG_STDOUT
89
96
  Package: libmysqlclient15-dev
90
97
  Versions:
@@ -104,7 +111,10 @@ libmysqlclient-dev 5.1.41-3ubuntu12.10
104
111
  libmysqlclient-dev 5.1.41-3ubuntu12
105
112
  SHOWPKG_STDOUT
106
113
  showpkg = double(:stdout => showpkg_out,:exitstatus => 0)
107
- @provider.should_receive(:shell_out!).with("apt-cache showpkg libmysqlclient15-dev").and_return(showpkg)
114
+ @provider.should_receive(:shell_out!).with(
115
+ "apt-cache showpkg libmysqlclient15-dev",
116
+ :timeout => @timeout
117
+ ).and_return(showpkg)
108
118
  real_package_out=<<-RPKG_STDOUT
109
119
  libmysqlclient-dev:
110
120
  Installed: 5.1.41-3ubuntu12.10
@@ -119,7 +129,10 @@ libmysqlclient-dev:
119
129
  500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages
120
130
  RPKG_STDOUT
121
131
  real_package = double(:stdout => real_package_out,:exitstatus => 0)
122
- @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient-dev").and_return(real_package)
132
+ @provider.should_receive(:shell_out!).with(
133
+ "apt-cache policy libmysqlclient-dev",
134
+ :timeout => @timeout
135
+ ).and_return(real_package)
123
136
  @provider.load_current_resource
124
137
  end
125
138
 
@@ -132,7 +145,10 @@ mp3-decoder:
132
145
  Version table:
133
146
  VPKG_STDOUT
134
147
  virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0)
135
- @provider.should_receive(:shell_out!).with("apt-cache policy mp3-decoder").and_return(virtual_package)
148
+ @provider.should_receive(:shell_out!).with(
149
+ "apt-cache policy mp3-decoder",
150
+ :timeout => @timeout
151
+ ).and_return(virtual_package)
136
152
  showpkg_out=<<-SHOWPKG_STDOUT
137
153
  Package: mp3-decoder
138
154
  Versions:
@@ -155,7 +171,10 @@ mpg321 0.2.10.6
155
171
  mpg123 1.12.1-0ubuntu1
156
172
  SHOWPKG_STDOUT
157
173
  showpkg = double(:stdout => showpkg_out,:exitstatus => 0)
158
- @provider.should_receive(:shell_out!).with("apt-cache showpkg mp3-decoder").and_return(showpkg)
174
+ @provider.should_receive(:shell_out!).with(
175
+ "apt-cache showpkg mp3-decoder",
176
+ :timeout => @timeout
177
+ ).and_return(showpkg)
159
178
  lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
160
179
  end
161
180
 
@@ -165,13 +184,17 @@ SHOWPKG_STDOUT
165
184
 
166
185
  @new_resource.stub(:default_release).and_return("lenny-backports")
167
186
  @new_resource.stub(:provider).and_return("Chef::Provider::Package::Apt")
168
- @provider.should_receive(:shell_out!).with("apt-cache -o APT::Default-Release=lenny-backports policy irssi").and_return(@shell_out)
187
+ @provider.should_receive(:shell_out!).with(
188
+ "apt-cache -o APT::Default-Release=lenny-backports policy irssi",
189
+ :timeout => @timeout
190
+ ).and_return(@shell_out)
169
191
  @provider.load_current_resource
170
192
  end
171
193
 
172
194
  it "raises an exception if a source is specified (CHEF-5113)" do
173
195
  @new_resource.source "pluto"
174
196
  @provider.define_resource_requirements
197
+ @provider.should_receive(:shell_out!).with("apt-cache policy irssi", {:timeout=>900}).and_return(@shell_out)
175
198
  expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
176
199
  end
177
200
  end
@@ -184,16 +207,20 @@ SHOWPKG_STDOUT
184
207
 
185
208
  describe "install_package" do
186
209
  it "should run apt-get install with the package name and version" do
187
- @provider.should_receive(:shell_out!).
188
- with("apt-get -q -y install irssi=0.8.12-7",
189
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
210
+ @provider.should_receive(:shell_out!). with(
211
+ "apt-get -q -y install irssi=0.8.12-7",
212
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
213
+ :timeout => @timeout
214
+ )
190
215
  @provider.install_package("irssi", "0.8.12-7")
191
216
  end
192
217
 
193
218
  it "should run apt-get install with the package name and version and options if specified" do
194
- @provider.should_receive(:shell_out!).
195
- with("apt-get -q -y --force-yes install irssi=0.8.12-7",
196
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
219
+ @provider.should_receive(:shell_out!).with(
220
+ "apt-get -q -y --force-yes install irssi=0.8.12-7",
221
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
222
+ :timeout => @timeout
223
+ )
197
224
  @new_resource.options("--force-yes")
198
225
  @provider.install_package("irssi", "0.8.12-7")
199
226
  end
@@ -205,9 +232,11 @@ SHOWPKG_STDOUT
205
232
 
206
233
  @provider.new_resource = @new_resource
207
234
 
208
- @provider.should_receive(:shell_out!).
209
- with("apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7",
210
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
235
+ @provider.should_receive(:shell_out!).with(
236
+ "apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7",
237
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
238
+ :timeout => @timeout
239
+ )
211
240
 
212
241
  @provider.install_package("irssi", "0.8.12-7")
213
242
  end
@@ -224,16 +253,20 @@ SHOWPKG_STDOUT
224
253
  describe Chef::Provider::Package::Apt, "remove_package" do
225
254
 
226
255
  it "should run apt-get remove with the package name" do
227
- @provider.should_receive(:shell_out!).
228
- with("apt-get -q -y remove irssi",
229
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
256
+ @provider.should_receive(:shell_out!).with(
257
+ "apt-get -q -y remove irssi",
258
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
259
+ :timeout => @timeout
260
+ )
230
261
  @provider.remove_package("irssi", "0.8.12-7")
231
262
  end
232
263
 
233
264
  it "should run apt-get remove with the package name and options if specified" do
234
- @provider.should_receive(:shell_out!).
235
- with("apt-get -q -y --force-yes remove irssi",
236
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
265
+ @provider.should_receive(:shell_out!).with(
266
+ "apt-get -q -y --force-yes remove irssi",
267
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
268
+ :timeout => @timeout
269
+ )
237
270
  @new_resource.options("--force-yes")
238
271
 
239
272
  @provider.remove_package("irssi", "0.8.12-7")
@@ -243,16 +276,20 @@ SHOWPKG_STDOUT
243
276
  describe "when purging a package" do
244
277
 
245
278
  it "should run apt-get purge with the package name" do
246
- @provider.should_receive(:shell_out!).
247
- with("apt-get -q -y purge irssi",
248
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
279
+ @provider.should_receive(:shell_out!).with(
280
+ "apt-get -q -y purge irssi",
281
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
282
+ :timeout => @timeout
283
+ )
249
284
  @provider.purge_package("irssi", "0.8.12-7")
250
285
  end
251
286
 
252
287
  it "should run apt-get purge with the package name and options if specified" do
253
- @provider.should_receive(:shell_out!).
254
- with("apt-get -q -y --force-yes purge irssi",
255
- :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
288
+ @provider.should_receive(:shell_out!).with(
289
+ "apt-get -q -y --force-yes purge irssi",
290
+ :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
291
+ :timeout => @timeout
292
+ )
256
293
  @new_resource.options("--force-yes")
257
294
 
258
295
  @provider.purge_package("irssi", "0.8.12-7")
@@ -268,17 +305,21 @@ SHOWPKG_STDOUT
268
305
  @provider.should_receive(:get_preseed_file).with("irssi", "0.8.12-7").and_return("/tmp/irssi-0.8.12-7.seed")
269
306
  file = @provider.get_preseed_file("irssi", "0.8.12-7")
270
307
 
271
- @provider.should_receive(:shell_out!).
272
- with("debconf-set-selections /tmp/irssi-0.8.12-7.seed",
273
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
308
+ @provider.should_receive(:shell_out!).with(
309
+ "debconf-set-selections /tmp/irssi-0.8.12-7.seed",
310
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
311
+ :timeout => @timeout
312
+ )
274
313
 
275
314
  @provider.preseed_package(file)
276
315
  end
277
316
 
278
317
  it "should run debconf-set-selections on the preseed file if it has changed" do
279
- @provider.should_receive(:shell_out!).
280
- with("debconf-set-selections /tmp/irssi-0.8.12-7.seed",
281
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil})
318
+ @provider.should_receive(:shell_out!).with(
319
+ "debconf-set-selections /tmp/irssi-0.8.12-7.seed",
320
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil},
321
+ :timeout => @timeout
322
+ )
282
323
  file = @provider.get_preseed_file("irssi", "0.8.12-7")
283
324
  @provider.preseed_package(file)
284
325
  end
@@ -295,9 +336,11 @@ SHOWPKG_STDOUT
295
336
 
296
337
  describe "when reconfiguring a package" do
297
338
  it "should run dpkg-reconfigure package" do
298
- @provider.should_receive(:shell_out!).
299
- with("dpkg-reconfigure irssi",
300
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
339
+ @provider.should_receive(:shell_out!).with(
340
+ "dpkg-reconfigure irssi",
341
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
342
+ :timeout => @timeout
343
+ )
301
344
  @provider.reconfig_package("irssi", "0.8.12-7")
302
345
  end
303
346
  end
@@ -305,9 +348,11 @@ SHOWPKG_STDOUT
305
348
  describe "when installing a virtual package" do
306
349
  it "should install the package without specifying a version" do
307
350
  @provider.is_virtual_package = true
308
- @provider.should_receive(:shell_out!).
309
- with("apt-get -q -y install libmysqlclient-dev",
310
- :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil })
351
+ @provider.should_receive(:shell_out!).with(
352
+ "apt-get -q -y install libmysqlclient-dev",
353
+ :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },
354
+ :timeout => @timeout
355
+ )
311
356
  @provider.install_package("libmysqlclient-dev", "not_a_real_version")
312
357
  end
313
358
  end
@@ -122,46 +122,34 @@ DPKG_S
122
122
 
123
123
  describe Chef::Provider::Package::Dpkg, "install and upgrade" do
124
124
  it "should run dpkg -i with the package source" do
125
- @provider.should_receive(:run_command_with_systems_locale).with({
126
- :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb",
127
- :environment => {
128
- "DEBIAN_FRONTEND" => "noninteractive"
129
- }
130
- })
125
+ @provider.should_receive(:run_noninteractive).with(
126
+ "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
127
+ )
131
128
  @provider.install_package("wget", "1.11.4-1ubuntu1")
132
129
  end
133
130
 
134
131
  it "should run dpkg -i if the package is a path and the source is nil" do
135
132
  @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb")
136
133
  @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
137
- @provider.should_receive(:run_command_with_systems_locale).with({
138
- :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb",
139
- :environment => {
140
- "DEBIAN_FRONTEND" => "noninteractive"
141
- }
142
- })
134
+ @provider.should_receive(:run_noninteractive).with(
135
+ "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
136
+ )
143
137
  @provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1")
144
138
  end
145
139
 
146
140
  it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do
147
141
  @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb")
148
142
  @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
149
- @provider.should_receive(:run_command_with_systems_locale).with({
150
- :command => "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb",
151
- :environment => {
152
- "DEBIAN_FRONTEND" => "noninteractive"
153
- }
154
- })
143
+ @provider.should_receive(:run_noninteractive).with(
144
+ "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
145
+ )
155
146
  @provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1")
156
147
  end
157
148
 
158
149
  it "should run dpkg -i with the package source and options if specified" do
159
- @provider.should_receive(:run_command_with_systems_locale).with({
160
- :command => "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb",
161
- :environment => {
162
- "DEBIAN_FRONTEND" => "noninteractive"
163
- }
164
- })
150
+ @provider.should_receive(:run_noninteractive).with(
151
+ "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb"
152
+ )
165
153
  @new_resource.stub(:options).and_return("--force-yes")
166
154
 
167
155
  @provider.install_package("wget", "1.11.4-1ubuntu1")
@@ -174,44 +162,32 @@ DPKG_S
174
162
 
175
163
  describe Chef::Provider::Package::Dpkg, "remove and purge" do
176
164
  it "should run dpkg -r to remove the package" do
177
- @provider.should_receive(:run_command_with_systems_locale).with({
178
- :command => "dpkg -r wget",
179
- :environment => {
180
- "DEBIAN_FRONTEND" => "noninteractive"
181
- }
182
- })
165
+ @provider.should_receive(:run_noninteractive).with(
166
+ "dpkg -r wget"
167
+ )
183
168
  @provider.remove_package("wget", "1.11.4-1ubuntu1")
184
169
  end
185
170
 
186
171
  it "should run dpkg -r to remove the package with options if specified" do
187
- @provider.should_receive(:run_command_with_systems_locale).with({
188
- :command => "dpkg -r --force-yes wget",
189
- :environment => {
190
- "DEBIAN_FRONTEND" => "noninteractive"
191
- }
192
- })
172
+ @provider.should_receive(:run_noninteractive).with(
173
+ "dpkg -r --force-yes wget"
174
+ )
193
175
  @new_resource.stub(:options).and_return("--force-yes")
194
176
 
195
177
  @provider.remove_package("wget", "1.11.4-1ubuntu1")
196
178
  end
197
179
 
198
180
  it "should run dpkg -P to purge the package" do
199
- @provider.should_receive(:run_command_with_systems_locale).with({
200
- :command => "dpkg -P wget",
201
- :environment => {
202
- "DEBIAN_FRONTEND" => "noninteractive"
203
- }
204
- })
181
+ @provider.should_receive(:run_noninteractive).with(
182
+ "dpkg -P wget"
183
+ )
205
184
  @provider.purge_package("wget", "1.11.4-1ubuntu1")
206
185
  end
207
186
 
208
187
  it "should run dpkg -P to purge the package with options if specified" do
209
- @provider.should_receive(:run_command_with_systems_locale).with({
210
- :command => "dpkg -P --force-yes wget",
211
- :environment => {
212
- "DEBIAN_FRONTEND" => "noninteractive"
213
- }
214
- })
188
+ @provider.should_receive(:run_noninteractive).with(
189
+ "dpkg -P --force-yes wget"
190
+ )
215
191
  @new_resource.stub(:options).and_return("--force-yes")
216
192
 
217
193
  @provider.purge_package("wget", "1.11.4-1ubuntu1")
@@ -0,0 +1,135 @@
1
+ #
2
+ # Author:: Vasiliy Tolstov <v.tolstov@selfip.ru>
3
+ # Copyright:: Copyright (c) 2014 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 'ostruct'
21
+
22
+ # based on the ips specs
23
+
24
+ describe Chef::Provider::Package::Paludis do
25
+ before(:each) do
26
+ @node = Chef::Node.new
27
+ @events = Chef::EventDispatch::Dispatcher.new
28
+ @run_context = Chef::RunContext.new(@node, {}, @events)
29
+ @new_resource = Chef::Resource::Package.new("net/ntp")
30
+ @current_resource = Chef::Resource::Package.new("net/ntp")
31
+ Chef::Resource::Package.stub(:new).and_return(@current_resource)
32
+ @provider = Chef::Provider::Package::Paludis.new(@new_resource, @run_context)
33
+
34
+ @stdin = StringIO.new
35
+ @stderr = StringIO.new
36
+ @stdout =<<-PKG_STATUS
37
+ group/ntp 0 accounts
38
+ group/ntp 0 installed-accounts
39
+ net/ntp 4.2.6_p5-r2 arbor
40
+ user/ntp 0 accounts
41
+ user/ntp 0 installed-accounts
42
+ net/ntp 4.2.6_p5-r1 installed
43
+ PKG_STATUS
44
+ @pid = 12345
45
+ @shell_out = OpenStruct.new(:stdout => @stdout,:stdin => @stdin,:stderr => @stderr,:status => @status,:exitstatus => 0)
46
+ end
47
+
48
+ context "when loading current resource" do
49
+ it "should create a current resource with the name of the new_resource" do
50
+ @provider.should_receive(:shell_out!).and_return(@shell_out)
51
+ Chef::Resource::Package.should_receive(:new).and_return(@current_resource)
52
+ @provider.load_current_resource
53
+ end
54
+
55
+ it "should set the current resources package name to the new resources package name" do
56
+ @provider.should_receive(:shell_out!).and_return(@shell_out)
57
+ @current_resource.should_receive(:package_name).with(@new_resource.package_name)
58
+ @provider.load_current_resource
59
+ end
60
+
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)
63
+ @provider.load_current_resource
64
+ end
65
+
66
+ it "should return new version if package is installed" do
67
+ @stdout.replace(<<-INSTALLED)
68
+ group/ntp 0 accounts
69
+ group/ntp 0 installed-accounts
70
+ net/ntp 4.2.6_p5-r2 arbor
71
+ user/ntp 0 accounts
72
+ user/ntp 0 installed-accounts
73
+ net/ntp 4.2.6_p5-r1 installed
74
+ INSTALLED
75
+ @provider.should_receive(:shell_out!).and_return(@shell_out)
76
+ @provider.load_current_resource
77
+ @current_resource.version.should == "4.2.6_p5-r1"
78
+ @provider.candidate_version.should eql("4.2.6_p5-r2")
79
+ end
80
+
81
+ it "should return the current resource" do
82
+ @provider.should_receive(:shell_out!).and_return(@shell_out)
83
+ @provider.load_current_resource.should eql(@current_resource)
84
+ end
85
+ end
86
+
87
+ context "when installing a package" do
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\"")
90
+ @provider.install_package("net/ntp", "4.2.6_p5-r2")
91
+ end
92
+
93
+
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\"")
96
+ @new_resource.stub(:options).and_return("--preserve-world")
97
+ @provider.install_package("net/ntp", "4.2.6_p5-r2")
98
+ end
99
+
100
+ it "should not contain invalid characters for the version string" do
101
+ @stdout.replace(<<-PKG_STATUS)
102
+ sys-process/lsof 4.87 arbor
103
+ sys-process/lsof 4.87 x86_64
104
+ PKG_STATUS
105
+ @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"")
106
+ @provider.install_package("sys-process/lsof", "4.87")
107
+ end
108
+
109
+ it "should not include the human-readable version in the candidate_version" do
110
+ @stdout.replace(<<-PKG_STATUS)
111
+ sys-process/lsof 4.87 arbor
112
+ sys-process/lsof 4.87 x86_64
113
+ PKG_STATUS
114
+ @provider.should_receive(:shell_out!).and_return(@shell_out)
115
+ @provider.load_current_resource
116
+ @current_resource.version.should be_nil
117
+ @provider.candidate_version.should eql("4.87")
118
+ end
119
+ end
120
+
121
+ context "when upgrading a package" do
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\"")
124
+ @provider.upgrade_package("net/ntp", "4.2.6_p5-r2")
125
+ end
126
+ end
127
+
128
+ context "when uninstalling a package" do
129
+ it "should run pkg uninstall with the package name and version" do
130
+ @provider.should_receive(:shell_out!).with("cave -L warning uninstall -x \"=net/ntp-4.2.6_p5-r2\"")
131
+ @provider.remove_package("net/ntp", "4.2.6_p5-r2")
132
+ end
133
+
134
+ end
135
+ end