chef 12.4.3 → 12.5.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -2
  3. data/lib/chef.rb +1 -1
  4. data/lib/chef/application/solo.rb +1 -1
  5. data/lib/chef/application/windows_service_manager.rb +17 -12
  6. data/lib/chef/chef_class.rb +7 -0
  7. data/lib/chef/chef_fs/config.rb +22 -24
  8. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  9. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -0
  10. data/lib/chef/chef_fs/knife.rb +35 -7
  11. data/lib/chef/chef_fs/path_utils.rb +65 -34
  12. data/lib/chef/constants.rb +27 -0
  13. data/lib/chef/delayed_evaluator.rb +21 -0
  14. data/lib/chef/dsl/recipe.rb +20 -2
  15. data/lib/chef/event_dispatch/base.rb +40 -16
  16. data/lib/chef/event_dispatch/dsl.rb +64 -0
  17. data/lib/chef/exceptions.rb +6 -1
  18. data/lib/chef/formatters/doc.rb +3 -1
  19. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  20. data/lib/chef/http/http_request.rb +1 -1
  21. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  22. data/lib/chef/knife/ssl_check.rb +3 -2
  23. data/lib/chef/knife/user_edit.rb +1 -2
  24. data/lib/chef/mixin/params_validate.rb +362 -135
  25. data/lib/chef/node.rb +19 -0
  26. data/lib/chef/platform/handler_map.rb +0 -5
  27. data/lib/chef/platform/rebooter.rb +1 -1
  28. data/lib/chef/property.rb +539 -0
  29. data/lib/chef/provider.rb +129 -12
  30. data/lib/chef/provider/deploy.rb +3 -5
  31. data/lib/chef/provider/lwrp_base.rb +1 -75
  32. data/lib/chef/provider/package.rb +1 -1
  33. data/lib/chef/provider/powershell_script.rb +32 -19
  34. data/lib/chef/provider/registry_key.rb +5 -5
  35. data/lib/chef/provider/service/macosx.rb +5 -1
  36. data/lib/chef/recipe.rb +1 -8
  37. data/lib/chef/resource.rb +499 -84
  38. data/lib/chef/resource/file/verification.rb +7 -1
  39. data/lib/chef/resource/lwrp_base.rb +1 -7
  40. data/lib/chef/run_context.rb +404 -83
  41. data/lib/chef/version.rb +1 -1
  42. data/lib/chef/win32/registry.rb +10 -2
  43. data/lib/chef/workstation_config_loader.rb +3 -158
  44. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  45. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  46. data/spec/functional/rebooter_spec.rb +1 -1
  47. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +3 -3
  48. data/spec/functional/win32/registry_helper_spec.rb +12 -0
  49. data/spec/functional/win32/service_manager_spec.rb +2 -2
  50. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  51. data/spec/integration/recipes/recipe_dsl_spec.rb +0 -15
  52. data/spec/integration/recipes/resource_action_spec.rb +343 -0
  53. data/spec/spec_helper.rb +1 -0
  54. data/spec/support/shared/functional/win32_service.rb +2 -1
  55. data/spec/unit/application/solo_spec.rb +4 -3
  56. data/spec/unit/chef_class_spec.rb +23 -0
  57. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  58. data/spec/unit/event_dispatch/dsl_spec.rb +87 -0
  59. data/spec/unit/json_compat_spec.rb +4 -3
  60. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  61. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  62. data/spec/unit/node_spec.rb +7 -0
  63. data/spec/unit/property/state_spec.rb +506 -0
  64. data/spec/unit/property/validation_spec.rb +658 -0
  65. data/spec/unit/property_spec.rb +968 -0
  66. data/spec/unit/provider/{powershell_spec.rb → powershell_script_spec.rb} +0 -0
  67. data/spec/unit/provider/registry_key_spec.rb +12 -0
  68. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  69. data/spec/unit/provider_spec.rb +1 -3
  70. data/spec/unit/recipe_spec.rb +0 -4
  71. data/spec/unit/registry_helper_spec.rb +15 -1
  72. data/spec/unit/resource/file/verification_spec.rb +33 -5
  73. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +0 -0
  74. data/spec/unit/resource_spec.rb +2 -2
  75. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  76. data/spec/unit/run_context_spec.rb +7 -0
  77. metadata +25 -25
  78. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -1,283 +0,0 @@
