chef 13.7.16 → 13.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Daniel DeLeo (<dan@chef.io>)
3
- # Copyright:: Copyright 2012-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2012-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,18 +20,13 @@ require "spec_helper"
20
20
  require "chef/node/immutable_collections"
21
21
 
22
22
  describe Chef::Node::ImmutableMash do
23
-
24
23
  before do
25
- @data_in = { "key" =>
26
- { "top" => { "second_level" => "some value" },
27
- "top_level_2" => %w{array of values},
28
- "top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
29
- "top_level_4" => { "level2" => { "key" => "value" } },
30
- },
24
+ @data_in = { "top" => { "second_level" => "some value" },
25
+ "top_level_2" => %w{array of values},
26
+ "top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
27
+ "top_level_4" => { "level2" => { "key" => "value" } },
31
28
  }
32
- @node = Chef::Node.new()
33
- @node.attributes.default = @data_in
34
- @immutable_mash = @node["key"]
29
+ @immutable_mash = Chef::Node::ImmutableMash.new(@data_in)
35
30
  end
36
31
 
37
32
  it "element references like regular hash" do
@@ -62,9 +57,9 @@ describe Chef::Node::ImmutableMash do
62
57
  # we only ever absorb VividMashes from other precedence levels, which already have
63
58
  # been coerced to only have string keys, so we do not need to do that work twice (performance).
64
59
  it "does not call convert_value like Mash/VividMash" do
65
- @node.attributes.default = { test: "foo", "test2" => "bar" }
66
- expect(@node[:test]).to eql("foo")
67
- expect(@node["test2"]).to eql("bar")
60
+ @mash = Chef::Node::ImmutableMash.new({ test: "foo", "test2" => "bar" })
61
+ expect(@mash[:test]).to eql("foo")
62
+ expect(@mash["test2"]).to eql("bar")
68
63
  end
69
64
 
70
65
  describe "to_hash" do
@@ -85,7 +80,7 @@ describe Chef::Node::ImmutableMash do
85
80
  end
86
81
 
87
82
  it "should create a mash with the same content" do
88
- expect(@copy).to eql(@immutable_mash)
83
+ expect(@copy).to eq(@immutable_mash)
89
84
  end
90
85
 
91
86
  it "should allow mutation" do
@@ -180,11 +175,9 @@ end
180
175
  describe Chef::Node::ImmutableArray do
181
176
 
182
177
  before do
183
- @node = Chef::Node.new()
184
- @node.attributes.default = { "key" => ["level1", %w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ], { "m" => "m" }] }
185
- @immutable_array = @node["key"][1]
186
- @immutable_mash = @node["key"][2]
187
- @immutable_nested_array = @node["key"]
178
+ @immutable_array = Chef::Node::ImmutableArray.new(%w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ])
179
+ immutable_mash = Chef::Node::ImmutableMash.new({ "m" => "m" })
180
+ @immutable_nested_array = Chef::Node::ImmutableArray.new(["level1", @immutable_array, immutable_mash])
188
181
  end
189
182
 
190
183
  ##
@@ -256,7 +249,7 @@ describe Chef::Node::ImmutableArray do
256
249
  end
257
250
 
258
251
  it "should create an array with the same content" do
259
- expect(@immutable_nested_array).to eq(@copy)
252
+ expect(@copy).to eq(@immutable_nested_array)
260
253
  end
261
254
 
262
255
  it "should allow mutation" do
@@ -282,7 +275,7 @@ describe Chef::Node::ImmutableArray do
282
275
  end
283
276
 
284
277
  it "should create an array with the same content" do
285
- expect(@copy).to eq(@immutable_nested_array)
278
+ expect(@copy).to eql(@immutable_nested_array)
286
279
  end
287
280
 
288
281
  it "should allow mutation" do
@@ -308,7 +301,7 @@ describe Chef::Node::ImmutableArray do
308
301
  end
309
302
 
310
303
  it "should create an array with the same content" do
