chef 11.14.0.alpha.2 → 11.14.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/chef-service-manager +1 -1
  3. data/lib/chef/application.rb +8 -2
  4. data/lib/chef/chef_fs/command_line.rb +4 -4
  5. data/lib/chef/chef_fs/file_system.rb +3 -3
  6. data/lib/chef/chef_fs/parallelizer.rb +66 -90
  7. data/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb +35 -0
  8. data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +279 -0
  9. data/lib/chef/config.rb +36 -2
  10. data/lib/chef/cookbook/cookbook_version_loader.rb +0 -1
  11. data/lib/chef/cookbook/synchronizer.rb +64 -42
  12. data/lib/chef/cookbook_uploader.rb +4 -25
  13. data/lib/chef/cookbook_version.rb +12 -11
  14. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +18 -1
  15. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -3
  16. data/lib/chef/knife/bootstrap.rb +23 -1
  17. data/lib/chef/knife/bootstrap/chef-aix.erb +58 -0
  18. data/lib/chef/knife/bootstrap/chef-full.erb +16 -13
  19. data/lib/chef/knife/core/bootstrap_context.rb +25 -1
  20. data/lib/chef/knife/list.rb +9 -8
  21. data/lib/chef/knife/serve.rb +44 -0
  22. data/lib/chef/knife/show.rb +2 -3
  23. data/lib/chef/knife/ssh.rb +1 -0
  24. data/lib/chef/mixin/create_path.rb +20 -4
  25. data/lib/chef/node.rb +19 -3
  26. data/lib/chef/platform/provider_mapping.rb +0 -1
  27. data/lib/chef/platform/query_helpers.rb +4 -3
  28. data/lib/chef/provider/env/windows.rb +10 -3
  29. data/lib/chef/provider/file.rb +1 -1
  30. data/lib/chef/provider/mount.rb +84 -42
  31. data/lib/chef/provider/package/freebsd/base.rb +92 -0
  32. data/lib/chef/provider/package/freebsd/pkg.rb +113 -0
  33. data/lib/chef/provider/package/freebsd/pkgng.rb +80 -0
  34. data/lib/chef/provider/package/freebsd/port.rb +70 -0
  35. data/lib/chef/providers.rb +3 -1
  36. data/lib/chef/resource/chef_gem.rb +2 -1
  37. data/lib/chef/resource/freebsd_package.rb +39 -3
  38. data/lib/chef/resource/lwrp_base.rb +2 -2
  39. data/lib/chef/resource/mount.rb +9 -9
  40. data/lib/chef/util/threaded_job_queue.rb +61 -0
  41. data/lib/chef/version.rb +1 -1
  42. data/lib/chef/version/platform.rb +2 -0
  43. data/lib/chef/whitelist.rb +82 -0
  44. data/lib/chef/win32/registry.rb +0 -1
  45. data/lib/chef/win32/version.rb +4 -3
  46. data/spec/functional/win32/versions_spec.rb +4 -4
  47. data/spec/integration/client/ipv6_spec.rb +1 -1
  48. data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
  49. data/spec/integration/knife/chef_repo_path_spec.rb +4 -1
  50. data/spec/integration/knife/common_options_spec.rb +9 -9
  51. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
  52. data/spec/integration/knife/deps_spec.rb +3 -0
  53. data/spec/integration/knife/list_spec.rb +3 -0
  54. data/spec/integration/knife/raw_spec.rb +5 -2
  55. data/spec/integration/knife/redirection_spec.rb +4 -1
  56. data/spec/integration/knife/serve_spec.rb +57 -0
  57. data/spec/integration/knife/show_spec.rb +3 -0
  58. data/spec/support/pedant/run_pedant.rb +1 -0
  59. data/spec/support/platform_helpers.rb +7 -5
  60. data/spec/support/shared/context/config.rb +21 -0
  61. data/spec/support/shared/functional/file_resource.rb +52 -0
  62. data/spec/unit/chef_fs/parallelizer.rb +482 -0
  63. data/spec/unit/client_spec.rb +4 -2
  64. data/spec/unit/config_spec.rb +66 -12
  65. data/spec/unit/knife/bootstrap_spec.rb +6 -0
  66. data/spec/unit/knife/core/bootstrap_context_spec.rb +31 -1
  67. data/spec/unit/node_spec.rb +73 -3
  68. data/spec/unit/provider/mount_spec.rb +102 -79
  69. data/spec/unit/provider/package/{freebsd_spec.rb → freebsd/pkg_spec.rb} +19 -32
  70. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +155 -0
  71. data/spec/unit/provider/package/freebsd/port_spec.rb +160 -0
  72. data/spec/unit/resource/chef_gem_spec.rb +5 -0
  73. data/spec/unit/resource/freebsd_package_spec.rb +63 -11
  74. data/spec/unit/resource/mount_spec.rb +11 -0
  75. data/spec/unit/role_spec.rb +5 -1
  76. data/spec/unit/run_lock_spec.rb +2 -0
  77. data/spec/unit/util/threaded_job_queue_spec.rb +51 -0
  78. data/spec/unit/version/platform_spec.rb +1 -1
  79. metadata +162 -147
  80. data/lib/chef/provider/package/freebsd.rb +0 -149
