chef 10.26.0 → 10.28.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/distro/common/html/chef-client.8.html +4 -4
  2. data/distro/common/html/chef-expander.8.html +4 -4
  3. data/distro/common/html/chef-expanderctl.8.html +4 -4
  4. data/distro/common/html/chef-server-webui.8.html +4 -4
  5. data/distro/common/html/chef-server.8.html +4 -4
  6. data/distro/common/html/chef-solo.8.html +12 -18
  7. data/distro/common/html/chef-solr.8.html +4 -4
  8. data/distro/common/html/knife-bootstrap.1.html +4 -4
  9. data/distro/common/html/knife-client.1.html +4 -4
  10. data/distro/common/html/knife-configure.1.html +4 -4
  11. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  12. data/distro/common/html/knife-cookbook.1.html +7 -10
  13. data/distro/common/html/knife-data-bag.1.html +7 -10
  14. data/distro/common/html/knife-environment.1.html +6 -8
  15. data/distro/common/html/knife-exec.1.html +4 -4
  16. data/distro/common/html/knife-index.1.html +4 -4
  17. data/distro/common/html/knife-node.1.html +4 -4
  18. data/distro/common/html/knife-role.1.html +4 -4
  19. data/distro/common/html/knife-search.1.html +4 -4
  20. data/distro/common/html/knife-ssh.1.html +4 -4
  21. data/distro/common/html/knife-status.1.html +4 -4
  22. data/distro/common/html/knife-tag.1.html +4 -4
  23. data/distro/common/html/knife.1.html +4 -4
  24. data/distro/common/html/shef.1.html +4 -4
  25. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  26. data/distro/common/man/man1/knife-client.1 +1 -1
  27. data/distro/common/man/man1/knife-configure.1 +1 -1
  28. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook.1 +2 -15
  30. data/distro/common/man/man1/knife-data-bag.1 +2 -15
  31. data/distro/common/man/man1/knife-environment.1 +2 -12
  32. data/distro/common/man/man1/knife-exec.1 +1 -1
  33. data/distro/common/man/man1/knife-index.1 +1 -1
  34. data/distro/common/man/man1/knife-node.1 +1 -1
  35. data/distro/common/man/man1/knife-role.1 +1 -1
  36. data/distro/common/man/man1/knife-search.1 +1 -1
  37. data/distro/common/man/man1/knife-ssh.1 +1 -1
  38. data/distro/common/man/man1/knife-status.1 +1 -1
  39. data/distro/common/man/man1/knife-tag.1 +1 -1
  40. data/distro/common/man/man1/knife.1 +1 -1
  41. data/distro/common/man/man1/shef.1 +1 -1
  42. data/distro/common/man/man8/chef-client.8 +1 -1
  43. data/distro/common/man/man8/chef-expander.8 +1 -1
  44. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  45. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  46. data/distro/common/man/man8/chef-server.8 +1 -1
  47. data/distro/common/man/man8/chef-solo.8 +4 -36
  48. data/distro/common/man/man8/chef-solr.8 +1 -1
  49. data/lib/chef/application/windows_service.rb +1 -1
  50. data/lib/chef/config.rb +1 -0
  51. data/lib/chef/cookbook/synchronizer.rb +8 -6
  52. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
  53. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
  54. data/lib/chef/knife/bootstrap/chef-full.erb +3 -3
  55. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
  56. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  57. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
  58. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
  59. data/lib/chef/knife/bootstrap/ubuntu12.10-gems.erb +2 -2
  60. data/lib/chef/knife/core/node_presenter.rb +1 -1
  61. data/lib/chef/mixin/params_validate.rb +19 -6
  62. data/lib/chef/provider/package/portage.rb +9 -4
  63. data/lib/chef/provider/package/rubygems.rb +41 -9
  64. data/lib/chef/provider/package/yum.rb +18 -12
  65. data/lib/chef/resource.rb +9 -7
  66. data/lib/chef/version.rb +1 -1
  67. data/spec/data/cookbooks/openldap/files/default/.dotfile +1 -0
  68. data/spec/data/cookbooks/openldap/files/default/.ssh/id_rsa +1 -0
  69. data/spec/data/cookbooks/openldap/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir +1 -0
  70. data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/.a_dotfile +1 -0
  71. data/spec/data/knife-home/.chef/plugins/knife/example_home_subcommand.rb +0 -0
  72. data/spec/functional/knife/cookbook_delete_spec.rb +1 -1
  73. data/spec/unit/checksum/storage/filesystem_spec.rb +1 -1
  74. data/spec/unit/cookbook/synchronizer_spec.rb +49 -1
  75. data/spec/unit/mixin/params_validate_spec.rb +35 -0
  76. data/spec/unit/provider/env_spec.rb +2 -2
  77. data/spec/unit/provider/group_spec.rb +2 -2
  78. data/spec/unit/provider/package/portage_spec.rb +44 -0
  79. data/spec/unit/provider/package/rubygems_spec.rb +44 -1
  80. data/spec/unit/provider/package/yum_spec.rb +36 -39
  81. data/spec/unit/provider/service/arch_service_spec.rb +1 -1
  82. data/spec/unit/provider/service/freebsd_service_spec.rb +1 -1
  83. data/spec/unit/provider/service/init_service_spec.rb +1 -1
  84. data/spec/unit/provider/service/invokercd_service_spec.rb +1 -1
  85. data/spec/unit/provider/service/upstart_service_spec.rb +2 -2
  86. data/spec/unit/provider/user_spec.rb +1 -1
  87. metadata +1183 -1181
