chef 10.14.4 → 10.16.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) 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 +182 -0
  6. data/distro/common/html/chef-solo.8.html +4 -4
  7. data/distro/common/html/chef-solr.8.html +4 -4
  8. data/distro/common/html/knife-bootstrap.1.html +5 -5
  9. data/distro/common/html/knife-client.1.html +4 -4
  10. data/distro/common/html/knife-configure.1.html +5 -5
  11. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  12. data/distro/common/html/knife-cookbook.1.html +8 -8
  13. data/distro/common/html/knife-data-bag.1.html +4 -4
  14. data/distro/common/html/knife-environment.1.html +7 -7
  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 +5 -5
  18. data/distro/common/html/knife-role.1.html +4 -4
  19. data/distro/common/html/knife-search.1.html +6 -6
  20. data/distro/common/html/knife-ssh.1.html +4 -4
  21. data/distro/common/html/knife-status.1.html +5 -5
  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 +1 -1
  30. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  31. data/distro/common/man/man1/knife-environment.1 +1 -1
  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 +1 -1
  48. data/distro/common/man/man8/chef-solr.8 +1 -1
  49. data/distro/debian/etc/init.d/chef-client +1 -1
  50. data/distro/debian/etc/init.d/chef-expander +1 -1
  51. data/distro/debian/etc/init.d/chef-server +1 -1
  52. data/distro/debian/etc/init.d/chef-server-webui +1 -1
  53. data/distro/debian/etc/init.d/chef-solr +1 -1
  54. data/lib/chef/application/client.rb +3 -3
  55. data/lib/chef/client.rb +4 -1
  56. data/lib/chef/config.rb +2 -1
  57. data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -0
  58. data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -0
  59. data/lib/chef/knife/bootstrap/chef-full.erb +2 -1
  60. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -0
  61. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -0
  62. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -0
  63. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -0
  64. data/lib/chef/knife/configure.rb +19 -0
  65. data/lib/chef/knife/data_bag_from_file.rb +1 -1
  66. data/lib/chef/knife/environment_from_file.rb +41 -8
  67. data/lib/chef/knife/ssh.rb +5 -1
  68. data/lib/chef/provider/cookbook_file.rb +4 -4
  69. data/lib/chef/provider/directory.rb +3 -0
  70. data/lib/chef/provider/file.rb +49 -3
  71. data/lib/chef/provider/ifconfig.rb +1 -1
  72. data/lib/chef/provider/package.rb +2 -0
  73. data/lib/chef/provider/package/pacman.rb +10 -1
  74. data/lib/chef/provider/remote_file.rb +1 -1
  75. data/lib/chef/provider/service.rb +22 -0
  76. data/lib/chef/provider/template.rb +9 -1
  77. data/lib/chef/resource.rb +1 -1
  78. data/lib/chef/resource/cookbook_file.rb +1 -0
  79. data/lib/chef/resource/cron.rb +5 -0
  80. data/lib/chef/resource/deploy.rb +6 -1
  81. data/lib/chef/resource/directory.rb +6 -0
  82. data/lib/chef/resource/env.rb +5 -0
  83. data/lib/chef/resource/erl_call.rb +3 -0
  84. data/lib/chef/resource/execute.rb +3 -0
  85. data/lib/chef/resource/file.rb +5 -5
  86. data/lib/chef/resource/group.rb +5 -0
  87. data/lib/chef/resource/http_request.rb +3 -0
  88. data/lib/chef/resource/ifconfig.rb +5 -0
  89. data/lib/chef/resource/link.rb +6 -1
  90. data/lib/chef/resource/log.rb +19 -16
  91. data/lib/chef/resource/mdadm.rb +5 -0
  92. data/lib/chef/resource/mount.rb +5 -0
  93. data/lib/chef/resource/ohai.rb +14 -0
  94. data/lib/chef/resource/package.rb +2 -1
  95. data/lib/chef/resource/remote_directory.rb +5 -0
  96. data/lib/chef/resource/route.rb +6 -1
  97. data/lib/chef/resource/ruby_block.rb +11 -0
  98. data/lib/chef/resource/scm.rb +4 -0
  99. data/lib/chef/resource/script.rb +3 -0
  100. data/lib/chef/resource/service.rb +5 -0
  101. data/lib/chef/resource/subversion.rb +2 -1
  102. data/lib/chef/resource/template.rb +1 -0
  103. data/lib/chef/resource/user.rb +4 -0
  104. data/lib/chef/resource_reporter.rb +71 -27
  105. data/lib/chef/rest.rb +8 -4
  106. data/lib/chef/run_list.rb +2 -2
  107. data/lib/chef/scan_access_control.rb +1 -1
  108. data/lib/chef/version.rb +1 -1
  109. data/spec/unit/client_spec.rb +6 -2
  110. data/spec/unit/knife/configure_spec.rb +121 -25
  111. data/spec/unit/knife/data_bag_from_file_spec.rb +5 -3
  112. data/spec/unit/knife/environment_from_file_spec.rb +23 -0
  113. data/spec/unit/provider/cookbook_file_spec.rb +3 -0
  114. data/spec/unit/provider/directory_spec.rb +16 -17
  115. data/spec/unit/provider/file_spec.rb +75 -0
  116. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  117. data/spec/unit/provider/package/pacman_spec.rb +29 -0
  118. data/spec/unit/provider/package_spec.rb +4 -0
  119. data/spec/unit/provider/remote_directory_spec.rb +6 -1
  120. data/spec/unit/provider/remote_file_spec.rb +7 -0
  121. data/spec/unit/resource/cookbook_file_spec.rb +42 -1
  122. data/spec/unit/resource/cron_spec.rb +27 -0
  123. data/spec/unit/resource/deploy_spec.rb +27 -0
  124. data/spec/unit/resource/directory_spec.rb +20 -0
  125. data/spec/unit/resource/env_spec.rb +19 -0
  126. data/spec/unit/resource/erl_call_spec.rb +12 -0
  127. data/spec/unit/resource/execute_spec.rb +16 -0
  128. data/spec/unit/resource/group_spec.rb +17 -1
  129. data/spec/unit/resource/http_request_spec.rb +13 -0
  130. data/spec/unit/resource/ifconfig_spec.rb +46 -0
  131. data/spec/unit/resource/link_spec.rb +21 -0
  132. data/spec/unit/resource/log_spec.rb +10 -0
  133. data/spec/unit/resource/mdadm_spec.rb +22 -0
  134. data/spec/unit/resource/mount_spec.rb +20 -0
  135. data/spec/unit/resource/ohai_spec.rb +18 -0
  136. data/spec/unit/resource/package_spec.rb +3 -0
  137. data/spec/unit/resource/remote_directory_spec.rb +22 -0
  138. data/spec/unit/resource/remote_file_spec.rb +40 -0
  139. data/spec/unit/resource/route_spec.rb +19 -0
  140. data/spec/unit/resource/ruby_block_spec.rb +11 -0
  141. data/spec/unit/resource/scm_spec.rb +20 -0
  142. data/spec/unit/resource/script_spec.rb +14 -0
  143. data/spec/unit/resource/service_spec.rb +21 -0
  144. data/spec/unit/resource/user_spec.rb +21 -0
  145. data/spec/unit/resource_reporter_spec.rb +260 -134
  146. data/spec/unit/run_list_spec.rb +14 -0
  147. metadata +15 -10