@@ -253,9 +253,11 @@ describe Chef::Client do
253
253
  end
254
254
 
255
255
  def stub_for_node_save
256
+ node.stub(:data_for_save).and_return(node.for_json)
257
+
256
258
  # --Client#save_updated_node
257
259
  Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_node_save)
258
- http_node_save.should_receive(:put_rest).with("nodes/#{fqdn}", node).and_return(true)
260
+ http_node_save.should_receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
259
261
  end
260
262
 
261
263
  def stub_for_run
@@ -270,6 +272,7 @@ describe Chef::Client do
270
272
 
271
273
  before do
272
274
  Chef::Config[:client_fork] = enable_fork
275
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
273
276
 
274
277
  stub_const("Chef::Client::STDOUT_FD", stdout)
275
278
  stub_const("Chef::Client::STDERR_FD", stderr)
@@ -614,4 +617,3 @@ describe Chef::Client do
614
617
 
615
618
  end
616
619
  end
617
-
@@ -138,13 +138,71 @@ describe Chef::Config do
138
138
  end
139
139
 
140
140
  describe "default values" do
141
+ def primary_cache_path
142
+ if windows?
143
+ "#{Chef::Config.env['SYSTEMDRIVE']}\\chef"
144
+ else
145
+ "/var/chef"
146
+ end
147
+ end
141
148
 
142
- it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
143
- backup_path = if windows?
144
- "#{ENV['SYSTEMDRIVE']}\\chef\\backup"
149
+ def secondary_cache_path
150
+ if windows?
151
+ "#{Chef::Config[:user_home]}\\.chef"
152
+ else
153
+ "#{Chef::Config[:user_home]}/.chef"
154
+ end
155
+ end
156
+
157
+ before do
158
+ if windows?
159
+ Chef::Config.stub(:env).and_return({ 'SYSTEMDRIVE' => 'C:' })
160
+ Chef::Config[:user_home] = 'C:\Users\charlie'
145
161
  else
146
- "/var/chef/backup"
162
+ Chef::Config[:user_home] = '/Users/charlie'
163
+ end
164
+
165
+ Chef::Config.stub(:path_accessible?).and_return(false)
166
+ end
167
+
168
+ describe "Chef::Config[:cache_path]" do
169
+ context "when /var/chef exists and is accessible" do
170
+ it "defaults to /var/chef" do
171
+ Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
172
+ Chef::Config[:cache_path].should == primary_cache_path
173
+ end
147
174
  end