@@ -16,8 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'chef/config'
19
20
  require 'chef/provider/package'
20
21
  require 'chef/mixin/command'
22
+ require 'chef/mixin/shell_out'
21
23
  require 'chef/resource/package'
22
24
  require 'singleton'
23
25
  require 'chef/mixin/get_source_from_package'
@@ -645,6 +647,7 @@ class Chef
645
647
  # Cache for our installed and available packages, pulled in from yum-dump.py
646
648
  class YumCache
647
649
  include Chef::Mixin::Command
650
+ include Chef::Mixin::ShellOut
648
651
  include Singleton
649
652
 
650
653
  def initialize
@@ -705,9 +708,11 @@ class Chef
705
708
  error = nil
706
709
 
707
710
  helper = ::File.join(::File.dirname(__FILE__), 'yum-dump.py')
711
+ status = nil
708
712
 
709
- status = popen4("/usr/bin/python #{helper}#{opts}", :waitlast => true) do |pid, stdin, stdout, stderr|
710
- stdout.each do |line|
713
+ begin
714
+ status = shell_out!("/usr/bin/python #{helper}#{opts}", :timeout => Chef::Config[:yum_timeout])
715
+ status.stdout.each_line do |line|
711
716
  one_line = true
712
717
 
713
718
  line.chomp!
@@ -754,7 +759,10 @@ class Chef
754
759
  @rpmdb << pkg
755
760
  end
756
761
 
757
- error = stderr.readlines
762
+ error = status.stderr
763
+ rescue Mixlib::ShellOut::CommandTimeout => e
764
+ Chef::Log.error("#{helper} exceeded timeout #{Chef::Config[:yum_timeout]}")
765
+ raise(e)
758
766
  end
759
767
 
760
768
  if status.exitstatus != 0
@@ -981,7 +989,7 @@ class Chef
981
989
  end
982
990
 
983
991
  def yum_command(command)
984
- status, stdout, stderr = output_of_command(command, {})
992
+ status, stdout, stderr = output_of_command(command, {:timeout => Chef::Config[:yum_timeout]})
985
993
 
986
994
  # This is fun: rpm can encounter errors in the %post/%postun scripts which aren't
987
995
  # considered fatal - meaning the rpm is still successfully installed. These issue
@@ -998,7 +1006,7 @@ class Chef
998
1006
  if l =~ %r{^error: %(post|postun)\(.*\) scriptlet failed, exit status \d+$}
999
1007
  Chef::Log.warn("#{@new_resource} caught non-fatal scriptlet issue: \"#{l}\". Can't trust yum exit status " +
1000
1008
  "so running install again to verify.")
1001
- status, stdout, stderr = output_of_command(command, {})
1009
+ status, stdout, stderr = output_of_command(command, {:timeout => Chef::Config[:yum_timeout]})
1002
1010
  break
1003
1011
  end
1004
1012
  end
@@ -1062,13 +1070,11 @@ class Chef
1062
1070
  end
1063
1071
 
1064
1072
  Chef::Log.debug("#{@new_resource} checking rpm status")