311
- expect(@immutable_nested_array).to eq(@copy)
304
+ expect(@copy).to eq(@immutable_nested_array)
312
305
  end
313
306
 
314
307
  it "should allow mutation" do
@@ -321,11 +314,4 @@ describe Chef::Node::ImmutableArray do
321
314
  expect(@immutable_array[1, 2]).to eql(%w{bar baz})
322
315
  end
323
316
  end
324
-
325
- describe "uniq" do
326
- it "works" do
327
- @node.attributes.default = { "key" => %w{foo bar foo baz bar} }
328
- expect(@node["key"].uniq).to eql(%w{foo bar baz})
329
- end
330
- end
331
317
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2016-2017, Chef Software Inc.
2
+ # Copyright:: Copyright 2016, Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -60,7 +60,7 @@ describe Chef::Node::VividMash do
60
60
  end
61
61
 
62
62
  it "deep converts values through arrays" do
63
- expect(root).to receive(:reset_cache).with(no_args)
63
+ expect(root).to receive(:reset_cache).with("foo")
64
64
  vivid["foo"] = [ { :bar => true } ]
65
65
  expect(vivid["foo"].class).to eql(Chef::Node::AttrArray)
66
66
  expect(vivid["foo"][0].class).to eql(Chef::Node::VividMash)
@@ -68,7 +68,7 @@ describe Chef::Node::VividMash do
68
68
  end
69
69
 
70
70
  it "deep converts values through nested arrays" do
71
- expect(root).to receive(:reset_cache).with(no_args)
71
+ expect(root).to receive(:reset_cache).with("foo")
72
72
  vivid["foo"] = [ [ { :bar => true } ] ]
73
73
  expect(vivid["foo"].class).to eql(Chef::Node::AttrArray)
74
74
  expect(vivid["foo"][0].class).to eql(Chef::Node::AttrArray)
@@ -77,7 +77,7 @@ describe Chef::Node::VividMash do
77
77
  end
78
78
 
79
79
  it "deep converts values through hashes" do
80
- expect(root).to receive(:reset_cache).with(no_args)
80
+ expect(root).to receive(:reset_cache).with("foo")
81
81
  vivid["foo"] = { baz: { :bar => true } }
82
82
  expect(vivid["foo"]).to be_an_instance_of(Chef::Node::VividMash)
83
83
  expect(vivid["foo"]["baz"]).to be_an_instance_of(Chef::Node::VividMash)
@@ -184,55 +184,42 @@ describe Chef::Node::VividMash do
184
184
 
185
185
  it "should deeply autovivify" do
186
186
  expect(root).to receive(:reset_cache).at_least(:once).with("one")
187
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five")
188
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six")
189
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven")
190
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight")
191
187
  vivid.write("one", "five", "six", "seven", "eight", "nine", "ten")
192
188
  expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten")
193
189
  end
194
190
 
195
191
  it "should raise an exception if you overwrite an array with a hash" do
196
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
197
192
  expect(root).to receive(:reset_cache).at_least(:once).with("array")
198
193
  vivid.write("array", "five", "six")
199
194
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => "six" }, "nil" => nil })
200
195
  end
201
196
 
202
197
  it "should raise an exception if you traverse through an array with a hash" do
203
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
204
198
  expect(root).to receive(:reset_cache).at_least(:once).with("array")
205
- expect(root).to receive(:reset_cache).at_least(:once).with("array", "five")
206
199
  vivid.write("array", "five", "six", "seven")
207
200
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => { "six" => "seven" } }, "nil" => nil })
208
201
  end
209
202
 
210
203
  it "should raise an exception if you overwrite a string with a hash" do
211
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "two")
212
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three")
204
+ expect(root).to receive(:reset_cache).at_least(:once).with("one")
213
205
  vivid.write("one", "two", "three", "four", "five")
214
206
  expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => "five" } } }, "array" => [ 0, 1, 2 ], "nil" => nil })
215
207
  end
216
208
 