175
+
176
+ context "when /var/chef does not exist and /var is accessible" do
177
+ it "defaults to /var/chef" do
178
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
179
+ Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(true)
180
+ Chef::Config[:cache_path].should == primary_cache_path
181
+ end
182
+ end
183
+
184
+ context "when /var/chef does not exist and /var is not accessible" do
185
+ it "defaults to $HOME/.chef" do
186
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
187
+ Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(false)
188
+ Chef::Config[:cache_path].should == secondary_cache_path
189
+ end
190
+ end
191
+
192
+ context "when /var/chef exists and is not accessible" do
193
+ it "defaults to $HOME/.chef" do
194
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
195
+ File.stub(:readable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
196
+ File.stub(:writable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
197
+
198
+ Chef::Config[:cache_path].should == secondary_cache_path
199
+ end
200
+ end
201
+ end
202
+
203
+ it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
204
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
205
+ backup_path = windows? ? "#{primary_cache_path}\\backup" : "#{primary_cache_path}/backup"
148
206
  Chef::Config[:file_backup_path].should == backup_path
149
207
  end
150
208
 
@@ -167,18 +225,14 @@ describe Chef::Config do
167
225
  end
168
226
 
169
227
  it "Chef::Config[:data_bag_path] defaults to /var/chef/data_bags" do
170
- data_bag_path =
171
- Chef::Config.platform_specific_path("/var/chef/data_bags")
228
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
229
+ data_bag_path = windows? ? "#{primary_cache_path}\\data_bags" : "#{primary_cache_path}/data_bags"
172
230
  Chef::Config[:data_bag_path].should == data_bag_path
173
231
  end
174
232
 
175
233
  it "Chef::Config[:environment_path] defaults to /var/chef/environments" do
176
- environment_path = if windows?
177
- "C:\\chef\\environments"
178
- else
179
- "/var/chef/environments"
180
- end
181
-
234
+ Chef::Config.stub(:cache_path).and_return(primary_cache_path)
235
+ environment_path = windows? ? "#{primary_cache_path}\\environments" : "#{primary_cache_path}/environments"
182
236
  Chef::Config[:environment_path].should == environment_path
183
237
  end
184
238
 
@@ -376,6 +376,12 @@ describe Chef::Knife::Bootstrap do
376
376
  @knife.run
377
377
  end
378
378
 
379
+ it "raises the exception if config[:ssh_password] is set and an authentication exception is raised" do
380
+ @knife.config[:ssh_password] = "password"
381
+ @knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed)
382
+ lambda { @knife.run }.should raise_error(Net::SSH::AuthenticationFailed)
383
+ end
384
+
379
385
  context "Chef::Config[:encrypted_data_bag_secret] is set" do
380
386
  let(:secret_file) { File.join(CHEF_SPEC_DATA, 'bootstrap', 'encrypted_data_bag_secret') }
381
387
  before { Chef::Config[:encrypted_data_bag_secret] = secret_file }
@@ -166,5 +166,35 @@ EXPECTED
166
166
  end
167
167
  end
168
168
  end
169
- end
170
169
 
170
+ describe "when a bootstrap_version is specified" do
171
+ let(:chef_config) do
172
+ {
173
+ :knife => {:bootstrap_version => "11.12.4" }
174
+ }
175
+ end
176
+
177
+ it "should send the full version to the installer" do
178
+ bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4")
179
+ end
180
+ end
181
+
182
+ describe "when a pre-release bootstrap_version is specified" do
183
+ let(:chef_config) do
184
+ {
185
+ :knife => {:bootstrap_version => "11.12.4.rc.0" }
186
+ }
187
+ end
188
+
189
+ it "should send the full version to the installer and set the pre-release flag" do
190
+ bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4.rc.0 -p")
191
+ end
192
+ end
193
+
194
+ describe "when a bootstrap_version is not specified" do
195
+ it "should send the latest current to the installer" do
196
+ # Intentionally hard coded in order not to replicate the logic.
197
+ bootstrap_context.latest_current_chef_version_string.should eq("-v 11")
198
+ end
199
+ end
200
+ end
@@ -814,22 +814,25 @@ describe Chef::Node do
814
814
  describe "save" do
815
815
  it "should update a node if it already exists" do
816
816
  node.name("monkey")
817
- @rest.should_receive(:put_rest).with("nodes/monkey", node).and_return("foo")
817
+ node.stub(:data_for_save).and_return({})
818
+ @rest.should_receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
818
819
  node.save
819
820
  end
820
821
 
821
822
  it "should not try and create if it can update" do
822
823
  node.name("monkey")
823
- @rest.should_receive(:put_rest).with("nodes/monkey", node).and_return("foo")
824
+ node.stub(:data_for_save).and_return({})
825
+ @rest.should_receive(:put_rest).with("nodes/monkey", {}).and_return("foo")
824
826
  @rest.should_not_receive(:post_rest)
825
827
  node.save
826
828
  end
827
829
 
828
830
  it "should create if it cannot update" do
829
831
  node.name("monkey")
832
+ node.stub(:data_for_save).and_return({})
830
833
  exception = double("404 error", :code => "404")
831
834
  @rest.should_receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception))