1065
- status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
1066
- stdout.each do |line|
1067
- case line
1068
- when /([\w\d_.-]+)\s([\w\d_.-]+)/
1069
- @current_resource.package_name($1)
1070
- @new_resource.version($2)
1071
- end
1073
+ shell_out!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}", :timeout => Chef::Config[:yum_timeout]).stdout.each_line do |line|
1074
+ case line
1075
+ when /([\w\d_.-]+)\s([\w\d_.-]+)/
1076
+ @current_resource.package_name($1)
1077
+ @new_resource.version($2)
1072
1078
  end
1073
1079
  end
1074
1080
  end
@@ -789,16 +789,18 @@ F
789
789
 
790
790
  # create a new constructor that wraps the old one and adds the actions
791
791
  # specified in the DSL
792
- old_init = instance_method(:initialize)
792
+ alias_method :old_init, :initialize
793
793
 
794
- define_method(:initialize) do |name, *optional_args|
795
- args_run_context = optional_args.shift
796
- @resource_name = rname.to_sym
797
- old_init.bind(self).call(name, args_run_context)
794
+ new_init =<<INIT
795
+ def initialize(name, run_context=nil)
796
+ @resource_name = "#{rname}".to_sym
797
+ old_init(name, run_context)
798
798
  @action = self.class.action_to_set_default || @action
799
799
  allowed_actions.push(self.class.actions_to_create).flatten!
800
- end
801
- end
800
+ end
801
+ INIT
802
+ class_eval(new_init)
803
+ end
802
804
 
803
805
  # register new class as a Chef::Resource
804
806
  class_name = convert_to_class_name(rname)
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '10.26.0'
20
+ VERSION = '10.28.0.rc.0'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -0,0 +1 @@
1
+ I am here to test .dotfiles work in file directories.
@@ -0,0 +1 @@
1
+ this is a file with a name beginning with a . dot
@@ -42,7 +42,7 @@ describe Chef::Knife::CookbookDelete do
42
42
  @server.stop
43
43
  end
44
44
 
45
- context "when the the cookbook doesn't exist" do
45
+ context "when the cookbook doesn't exist" do
46
46
  before do
47
47
  @log_output = StringIO.new
48
48
 
@@ -36,7 +36,7 @@ describe Chef::Checksum::Storage::Filesystem do
36
36
  @storage.file_location.should == "/var/chef/checksums/3f/3fafecfb15585ede6b840158cbc2f399"
37
37
  end
38
38
 
39
- it "has the path the the file's subdirectory in the checksum repo" do
39
+ it "has the path to the file's subdirectory in the checksum repo" do
40
40
  @storage.checksum_repo_directory.should == "/var/chef/checksums/3f"
41
41
  end
42
42
 
@@ -63,6 +63,7 @@ describe Chef::CookbookSynchronizer do
63
63
  "checksum" => "abc456" }
64
64
  @cookbook_a_manifest["attributes"] = [ @cookbook_a_default_attrs ]
65
65
  @cookbook_a_manifest["templates"] = [{"path" => "templates/default/apache2.conf.erb", "url" => "http://chef.example.com/ffffff"}]
66
+ @cookbook_a_manifest["files"] = [{"path" => "files/default/megaman.conf", "url" => "http://chef.example.com/megaman.conf"}]
66
67
  @cookbook_a.manifest = @cookbook_a_manifest
67
68
  @cookbook_manifest["cookbook_a"] = @cookbook_a
68
69
 
@@ -102,7 +103,7 @@ describe Chef::CookbookSynchronizer do
102
103
  before do
103
104
  # Would rather not stub out methods on the test subject, but setting up
104
105
  # the state is a PITA and tests for this behavior are above.
105
- @synchronizer.should_receive(:clear_obsoleted_cookbooks)
106
+ @synchronizer.stub!(:clear_obsoleted_cookbooks)
106
107
 
107
108
  @server_api = mock("Chef::REST (mock)")
108
109
  @file_cache = mock("Chef::FileCache (mock)")
@@ -162,6 +163,53 @@ describe Chef::CookbookSynchronizer do
162
163
  @synchronizer.sync_cookbooks
163
164
  end
164
165
 