@@ -233,16 +233,20 @@ class Chef
233
233
  end
234
234
  end
235
235
 
236
- # Runs an HTTP request to a JSON API. File Download not supported.
236
+ # Runs an HTTP request to a JSON API with JSON body. File Download not supported.
237
237
  def api_request(method, url, headers={}, data=false)
238
238
  json_body = data ? Chef::JSONCompat.to_json(data) : nil
239
239
  # Force encoding to binary to fix SSL related EOFErrors
240
240
  # cf. http://tickets.opscode.com/browse/CHEF-2363
241
241
  # http://redmine.ruby-lang.org/issues/5233
242
242
  json_body.force_encoding(Encoding::BINARY) if json_body.respond_to?(:force_encoding)
243
- headers = build_headers(method, url, headers, json_body)
244
-
245
- retriable_rest_request(method, url, json_body, headers) do |rest_request|
243
+ raw_http_request(method, url, headers, json_body)
244
+ end
245
+
246
+ # Runs an HTTP request to a JSON API with raw body. File Download not supported.
247
+ def raw_http_request(method, url, headers, body)
248
+ headers = build_headers(method, url, headers, body)
249
+ retriable_rest_request(method, url, body, headers) do |rest_request|
246
250
  begin
247
251
  response = rest_request.call {|r| r.read_body}