832
- @rest.should_receive(:post_rest).with("nodes", node)
835
+ @rest.should_receive(:post_rest).with("nodes", {})
833
836
  node.save
834
837
  end
835
838
 
@@ -847,6 +850,73 @@ describe Chef::Node do
847
850
  node.save
848
851
  end
849
852
  end
853
+
854
+ context "with whitelisted attributes configured" do
855
+ it "should only save whitelisted attributes (and subattributes)" do
856
+ Chef::Config[:automatic_attribute_whitelist] = [
857
+ ["filesystem", "/dev/disk0s2"],
858
+ "network/interfaces/eth0"
859
+ ]
860
+
861
+ data = {
862
+ "automatic" => {
863
+ "filesystem" => {
864
+ "/dev/disk0s2" => { "size" => "10mb" },
865
+ "map - autohome" => { "size" => "10mb" }
866
+ },
867
+ "network" => {
868
+ "interfaces" => {
869
+ "eth0" => {},
870
+ "eth1" => {}
871
+ }
872
+ }
873
+ },
874
+ "default" => {}, "normal" => {}, "override" => {}
875
+ }
876
+
877
+ selected_data = {
878
+ "automatic" => {
879
+ "filesystem" => {
880
+ "/dev/disk0s2" => { "size" => "10mb" }
881
+ },
882
+ "network" => {
883
+ "interfaces" => {
884
+ "eth0" => {}
885
+ }
886
+ }
887
+ },
888
+ "default" => {}, "normal" => {}, "override" => {}
889
+ }
890
+
891
+ node.name("picky-monkey")
892
+ node.stub(:for_json).and_return(data)
893
+ @rest.should_receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
894
+ node.save
895
+ end
896
+
897
+ it "should not save any attributes if the whitelist is empty" do
898
+ Chef::Config[:automatic_attribute_whitelist] = []
899
+
900
+ data = {
901
+ "automatic" => {
902
+ "filesystem" => {
903
+ "/dev/disk0s2" => { "size" => "10mb" },
904
+ "map - autohome" => { "size" => "10mb" }
905
+ }
906
+ },
907
+ "default" => {}, "normal" => {}, "override" => {}
908
+ }
909
+
910
+ selected_data = {
911
+ "automatic" => {}, "default" => {}, "normal" => {}, "override" => {}
912
+ }
913
+
914
+ node.name("picky-monkey")
915
+ node.stub(:for_json).and_return(data)
916
+ @rest.should_receive(:put_rest).with("nodes/picky-monkey", selected_data).and_return("foo")
917
+ node.save
918
+ end
919
+ end
850
920
  end
851
921
  end
852
922
 
@@ -1,6 +1,7 @@
1
1
  #