166
+ context "Chef::Config[:no_lazy_load] is true" do
167
+ before do
168
+ Chef::Config[:no_lazy_load] = true
169
+ @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events)
170
+ @synchronizer.stub!(:server_api).and_return(@server_api)
171
+ @synchronizer.stub!(:cache).and_return(@file_cache)
172
+ @synchronizer.stub!(:clear_obsoleted_cookbooks)
173
+
174
+ @cookbook_a_file_default_tempfile = mock("Tempfile for cookbook_a megaman.conf file",
175
+ :path => "/tmp/cookbook_a_file_default_tempfile")
176
+ @cookbook_a_template_default_tempfile = mock("Tempfile for cookbook_a apache.conf.erb template",
177
+ :path => "/tmp/cookbook_a_template_default_tempfile")
178
+ end
179
+
180
+ after do
181
+ Chef::Config[:no_lazy_load] = false
182
+ end
183
+
184
+ it "fetches templates and cookbook files" do
185
+ @file_cache.should_receive(:has_key?).
186
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
187
+ and_return(false)
188
+ @file_cache.should_receive(:has_key?).
189
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
190
+ and_return(false)
191
+
192
+ @server_api.should_receive(:get_rest).
193
+ with('http://chef.example.com/megaman.conf', true).
194
+ and_return(@cookbook_a_file_default_tempfile)
195
+ @file_cache.should_receive(:move_to).
196
+ with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
197
+ @file_cache.should_receive(:load).
198
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
199
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
200
+
201
+ @server_api.should_receive(:get_rest).
202
+ with('http://chef.example.com/ffffff', true).
203
+ and_return(@cookbook_a_template_default_tempfile)
204
+ @file_cache.should_receive(:move_to).
205
+ with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
206
+ @file_cache.should_receive(:load).
207
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
208
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
209
+
210
+ @synchronizer.sync_cookbooks
211
+ end
212
+ end
165
213
  end
166
214
 
167
215
  context "when the cache contains outdated files" do
@@ -366,5 +366,40 @@ describe Chef::Mixin::ParamsValidate do
366
366
  @vo.set_or_return(:name, value, { }).object_id.should == value.object_id
367
367
  @vo.set_or_return(:foo, nil, { :name_attribute => true }).object_id.should == value.object_id
368
368
  end
369
+
370
+ it "should allow DelayedEvaluator instance to be set for value regardless of restriction" do
371
+ value = Chef::DelayedEvaluator.new{ 'test' }
372
+ @vo.set_or_return(:test, value, {:kind_of => Numeric})
373
+ end
374
+
375
+ it "should raise an error when delayed evaluated attribute is not valid" do
376
+ value = Chef::DelayedEvaluator.new{ 'test' }
377
+ @vo.set_or_return(:test, value, {:kind_of => Numeric})
378
+ lambda do
379
+ @vo.set_or_return(:test, nil, {:kind_of => Numeric})
380
+ end.should raise_error(Chef::Exceptions::ValidationFailed)
381
+ end
382
+
383
+ it "should create DelayedEvaluator instance when #lazy is used" do
384
+ @vo.set_or_return(:delayed, @vo.lazy{ 'test' }, {})
385
+ @vo.instance_variable_get(:@delayed).should be_a(Chef::DelayedEvaluator)
386
+ end
387
+
388
+ it "should execute block on each call when DelayedEvaluator" do
389
+ value = 'fubar'
390
+ @vo.set_or_return(:test, @vo.lazy{ value }, {})
391
+ @vo.set_or_return(:test, nil, {}).should == 'fubar'
392
+ value = 'foobar'
393
+ @vo.set_or_return(:test, nil, {}).should == 'foobar'
394
+ value = 'fauxbar'
395
+ @vo.set_or_return(:test, nil, {}).should == 'fauxbar'
396
+ end
397
+
398
+ it "should not evaluate non DelayedEvaluator instances" do
399
+ value = lambda{ 'test' }
400
+ @vo.set_or_return(:test, value, {})
401
+ @vo.set_or_return(:test, nil, {}).object_id.should == value.object_id
402
+ @vo.set_or_return(:test, nil, {}).should be_a(Proc)
403
+ end
369
404
 
370
405
  end
@@ -81,7 +81,7 @@ describe Chef::Provider::Env do
81
81
  @provider.action_create
82
82
  end
83
83
 
84
- it "should set the the new_resources updated flag when it creates the key" do
84
+ it "should set the new_resources updated flag when it creates the key" do
85
85
  @provider.action_create
86
86
  @new_resource.should be_updated
87
87
  end
@@ -99,7 +99,7 @@ describe Chef::Provider::Env do
99
99
  @provider.action_create
100
100
  end
101
101
 
102
- it "should set the the new_resources updated flag when it updates an existing value" do
102
+ it "should set the new_resources updated flag when it updates an existing value" do
103
103
  @provider.key_exists = true