248
252
 
@@ -29,7 +29,7 @@ class Chef
29
29
  include Enumerable
30
30
  include Chef::Mixin::ParamsValidate
31
31
 
32
- # @run_list_items is an array of RunListItems that describe the items to
32
+ # @run_list_items is an array of RunListItems that describe the items to
33
33
  # execute in order. RunListItems can load from and convert to the string
34
34
  # forms users set on roles and nodes.
35
35
  # For example:
@@ -67,6 +67,7 @@ class Chef
67
67
  end
68
68
 
69
69
  alias :push :<<
70
+ alias :add :<<
70
71
 
71
72
  def ==(other)
72
73
  if other.kind_of?(Chef::RunList)
@@ -162,4 +163,3 @@ class Chef
162
163
 
163
164
  end
164
165
  end
165
-
@@ -46,7 +46,7 @@ class Chef
46
46
 
47
47
  # Modifies @current_resource, setting the current access control state.
48
48
  def set_all!
49
- if File.exist?(new_resource.path)
49
+ if ::File.exist?(new_resource.path)
50
50
  set_owner
51
51
  set_group
52
52
  set_mode
@@ -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.14.4'
20
+ VERSION = '10.16.0.rc.0'
21
21
  end
22
22
 
23
23
  # NOTE: the Chef::Version class is defined in version_class.rb
@@ -239,12 +239,16 @@ shared_examples_for Chef::Client do
239
239
  @node.chef_environment("_default")
240
240
  @node[:platform] = "example-platform"
241
241
  @node[:platform_version] = "example-platform-1.0"
242
+ end
242
243
 
243
- @client = Chef::Client.new(nil, :override_runlist => 'role[test_role]')
244
- @client.node = @node
244
+ it "should permit spaces in overriding run list" do
245
+ @client = Chef::Client.new(nil, :override_runlist => 'role[a], role[b]')
245
246
  end
246
247
 
247
248
  it "should override the run list and save original runlist" do
249
+ @client = Chef::Client.new(nil, :override_runlist => 'role[test_role]')
250
+ @client.node = @node
251
+
248
252
  @node.run_list << "role[role_containing_cookbook1]"
249
253
 
250
254
  override_role = Chef::Role.new
@@ -45,6 +45,15 @@ describe Chef::Knife::Configure do
45
45
  @knife.new_client_name.should == Etc.getlogin
46
46
  end
47
47
 
48
+ it "should not ask the user for the clientname they want for the new client if -i and --node_name are specified" do
49
+ @knife.config[:initial] = true
50
+ @knife.config[:node_name] = 'testnode'
51
+ Etc.stub!(:getlogin).and_return("a-new-user")
52
+ @knife.ask_user_for_config
53
+ @out.string.should_not match(Regexp.escape("Please enter a clientname for the new client"))
54
+ @knife.new_client_name.should == 'testnode'
55
+ end
56
+
48
57
  it "asks the user for the existing API username or clientname if -i is not specified" do
49
58
  Etc.stub!(:getlogin).and_return("a-new-user")
50
59
  @knife.ask_user_for_config
@@ -53,30 +62,58 @@ describe Chef::Knife::Configure do
53
62
  end
54
63
 
55
64
  it "asks the user for the existing admin client's name if -i is specified" do