1
- #
2
- # Author:: Daniel DeLeo (<dan@getchef.com>)
3
- # Copyright:: Copyright (c) 2014 Chef Software, 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 'tempfile'
21
- require 'chef/workstation_config_loader'
22
-
23
- describe Chef::WorkstationConfigLoader do
24
-
25
- let(:explicit_config_location) { nil }
26
-
27
- let(:env) { {} }
28
-
29
- let(:config_loader) do
30
- described_class.new(explicit_config_location).tap do |c|
31
- allow(c).to receive(:env).and_return(env)
32
- end
33
- end
34
-
35
- # Test methods that do I/O or reference external state which are stubbed out
36
- # elsewhere.
37
- describe "external dependencies" do
38
- let(:config_loader) { described_class.new(nil) }
39
-
40
- it "delegates to ENV for env" do
41
- expect(config_loader.env).to equal(ENV)
42
- end
43
-
44
- it "tests a path's existence" do
45
- expect(config_loader.path_exists?('/nope/nope/nope/nope/frab/jab/nab')).to be(false)
46
- expect(config_loader.path_exists?(__FILE__)).to be(true)
47
- end
48
-
49
- end
50
-
51
- describe "locating the config file" do
52
- context "without an explicit config" do
53
-
54
- before do
55
- allow(config_loader).to receive(:path_exists?).with(an_instance_of(String)).and_return(false)
56
- end
57
-
58
- it "has no config if HOME is not set" do
59
- expect(config_loader.config_location).to be(nil)
60
- expect(config_loader.no_config_found?).to be(true)
61
- end
62
-
63
- context "when HOME is set and contains a knife.rb" do
64
-
65
- let(:home) { "/Users/example.user" }
66
-
67
- before do
68
- allow(Chef::Util::PathHelper).to receive(:home).with('.chef').and_yield(File.join(home, '.chef'))
69
- allow(config_loader).to receive(:path_exists?).with("#{home}/.chef/knife.rb").and_return(true)
70
- end
71
-
72
- it "uses the config in HOME/.chef/knife.rb" do
73
- expect(config_loader.config_location).to eq("#{home}/.chef/knife.rb")
74
- end
75
-
76
- context "and has a config.rb" do
77
-
78
- before do
79
- allow(config_loader).to receive(:path_exists?).with("#{home}/.chef/config.rb").and_return(true)
80
- end
81
-
82
- it "uses the config in HOME/.chef/config.rb" do
83
- expect(config_loader.config_location).to eq("#{home}/.chef/config.rb")
84
- end
85
-
86
- context "and/or a parent dir contains a .chef dir" do
87
-
88
- let(:env_pwd) { "/path/to/cwd" }
89
-
90
- before do
91
- if Chef::Platform.windows?
92
- env["CD"] = env_pwd
93
- else
94
- env["PWD"] = env_pwd
95
- end
96
-
97
- allow(config_loader).to receive(:path_exists?).with("#{env_pwd}/.chef/knife.rb").and_return(true)
98
- allow(File).to receive(:exist?).with("#{env_pwd}/.chef").and_return(true)
99
- allow(File).to receive(:directory?).with("#{env_pwd}/.chef").and_return(true)
100
- end
101
-
102
- it "prefers the config from parent_dir/.chef" do
103
- expect(config_loader.config_location).to eq("#{env_pwd}/.chef/knife.rb")
104
- end
105
-
106
- context "and the parent dir's .chef dir has a config.rb" do
107
-
108
- before do
109
- allow(config_loader).to receive(:path_exists?).with("#{env_pwd}/.chef/config.rb").and_return(true)
110
- end
111
-
112
- it "prefers the config from parent_dir/.chef" do
113
- expect(config_loader.config_location).to eq("#{env_pwd}/.chef/config.rb")
114
- end
115
-
116
- context "and/or the current working directory contains a .chef dir" do
117
-
118
- let(:cwd) { Dir.pwd }
119
-
120
- before do
121
- allow(config_loader).to receive(:path_exists?).with("#{cwd}/knife.rb").and_return(true)
122
- end
123
-
124
- it "prefers a knife.rb located in the cwd" do
125
- expect(config_loader.config_location).to eq("#{cwd}/knife.rb")
126
- end
127
-
128
- context "and the CWD's .chef dir has a config.rb" do
129
-
130
- before do
131
- allow(config_loader).to receive(:path_exists?).with("#{cwd}/config.rb").and_return(true)
132
- end
133
-
134
- it "prefers a config located in the cwd" do
135
- expect(config_loader.config_location).to eq("#{cwd}/config.rb")
136
- end
137
-
138
-
139
- context "and/or KNIFE_HOME is set" do
140
-
141
- let(:knife_home) { "/path/to/knife/home" }
142
-
143
- before do
144
- env["KNIFE_HOME"] = knife_home
145
- allow(config_loader).to receive(:path_exists?).with("#{knife_home}/knife.rb").and_return(true)
146
- end
147
-
148
- it "prefers a knife located in KNIFE_HOME" do
149
- expect(config_loader.config_location).to eq("/path/to/knife/home/knife.rb")
150
- end
151
-
152
- context "and KNIFE_HOME contains a config.rb" do
153
-
154
- before do
155
- env["KNIFE_HOME"] = knife_home
156
- allow(config_loader).to receive(:path_exists?).with("#{knife_home}/config.rb").and_return(true)
157
- end
158
-
159
- it "prefers a config.rb located in KNIFE_HOME" do
160
- expect(config_loader.config_location).to eq("/path/to/knife/home/config.rb")
161
- end
162
-
163
- end
164
-
165
- end
166
- end
167
- end
168
- end
169
- end
170
- end
171
- end
172
-
173
- context "when the current working dir is inside a symlinked directory" do
174
- before do
175
- # pwd according to your shell is /home/someuser/prod/chef-repo, but
176
- # chef-repo is a symlink to /home/someuser/codes/chef-repo
177
- env["CD"] = "/home/someuser/prod/chef-repo" # windows
178
- env["PWD"] = "/home/someuser/prod/chef-repo" # unix
179
-
180
- allow(Dir).to receive(:pwd).and_return("/home/someuser/codes/chef-repo")
181
- end
182
-
183
- it "loads the config from the non-dereferenced directory path" do
184
- expect(File).to receive(:exist?).with("/home/someuser/prod/chef-repo/.chef").and_return(false)
185
- expect(File).to receive(:exist?).with("/home/someuser/prod/.chef").and_return(true)
186
- expect(File).to receive(:directory?).with("/home/someuser/prod/.chef").and_return(true)
187
-
188
- expect(config_loader).to receive(:path_exists?).with("/home/someuser/prod/.chef/knife.rb").and_return(true)
189
-
190
- expect(config_loader.config_location).to eq("/home/someuser/prod/.chef/knife.rb")
191
- end
192
- end
193
- end
194
-
195
- context "when given an explicit config to load" do
196
-
197
- let(:explicit_config_location) { "/path/to/explicit/config.rb" }
198
-
199
- it "prefers the explicit config" do
200
- expect(config_loader.config_location).to eq(explicit_config_location)
201
- end
202
-
203
- end
204
- end
205
-
206
-
207
- describe "loading the config file" do
208
-
209
- context "when no explicit config is specifed and no implicit config is found" do
210
-
211
- before do
212
- allow(config_loader).to receive(:path_exists?).with(an_instance_of(String)).and_return(false)
213
- end
214
-
215
- it "skips loading" do
216
- expect(config_loader.config_location).to be(nil)
217
- expect(config_loader.load).to be(false)
218
- end
219
-
220
- end
221
-
222
- context "when an explicit config is given but it doesn't exist" do
223
-
224
- let(:explicit_config_location) { "/nope/nope/nope/frab/jab/nab" }
225
-
226
- it "raises a configuration error" do
227
- expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
228
- end
229
-
230
- end
231
-
232
- context "when the config file exists" do
233
-
234
- let(:config_content) { "" }
235
-
236
- let(:explicit_config_location) do
237
- # could use described_class, but remove all ':' from the path if so.
238
- t = Tempfile.new("Chef-WorkstationConfigLoader-rspec-test")
239
- t.print(config_content)
240
- t.close
241
- t.path
242
- end
243
-
244
- after { File.unlink(explicit_config_location) if File.exists?(explicit_config_location) }
245
-
246
- context "and is valid" do
247
-
248
- let(:config_content) { "config_file_evaluated(true)" }
249
-
250
- it "loads the config" do
251
- expect(config_loader.load).to be(true)
252
- expect(Chef::Config.config_file_evaluated).to be(true)
253
- end
254
-
255
- it "sets Chef::Config.config_file" do
256
- config_loader.load
257
- expect(Chef::Config.config_file).to eq(explicit_config_location)
258
- end
259
- end
260
-
261
- context "and has a syntax error" do
262
-
263
- let(:config_content) { "{{{{{:{{" }
264
-
265
- it "raises a ConfigurationError" do
266
- expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
267
- end
268
- end
269
-
270
- context "and raises a ruby exception during evaluation" do
271
-
272
- let(:config_content) { ":foo\n:bar\nraise 'oops'\n:baz\n" }
273
-
274
- it "raises a ConfigurationError" do
275
- expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
276
- end
277
- end
278
-
279
- end
280
-
281
- end
282
-
283
- end