104
104
  @provider.stub!(:compare_value).and_return(true)
105
105
  @provider.stub!(:modify_env).and_return(true)
@@ -117,7 +117,7 @@ describe Chef::Provider::User do
117
117
  @provider.run_action(:create)
118
118
  end
119
119
 
120
- it "should set the the new_resources updated flag when it creates the group" do
120
+ it "should set the new_resources updated flag when it creates the group" do
121
121
  @provider.group_exists = false
122
122
  @provider.stub!(:create_group)
123
123
  @provider.run_action(:create)
@@ -138,7 +138,7 @@ describe Chef::Provider::User do
138
138
  @provider.run_action(:create)
139
139
  end
140
140
 
141
- it "should set the the new_resources updated flag when it creates the group if we call manage_group" do
141
+ it "should set the new_resources updated flag when it creates the group if we call manage_group" do
142
142
  @provider.group_exists = true
143
143
  @provider.stub!(:compare_group).and_return(true)
144
144
  @provider.stub!(:manage_group).and_return(true)
@@ -230,6 +230,50 @@ EOF
230
230
  lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package)
231
231
  end
232
232
 
233
+ it "should find the candidate_version if a category is specifed and there are category duplicates" do
234
+ output = <<EOF
235
+ Searching...
236
+ [ Results for search key : git ]
237
+ [ Applications found : 14 ]
238
+
239
+ * app-misc/digitemp [ Masked ]
240
+ Latest version available: 3.5.0
241
+ Latest version installed: [ Not Installed ]
242
+ Size of files: 261 kB
243
+ Homepage: http://www.digitemp.com/ http://www.ibutton.com/
244
+ Description: Temperature logging and reporting using Dallas Semiconductor's iButtons and 1-Wire protocol
245
+ License: GPL-2
246
+
247
+ * app-misc/git
248
+ Latest version available: 4.3.20
249
+ Latest version installed: [ Not Installed ]
250
+ Size of files: 416 kB
251
+ Homepage: http://www.gnu.org/software/git/
252
+ Description: GNU Interactive Tools - increase speed and efficiency of most daily task
253
+ License: GPL-2
254
+
255
+ * dev-util/git
256
+ Latest version available: 1.6.0.6
257
+ Latest version installed: ignore
258
+ Size of files: 2,725 kB
259
+ Homepage: http://git.or.cz/
260
+ Description: GIT - the stupid content tracker, the revision control system heavily used by the Linux kernel team
261
+ License: GPL-2
262
+
263
+ * dev-util/gitosis [ Masked ]
264
+ Latest version available: 0.2_p20080825
265
+ Latest version installed: [ Not Installed ]
266
+ Size of files: 31 kB
267
+ Homepage: http://eagain.net/gitweb/?p=gitosis.git;a=summary
268
+ Description: gitosis -- software for hosting git repositories
269
+ License: GPL-2
270
+ EOF
271
+
272
+ @status = mock("Status", :exitstatus => 0)
273
+ @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context)
274
+ @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status)
275
+ @provider.candidate_version.should == "1.6.0.6"
276
+ end
233
277
  end
234
278
 
235
279
  describe Chef::Provider::Package::Portage, "install_package" do
@@ -95,6 +95,49 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do
95
95
  @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0')
96
96
  end
97
97
 
98
+ it "finds a matching gem candidate version on rubygems 2.0.0+" do
99
+ dep = Gem::Dependency.new('rspec', '>= 0')
100
+ dep_installer = Gem::DependencyInstaller.new
101
+ @gem_env.stub!(:dependency_installer).and_return(dep_installer)
102
+ best_gem = mock("best gem match", :spec => gemspec("rspec", Gem::Version.new("1.3.0")), :source => "https://rubygems.org")
103
+ available_set = mock("Gem::AvailableSet test double")
104
+ available_set.should_receive(:pick_best!)
105
+ available_set.should_receive(:set).and_return([best_gem])
106
+ dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(available_set)
107
+ @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0')
108
+ end
109
+
110
+ context "when rubygems was upgraded from 1.8->2.0" do
111
+ # https://github.com/rubygems/rubygems/issues/404
112
+ # tl;dr rubygems 1.8 and 2.0 can both be in the load path, which means that
113
+ # require "rubygems/format" will load even though rubygems 2.0 doesn't have
114
+ # that file.
115
+
116
+ before do
117
+ if defined?(Gem::Format)
118
+ # tests are running under rubygems 1.8, or 2.0 upgraded from 1.8
119
+ @remove_gem_format = false
120
+ else
121
+ Gem.const_set(:Format, Object.new)
122
+ @remove_gem_format = true
123
+ end
124
+ Gem::Package.stub!(:respond_to?).with(:open).and_return(false)
125
+ end
126
+
127
+ after do
128
+ if @remove_gem_format
129
+ Gem.send(:remove_const, :Format)
130
+ end
131
+ end
132
+
133
+ it "finds a matching gem candidate version on rubygems 2.0+ with some rubygems 1.8 code loaded" do
134
+ package = mock("Gem::Package", :spec => "a gemspec from package")
135
+ Gem::Package.should_receive(:new).with("/path/to/package.gem").and_return(package)
136
+ @gem_env.spec_from_file("/path/to/package.gem").should == "a gemspec from package"
137
+ end
138
+
139
+ end
140
+
98
141
  it "gives the candidate version as nil if none is found" do