217
209
  it "should raise an exception if you traverse through a string with a hash" do
218
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "two")
219
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three")
220
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three", "four")
210
+ expect(root).to receive(:reset_cache).at_least(:once).with("one")
221
211
  vivid.write("one", "two", "three", "four", "five", "six")
222
212
  expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => { "five" => "six" } } } }, "array" => [ 0, 1, 2 ], "nil" => nil })
223
213
  end
224
214
 
225
215
  it "should raise an exception if you overwrite a nil with a hash" do
226
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
227
216
  expect(root).to receive(:reset_cache).at_least(:once).with("nil")
228
217
  vivid.write("nil", "one", "two")
229
218
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => "two" } })
230
219
  end
231
220
 
232
221
  it "should raise an exception if you traverse through a nil with a hash" do
233
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
234
222
  expect(root).to receive(:reset_cache).at_least(:once).with("nil")
235
- expect(root).to receive(:reset_cache).at_least(:once).with("nil", "one")
236
223
  vivid.write("nil", "one", "two", "three")
237
224
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => { "two" => "three" } } })
238
225
  end
@@ -253,10 +240,6 @@ describe Chef::Node::VividMash do
253
240
 
254
241
  it "should deeply autovivify" do
255
242
  expect(root).to receive(:reset_cache).at_least(:once).with("one")
256
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five")
257
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six")
258
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven")
259
- expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight")
260
243
  vivid.write!("one", "five", "six", "seven", "eight", "nine", "ten")
261
244
  expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten")
262
245
  end
@@ -312,7 +295,7 @@ describe Chef::Node::VividMash do
312
295
  end
313
296
 
314
297
  it "should unlink hashes" do
315
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
298
+ expect(root).to receive(:reset_cache).at_least(:once).with("one")
316
299
  expect( vivid.unlink("one") ).to eql({ "two" => { "three" => "four" } })
317
300
  expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil })
318
301
  end
@@ -324,7 +307,7 @@ describe Chef::Node::VividMash do
324
307
  end
325
308
 
326
309
  it "should unlink nil" do
327
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
310
+ expect(root).to receive(:reset_cache).at_least(:once).with("nil")
328
311
  expect(vivid.unlink("nil")).to eql(nil)
329
312
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] })
330
313
  end
@@ -344,7 +327,7 @@ describe Chef::Node::VividMash do
344
327
  end
345
328
 
346
329
  it "should unlink! hashes" do
347
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
330
+ expect(root).to receive(:reset_cache).at_least(:once).with("one")
348
331
  expect( vivid.unlink!("one") ).to eql({ "two" => { "three" => "four" } })
349
332
  expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil })
350
333
  end
@@ -356,7 +339,7 @@ describe Chef::Node::VividMash do
356
339
  end
357
340
 
358
341
  it "should unlink! nil" do
359
- expect(root).to receive(:reset_cache).at_least(:once).with(no_args)
342
+ expect(root).to receive(:reset_cache).at_least(:once).with("nil")
360
343
  expect(vivid.unlink!("nil")).to eql(nil)
361
344
  expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] })
362
345
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Lamont Granquist (<lamont@chef.io>)
3
- # Copyright:: Copyright 2014-2017, Chef Software Inc.
3
+ # Copyright:: Copyright 2014-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,9 @@
19
19
  require "spec_helper"
20
20
  require "chef/node_map"
21
21
 
22
+ class Foo; end
23
+ class Bar; end
24
+
22
25
  describe Chef::NodeMap do
23
26
 
24
27
  let(:node_map) { Chef::NodeMap.new }
@@ -120,9 +123,7 @@ describe Chef::NodeMap do
120
123
  end
121
124
 
122
125
  describe "ordering classes" do
123
- class Foo; end
124
- class Bar; end
125
- it "orders them alphabetically when they're set in the reverse order" do
126
+ it "last writer wins when its reverse alphabetic order" do
126
127
  node_map.set(:thing, Foo)
127
128
  node_map.set(:thing, Bar)