2
- # Author:: Joshua Timberman (<joshua@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 OpsCode, Inc.
2
+ # Author:: Joshua Timberman (<joshua@getchef.com>)
3
+ # Author:: Lamont Granquist (<lamont@getchef.com>)
4
+ # Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,152 +20,174 @@
19
20
  require 'spec_helper'
20
21
 
21
22
  describe Chef::Provider::Mount do
22
- before(:each) do
23
- @node = Chef::Node.new
24
- @events = Chef::EventDispatch::Dispatcher.new
25
- @run_context = Chef::RunContext.new(@node, {}, @events)
26
-
27
- @new_resource = Chef::Resource::Mount.new('/tmp/foo')
28
- @new_resource.device "/dev/sdz1"
29
- @new_resource.name "/tmp/foo"
30
- @new_resource.mount_point "/tmp/foo"
31
- @new_resource.fstype "ext3"
32
-
33
- @current_resource = Chef::Resource::Mount.new('/tmp/foo')
34
- @current_resource.device "/dev/sdz1"
35
- @current_resource.name "/tmp/foo"
36
- @current_resource.mount_point "/tmp/foo"
37
- @current_resource.fstype "ext3"
38
-
39
- @provider = Chef::Provider::Mount.new(@new_resource, @run_context)
40
- @provider.current_resource = @current_resource
23
+
24
+ let(:node) { Chef::Node.new }
25
+
26
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
27
+
28
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
29
+
30
+ let(:new_resource) do
31
+ new_resource = Chef::Resource::Mount.new('/tmp/foo')
32
+ new_resource.device "/dev/sdz1"
33
+ new_resource.name "/tmp/foo"
34
+ new_resource.mount_point "/tmp/foo"
35
+ new_resource.fstype "ext3"
36
+ new_resource
37
+ end
38
+
39
+ let(:current_resource) do
40
+ # this abstract superclass has no load_current_resource to call
41
+ current_resource = Chef::Resource::Mount.new('/tmp/foo')
42
+ current_resource.device "/dev/sdz1"
43
+ current_resource.name "/tmp/foo"
44
+ current_resource.mount_point "/tmp/foo"
45
+ current_resource.fstype "ext3"
46
+ current_resource
47
+ end
48
+
49
+ let(:provider) do
50
+ provider = Chef::Provider::Mount.new(new_resource, run_context)
51
+ provider.current_resource = current_resource
52
+ provider
41
53
  end
42
54
 
43
55
  describe "when the target state is a mounted filesystem" do
44
56
 
45
57
  it "should mount the filesystem if it isn't mounted" do
46
- @current_resource.stub(:mounted).and_return(false)
47
- @provider.should_receive(:mount_fs).with.and_return(true)
48
- @provider.run_action(:mount)
49
- @new_resource.should be_updated_by_last_action
58
+ allow(current_resource).to receive(:mounted).and_return(false)
59
+ expect(provider).to receive(:mount_fs).and_return(true)
60
+ provider.run_action(:mount)
61
+ expect(new_resource).to be_updated_by_last_action
50
62
  end
51
63
 
52
64
  it "should not mount the filesystem if it is mounted" do
53
- @current_resource.stub(:mounted).and_return(true)
54
- @provider.should_not_receive(:mount_fs)
55
- @provider.run_action(:mount)
56
- @new_resource.should_not be_updated_by_last_action
65
+ allow(current_resource).to receive(:mounted).and_return(true)
66
+ expect(provider).not_to receive(:mount_fs)
67
+ provider.run_action(:mount)
68
+ expect(new_resource).not_to be_updated_by_last_action
57
69
  end
58
70
 
59
71
  end
60
72
 
61
73
  describe "when the target state is an unmounted filesystem" do
62
74
  it "should umount the filesystem if it is mounted" do