99
142
  dep = Gem::Dependency.new('rspec', '>= 0')
100
143
  latest = []
@@ -213,7 +256,7 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do
213
256
  it "determines the installed versions of gems from the source index (part2: the unmockening)" do
214
257
  $stdout.stub!(:write)
215
258
  path_to_gem = if windows?
216
- `where gem`.split[-1]
259
+ `where gem`.split[1]
217
260
  else
218
261
  `which gem`.strip
219
262
  end
@@ -39,7 +39,6 @@ describe Chef::Provider::Package::Yum do
39
39
  )
40
40
  Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
41
41
  @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
42
- @stderr = StringIO.new
43
42
  @pid = mock("PID")
44
43
  end
45
44
 
@@ -542,7 +541,7 @@ describe Chef::Provider::Package::Yum do
542
541
  it "should call action_upgrade in the parent if the candidate version is nil" do
543
542
  @provider.load_current_resource
544
543
  @current_resource = Chef::Resource::Package.new('cups')
545
- @provider.candidate_version = nil
544
+ @provider.candidate_version = nil
546
545
  @provider.should_not_receive(:upgrade_package)
547
546
  @provider.action_upgrade
548
547
  end
@@ -600,7 +599,7 @@ describe Chef::Provider::Package::Yum do
600
599
  @provider.stub!(:output_of_command).and_return([@status, "", ""])
601
600
  @provider.should_receive(:output_of_command).once.with(
602
601
  "yum -d0 -e0 -y install emacs-1.0",
603
- {}
602
+ {:timeout => Chef::Config[:yum_timeout]}
604
603
  )
605
604
  @provider.yum_command("yum -d0 -e0 -y install emacs-1.0")
606
605
  end
@@ -610,7 +609,7 @@ describe Chef::Provider::Package::Yum do
610
609
  @provider.stub!(:output_of_command).and_return([@status, "failure failure", "problem problem"])
611
610
  @provider.should_receive(:output_of_command).once.with(
612
611
  "yum -d0 -e0 -y install emacs-1.0",
613
- {}
612
+ {:timeout => Chef::Config[:yum_timeout]}
614
613
  )
615
614
  lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec)
616
615
  end