56
- @knife.config[:initial] = true
57
- @knife.ask_user_for_config
58
- @out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
59
- @knife.admin_client_name.should == 'chef-webui'
60
- end
61
-
62
- it "should not ask the user for the existing admin client's name if -i is not specified" do
63
- @knife.ask_user_for_config
64
- @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
65
- @knife.admin_client_name.should_not == 'chef-webui'
66
- end
67
-
68
- it "asks the user for the location of the existing admin key if -i is specified" do
69
- @knife.config[:initial] = true
70
- @knife.ask_user_for_config
71
- @out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
72
- @knife.admin_client_key.should == '/etc/chef/webui.pem'
73
- end
74
-
75
- it "should not ask the user for the location of the existing admin key if -i is not specified" do
76
- @knife.ask_user_for_config
77
- @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
78
- @knife.admin_client_key.should_not == '/etc/chef/webui.pem'
79
- end
65
+ @knife.config[:initial] = true
66
+ @knife.ask_user_for_config
67
+ @out.string.should match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
68
+ @knife.admin_client_name.should == 'chef-webui'
69
+ end
70
+
71
+ it "should not ask the user for the existing admin client's name if -i and --admin-client_name are specified" do
72
+ @knife.config[:initial] = true
73
+ @knife.config[:admin_client_name] = 'my-webui'
74
+ @knife.ask_user_for_config
75
+ @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname:"))
76
+ @knife.admin_client_name.should == 'my-webui'
77
+ end
78
+
79
+ it "should not ask the user for the existing admin client's name if -i is not specified" do
80
+ @knife.ask_user_for_config
81
+ @out.string.should_not match(Regexp.escape("Please enter the existing admin clientname: [chef-webui]"))
82
+ @knife.admin_client_name.should_not == 'chef-webui'
83
+ end
84
+
85
+ it "asks the user for the location of the existing admin key if -i is specified" do
86
+ @knife.config[:initial] = true
87
+ @knife.ask_user_for_config
88
+ @out.string.should match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
89
+ if windows?
90
+ @knife.admin_client_key.should == 'C:/etc/chef/webui.pem'
91
+ else
92
+ @knife.admin_client_key.should == '/etc/chef/webui.pem'
93
+ end
94
+ end
95
+
96
+ it "should not ask the user for the location of the existing admin key if -i and --admin_client_key are specified" do
97
+ @knife.config[:initial] = true
98
+ @knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem'
99
+ @knife.ask_user_for_config
100
+ @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key:"))
101
+ if windows?
102
+ @knife.admin_client_key.should == 'C:/home/you/.chef/my-webui.pem'
103
+ else
104
+ @knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
105
+ end
106
+ end
107
+
108
+ it "should not ask the user for the location of the existing admin key if -i is not specified" do
109
+ @knife.ask_user_for_config
110
+ @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [/etc/chef/webui.pem]"))
111
+ if windows?
112
+ @knife.admin_client_key.should_not == 'C:/etc//chef/webui.pem'
113
+ else
114
+ @knife.admin_client_key.should_not == '/etc/chef/webui.pem'
115
+ end
116
+ end
80
117
 
81
118
  it "asks the user for the location of a chef repo" do
82
119
  @knife.ask_user_for_config
@@ -90,14 +127,70 @@ describe Chef::Knife::Configure do
90
127
  @knife.validation_client_name.should == 'chef-validator'
91
128
  end
92
129
 
130
+ it "should not ask the users for the name of the validation client if --validation_client_name is specified" do
131
+ @knife.config[:validation_client_name] = 'my-validator'
132
+ @knife.ask_user_for_config
133
+ @out.string.should_not match(Regexp.escape("Please enter the validation clientname:"))
134
+ @knife.validation_client_name.should == 'my-validator'
135
+ end
136
+
93
137
  it "asks the users for the location of the validation key" do
94
138
  @knife.ask_user_for_config
95
139
  @out.string.should match(Regexp.escape("Please enter the location of the validation key: [/etc/chef/validation.pem]"))