63
- @current_resource.stub(:mounted).and_return(true)
64
- @provider.should_receive(:umount_fs).with.and_return(true)
65
- @provider.run_action(:umount)
66
- @new_resource.should be_updated_by_last_action
75
+ allow(current_resource).to receive(:mounted).and_return(true)
76
+ expect(provider).to receive(:umount_fs).and_return(true)
77
+ provider.run_action(:umount)
78
+ expect(new_resource).to be_updated_by_last_action
67
79
  end
68
80
 
69
81
  it "should not umount the filesystem if it is not mounted" do
70
- @current_resource.stub(:mounted).and_return(false)
71
- @provider.should_not_receive(:umount_fs)
72
- @provider.run_action(:umount)
73
- @new_resource.should_not be_updated_by_last_action
82
+ allow(current_resource).to receive(:mounted).and_return(false)
83
+ expect(provider).not_to receive(:umount_fs)
84
+ provider.run_action(:umount)
85
+ expect(new_resource).not_to be_updated_by_last_action
74
86
  end
75
87
  end
76
88
 
77
89
  describe "when the filesystem should be remounted and the resource supports remounting" do
78
90
  before do
79
- @new_resource.supports[:remount] = true
91
+ new_resource.supports[:remount] = true
80
92
  end
81
93
 
82
94
  it "should remount the filesystem if it is mounted" do
83
- @current_resource.stub(:mounted).and_return(true)
84
- @provider.should_receive(:remount_fs).and_return(true)
85
- @provider.run_action(:remount)
86
- @new_resource.should be_updated_by_last_action
95
+ allow(current_resource).to receive(:mounted).and_return(true)
96
+ expect(provider).to receive(:remount_fs).and_return(true)
97
+ provider.run_action(:remount)
98
+ expect(new_resource).to be_updated_by_last_action
87
99
  end
88
100
 
89
101
  it "should not remount the filesystem if it is not mounted" do
90
- @current_resource.stub(:mounted).and_return(false)
91
- @provider.should_not_receive(:remount_fs)
92
- @provider.run_action(:remount)
93
- @new_resource.should_not be_updated_by_last_action
102
+ allow(current_resource).to receive(:mounted).and_return(false)
103
+ expect(provider).not_to receive(:remount_fs)
104
+ provider.run_action(:remount)
105
+ expect(new_resource).not_to be_updated_by_last_action
94
106
  end
95
107
  end
108
+
96
109
  describe "when the filesystem should be remounted and the resource does not support remounting" do
97
110
  before do
98
- @new_resource.supports[:remount] = false
111
+ new_resource.supports[:remount] = false
112
+ allow(current_resource).to receive(:mounted).and_return(true)
99
113
  end
100
114
 
101
- it "should fail to remount the filesystem" do
102
- @provider.should_not_receive(:remount_fs)
103
- lambda {@provider.run_action(:remount)}.should raise_error(Chef::Exceptions::UnsupportedAction)
104
- @new_resource.should_not be_updated_by_last_action
115
+ it "should try a umount/remount of the filesystem" do
116
+ expect(provider).to receive(:umount_fs)
117
+ expect(provider).to receive(:mounted?).and_return(true, false)
118
+ expect(provider).to receive(:mount_fs)
119
+ provider.run_action(:remount)
120
+ expect(new_resource).to be_updated_by_last_action
105
121
  end
106
122
 