@@ -620,7 +619,7 @@ describe Chef::Provider::Package::Yum do
620
619
  @provider.stub!(:output_of_command).and_return([@status, "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""])
621
620
  @provider.should_receive(:output_of_command).once.with(
622
621
  "yum -d0 -e0 -y install emacs-1.0",
623
- {}
622
+ {:timeout => Chef::Config[:yum_timeout]}
624
623
  )
625
624
  # will still raise an exception, can't stub out the subsequent call
626
625
  lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec)
@@ -631,7 +630,7 @@ describe Chef::Provider::Package::Yum do
631
630
  @provider.stub!(:output_of_command).and_return([@status, "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""])
632
631
  @provider.should_receive(:output_of_command).twice.with(
633
632
  "yum -d0 -e0 -y install emacs-1.0",
634
- {}
633
+ {:timeout => Chef::Config[:yum_timeout]}
635
634
  )
636
635
  # will still raise an exception, can't stub out the subsequent call
637
636
  lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec)
@@ -1155,7 +1154,7 @@ describe Chef::Provider::Package::Yum::RPMDbPackage do
1155
1154
 
1156
1155
  describe "repoid" do
1157
1156
  it "should return the source repository repoid" do
1158
- @rpm_x.repoid.should be == "base"
1157
+ @rpm_x.repoid.should be == "base"
1159
1158
  @rpm_y.repoid.should be == "extras"
1160
1159
  @rpm_z.repoid.should be == "other"
1161
1160
  end
@@ -1544,7 +1543,10 @@ describe Chef::Provider::Package::Yum::YumCache do
1544
1543
  end
1545
1544
 
1546
1545
  before(:each) do
1547
- yum_dump_good_output = <<EOF
1546
+ @stdin = mock("STDIN", :nil_object => true)
1547
+ @stdout = mock("STDOUT", :nil_object => true)
1548
+
1549
+ @stdout_good = <<EOF
1548
1550
  [option installonlypkgs] kernel kernel-bigmem kernel-enterprise
1549
1551
  erlang-mochiweb 0 1.4.1 5.el5 x86_64 ['erlang-mochiweb = 1.4.1-5.el5', 'mochiweb = 1.4.1-5.el5'] i installed
1550
1552
  zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
@@ -1560,9 +1562,16 @@ znc-extra 0 0.098 1.el5 x86_64 [] a base
1560
1562
  znc-modtcl 0 0.098 1.el5 x86_64 [] a base
1561
1563
  znc-test.beta1 0 0.098 1.el5 x86_64 [] a extras
1562
1564
  znc-test.test.beta1 0 0.098 1.el5 x86_64 [] a base
1565
+ EOF
1566
+ @stdout_bad_type = <<EOF
1567
+ zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
1568
+ zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] c base
1569
+ zlib-devel 0 1.2.3 3 i386 [] a extras
1570
+ zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] bad installed
1571
+ znc-modtcl 0 0.098 1.el5 x86_64 [] a base
1563
1572
  EOF
1564
1573
 
1565
- yum_dump_bad_output_separators = <<EOF
1574
+ @stdout_bad_separators = <<EOF
1566
1575
  zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
1567
1576
  zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] i base bad
1568
1577
  zlib-devel 0 1.2.3 3 i386 [] a extras
@@ -1570,36 +1579,20 @@ bad zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] i installed
1570
1579
  znc-modtcl 0 0.098 1.el5 x86_64 [] a base bad
1571
1580
  EOF
1572
1581
 
1573
- yum_dump_bad_output_type = <<EOF
1574
- zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
1575
- zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] c base
1576
- zlib-devel 0 1.2.3 3 i386 [] a extras
1577
- zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] bad installed
1578
- znc-modtcl 0 0.098 1.el5 x86_64 [] a base
1579
- EOF
1582
+ @stdout_no_output = ""
1580
1583
 
1581
- yum_dump_error = <<EOF
1584
+ @stderr = <<EOF
1582
1585
  yum-dump Config Error: File contains no section headers.
1583
1586
  file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12
1584
1587
  'qeqwewe\n'
1585
1588
  EOF
1586
-
1587
- @status = mock("Status", :exitstatus => 0)
1588
- @status_bad = mock("Status", :exitstatus => 1)
1589
- @stdin = mock("STDIN", :nil_object => true)
1590
- @stdout = mock("STDOUT", :nil_object => true)
1591
- @stdout_good = yum_dump_good_output.split("\n")
1592
- @stdout_bad_type = yum_dump_bad_output_type.split("\n")
1593
- @stdout_bad_separators = yum_dump_bad_output_separators.split("\n")
1594
- @stderr = mock("STDERR", :nil_object => true)
1595
- @stderr.stub!(:readlines).and_return(yum_dump_error.split("\n"))
1596
- @pid = mock("PID", :nil_object => true)
1589
+ @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr)
1597
1590
 
1598
1591
  # new singleton each time
1599
1592
  Chef::Provider::Package::Yum::YumCache.reset_instance
1600
1593
  @yc = Chef::Provider::Package::Yum::YumCache.instance
1601
1594
  # load valid data
1602
- @yc.stub!(:popen4).and_yield(@pid, @stdin, @stdout_good, @stderr).and_return(@status)
1595
+ @yc.stub!(:shell_out!).and_return(@status)
1603
1596
  end
1604
1597
 
1605
1598
  describe "initialize" do
@@ -1618,7 +1611,7 @@ EOF
1618
1611
 
1619
1612
  describe "refresh" do
1620
1613
  it "should implicitly call yum-dump.py only once by default after being instantiated" do