96
- @knife.validation_key.should == '/etc/chef/validation.pem'
140
+ if windows?
141
+ @knife.validation_key.should == 'C:/etc/chef/validation.pem'
142
+ else
143
+ @knife.validation_key.should == '/etc/chef/validation.pem'
144
+ end
145
+ end
146
+
147
+ it "should not ask the users for the location of the validation key if --validation_key is specified" do
148
+ @knife.config[:validation_key] = '/home/you/.chef/my-validation.pem'
149
+ @knife.ask_user_for_config
150
+ @out.string.should_not match(Regexp.escape("Please enter the location of the validation key:"))
151
+ if windows?
152
+ @knife.validation_key.should == 'C:/home/you/.chef/my-validation.pem'
153
+ else
154
+ @knife.validation_key.should == '/home/you/.chef/my-validation.pem'
155
+ end
156
+ end
157
+
158
+ it "should not ask the user for anything if -i and all other properties are specified" do
159
+ @knife.config[:initial] = true
160
+ @knife.config[:chef_server_url] = 'http://localhost:5000'
161
+ @knife.config[:node_name] = 'testnode'
162
+ @knife.config[:admin_client_name] = 'my-webui'
163
+ @knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem'
164
+ @knife.config[:validation_client_name] = 'my-validator'
165
+ @knife.config[:validation_key] = '/home/you/.chef/my-validation.pem'
166
+ @knife.config[:repository] = ''
167
+ @knife.config[:client_key] = '/home/you/a-new-user.pem'
168
+ Etc.stub!(:getlogin).and_return('a-new-user')
169
+
170
+ @knife.ask_user_for_config
171
+ @out.string.should match(/\s*/)
172
+
173
+ @knife.new_client_name.should == 'testnode'
174
+ @knife.chef_server.should == 'http://localhost:5000'
175
+ @knife.admin_client_name.should == 'my-webui'
176
+ if windows?
177
+ @knife.admin_client_key.should == 'C:/home/you/.chef/my-webui.pem'
178
+ @knife.validation_key.should == 'C:/home/you/.chef/my-validation.pem'
179
+ @knife.new_client_key.should == 'C:/home/you/a-new-user.pem'
180
+ else
181
+ @knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
182
+ @knife.validation_key.should == '/home/you/.chef/my-validation.pem'
183
+ @knife.new_client_key.should == '/home/you/a-new-user.pem'
184
+ end
185
+ @knife.validation_client_name.should == 'my-validator'
186
+ @knife.chef_repo.should == ''
97
187
  end
98
188
 
99
189
  it "writes the new data to a config file" do
100
190
  File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
