chef 14.7.17 → 14.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/mixin/which.rb +3 -1
- data/lib/chef/provider/apt_repository.rb +1 -1
- data/lib/chef/provider/execute.rb +1 -1
- data/lib/chef/provider/osx_profile.rb +1 -1
- data/lib/chef/provider/package/apt.rb +15 -3
- data/lib/chef/provider/package/cab.rb +6 -2
- data/lib/chef/provider/package/chocolatey.rb +1 -1
- data/lib/chef/provider/package/dnf/python_helper.rb +2 -1
- data/lib/chef/provider/package/openbsd.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +38 -16
- data/lib/chef/resource/apt_package.rb +1 -1
- data/lib/chef/resource/apt_preference.rb +1 -1
- data/lib/chef/resource/apt_repository.rb +1 -1
- data/lib/chef/resource/chocolatey_config.rb +1 -1
- data/lib/chef/resource/chocolatey_source.rb +1 -1
- data/lib/chef/resource/cron.rb +27 -8
- data/lib/chef/resource/cron_access.rb +1 -1
- data/lib/chef/resource/cron_d.rb +8 -8
- data/lib/chef/resource/directory.rb +1 -1
- data/lib/chef/resource/dmg_package.rb +9 -9
- data/lib/chef/resource/execute.rb +2 -2
- data/lib/chef/resource/homebrew_cask.rb +1 -1
- data/lib/chef/resource/homebrew_tap.rb +1 -1
- data/lib/chef/resource/hostname.rb +2 -2
- data/lib/chef/resource/kernel_module.rb +1 -1
- data/lib/chef/resource/link.rb +1 -1
- data/lib/chef/resource/ohai_hint.rb +1 -1
- data/lib/chef/resource/package.rb +1 -1
- data/lib/chef/resource/scm.rb +1 -1
- data/lib/chef/resource/swap_file.rb +1 -1
- data/lib/chef/resource/sysctl.rb +1 -1
- data/lib/chef/resource/systemd_unit.rb +1 -1
- data/lib/chef/resource/template.rb +11 -3
- data/lib/chef/resource/windows_ad_join.rb +1 -1
- data/lib/chef/resource/windows_auto_run.rb +1 -1
- data/lib/chef/resource/windows_certificate.rb +2 -1
- data/lib/chef/resource/windows_feature.rb +6 -6
- data/lib/chef/resource/windows_feature_dism.rb +13 -17
- data/lib/chef/resource/windows_feature_powershell.rb +1 -1
- data/lib/chef/resource/windows_share.rb +9 -3
- data/lib/chef/resource/windows_task.rb +230 -231
- data/lib/chef/resource/windows_workgroup.rb +32 -23
- data/lib/chef/resource/yum_repository.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/spec/functional/resource/msu_package_spec.rb +14 -0
- data/spec/integration/knife/raw_spec.rb +11 -7
- data/spec/integration/knife/redirection_spec.rb +6 -4
- data/spec/support/shared/integration/app_server_support.rb +2 -2
- data/spec/unit/provider/apt_repository_spec.rb +3 -3
- data/spec/unit/provider/package/apt_spec.rb +81 -4
- data/spec/unit/provider/package/rubygems_spec.rb +47 -9
- data/spec/unit/resource/windows_certificate.rb +30 -0
- data/spec/unit/resource/windows_feature.rb +4 -0
- data/spec/unit/resource/windows_workgroup_spec.rb +27 -0
- metadata +4 -4
@@ -36,19 +36,36 @@ class Chef
|
|
36
36
|
name_property: true
|
37
37
|
|
38
38
|
property :user, String,
|
39
|
-
description: "The local administrator user to use to change the workgroup.",
|
39
|
+
description: "The local administrator user to use to change the workgroup. Required if using the password property.",
|
40
40
|
desired_state: false
|
41
41
|
|
42
42
|
property :password, String,
|
43
|
-
description: "The password for the local administrator user.",
|
43
|
+
description: "The password for the local administrator user. Required if using the user property.",
|
44
44
|
desired_state: false
|
45
45
|
|
46
46
|
property :reboot, Symbol,
|
47
|
-
equal_to: [:
|
47
|
+
equal_to: [:never, :request_reboot, :reboot_now],
|
48
48
|
validation_message: "The reboot property accepts :immediate (reboot as soon as the resource completes), :delayed (reboot once the Chef run completes), and :never (Don't reboot)",
|
49
49
|
description: "Controls the system reboot behavior post workgroup joining. Reboot immediately, after the Chef run completes, or never. Note that a reboot is necessary for changes to take effect.",
|
50
|
+
coerce: proc { |x| clarify_reboot(x) },
|
50
51
|
default: :immediate, desired_state: false
|
51
52
|
|
53
|
+
# This resource historically took `:immediate` and `:delayed` as arguments to the reboot property but then
|
54
|
+
# tried to shove that straight to the `reboot` resource which objected strenuously. We need to convert these
|
55
|
+
# legacy actions into actual reboot actions
|
56
|
+
#
|
57
|
+
# @return [Symbol] chef reboot resource action
|
58
|
+
def clarify_reboot(reboot_action)
|
59
|
+
case reboot_action
|
60
|
+
when :immediate
|
61
|
+
:reboot_now
|
62
|
+
when :delayed
|
63
|
+
:request_reboot
|
64
|
+
else
|
65
|
+
reboot_action
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
52
69
|
# define this again so we can default it to true. Otherwise failures print the password
|
53
70
|
property :sensitive, [TrueClass, FalseClass],
|
54
71
|
default: true, desired_state: false
|
@@ -57,20 +74,13 @@ class Chef
|
|
57
74
|
description "Update the workgroup."
|
58
75
|
|
59
76
|
unless workgroup_member?
|
60
|
-
cmd = ""
|
61
|
-
cmd << "$pswd = ConvertTo-SecureString \'#{new_resource.password}\' -AsPlainText -Force;" if new_resource.password
|
62
|
-
cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{new_resource.user}\",$pswd);" if new_resource.password
|
63
|
-
cmd << "Add-Computer -WorkgroupName #{new_resource.workgroup_name}"
|
64
|
-
cmd << " -Credential $credential" if new_resource.password
|
65
|
-
cmd << " -Force"
|
66
|
-
|
67
77
|
converge_by("join workstation workgroup #{new_resource.workgroup_name}") do
|
68
|
-
ps_run = powershell_out(
|
78
|
+
ps_run = powershell_out(join_command)
|
69
79
|
raise "Failed to join the workgroup #{new_resource.workgroup_name}: #{ps_run.stderr}}" if ps_run.error?
|
70
80
|
|
71
81
|
unless new_resource.reboot == :never
|
72
82
|
reboot "Reboot to join workgroup #{new_resource.workgroup_name}" do
|
73
|
-
action
|
83
|
+
action new_resource.reboot
|
74
84
|
reason "Reboot to join workgroup #{new_resource.workgroup_name}"
|
75
85
|
end
|
76
86
|
end
|
@@ -79,19 +89,18 @@ class Chef
|
|
79
89
|
end
|
80
90
|
|
81
91
|
action_class do
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
reboot_action
|
92
|
-
end
|
92
|
+
# return [String] the appropriate PS command to joint the workgroup
|
93
|
+
def join_command
|
94
|
+
cmd = ""
|
95
|
+
cmd << "$pswd = ConvertTo-SecureString \'#{new_resource.password}\' -AsPlainText -Force;" if new_resource.password
|
96
|
+
cmd << "$credential = New-Object System.Management.Automation.PSCredential (\"#{new_resource.user}\",$pswd);" if new_resource.password
|
97
|
+
cmd << "Add-Computer -WorkgroupName #{new_resource.workgroup_name}"
|
98
|
+
cmd << " -Credential $credential" if new_resource.password
|
99
|
+
cmd << " -Force"
|
100
|
+
cmd
|
93
101
|
end
|
94
102
|
|
103
|
+
# @return [Boolean] is the node a member of the workgroup specified in the resource
|
95
104
|
def workgroup_member?
|
96
105
|
node_workgroup = powershell_out!("(Get-WmiObject -Class Win32_ComputerSystem).Workgroup")
|
97
106
|
raise "Failed to determine if system already a member of workgroup #{new_resource.workgroup_name}" if node_workgroup.error?
|
@@ -143,7 +143,7 @@ class Chef
|
|
143
143
|
description: "Determines whether to report the instance ID when using Amazon Linux AMIs and repositories."
|
144
144
|
|
145
145
|
property :repositoryid, String, regex: [/^[^\/]+$/],
|
146
|
-
description: "Specifies a unique name for each repository, one word. Defaults to name
|
146
|
+
description: "Specifies a unique name for each repository, one word. Defaults to name property.",
|
147
147
|
validation_message: "repositoryid property cannot contain a forward slash '/'",
|
148
148
|
name_property: true
|
149
149
|
|
data/lib/chef/version.rb
CHANGED
@@ -76,6 +76,20 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
context "when an msu package is not applicable to the image." do
|
80
|
+
def package_name
|
81
|
+
"Package_for_KB4019990"
|
82
|
+
end
|
83
|
+
|
84
|
+
def package_source
|
85
|
+
"http://download.windowsupdate.com/c/msdownload/update/software/updt/2017/05/windows8-rt-kb4019990-x64_a77f4e3e1f2d47205824763e7121bb11979c2716.msu"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises error while installing" do
|
89
|
+
expect { subject.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /The specified package is not applicable to this image./)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
79
93
|
def remove_package
|
80
94
|
pkg_to_remove = Chef::Resource::MsuPackage.new(package_name, run_context)
|
81
95
|
pkg_to_remove.source = package_source
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
-
# Copyright:: Copyright 2013-
|
3
|
+
# Copyright:: Copyright 2013-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");
|
@@ -190,12 +190,14 @@ EOM
|
|
190
190
|
app = lambda do |env|
|
191
191
|
[200, { "Content-Type" => "application/json" }, ['{ "x": "y", "a": "b" }'] ]
|
192
192
|
end
|
193
|
-
@
|
193
|
+
@raw_server_thread = start_app_server(app, 9018)
|
194
194
|
end
|
195
195
|
|
196
196
|
after :each do
|
197
|
-
|
198
|
-
|
197
|
+
if @raw_server_thread
|
198
|
+
@raw_server_thread.kill
|
199
|
+
@raw_server_thread.join(30)
|
200
|
+
end
|
199
201
|
end
|
200
202
|
|
201
203
|
it "knife raw /blah returns the prettified json", skip: (RUBY_VERSION < "1.9") do
|
@@ -220,12 +222,14 @@ EOM
|
|
220
222
|
app = lambda do |env|
|
221
223
|
[200, { "Content-Type" => "text" }, ['{ "x": "y", "a": "b" }'] ]
|
222
224
|
end
|
223
|
-
@
|
225
|
+
@raw_server_thread = start_app_server(app, 9018)
|
224
226
|
end
|
225
227
|
|
226
228
|
after :each do
|
227
|
-
|
228
|
-
|
229
|
+
if @raw_server_thread
|
230
|
+
@raw_server_thread.kill
|
231
|
+
@raw_server_thread.join(30)
|
232
|
+
end
|
229
233
|
end
|
230
234
|
|
231
235
|
it "knife raw /blah returns the raw text" do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
-
# Copyright:: Copyright 2013-
|
3
|
+
# Copyright:: Copyright 2013-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");
|
@@ -36,12 +36,14 @@ describe "redirection", :workstation do
|
|
36
36
|
app = lambda do |env|
|
37
37
|
[302, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}#{env['PATH_INFO']}" }, ["302 found"] ]
|
38
38
|
end
|
39
|
-
@
|
39
|
+
@redirector_server_thread = start_app_server(app, 9018)
|
40
40
|
end
|
41
41
|
|
42
42
|
after :each do
|
43
|
-
|
44
|
-
|
43
|
+
if @redirector_thread
|
44
|
+
@redirector_thread.kill
|
45
|
+
@redirector_thread.join(30)
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
it "knife list /roles returns the role" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
3
|
# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
|
4
|
-
# Copyright:: Copyright 2012-
|
4
|
+
# Copyright:: Copyright 2012-2018, Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -35,6 +35,6 @@ module AppServerSupport
|
|
35
35
|
Timeout.timeout(30) do
|
36
36
|
sleep(0.01) until server && server.status == :Running
|
37
37
|
end
|
38
|
-
|
38
|
+
thread
|
39
39
|
end
|
40
40
|
end
|
@@ -162,16 +162,16 @@ C5986B4F1257FFA86632CBA746181433FBB75451
|
|
162
162
|
|
163
163
|
describe "#keyserver_install_cmd" do
|
164
164
|
it "returns keyserver install command" do
|
165
|
-
expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --recv --keyserver hkp://gpg.mit.edu:80 ABC")
|
165
|
+
expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --no-tty --recv --keyserver hkp://gpg.mit.edu:80 ABC")
|
166
166
|
end
|
167
167
|
|
168
168
|
it "uses proxy if key_proxy property is set" do
|
169
169
|
new_resource.key_proxy("proxy.mycorp.dmz:3128")
|
170
|
-
expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --recv --keyserver-options http-proxy=proxy.mycorp.dmz:3128 --keyserver hkp://gpg.mit.edu:80 ABC")
|
170
|
+
expect(provider.keyserver_install_cmd("ABC", "gpg.mit.edu")).to eq("apt-key adv --no-tty --recv --keyserver-options http-proxy=proxy.mycorp.dmz:3128 --keyserver hkp://gpg.mit.edu:80 ABC")
|
171
171
|
end
|
172
172
|
|
173
173
|
it "properly handles keyservers passed with hkp:// URIs" do
|
174
|
-
expect(provider.keyserver_install_cmd("ABC", "hkp://gpg.mit.edu")).to eq("apt-key adv --recv --keyserver hkp://gpg.mit.edu ABC")
|
174
|
+
expect(provider.keyserver_install_cmd("ABC", "hkp://gpg.mit.edu")).to eq("apt-key adv --no-tty --recv --keyserver hkp://gpg.mit.edu ABC")
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -256,7 +256,78 @@ describe Chef::Provider::Package::Apt do
|
|
256
256
|
})
|
257
257
|
end
|
258
258
|
|
259
|
+
def ubuntu1804downgrade_stubs
|
260
|
+
so = instance_double(Mixlib::ShellOut, stdout: "apt 1.6~beta1 (amd64)\notherstuff\n")
|
261
|
+
so2 = instance_double(Mixlib::ShellOut, error?: false)
|
262
|
+
allow(@provider).to receive(:shell_out).with("apt-get --version").and_return(so)
|
263
|
+
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.6~beta1", "gt", "1.1.0").and_return(so2)
|
264
|
+
end
|
265
|
+
|
266
|
+
def ubuntu1404downgrade_stubs
|
267
|
+
so = instance_double(Mixlib::ShellOut, stdout: "apt 1.0.1ubuntu2 for amd64 compiled on Dec 8 2016 16:23:38\notherstuff\n")
|
268
|
+
so2 = instance_double(Mixlib::ShellOut, error?: true)
|
269
|
+
allow(@provider).to receive(:shell_out).with("apt-get --version").and_return(so)
|
270
|
+
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.0.1ubuntu2", "gt", "1.1.0").and_return(so2)
|
271
|
+
allow(@provider).to receive(:shell_out).with("dpkg", "--compare-versions", "1.0.1ubuntu2", "eq", "1.1.0").and_return(so2)
|
272
|
+
end
|
273
|
+
|
259
274
|
describe "install_package" do
|
275
|
+
before(:each) do
|
276
|
+
ubuntu1804downgrade_stubs
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should run apt-get install with the package name and version" do
|
280
|
+
expect(@provider).to receive(:shell_out_compacted!). with(
|
281
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
|
282
|
+
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
283
|
+
timeout: @timeout
|
284
|
+
)
|
285
|
+
@provider.install_package(["irssi"], ["0.8.12-7"])
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should run apt-get install with the package name and version and options if specified" do
|
289
|
+
expect(@provider).to receive(:shell_out_compacted!).with(
|
290
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--force-yes", "install", "irssi=0.8.12-7",
|
291
|
+
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
292
|
+
timeout: @timeout
|
293
|
+
)
|
294
|
+
@new_resource.options("--force-yes")
|
295
|
+
@provider.install_package(["irssi"], ["0.8.12-7"])
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should run apt-get install with the package name and version and default_release if there is one and provider is explicitly defined" do
|
299
|
+
@new_resource = nil
|
300
|
+
@new_resource = Chef::Resource::AptPackage.new("irssi", @run_context)
|
301
|
+
@new_resource.default_release("lenny-backports")
|
302
|
+
@new_resource.provider = nil
|
303
|
+
@provider.new_resource = @new_resource
|
304
|
+
|
305
|
+
expect(@provider).to receive(:shell_out_compacted!).with(
|
306
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "-o", "APT::Default-Release=lenny-backports", "install", "irssi=0.8.12-7",
|
307
|
+
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
308
|
+
timeout: @timeout
|
309
|
+
)
|
310
|
+
|
311
|
+
@provider.install_package(["irssi"], ["0.8.12-7"])
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should run apt-get install with the package name and quotes options if specified" do
|
315
|
+
expect(@provider).to receive(:shell_out_compacted!).with(
|
316
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "--force-yes", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confnew", "install", "irssi=0.8.12-7",
|
317
|
+
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
318
|
+
timeout: @timeout
|
319
|
+
)
|
320
|
+
@new_resource.options('--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew"')
|
321
|
+
@provider.install_package(["irssi"], ["0.8.12-7"])
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe "install_package with old apt-get" do
|
326
|
+
# tests apt-get on 1404 that does not support --allow-downgrades
|
327
|
+
before(:each) do
|
328
|
+
ubuntu1404downgrade_stubs
|
329
|
+
end
|
330
|
+
|
260
331
|
it "should run apt-get install with the package name and version" do
|
261
332
|
expect(@provider).to receive(:shell_out_compacted!). with(
|
262
333
|
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
|
@@ -449,9 +520,10 @@ describe Chef::Provider::Package::Apt do
|
|
449
520
|
|
450
521
|
describe "when installing a virtual package" do
|
451
522
|
it "should install the package without specifying a version" do
|
523
|
+
ubuntu1804downgrade_stubs
|
452
524
|
@provider.package_data["libmysqlclient15-dev"][:virtual] = true
|
453
525
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
454
|
-
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev",
|
526
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev",
|
455
527
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
456
528
|
timeout: @timeout
|
457
529
|
)
|
@@ -485,9 +557,10 @@ describe Chef::Provider::Package::Apt do
|
|
485
557
|
|
486
558
|
describe "when installing multiple packages" do
|
487
559
|
it "can install a virtual package followed by a non-virtual package" do
|
560
|
+
ubuntu1804downgrade_stubs
|
488
561
|
# https://github.com/chef/chef/issues/2914
|
489
562
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
490
|
-
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev", "irssi=0.8.12-7",
|
563
|
+
"apt-get", "-q", "-y", "--allow-downgrades", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "libmysqlclient15-dev", "irssi=0.8.12-7",
|
491
564
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
492
565
|
timeout: @timeout
|
493
566
|
)
|
@@ -506,9 +579,11 @@ describe Chef::Provider::Package::Apt do
|
|
506
579
|
end
|
507
580
|
|
508
581
|
it "should install the package if the installed version is older" do
|
582
|
+
ubuntu1804downgrade_stubs
|
583
|
+
expect(@provider).to receive(:version_compare).with("1.6~beta1", "1.1.0").and_return(1)
|
509
584
|
allow(@provider).to receive(:get_current_versions).and_return("0.4.0")
|
510
585
|
allow(@new_resource).to receive(:allow_downgrade).and_return(false)
|
511
|
-
expect(@provider).to receive(:version_compare).and_return(-1)
|
586
|
+
expect(@provider).to receive(:version_compare).with("0.4.0", any_args).and_return(-1)
|
512
587
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
513
588
|
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
|
514
589
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
@@ -518,9 +593,11 @@ describe Chef::Provider::Package::Apt do
|
|
518
593
|
end
|
519
594
|
|
520
595
|
it "should not compare versions if an existing version is not installed" do
|
596
|
+
ubuntu1804downgrade_stubs
|
597
|
+
expect(@provider).to receive(:version_compare).with("1.6~beta1", "1.1.0").and_return(1)
|
521
598
|
allow(@provider).to receive(:get_current_versions).and_return(nil)
|
522
599
|
allow(@new_resource).to receive(:allow_downgrade).and_return(false)
|
523
|
-
expect(@provider).not_to receive(:version_compare)
|
600
|
+
expect(@provider).not_to receive(:version_compare).with("0.4.0", any_args)
|
524
601
|
expect(@provider).to receive(:shell_out_compacted!).with(
|
525
602
|
"apt-get", "-q", "-y", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "irssi=0.8.12-7",
|
526
603
|
env: { "DEBIAN_FRONTEND" => "noninteractive" },
|
@@ -396,6 +396,10 @@ describe Chef::Provider::Package::Rubygems do
|
|
396
396
|
allow(RbConfig::CONFIG).to receive(:[]).with("arch").and_call_original
|
397
397
|
allow(File).to receive(:executable?).and_return false
|
398
398
|
allow(File).to receive(:executable?).with("#{bindir}/gem").and_return true
|
399
|
+
# XXX: we can't stub the provider object directly here because referencing it will create it and that
|
400
|
+
# will break later tests that want to test the initialize method, so we stub any instance
|
401
|
+
# (yet more evidence that initialize methods should be thin and do very little work)
|
402
|
+
allow_any_instance_of(Chef::Provider::Package::Rubygems).to receive(:needs_nodocument?).and_return true
|
399
403
|
end
|
400
404
|
|
401
405
|
describe "when new_resource version is nil" do
|
@@ -696,7 +700,25 @@ describe Chef::Provider::Package::Rubygems do
|
|
696
700
|
let(:options) { "-i /alt/install/location" }
|
697
701
|
|
698
702
|
it "installs the gem by shelling out when options are provided as a String" do
|
703
|
+
expected = "gem install rspec-core -q --no-document -v \"#{target_version}\" --source=https://www.rubygems.org #{options}"
|
704
|
+
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
705
|
+
provider.run_action(:install)
|
706
|
+
expect(new_resource).to be_updated_by_last_action
|
707
|
+
end
|
708
|
+
|
709
|
+
it "unmockening needs_nodocument?" do
|
710
|
+
expected = "gem install rspec-core -q --no-document -v \"#{target_version}\" --source=https://www.rubygems.org #{options}"
|
711
|
+
expect(provider).to receive(:needs_nodocument?).and_call_original
|
712
|
+
stub_const("Gem::VERSION", "3.0.0")
|
713
|
+
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
714
|
+
provider.run_action(:install)
|
715
|
+
expect(new_resource).to be_updated_by_last_action
|
716
|
+
end
|
717
|
+
|
718
|
+
it "when the rubygems_version is old it uses the old flags" do
|
699
719
|
expected = "gem install rspec-core -q --no-rdoc --no-ri -v \"#{target_version}\" --source=https://www.rubygems.org #{options}"
|
720
|
+
expect(provider).to receive(:needs_nodocument?).and_call_original
|
721
|
+
stub_const("Gem::VERSION", "2.8.0")
|
700
722
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
701
723
|
provider.run_action(:install)
|
702
724
|
expect(new_resource).to be_updated_by_last_action
|
@@ -709,7 +731,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
709
731
|
it "installs the gem with rubygems.org as an added source" do
|
710
732
|
Chef::Config[:rubygems_url] = "https://mirror1"
|
711
733
|
expect(provider.gem_env).to receive(:candidate_version_from_remote).with(gem_dep, Chef::Config[:rubygems_url]).and_return(version)
|
712
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
734
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://mirror1"
|
713
735
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
714
736
|
provider.run_action(:install)
|
715
737
|
expect(new_resource).to be_updated_by_last_action
|
@@ -721,7 +743,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
721
743
|
let(:gem_binary) { "/foo/bar" }
|
722
744
|
|
723
745
|
it "installs the gem with rubygems.org as an added source" do
|
724
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
746
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=#{source} --source=https://www.rubygems.org"
|
725
747
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
726
748
|
provider.run_action(:install)
|
727
749
|
expect(new_resource).to be_updated_by_last_action
|
@@ -732,7 +754,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
732
754
|
|
733
755
|
it "ignores the Chef::Config setting" do
|
734
756
|
Chef::Config[:rubygems_url] = "https://ignored"
|
735
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
757
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=#{source}"
|
736
758
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
737
759
|
provider.run_action(:install)
|
738
760
|
expect(new_resource).to be_updated_by_last_action
|
@@ -745,7 +767,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
745
767
|
let(:gem_binary) { "/foo/bar" }
|
746
768
|
|
747
769
|
it "installs the gem with an array as an added source" do
|
748
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
770
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://mirror1 --source=https://mirror2 --source=https://www.rubygems.org"
|
749
771
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
750
772
|
provider.run_action(:install)
|
751
773
|
expect(new_resource).to be_updated_by_last_action
|
@@ -756,7 +778,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
756
778
|
|
757
779
|
it "ignores the Chef::Config setting" do
|
758
780
|
Chef::Config[:rubygems_url] = "https://ignored"
|
759
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
781
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://mirror1 --source=https://mirror2"
|
760
782
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
761
783
|
provider.run_action(:install)
|
762
784
|
expect(new_resource).to be_updated_by_last_action
|
@@ -770,7 +792,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
770
792
|
|
771
793
|
it "installs the gem" do
|
772
794
|
new_resource.clear_sources(true)
|
773
|
-
expected = "#{gem_binary} install rspec-core -q --no-
|
795
|
+
expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --clear-sources --source=#{source} --source=https://www.rubygems.org"
|
774
796
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
775
797
|
provider.run_action(:install)
|
776
798
|
expect(new_resource).to be_updated_by_last_action
|
@@ -782,7 +804,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
782
804
|
let(:options) { "-i /alt/install/location" }
|
783
805
|
|
784
806
|
it "installs the gem by shelling out when options are provided but no version is given" do
|
785
|
-
expected = "gem install rspec-core -q --no-
|
807
|
+
expected = "gem install rspec-core -q --no-document -v \"#{candidate_version}\" --source=https://www.rubygems.org #{options}"
|
786
808
|
expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900)
|
787
809
|
provider.run_action(:install)
|
788
810
|
expect(new_resource).to be_updated_by_last_action
|
@@ -846,6 +868,22 @@ describe Chef::Provider::Package::Rubygems do
|
|
846
868
|
let(:gem_binary) { "/usr/weird/bin/gem" }
|
847
869
|
|
848
870
|
it "installs the gem by shelling out to gem install" do
|
871
|
+
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://www.rubygems.org", env: nil, timeout: 900)
|
872
|
+
provider.run_action(:install)
|
873
|
+
expect(new_resource).to be_updated_by_last_action
|
874
|
+
end
|
875
|
+
|
876
|
+
it "unmockening needs_nodocument?" do
|
877
|
+
expect(provider).to receive(:needs_nodocument?).and_call_original
|
878
|
+
expect(provider.gem_env).to receive(:shell_out!).with("#{gem_binary} --version").and_return(instance_double(Mixlib::ShellOut, stdout: "3.0.0\n"))
|
879
|
+
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://www.rubygems.org", env: nil, timeout: 900)
|
880
|
+
provider.run_action(:install)
|
881
|
+
expect(new_resource).to be_updated_by_last_action
|
882
|
+
end
|
883
|
+
|
884
|
+
it "when the rubygems_version is old it uses the old flags" do
|
885
|
+
expect(provider).to receive(:needs_nodocument?).and_call_original
|
886
|
+
expect(provider.gem_env).to receive(:shell_out!).with("#{gem_binary} --version").and_return(instance_double(Mixlib::ShellOut, stdout: "2.8.0\n"))
|
849
887
|
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install rspec-core -q --no-rdoc --no-ri -v \"#{target_version}\" --source=https://www.rubygems.org", env: nil, timeout: 900)
|
850
888
|
provider.run_action(:install)
|
851
889
|
expect(new_resource).to be_updated_by_last_action
|
@@ -856,7 +894,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
856
894
|
let(:target_version) { ">= 0" }
|
857
895
|
|
858
896
|
it "installs the gem by shelling out to gem install" do
|
859
|
-
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install #{source} -q --no-
|
897
|
+
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install #{source} -q --no-document -v \"#{target_version}\"", env: nil, timeout: 900)
|
860
898
|
provider.run_action(:install)
|
861
899
|
expect(new_resource).to be_updated_by_last_action
|
862
900
|
end
|
@@ -868,7 +906,7 @@ describe Chef::Provider::Package::Rubygems do
|
|
868
906
|
|
869
907
|
it "installs the gem from file by shelling out to gem install when the package is a path and the source is nil" do
|
870
908
|
expect(new_resource.source).to eq(gem_name)
|
871
|
-
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install #{gem_name} -q --no-
|
909
|
+
expect(provider).to receive(:shell_out_compacted!).with("#{gem_binary} install #{gem_name} -q --no-document -v \"#{target_version}\"", env: nil, timeout: 900)
|
872
910
|
provider.run_action(:install)
|
873
911
|
expect(new_resource).to be_updated_by_last_action
|
874
912
|
end
|