1621
- @yc.should_receive(:popen4).once
1614
+ @yc.should_receive(:shell_out!).once
1622
1615
  @yc.installed_version("zlib")
1623
1616
  @yc.reset
1624
1617
  @yc.installed_version("zlib")
@@ -1626,48 +1619,52 @@ EOF
1626
1619
 
1627
1620
  it "should run yum-dump.py using the system python when next_refresh is for :all" do
1628
1621
  @yc.reload
1629
- @yc.should_receive(:popen4).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides$}, :waitlast=>true)
1622
+ @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides$}, :timeout=>Chef::Config[:yum_timeout])
1630
1623
  @yc.refresh
1631
1624
  end
1632
1625
 
1633
1626
  it "should run yum-dump.py with the installed flag when next_refresh is for :installed" do
1634
1627
  @yc.reload_installed
1635
- @yc.should_receive(:popen4).with(%r{^/usr/bin/python .*/yum-dump.py --installed$}, :waitlast=>true)
1628
+ @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed$}, :timeout=>Chef::Config[:yum_timeout])
1636
1629
  @yc.refresh
1637
1630
  end
1638
1631
 
1639
1632
  it "should run yum-dump.py with the all-provides flag when next_refresh is for :provides" do
1640
1633
  @yc.reload_provides
1641
- @yc.should_receive(:popen4).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides$}, :waitlast=>true)
1634
+ @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides$}, :timeout=>Chef::Config[:yum_timeout])
1642
1635
  @yc.refresh
1643
1636
  end
1644
1637
 
1645
1638
  it "should pass extra_repo_control args to yum-dump.py" do
1646
1639
  @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar")
1647
- @yc.should_receive(:popen4).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar$}, :waitlast=>true)
1640
+ @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar$}, :timeout=>Chef::Config[:yum_timeout])
1648
1641
  @yc.refresh
1649
1642
  end
1650
1643
 
1651
1644
  it "should warn about invalid data with too many separators" do
1652
- @yc.stub!(:popen4).and_yield(@pid, @stdin, @stdout_bad_separators, @stderr).and_return(@status)
1645
+ @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_separators, :stderr => @stderr)
1646
+ @yc.stub!(:shell_out!).and_return(@status)
1653
1647
  Chef::Log.should_receive(:warn).exactly(3).times.with(%r{Problem parsing})
1654
1648
  @yc.refresh
1655
1649
  end
1656
1650
 
1657
1651
  it "should warn about invalid data with an incorrect type" do
1658
- @yc.stub!(:popen4).and_yield(@pid, @stdin, @stdout_bad_type, @stderr).and_return(@status)
1652
+ @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_type, :stderr => @stderr)
1653
+ @yc.stub!(:shell_out!).and_return(@status)
1659
1654
  Chef::Log.should_receive(:warn).exactly(2).times.with(%r{Problem parsing})
1660
1655
  @yc.refresh
1661
1656
  end
1662
1657
 
1663
1658
  it "should warn about no output from yum-dump.py" do
1664
- @yc.stub!(:popen4).and_yield(@pid, @stdin, [], @stderr).and_return(@status)
1659
+ @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr)
1660
+ @yc.stub!(:shell_out!).and_return(@status)
1665
1661
  Chef::Log.should_receive(:warn).exactly(1).times.with(%r{no output from yum-dump.py})
1666
1662
  @yc.refresh
1667
1663
  end
1668
1664
 
1669
1665
  it "should raise exception yum-dump.py exits with a non zero status" do
1670
- @yc.stub!(:popen4).and_yield(@pid, @stdin, [], @stderr).and_return(@status_bad)
1666
+ @status = mock("Status", :exitstatus => 1, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr)
1667
+ @yc.stub!(:shell_out!).and_return(@status)
1671
1668
  lambda { @yc.refresh}.should raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12})
1672
1669
  end
1673
1670
 
@@ -1792,7 +1789,7 @@ EOF
1792
1789
  end
1793
1790
 
1794
1791
  it "should return nil when no match for package-version, no arch" do
1795
- @yc.package_repository("zisofs-tools", "pretend", nil).should be == nil
1792
+ @yc.package_repository("zisofs-tools", "pretend", nil).should be == nil
1796
1793
  @yc.package_repository("zisofs-tools", "pretend").should be == nil
1797
1794
  @yc.package_repository("pretend", "1.0.6-3.2.2").should be == nil
1798
1795
  end