chef 13.3.42-universal-mingw32 → 13.4.19-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/.DS_Store +0 -0
- data/lib/chef/.DS_Store +0 -0
- data/lib/chef/knife/core/ui.rb +1 -1
- data/lib/chef/mash.rb +6 -0
- data/lib/chef/mixin/deep_merge.rb +1 -1
- data/lib/chef/mixin/user_context.rb +52 -0
- data/lib/chef/node/attribute.rb +80 -14
- data/lib/chef/node/immutable_collections.rb +16 -19
- data/lib/chef/provider/apt_repository.rb +12 -10
- data/lib/chef/provider/git.rb +20 -3
- data/lib/chef/provider/ifconfig/redhat.rb +4 -0
- data/lib/chef/provider/launchd.rb +20 -0
- data/lib/chef/provider/package/dnf.rb +3 -1
- data/lib/chef/provider/remote_file.rb +19 -0
- data/lib/chef/provider/remote_file/fetcher.rb +3 -0
- data/lib/chef/provider/remote_file/network_file.rb +18 -5
- data/lib/chef/provider/service/macosx.rb +4 -3
- data/lib/chef/provider/windows_path.rb +62 -0
- data/lib/chef/provider/zypper_repository.rb +1 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +5 -1
- data/lib/chef/resource/apt_repository.rb +1 -1
- data/lib/chef/resource/ifconfig.rb +36 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/windows_path.rb +41 -0
- data/lib/chef/resource/zypper_repository.rb +1 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/shell.rb +1 -0
- data/lib/chef/shell/shell_session.rb +4 -4
- data/lib/chef/util/windows/logon_session.rb +126 -0
- data/lib/chef/version.rb +4 -3
- data/lib/chef/win32/api/security.rb +2 -0
- data/spec/.DS_Store +0 -0
- data/spec/data/nodes/Timothys-MacBook-Pro.local.json +3 -0
- data/spec/functional/.DS_Store +0 -0
- data/spec/functional/mixin/user_context_spec.rb +117 -0
- data/spec/functional/resource/remote_file_spec.rb +171 -0
- data/spec/functional/resource/windows_path_spec.rb +64 -0
- data/spec/support/.DS_Store +0 -0
- data/spec/unit/.DS_Store +0 -0
- data/spec/unit/knife/client_delete_spec.rb +1 -1
- data/spec/unit/mixin/user_context_spec.rb +109 -0
- data/spec/unit/node/immutable_collections_spec.rb +12 -4
- data/spec/unit/node_spec.rb +7 -0
- data/spec/unit/provider/git_spec.rb +55 -0
- data/spec/unit/provider/ifconfig/redhat_spec.rb +8 -0
- data/spec/unit/provider/remote_file/fetcher_spec.rb +1 -0
- data/spec/unit/provider/remote_file/network_file_spec.rb +7 -2
- data/spec/unit/provider/service/macosx_spec.rb +4 -1
- data/spec/unit/provider/windows_path_spec.rb +65 -0
- data/spec/unit/resource/windows_path_spec.rb +38 -0
- data/spec/unit/resource_spec.rb +8 -0
- data/spec/unit/shell/shell_session_spec.rb +82 -58
- data/spec/unit/util/windows/logon_session_spec.rb +284 -0
- data/tasks/maintainers.rb +3 -3
- metadata +22 -5
@@ -21,10 +21,10 @@ require "chef/node/immutable_collections"
|
|
21
21
|
|
22
22
|
describe Chef::Node::ImmutableMash do
|
23
23
|
before do
|
24
|
-
@data_in = {
|
24
|
+
@data_in = { "top" => { "second_level" => "some value" },
|
25
25
|
"top_level_2" => %w{array of values},
|
26
|
-
|
27
|
-
|
26
|
+
"top_level_3" => [{ "hash_array" => 1, "hash_array_b" => 2 }],
|
27
|
+
"top_level_4" => { "level2" => { "key" => "value" } },
|
28
28
|
}
|
29
29
|
@immutable_mash = Chef::Node::ImmutableMash.new(@data_in)
|
30
30
|
end
|
@@ -54,6 +54,14 @@ describe Chef::Node::ImmutableMash do
|
|
54
54
|
expect(@immutable_mash[:top_level_4][:level2]).to be_a(Chef::Node::ImmutableMash)
|
55
55
|
end
|
56
56
|
|
57
|
+
# we only ever absorb VividMashes from other precedence levels, which already have
|
58
|
+
# been coerced to only have string keys, so we do not need to do that work twice (performance).
|
59
|
+
it "does not call convert_value like Mash/VividMash" do
|
60
|
+
@mash = Chef::Node::ImmutableMash.new({ test: "foo", "test2" => "bar" })
|
61
|
+
expect(@mash[:test]).to eql("foo")
|
62
|
+
expect(@mash["test2"]).to eql("bar")
|
63
|
+
end
|
64
|
+
|
57
65
|
describe "to_hash" do
|
58
66
|
before do
|
59
67
|
@copy = @immutable_mash.to_hash
|
@@ -168,7 +176,7 @@ describe Chef::Node::ImmutableArray do
|
|
168
176
|
|
169
177
|
before do
|
170
178
|
@immutable_array = Chef::Node::ImmutableArray.new(%w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ])
|
171
|
-
immutable_mash = Chef::Node::ImmutableMash.new({
|
179
|
+
immutable_mash = Chef::Node::ImmutableMash.new({ "m" => "m" })
|
172
180
|
@immutable_nested_array = Chef::Node::ImmutableArray.new(["level1", @immutable_array, immutable_mash])
|
173
181
|
end
|
174
182
|
|
data/spec/unit/node_spec.rb
CHANGED
@@ -337,6 +337,13 @@ describe Chef::Node do
|
|
337
337
|
node.override_unless[:decontamination] = "foo"
|
338
338
|
expect(node.override[:decontamination]).to eql("foo")
|
339
339
|
end
|
340
|
+
|
341
|
+
it "consume_attributes does not exhibit chef/chef/issues/6302 bug" do
|
342
|
+
node.normal["a"]["r1"] = nil
|
343
|
+
node.consume_attributes({ "a" => { "r2" => nil } })
|
344
|
+
expect(node["a"]["r1"]).to be_nil
|
345
|
+
expect(node["a"]["r2"]).to be_nil
|
346
|
+
end
|
340
347
|
end
|
341
348
|
|
342
349
|
describe "default attributes" do
|
@@ -83,6 +83,61 @@ describe Chef::Provider::Git do
|
|
83
83
|
expect(@provider.new_resource).to equal(@resource)
|
84
84
|
end
|
85
85
|
|
86
|
+
context "cast git version into gem version object" do
|
87
|
+
it "returns correct version with standard git" do
|
88
|
+
expect(@provider).to receive(:shell_out!)
|
89
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
90
|
+
.and_return(double("ShellOut result", stdout: "git version 2.14.1"))
|
91
|
+
expect(@provider.git_gem_version).to eq Gem::Version.new("2.14.1")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns correct version with Apple git" do
|
95
|
+
expect(@provider).to receive(:shell_out!)
|
96
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
97
|
+
.and_return(double("ShellOut result", stdout: "git version 2.11.0 (Apple Git-81)"))
|
98
|
+
expect(@provider.git_gem_version).to eq Gem::Version.new("2.11.0")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "maintains deprecated method name" do
|
102
|
+
expect(@provider).to receive(:shell_out!)
|
103
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
104
|
+
.and_return(double("ShellOut result", stdout: "git version 1.2.3"))
|
105
|
+
expect(@provider.git_minor_version).to eq Gem::Version.new("1.2.3")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not know how to handle other version" do
|
109
|
+
expect(@provider).to receive(:shell_out!)
|
110
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
111
|
+
.and_return(double("ShellOut result", stdout: "git version home-grown-git-99"))
|
112
|
+
expect(@provider.git_gem_version).to be_nil
|
113
|
+
end
|
114
|
+
|
115
|
+
it "determines single branch option when it fails to parse git version" do
|
116
|
+
expect(@provider).to receive(:shell_out!)
|
117
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
118
|
+
.and_return(double("ShellOut result", stdout: "git version home-grown-git-99"))
|
119
|
+
expect(@provider.git_has_single_branch_option?).to be false
|
120
|
+
end
|
121
|
+
|
122
|
+
it "determines single branch option as true when it parses git version and version is large" do
|
123
|
+
expect(@provider).to receive(:shell_out!)
|
124
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
125
|
+
.and_return(double("ShellOut result", stdout: "git version 1.8.0"))
|
126
|
+
expect(@provider.git_has_single_branch_option?).to be true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "determines single branch option as false when it parses git version and version is small" do
|
130
|
+
expect(@provider).to receive(:shell_out!)
|
131
|
+
.with("git --version", log_tag: "git[web2.0 app]")
|
132
|
+
.and_return(double("ShellOut result", stdout: "git version 1.7.4"))
|
133
|
+
expect(@provider.git_has_single_branch_option?).to be false
|
134
|
+
end
|
135
|
+
|
136
|
+
it "is compatible with git in travis" do
|
137
|
+
expect(@provider.git_gem_version).to be > Gem::Version.new("1.0")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
86
141
|
context "resolving revisions to a SHA" do
|
87
142
|
|
88
143
|
before do
|
@@ -31,6 +31,10 @@ describe Chef::Provider::Ifconfig::Redhat do
|
|
31
31
|
@new_resource.metric "1"
|
32
32
|
@new_resource.mtu "1500"
|
33
33
|
@new_resource.device "eth0"
|
34
|
+
@new_resource.ethtool_opts "-A eth0 autoneg off"
|
35
|
+
@new_resource.bonding_opts "mode=active-backup miimon=100"
|
36
|
+
@new_resource.master "bond0"
|
37
|
+
@new_resource.slave "yes"
|
34
38
|
@provider = Chef::Provider::Ifconfig::Redhat.new(@new_resource, @run_context)
|
35
39
|
@current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)
|
36
40
|
|
@@ -52,6 +56,10 @@ describe Chef::Provider::Ifconfig::Redhat do
|
|
52
56
|
expect(arg).to match(/^\s*DEVICE=eth0\s*$/)
|
53
57
|
expect(arg).to match(/^\s*IPADDR=10\.0\.0\.1\s*$/)
|
54
58
|
expect(arg).to match(/^\s*NETMASK=255\.255\.254\.0\s*$/)
|
59
|
+
expect(arg).to match(/^\s*ETHTOOL_OPTS="-A eth0 autoneg off"\s*$/)
|
60
|
+
expect(arg).to match(/^\s*BONDING_OPTS="mode=active-backup miimon=100"\s*$/)
|
61
|
+
expect(arg).to match(/^\s*MASTER=bond0\s*$/)
|
62
|
+
expect(arg).to match(/^\s*SLAVE=yes\s*$/)
|
55
63
|
end
|
56
64
|
expect(@config).to receive(:run_action).with(:create)
|
57
65
|
expect(@config).to receive(:updated?).and_return(true)
|
@@ -27,6 +27,7 @@ describe Chef::Provider::RemoteFile::Fetcher do
|
|
27
27
|
describe "when passed a network share" do
|
28
28
|
before do
|
29
29
|
expect(Chef::Provider::RemoteFile::NetworkFile).to receive(:new).and_return(fetcher_instance)
|
30
|
+
allow(Chef::Platform).to receive(:windows?).and_return(true)
|
30
31
|
end
|
31
32
|
|
32
33
|
context "when host is a name" do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
#
|
2
3
|
# Author:: Jay Mundrawala (<jdm@chef.io>)
|
3
4
|
# Copyright:: Copyright 2015-2016, Chef Software
|
@@ -19,7 +20,6 @@
|
|
19
20
|
require "spec_helper"
|
20
21
|
|
21
22
|
describe Chef::Provider::RemoteFile::NetworkFile do
|
22
|
-
|
23
23
|
let(:source) { "\\\\foohost\\fooshare\\Foo.tar.gz" }
|
24
24
|
|
25
25
|
let(:new_resource) { Chef::Resource::RemoteFile.new("network file (new_resource)") }
|
@@ -30,10 +30,15 @@ describe Chef::Provider::RemoteFile::NetworkFile do
|
|
30
30
|
|
31
31
|
let(:tempfile) { double("Tempfile", :path => "/tmp/foo/bar/Foo.tar.gz", :close => nil) }
|
32
32
|
let(:chef_tempfile) { double("Chef::FileContentManagement::Tempfile", :tempfile => tempfile) }
|
33
|
+
let(:source_file) { double("::File", :read => nil) }
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(fetcher).to receive(:node).and_return({ "platform_family" => "windows" })
|
37
|
+
end
|
33
38
|
|
34
39
|
it "stages the local file to a temporary file" do
|
35
40
|
expect(Chef::FileContentManagement::Tempfile).to receive(:new).with(new_resource).and_return(chef_tempfile)
|
36
|
-
expect(::
|
41
|
+
expect(::File).to receive(:open).with(source, "rb").and_return(source_file)
|
37
42
|
expect(tempfile).to receive(:close)
|
38
43
|
|
39
44
|
result = fetcher.fetch
|
@@ -74,7 +74,10 @@ XML
|
|
74
74
|
let(:service_label) { "io.redis.redis-server" }
|
75
75
|
before do
|
76
76
|
allow(Dir).to receive(:glob).and_return([plist], [])
|
77
|
-
|
77
|
+
@stat = double("File::Stat", { :uid => 501 })
|
78
|
+
allow(File).to receive(:stat).and_return(@stat)
|
79
|
+
@getpwuid = double("Etc::Passwd", { :name => "mikedodge04" })
|
80
|
+
allow(Etc).to receive(:getpwuid).and_return(@getpwuid)
|
78
81
|
allow(node).to receive(:[]).with("platform_version").and_return(platform_version)
|
79
82
|
cmd = "launchctl list #{service_label}"
|
80
83
|
allow(provider).to receive(:shell_out_with_systems_locale).
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Nimisha Sharad (<nimisha.sharad@msystechnologies.com>)
|
3
|
+
# Copyright:: Copyright 2008-2017, 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
|
+
|
21
|
+
describe Chef::Provider::WindowsPath, :windows_only do
|
22
|
+
before(:all) do
|
23
|
+
@old_path = ENV["PATH"].dup
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
ENV["PATH"] = @old_path
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:new_resource) { Chef::Resource::WindowsPath.new("some_path") }
|
31
|
+
|
32
|
+
let(:provider) do
|
33
|
+
node = Chef::Node.new
|
34
|
+
events = Chef::EventDispatch::Dispatcher.new
|
35
|
+
run_context = Chef::RunContext.new(node, {}, events)
|
36
|
+
Chef::Provider::WindowsPath.new(new_resource, run_context)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#load_current_resource" do
|
40
|
+
it "returns a current_resource" do
|
41
|
+
expect(provider.load_current_resource).to be_kind_of(Chef::Resource::WindowsPath)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sets the path of current resource as the path of new resource" do
|
45
|
+
current_resource = provider.load_current_resource
|
46
|
+
expect(current_resource.path).to eq("some_path")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#action_add" do
|
51
|
+
it "uses env resource to add 'path' environment variable" do
|
52
|
+
allow(provider).to receive(:expand_env_vars)
|
53
|
+
expect(provider).to receive(:declare_resource).with(:env, "path")
|
54
|
+
provider.run_action(:add)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#action_remove" do
|
59
|
+
it "uses env resource to remove 'path' environment variable" do
|
60
|
+
allow(provider).to receive(:expand_env_vars)
|
61
|
+
expect(provider).to receive(:declare_resource).with(:env, "path")
|
62
|
+
provider.run_action(:remove)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Nimisha Sharad (<nimisha.sharad@msystechnologies.com>)
|
3
|
+
# Copyright:: Copyright 2008-2017, 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
|
+
|
21
|
+
describe Chef::Resource::WindowsPath do
|
22
|
+
subject { Chef::Resource::WindowsPath.new("some_path") }
|
23
|
+
|
24
|
+
it { is_expected.to be_a_kind_of(Chef::Resource) }
|
25
|
+
it { is_expected.to be_a_instance_of(Chef::Resource::WindowsPath) }
|
26
|
+
|
27
|
+
it "sets resource name as :windows_path" do
|
28
|
+
expect(subject.resource_name).to eql(:windows_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets the path as it's name" do
|
32
|
+
expect(subject.path).to eql("some_path")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "sets the default action as :add" do
|
36
|
+
expect(subject.action).to eql(:add)
|
37
|
+
end
|
38
|
+
end
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -377,6 +377,14 @@ describe Chef::Resource do
|
|
377
377
|
expect(resource.to_text).to match(/foo "\*sensitive value suppressed\*"/)
|
378
378
|
end
|
379
379
|
end
|
380
|
+
|
381
|
+
context "when property is required" do
|
382
|
+
it "does not propagate vailidation errors" do
|
383
|
+
resource_class = Class.new(Chef::Resource) { property :foo, String, required: true }
|
384
|
+
resource = resource_class.new("required_property_tests")
|
385
|
+
expect { resource.to_text }.to_not raise_error Chef::Exceptions::ValidationFailed
|
386
|
+
end
|
387
|
+
end
|
380
388
|
end
|
381
389
|
|
382
390
|
describe "self.resource_name" do
|
@@ -47,119 +47,143 @@ describe Shell::ShellSession do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
describe Shell::ClientSession do
|
50
|
+
let(:json_attribs) { { "a" => "b" } }
|
51
|
+
let(:chef_rest) { double("Chef::ServerAPI") }
|
52
|
+
let(:node) { Chef::Node.build("foo") }
|
53
|
+
let(:session) { Shell::ClientSession.instance }
|
54
|
+
let(:client) do
|
55
|
+
double("Chef::Client.new",
|
56
|
+
:run_ohai => true,
|
57
|
+
:load_node => true,
|
58
|
+
:build_node => true,
|
59
|
+
:register => true,
|
60
|
+
:sync_cookbooks => {}
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
50
64
|
before do
|
51
65
|
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new("shell::override")] }
|
52
|
-
|
53
|
-
|
54
|
-
@node = Chef::Node.build("foo")
|
55
|
-
@session.node = @node
|
56
|
-
@client = double("Chef::Client.new",
|
57
|
-
:run_ohai => true,
|
58
|
-
:load_node => true,
|
59
|
-
:build_node => true,
|
60
|
-
:register => true,
|
61
|
-
:sync_cookbooks => {})
|
66
|
+
session.node = node
|
67
|
+
session.json_configuration = json_attribs
|
62
68
|
end
|
63
69
|
|
64
70
|
it "builds the node's run_context with the proper environment" do
|
65
|
-
|
66
|
-
|
71
|
+
session.instance_variable_set(:@client, client)
|
72
|
+
expansion = Chef::RunList::RunListExpansion.new(node.chef_environment, [])
|
67
73
|
|
68
|
-
expect(
|
69
|
-
expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(
|
70
|
-
|
74
|
+
expect(node.run_list).to receive(:expand).with(node.chef_environment).and_return(expansion)
|
75
|
+
expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
|
76
|
+
session.rebuild_context
|
71
77
|
end
|
72
78
|
|
73
79
|
it "passes the shell CLI args to the client" do
|
74
|
-
expect(Chef::Client).to receive(:new).with(
|
75
|
-
|
80
|
+
expect(Chef::Client).to receive(:new).with(json_attribs, Chef::Config[:shell_config]).and_return(client)
|
81
|
+
session.send(:rebuild_node)
|
76
82
|
end
|
77
83
|
|
78
84
|
end
|
79
85
|
|
80
86
|
describe Shell::SoloSession do
|
87
|
+
let(:json_attribs) { { "a" => "b" } }
|
88
|
+
let(:chef_rest) { double("Chef::ServerAPI") }
|
89
|
+
let(:node) { Chef::Node.build("foo") }
|
90
|
+
let(:session) { Shell::SoloSession.instance }
|
91
|
+
let(:client) do
|
92
|
+
double("Chef::Client.new",
|
93
|
+
:run_ohai => true,
|
94
|
+
:load_node => true,
|
95
|
+
:build_node => true,
|
96
|
+
:register => true,
|
97
|
+
:sync_cookbooks => {}
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
81
101
|
before do
|
82
102
|
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new("shell::override")] }
|
83
|
-
|
84
|
-
|
85
|
-
@node = Chef::Node.build("foo")
|
86
|
-
@session.node = @node
|
87
|
-
@client = double("Chef::Client.new",
|
88
|
-
:run_ohai => true,
|
89
|
-
:load_node => true,
|
90
|
-
:build_node => true,
|
91
|
-
:register => true,
|
92
|
-
:sync_cookbooks => {})
|
103
|
+
session.node = node
|
104
|
+
session.json_configuration = json_attribs
|
93
105
|
end
|
94
106
|
|
95
107
|
it "builds the node's run_context with the proper environment" do
|
96
|
-
|
97
|
-
|
108
|
+
session.instance_variable_set(:@client, client)
|
109
|
+
expansion = Chef::RunList::RunListExpansion.new(node.chef_environment, [])
|
98
110
|
|
99
|
-
expect(
|
100
|
-
expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(
|
101
|
-
|
111
|
+
expect(node.run_list).to receive(:expand).with(node.chef_environment).and_return(expansion)
|
112
|
+
expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
|
113
|
+
session.rebuild_context
|
102
114
|
end
|
103
115
|
|
104
116
|
it "passes the shell CLI args to the client" do
|
105
|
-
expect(Chef::Client).to receive(:new).with(
|
106
|
-
|
117
|
+
expect(Chef::Client).to receive(:new).with(json_attribs, Chef::Config[:shell_config]).and_return(client)
|
118
|
+
session.send(:rebuild_node)
|
107
119
|
end
|
108
120
|
|
109
121
|
end
|
110
122
|
|
111
123
|
describe Shell::StandAloneSession do
|
124
|
+
let(:json_attribs) { { "a" => "b" } }
|
125
|
+
let(:chef_rest) { double("Chef::ServerAPI") }
|
126
|
+
let(:node) { Chef::Node.new }
|
127
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
128
|
+
let(:session) { Shell::StandAloneSession.instance }
|
129
|
+
let(:client) do
|
130
|
+
double("Chef::Client.new",
|
131
|
+
:run_ohai => true,
|
132
|
+
:load_node => true,
|
133
|
+
:build_node => true,
|
134
|
+
:register => true,
|
135
|
+
:sync_cookbooks => {}
|
136
|
+
)
|
137
|
+
end
|
138
|
+
let(:recipe) { Chef::Recipe.new(nil, nil, run_context) }
|
139
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
140
|
+
|
112
141
|
before do
|
113
142
|
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new("shell::override")] }
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Shell::Extensions.extend_context_recipe(@recipe)
|
143
|
+
session.node = node
|
144
|
+
session.json_configuration = json_attribs
|
145
|
+
session.run_context = run_context
|
146
|
+
session.recipe = recipe
|
147
|
+
Shell::Extensions.extend_context_recipe(recipe)
|
120
148
|
end
|
121
149
|
|
122
150
|
it "has a run_context" do
|
123
|
-
expect(
|
151
|
+
expect(session.run_context).to equal(run_context)
|
124
152
|
end
|
125
153
|
|
126
154
|
it "returns a collection based on it's standalone recipe file" do
|
127
|
-
expect(
|
155
|
+
expect(session.resource_collection).to eq(recipe.run_context.resource_collection)
|
128
156
|
end
|
129
157
|
|
130
158
|
it "gives nil for the definitions (for now)" do
|
131
|
-
expect(
|
159
|
+
expect(session.definitions).to be_nil
|
132
160
|
end
|
133
161
|
|
134
162
|
it "gives nil for the cookbook_loader" do
|
135
|
-
expect(
|
163
|
+
expect(session.cookbook_loader).to be_nil
|
136
164
|
end
|
137
165
|
|
138
166
|
it "runs chef with the standalone recipe" do
|
139
|
-
allow(
|
167
|
+
allow(session).to receive(:node_built?).and_return(true)
|
140
168
|
allow(Chef::Log).to receive(:level)
|
141
169
|
chef_runner = double("Chef::Runner.new", :converge => :converged)
|
142
170
|
# pre-heat resource collection cache
|
143
|
-
|
171
|
+
session.resource_collection
|
144
172
|
|
145
|
-
expect(Chef::Runner).to receive(:new).with(
|
146
|
-
expect(
|
173
|
+
expect(Chef::Runner).to receive(:new).with(session.recipe.run_context).and_return(chef_runner)
|
174
|
+
expect(recipe.run_chef).to eq(:converged)
|
147
175
|
end
|
148
176
|
|
149
177
|
it "passes the shell CLI args to the client" do
|
150
|
-
|
151
|
-
|
152
|
-
:load_node => true,
|
153
|
-
:build_node => true,
|
154
|
-
:register => true,
|
155
|
-
:sync_cookbooks => {})
|
156
|
-
expect(Chef::Client).to receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client)
|
157
|
-
@session.send(:rebuild_node)
|
178
|
+
expect(Chef::Client).to receive(:new).with(json_attribs, Chef::Config[:shell_config]).and_return(client)
|
179
|
+
session.send(:rebuild_node)
|
158
180
|
end
|
159
181
|
|
160
182
|
end
|
161
183
|
|
162
184
|
describe Shell::SoloLegacySession do
|
185
|
+
let(:json_attribs) { { "a" => "b" } }
|
186
|
+
|
163
187
|
before do
|
164
188
|
Chef::Config[:shell_config] = { :override_runlist => [Chef::RunList::RunListItem.new("shell::override")] }
|
165
189
|
Chef::Config[:shell_solo] = true
|
@@ -219,8 +243,8 @@ describe Shell::SoloLegacySession do
|
|
219
243
|
:build_node => true,
|
220
244
|
:register => true,
|
221
245
|
:sync_cookbooks => {})
|
222
|
-
expect(Chef::Client).to receive(:new).with(
|
246
|
+
expect(Chef::Client).to receive(:new).with(json_attribs, Chef::Config[:shell_config]).and_return(@client)
|
247
|
+
@session.json_configuration = json_attribs
|
223
248
|
@session.send(:rebuild_node)
|
224
249
|
end
|
225
|
-
|
226
250
|
end
|