191
+ File.stub!(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem")
192
+ File.stub!(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
193
+ File.stub!(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem")
101
194
  FileUtils.should_receive(:mkdir_p).with("/home/you/.chef")
102
195
  config_file = StringIO.new
103
196
  ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file
@@ -113,6 +206,9 @@ describe Chef::Knife::Configure do
113
206
 
114
207
  it "creates a new client when given the --initial option" do
115
208
  File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
209
+ File.stub!(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
210
+ File.stub!(:expand_path).with("/etc/chef/validation.pem").and_return("/etc/chef/validation.pem")
211
+ File.stub!(:expand_path).with("/etc/chef/webui.pem").and_return("/etc/chef/webui.pem")
116
212
  Chef::Config[:node_name] = "webmonkey.example.com"
117
213
  client_command = Chef::Knife::ClientCreate.new
118
214
  client_command.should_receive(:run)
@@ -33,11 +33,12 @@ describe Chef::Knife::DataBagFromFile do
33
33
  @knife.stub!(:rest).and_return(@rest)
34
34
  @stdout = StringIO.new
35
35
  @knife.ui.stub!(:stdout).and_return(@stdout)
36
- @db_folder = File.join(Dir.tmpdir, 'data_bags', 'bag_name')
36
+ @tmp_dir = Dir.mktmpdir
37
+ @db_folder = File.join(@tmp_dir, 'data_bags', 'bag_name')
37
38
  FileUtils.mkdir_p(@db_folder)
38
39
  @db_file = Tempfile.new(["data_bag_from_file_test", ".json"], @db_folder)
39
40
  @db_file2 = Tempfile.new(["data_bag_from_file_test2", ".json"], @db_folder)
40
- @db_folder2 = File.join(Dir.tmpdir, 'data_bags', 'bag_name2')
41
+ @db_folder2 = File.join(@tmp_dir, 'data_bags', 'bag_name2')
41
42
  FileUtils.mkdir_p(@db_folder2)
42
43
  @db_file3 = Tempfile.new(["data_bag_from_file_test3", ".json"], @db_folder2)
43
44
  @plain_data = {
@@ -57,6 +58,7 @@ describe Chef::Knife::DataBagFromFile do
57
58
  @db_file3.close
58
59
  FileUtils.rm_rf(@db_folder)
59
60
  FileUtils.rm_rf(@db_folder2)
61
+ FileUtils.remove_entry_secure @tmp_dir
60
62
  end
61
63
 
62
64
  it "loads from a file and saves" do
@@ -98,7 +100,7 @@ describe Chef::Knife::DataBagFromFile do
98
100
 
99
101
  before do
100
102
  @pwd = Dir.pwd
101
- Dir.chdir(Dir.tmpdir)
103
+ Dir.chdir(@tmp_dir)
102
104
  end
103
105
 
104
106
  after do
@@ -43,6 +43,29 @@ describe Chef::Knife::EnvironmentFromFile do
43
43
  @knife.run
44
44
  end
45
45
 
46
+ context "when handling multiple environments" do
47
+ before(:each) do
48
+ @env_apple = @environment.dup
49
+ @env_apple.name("apple")
50
+ @knife.loader.stub!(:load_from).with("apple.rb").and_return @env_apple
51
+ end
52
+
53
+ it "loads multiple environments if given" do
54
+ @knife.name_args = [ "spec.rb", "apple.rb" ]
55
+ @environment.should_receive(:save).twice
56
+ @knife.run
57
+ end
58
+
59
+ it "loads all environments with -a" do
60
+ File.stub!(:expand_path).with("./environments/*.{json,rb}").and_return("/tmp/environments")
61
+ Dir.stub!(:glob).with("/tmp/environments").and_return(["spec.rb", "apple.rb"])
62
+ @knife.name_args = []
63
+ @knife.stub!(:config).and_return({:all => true})
64
+ @environment.should_receive(:save).twice
65
+ @knife.run
66
+ end
67
+ end
68
+
46
69
  it "should not print the environment" do
47
70
  @knife.should_not_receive(:output)
48
71
  @knife.run
@@ -104,6 +104,7 @@ EXPECTED
104
104
  it "installs the file from the cookbook cache" do
105
105
  @new_resource.path(@install_to)
106
106
  @provider.should_receive(:backup_new_resource)
107
+ @provider.stub!(:update_new_file_state)
107
108
  @provider.run_action(:create)
108
109
  actual = IO.read(@install_to)
109
110
  actual.should == @file_content
@@ -112,6 +113,7 @@ EXPECTED
112
113
  it "installs the file for create_if_missing --> from Provider::File" do
113
114
  @new_resource.path(@install_to)
114
115
  @provider.should_receive(:backup_new_resource)
116
+ @provider.stub!(:update_new_file_state)
115
117
  @provider.run_action(:create_if_missing)
116
118
  actual = IO.read(@install_to)
117
119
  actual.should == @file_content
@@ -121,6 +123,7 @@ EXPECTED
121
123
  @new_resource.path(@install_to)
122
124
  @provider.stub!(:backup_new_resource)
123
125
  @provider.stub!(:set_file_access_controls)
126
+ @provider.stub!(:update_new_file_state)
124
127
  @provider.run_action(:create)
125
128
  @new_resource.should be_updated
126
129
  @new_resource.should be_updated_by_last_action
@@ -39,7 +39,7 @@ describe Chef::Provider::Directory do
39
39
  cstats.stub!(:uid).and_return(500)
40
40
  cstats.stub!(:gid).and_return(500)
41
41
  cstats.stub!(:mode).and_return(0755)
42
- File.should_receive(:stat).once.and_return(cstats)
42
+ File.should_receive(:stat).twice.and_return(cstats)
43
43
  @directory.load_current_resource
44
44
  @directory.current_resource.path.should eql(@new_resource.path)
45
45
  @directory.current_resource.owner.should eql(500)
@@ -48,11 +48,13 @@ describe Chef::Provider::Directory do
48
48
  end
49
49
 
50
50
  it "should create a new directory on create, setting updated to true" do
51
- load_mock_provider
52
51
  @new_resource.path "/tmp/foo"
53
- File.should_receive(:exist?).twice.and_return(false)
52
+
53
+ File.should_receive(:exist?).exactly(3).and_return(false)
54
54
  Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true)
55
+
55
56
  @directory.should_receive(:set_all_access_controls)
57
+ @directory.stub!(:update_new_file_state)
56
58
  @directory.run_action(:create)
57
59
  @directory.new_resource.should be_updated
58
60
  end
@@ -64,10 +66,11 @@ describe Chef::Provider::Directory do
64
66
  end
65
67
 
66
68
  it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct" do
67
- load_mock_provider
68
69
  @new_resource.path "/path/to/dir"
69
70
  @new_resource.recursive true
70
71
  File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
72
+ File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
73
+
71
74
  File.should_receive(:exist?).with('/path/to').ordered.and_return(false)
72
75
  File.should_receive(:exist?).with('/path').ordered.and_return(true)
73
76
  File.should_receive(:writable?).with('/path').ordered.and_return(true)
@@ -75,6 +78,7 @@ describe Chef::Provider::Directory do
75
78
 
76
79
  FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true)
77
80
  @directory.should_receive(:set_all_access_controls)
81
+ @directory.stub!(:update_new_file_state)
78
82
  @directory.run_action(:create)
79
83
  @new_resource.should be_updated
80
84
  end
@@ -84,7 +88,6 @@ describe Chef::Provider::Directory do
84
88
  # end
85
89
 
86
90
  it "should raise an error when creating a directory when parent directory is a file" do
87
- load_mock_provider
88
91
  File.should_receive(:directory?).and_return(false)
89
92
  Dir.should_not_receive(:mkdir).with(@new_resource.path)
90
93
  lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
@@ -92,16 +95,15 @@ describe Chef::Provider::Directory do
92
95
  end
93
96
 
94
97
  it "should not create the directory if it already exists" do
95
- load_mock_provider
98
+ stub_file_cstats
96
99
  @new_resource.path "/tmp/foo"
97
- File.should_receive(:exist?).twice.and_return(true)
100
+ File.should_receive(:exist?).exactly(3).and_return(true)
98
101
  Dir.should_not_receive(:mkdir).with(@new_resource.path)
99
102
  @directory.should_receive(:set_all_access_controls)
100
103
  @directory.run_action(:create)
101
104
  end
102
105
 
103
106
  it "should delete the directory if it exists, and is writable with action_delete" do
104
- load_mock_provider
105
107
  File.should_receive(:directory?).and_return(true)
106
108
  File.should_receive(:writable?).once.and_return(true)
107
109
  Dir.should_receive(:delete).with(@new_resource.path).once.and_return(true)
@@ -109,7 +111,6 @@ describe Chef::Provider::Directory do
109
111
  end
110
112
 
111
113
  it "should raise an exception if it cannot delete the directory due to bad permissions" do
112
- load_mock_provider
113
114
  File.stub!(:exist?).and_return(true)
114
115
  File.stub!(:writable?).and_return(false)
115
116
  lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError)
@@ -124,25 +125,23 @@ describe Chef::Provider::Directory do
124
125
  end
125
126
 
126
127
  it "should raise an exception when deleting a directory when target directory is a file" do
127
- load_mock_provider
128
+ stub_file_cstats
128
129
  @new_resource.path "/an/invalid/path"
129
130
  File.stub!(:exist?).and_return(true)
130
131
  File.should_receive(:directory?).and_return(false)
131
132
  Dir.should_not_receive(:delete).with(@new_resource.path)
132
133
  lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError)
133
134
  @directory.new_resource.should_not be_updated
134
-
135
135
  end
136
136
 
137
-
138
- def load_mock_provider
139
- File.stub!(:exist?).and_return(true)
140
- File.stub!(:directory?).and_return(true)
137
+ def stub_file_cstats
141
138
  cstats = mock("stats")
142
139
  cstats.stub!(:uid).and_return(500)
143
140
  cstats.stub!(:gid).and_return(500)
144
141
  cstats.stub!(:mode).and_return(0755)
145
- File.stub!(:stat).once.and_return(cstats)
146
- # @directory.load_current_resource
142
+ # File.stat is called in:
143
+ # - Chef::Provider::File.load_current_resource_attrs
144
+ # - Chef::ScanAccessControl via Chef::Provider::File.setup_acl
145
+ File.stub!(:stat).and_return(cstats)
147
146
  end
148
147
  end