123
+ it "should fail when it runs out of remounts" do
124
+ provider.unmount_retries = 1
125
+ expect(provider).to receive(:umount_fs)
126
+ expect(provider).to receive(:mounted?).and_return(true, true)
127
+ expect{ provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
128
+ end
107
129
  end
130
+
108
131
  describe "when enabling the filesystem to be mounted" do
109
132
  it "should enable the mount if it isn't enable" do
110
- @current_resource.stub(:enabled).and_return(false)
111
- @provider.should_not_receive(:mount_options_unchanged?)
112
- @provider.should_receive(:enable_fs).and_return(true)
113
- @provider.run_action(:enable)
114
- @new_resource.should be_updated_by_last_action
133
+ allow(current_resource).to receive(:enabled).and_return(false)
134
+ expect(provider).not_to receive(:mount_options_unchanged?)
135
+ expect(provider).to receive(:enable_fs).and_return(true)
136
+ provider.run_action(:enable)
137
+ expect(new_resource).to be_updated_by_last_action
115
138
  end
116
139
 
117
140
  it "should enable the mount if it is enabled and mount options have changed" do
118
- @current_resource.stub(:enabled).and_return(true)
119
- @provider.should_receive(:mount_options_unchanged?).and_return(false)
120
- @provider.should_receive(:enable_fs).and_return(true)
121
- @provider.run_action(:enable)
122
- @new_resource.should be_updated_by_last_action
141
+ allow(current_resource).to receive(:enabled).and_return(true)
142
+ expect(provider).to receive(:mount_options_unchanged?).and_return(false)
143
+ expect(provider).to receive(:enable_fs).and_return(true)
144
+ provider.run_action(:enable)
145
+ expect(new_resource).to be_updated_by_last_action
123
146
  end
124
147
 
125
148
  it "should not enable the mount if it is enabled and mount options have not changed" do
126
- @current_resource.stub(:enabled).and_return(true)
127
- @provider.should_receive(:mount_options_unchanged?).and_return(true)
128
- @provider.should_not_receive(:enable_fs)
129
- @provider.run_action(:enable)
130
- @new_resource.should_not be_updated_by_last_action
149
+ allow(current_resource).to receive(:enabled).and_return(true)
150
+ expect(provider).to receive(:mount_options_unchanged?).and_return(true)
151
+ expect(provider).not_to receive(:enable_fs)
152
+ provider.run_action(:enable)
153
+ expect(new_resource).not_to be_updated_by_last_action
131
154
  end
132
155
  end
133
156
 
134
157
  describe "when the target state is to disable the mount" do
135
158
  it "should disable the mount if it is enabled" do
136
- @current_resource.stub(:enabled).and_return(true)
137
- @provider.should_receive(:disable_fs).with.and_return(true)
138
- @provider.run_action(:disable)
139
- @new_resource.should be_updated_by_last_action
159
+ allow(current_resource).to receive(:enabled).and_return(true)
160
+ expect(provider).to receive(:disable_fs).and_return(true)
161
+ provider.run_action(:disable)
162
+ expect(new_resource).to be_updated_by_last_action
140
163
  end
141
164
 
142
165
  it "should not disable the mount if it isn't enabled" do
143
- @current_resource.stub(:enabled).and_return(false)
144
- @provider.should_not_receive(:disable_fs)
145
- @provider.run_action(:disable)
146
- @new_resource.should_not be_updated_by_last_action
166
+ allow(current_resource).to receive(:enabled).and_return(false)
167
+ expect(provider).not_to receive(:disable_fs)
168
+ provider.run_action(:disable)
169
+ expect(new_resource).not_to be_updated_by_last_action
147
170
  end
148
171
  end
149
172
 
150
173
 
151
174
  it "should delegates the mount implementation to subclasses" do
152
- lambda { @provider.mount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
175
+ expect { provider.mount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
153
176
  end
154
177
 
155
178
  it "should delegates the umount implementation to subclasses" do
156
- lambda { @provider.umount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
179
+ expect { provider.umount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
157
180
  end
158
181
 
159
182
  it "should delegates the remount implementation to subclasses" do
160
- lambda { @provider.remount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
183
+ expect { provider.remount_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
161
184
  end
162
185
 
163
186
  it "should delegates the enable implementation to subclasses" do
164
- lambda { @provider.enable_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
187
+ expect { provider.enable_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
165
188
  end
166
189
 
167
190
  it "should delegates the disable implementation to subclasses" do
168
- lambda { @provider.disable_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)
191
+ expect { provider.disable_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
169
192
  end
170
193
  end