128
129
  expect(node_map.get(node, :thing)).to eql(Bar)
@@ -135,6 +136,30 @@ describe Chef::NodeMap do
135
136
  end
136
137
  end
137
138
 
139
+ describe "deleting classes" do
140
+ it "deletes a class and removes the mapping completely" do
141
+ node_map.set(:thing, Bar)
142
+ expect( node_map.delete_class(Bar) ).to eql({ :thing => [{ :klass => Bar }] })
143
+ expect( node_map.get(node, :thing) ).to eql(nil)
144
+ end
145
+
146
+ it "deletes a class and leaves the mapping that still has an entry" do
147
+ node_map.set(:thing, Bar)
148
+ node_map.set(:thing, Foo)
149
+ expect( node_map.delete_class(Bar) ).to eql({ :thing => [{ :klass => Bar }] })
150
+ expect( node_map.get(node, :thing) ).to eql(Foo)
151
+ end
152
+
153
+ it "handles deleting classes from multiple keys" do
154
+ node_map.set(:thing1, Bar)
155
+ node_map.set(:thing2, Bar)
156
+ node_map.set(:thing2, Foo)
157
+ expect( node_map.delete_class(Bar) ).to eql({ :thing1 => [{ :klass => Bar }], :thing2 => [{ :klass => Bar }] })
158
+ expect( node_map.get(node, :thing1) ).to eql(nil)
159
+ expect( node_map.get(node, :thing2) ).to eql(Foo)
160
+ end
161
+ end
162
+
138
163
  describe "with a block doing platform_version checks" do
139
164
  before do
140
165
  node_map.set(:thing, :foo, platform_family: "rhel") do |node|
@@ -185,14 +185,12 @@ describe Chef::Provider::RemoteFile::HTTP do
185
185
  expect(Chef::HTTP::Simple).to receive(:new).with(*expected_http_args).and_return(rest)
186
186
  end
187
187
 
188
- describe "and the request does not return new content" do
189
-
190
- it "should return a nil tempfile for a 304 HTTPNotModifed" do
191
- # Streaming request returns nil for 304 errors
192
- expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(nil)
193
- expect(fetcher.fetch).to be_nil
194
- end
195
-
188
+ it "should clean up the tempfile, and return a nil when streaming_request returns nil" do
189
+ # Streaming request returns nil for a 304 not modified (etags / last-modified)
190
+ expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(nil)
191
+ expect(tempfile).to receive(:close)
192
+ expect(tempfile).to receive(:unlink)
193
+ expect(fetcher.fetch).to be_nil
196
194
  end
197
195
 
198
196
  context "with progress reports" do
@@ -276,7 +276,9 @@ describe Chef::Resource::WindowsTask do
276
276
 
277
277
  context "#validate_idle_time" do
278
278
  it "raises error if frequency is not :on_idle" do
279
- expect { resource.send(:validate_idle_time, 5, :hourly) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
279
+ [:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency|
280
+ expect { resource.send(:validate_idle_time, 5, frequency) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle")
281
+ end
280
282
  end
281
283
 
282
284
  it "raises error if idle_time > 999" do
@@ -290,6 +292,12 @@ describe Chef::Resource::WindowsTask do
290
292
  it "raises error if idle_time is not set" do
291
293
  expect { resource.send(:validate_idle_time, nil, :on_idle) }.to raise_error(ArgumentError, "idle_time value should be set for :on_idle frequency.")
292
294
  end
295
+
296
+ it "does not raises error if idle_time is not set for other frequencies" do
297
+ [:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency|
298
+ expect { resource.send(:validate_idle_time, nil, frequency) }.not_to raise_error
299
+ end
300
+ end
293
301
  end
294
302
 
295
303
  context "#sec_to_dur" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.7.16
4
+ version: 13.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 13.7.16
19
+ version: 13.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 13.7.16
26
+ version: 13.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixlib-cli
29
29
  requirement: !ruby/object:Gem::Requirement