chef 12.5.1-universal-mingw32 → 12.6.0-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 +6 -1
- data/README.md +6 -4
- data/Rakefile +1 -4
- data/chef-windows.gemspec +21 -0
- data/chef.gemspec +58 -0
- data/lib/chef/api_client/registration.rb +9 -4
- data/lib/chef/application.rb +3 -84
- data/lib/chef/application/apply.rb +9 -2
- data/lib/chef/application/client.rb +8 -3
- data/lib/chef/application/solo.rb +7 -1
- data/lib/chef/application/windows_service.rb +21 -6
- data/lib/chef/application/windows_service_manager.rb +2 -3
- data/lib/chef/audit/runner.rb +1 -0
- data/lib/chef/chef_class.rb +1 -11
- data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
- data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
- data/lib/chef/client.rb +28 -1
- data/lib/chef/cookbook/cookbook_collection.rb +14 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +115 -9
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
- data/lib/chef/cookbook_version.rb +6 -2
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/digester.rb +5 -1
- data/lib/chef/dsl/chef_provisioning.rb +57 -0
- data/lib/chef/dsl/cheffish.rb +64 -0
- data/lib/chef/dsl/declare_resource.rb +108 -0
- data/lib/chef/dsl/platform_introspection.rb +3 -3
- data/lib/chef/dsl/recipe.rb +3 -73
- data/lib/chef/dsl/resources.rb +27 -1
- data/lib/chef/event_dispatch/base.rb +3 -0
- data/lib/chef/event_dispatch/dispatcher.rb +5 -0
- data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
- data/lib/chef/exceptions.rb +21 -1
- data/lib/chef/file_access_control/unix.rb +12 -12
- data/lib/chef/file_content_management/deploy/cp.rb +2 -2
- data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
- data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
- data/lib/chef/formatters/base.rb +7 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
- data/lib/chef/formatters/indentable_output_stream.rb +5 -0
- data/lib/chef/http.rb +19 -3
- data/lib/chef/http/decompressor.rb +2 -2
- data/lib/chef/json_compat.rb +1 -0
- data/lib/chef/knife.rb +16 -2
- data/lib/chef/knife/bootstrap.rb +55 -10
- data/lib/chef/knife/cookbook_site_install.rb +5 -1
- data/lib/chef/knife/core/bootstrap_context.rb +2 -1
- data/lib/chef/knife/core/node_presenter.rb +1 -1
- data/lib/chef/knife/ssh.rb +30 -16
- data/lib/chef/knife/ssl_check.rb +4 -2
- data/lib/chef/knife/ssl_fetch.rb +3 -2
- data/lib/chef/knife/status.rb +14 -1
- data/lib/chef/log.rb +14 -0
- data/lib/chef/mixin/get_source_from_package.rb +7 -2
- data/lib/chef/mixin/properties.rb +302 -0
- data/lib/chef/mixin/proxified_socket.rb +38 -0
- data/lib/chef/mixin/subclass_directive.rb +37 -0
- data/lib/chef/node.rb +13 -5
- data/lib/chef/platform/query_helpers.rb +14 -3
- data/lib/chef/platform/service_helpers.rb +20 -38
- data/lib/chef/policy_builder/expand_node_object.rb +3 -0
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/property.rb +51 -12
- data/lib/chef/provider.rb +40 -35
- data/lib/chef/provider/deploy.rb +1 -1
- data/lib/chef/provider/dsc_resource.rb +54 -20
- data/lib/chef/provider/execute.rb +25 -4
- data/lib/chef/provider/group.rb +1 -1
- data/lib/chef/provider/lwrp_base.rb +1 -0
- data/lib/chef/provider/package.rb +76 -30
- data/lib/chef/provider/package/dpkg.rb +152 -69
- data/lib/chef/provider/package/openbsd.rb +6 -8
- data/lib/chef/provider/package/solaris.rb +2 -0
- data/lib/chef/provider/package/windows.rb +95 -14
- data/lib/chef/provider/package/windows/exe.rb +129 -0
- data/lib/chef/provider/package/windows/msi.rb +37 -13
- data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
- data/lib/chef/provider/package/yum.rb +13 -3
- data/lib/chef/provider/powershell_script.rb +3 -0
- data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/script.rb +1 -0
- data/lib/chef/provider/service.rb +13 -10
- data/lib/chef/provider/service/solaris.rb +43 -17
- data/lib/chef/provider/service/upstart.rb +3 -3
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +111 -100
- data/lib/chef/provider/user/windows.rb +5 -3
- data/lib/chef/recipe.rb +3 -5
- data/lib/chef/resource.rb +77 -320
- data/lib/chef/resource/action_class.rb +4 -0
- data/lib/chef/resource/dpkg_package.rb +4 -3
- data/lib/chef/resource/dsc_resource.rb +40 -2
- data/lib/chef/resource/execute.rb +9 -1
- data/lib/chef/resource/ksh.rb +32 -0
- data/lib/chef/resource/lwrp_base.rb +6 -10
- data/lib/chef/resource/package.rb +8 -9
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/resource_notification.rb +14 -1
- data/lib/chef/resource/script.rb +1 -1
- data/lib/chef/resource/windows_package.rb +1 -1
- data/lib/chef/resource_builder.rb +14 -7
- data/lib/chef/resource_reporter.rb +6 -0
- data/lib/chef/resources.rb +1 -7
- data/lib/chef/rest.rb +1 -1
- data/lib/chef/run_context.rb +45 -2
- data/lib/chef/run_list/run_list_expansion.rb +47 -0
- data/lib/chef/runner.rb +25 -0
- data/lib/chef/search/query.rb +16 -2
- data/lib/chef/util/diff.rb +2 -2
- data/lib/chef/util/powershell/ps_credential.rb +2 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api/file.rb +51 -1
- data/lib/chef/win32/file.rb +5 -0
- data/lib/chef/win32/file/version_info.rb +93 -0
- data/lib/chef/win32/mutex.rb +1 -1
- data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
- data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
- data/spec/functional/application_spec.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +4 -0
- data/spec/functional/knife/ssh_spec.rb +5 -5
- data/spec/functional/notifications_spec.rb +74 -4
- data/spec/functional/resource/aix_service_spec.rb +2 -2
- data/spec/functional/resource/dpkg_package_spec.rb +339 -0
- data/spec/functional/resource/ifconfig_spec.rb +3 -1
- data/spec/functional/resource/mount_spec.rb +5 -2
- data/spec/functional/resource/package_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +8 -0
- data/spec/functional/resource/windows_package_spec.rb +177 -0
- data/spec/functional/win32/version_info_spec.rb +50 -0
- data/spec/integration/client/client_spec.rb +80 -0
- data/spec/integration/knife/download_spec.rb +9 -0
- data/spec/integration/knife/upload_spec.rb +28 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
- data/spec/integration/recipes/resource_action_spec.rb +211 -116
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
- data/spec/integration/solo/solo_spec.rb +34 -0
- data/spec/spec_helper.rb +11 -1
- data/spec/support/platform_helpers.rb +8 -0
- data/spec/support/shared/integration/integration_helper.rb +6 -0
- data/spec/support/shared/unit/execute_resource.rb +5 -0
- data/spec/support/shared/unit/platform_introspector.rb +7 -0
- data/spec/tiny_server.rb +6 -2
- data/spec/unit/api_client/registration_spec.rb +5 -4
- data/spec/unit/application_spec.rb +1 -181
- data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
- data/spec/unit/cookbook/metadata_spec.rb +122 -2
- data/spec/unit/http_spec.rb +102 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -13
- data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
- data/spec/unit/knife/ssl_check_spec.rb +7 -3
- data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
- data/spec/unit/knife/status_spec.rb +13 -13
- data/spec/unit/knife_spec.rb +26 -2
- data/spec/unit/lwrp_spec.rb +1 -1
- data/spec/unit/mixin/properties_spec.rb +97 -0
- data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
- data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
- data/spec/unit/node_spec.rb +9 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
- data/spec/unit/property/validation_spec.rb +14 -12
- data/spec/unit/property_spec.rb +56 -0
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/dsc_resource_spec.rb +63 -24
- data/spec/unit/provider/execute_spec.rb +95 -28
- data/spec/unit/provider/package/dpkg_spec.rb +185 -96
- data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
- data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
- data/spec/unit/provider/package/windows_spec.rb +227 -26
- data/spec/unit/provider/package/yum_spec.rb +6 -0
- data/spec/unit/provider/package_spec.rb +495 -366
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
- data/spec/unit/provider/script_spec.rb +2 -2
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
- data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
- data/spec/unit/provider/user/dscl_spec.rb +14 -0
- data/spec/unit/provider/user/windows_spec.rb +2 -2
- data/spec/unit/provider/user_spec.rb +9 -0
- data/spec/unit/provider_resolver_spec.rb +6 -30
- data/spec/unit/recipe_spec.rb +46 -20
- data/spec/unit/resource/chef_gem_spec.rb +1 -1
- data/spec/unit/resource/dsc_resource_spec.rb +14 -3
- data/spec/unit/resource/ksh_spec.rb +40 -0
- data/spec/unit/resource/registry_key_spec.rb +2 -2
- data/spec/unit/resource/resource_notification_spec.rb +44 -45
- data/spec/unit/resource_reporter_spec.rb +7 -0
- data/spec/unit/resource_spec.rb +268 -253
- data/spec/unit/rest_spec.rb +2 -2
- data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
- data/spec/unit/search/query_spec.rb +19 -1
- data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
- data/spec/unit/windows_service_spec.rb +83 -38
- data/tasks/external_tests.rb +19 -9
- data/tasks/rspec.rb +1 -1
- metadata +70 -21
- data/spec/support/pedant/Gemfile +0 -3
- data/spec/support/pedant/pedant_config.rb +0 -129
- data/spec/support/pedant/run_pedant.rb +0 -63
- data/spec/support/pedant/stickywicket.pem +0 -27
- data/spec/unit/provider/package_spec.rbe +0 -0
@@ -1844,6 +1844,12 @@ EOF
|
|
1844
1844
|
expect(@yc.python_bin).to eq("/usr/bin/python")
|
1845
1845
|
end
|
1846
1846
|
|
1847
|
+
it "should return /usr/bin/python if the interpreter is /bin/bash" do
|
1848
|
+
other = StringIO.new("#!/bin/bash\n# The yum executable redirecting to dnf from dnf-yum compatible package.")
|
1849
|
+
allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r}
|
1850
|
+
expect(@yc.python_bin).to eq("/usr/bin/python")
|
1851
|
+
end
|
1852
|
+
|
1847
1853
|
it "should return the interpreter for yum" do
|
1848
1854
|
other = StringIO.new("#!/usr/bin/super_python\n\nlasjdfdsaljf\nlasdjfs")
|
1849
1855
|
allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2008
|
3
|
+
# Copyright:: Copyright (c) 2008-2015 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,347 +19,351 @@
|
|
19
19
|
require 'spec_helper'
|
20
20
|
|
21
21
|
describe Chef::Provider::Package do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
let(:node) do
|
23
|
+
node = Chef::Node.new
|
24
|
+
node.automatic_attrs[:platform] = :just_testing
|
25
|
+
node.automatic_attrs[:platform_version] = :just_testing
|
26
|
+
node
|
27
|
+
end
|
28
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
29
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
30
|
+
let(:new_resource) { Chef::Resource::Package.new('emacs') }
|
31
|
+
let(:current_resource) { Chef::Resource::Package.new('emacs') }
|
32
|
+
let(:candidate_version) { "1.0" }
|
33
|
+
let(:provider) do
|
34
|
+
provider = Chef::Provider::Package.new(new_resource, run_context)
|
35
|
+
provider.current_resource = current_resource
|
36
|
+
provider.candidate_version = candidate_version
|
37
|
+
provider
|
32
38
|
end
|
33
39
|
|
34
40
|
describe "when installing a package" do
|
35
41
|
before(:each) do
|
36
|
-
|
37
|
-
allow(
|
42
|
+
provider.current_resource = current_resource
|
43
|
+
allow(provider).to receive(:install_package).and_return(true)
|
38
44
|
end
|
39
45
|
|
40
46
|
it "raises a Chef::Exceptions::InvalidResourceSpecification if both multipackage and source are provided" do
|
41
|
-
|
42
|
-
|
43
|
-
expect {
|
47
|
+
new_resource.package_name(['a', 'b'])
|
48
|
+
new_resource.source('foo')
|
49
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
|
44
50
|
end
|
45
51
|
|
46
52
|
it "should raise a Chef::Exceptions::Package if no version is specified, and no candidate is available" do
|
47
|
-
|
48
|
-
expect {
|
53
|
+
provider.candidate_version = nil
|
54
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
|
49
55
|
end
|
50
56
|
|
51
57
|
it "should call preseed_package if a response_file is given" do
|
52
|
-
|
53
|
-
expect(
|
54
|
-
|
55
|
-
|
58
|
+
new_resource.response_file("foo")
|
59
|
+
expect(provider).to receive(:get_preseed_file).with(
|
60
|
+
new_resource.name,
|
61
|
+
provider.candidate_version
|
56
62
|
).and_return("/var/cache/preseed-test")
|
57
63
|
|
58
|
-
expect(
|
64
|
+
expect(provider).to receive(:preseed_package).with(
|
59
65
|
"/var/cache/preseed-test"
|
60
66
|
).and_return(true)
|
61
|
-
|
67
|
+
provider.run_action(:install)
|
62
68
|
end
|
63
69
|
|
64
70
|
it "should not call preseed_package if a response_file is not given" do
|
65
|
-
expect(
|
66
|
-
|
71
|
+
expect(provider).not_to receive(:preseed_package)
|
72
|
+
provider.run_action(:install)
|
67
73
|
end
|
68
74
|
|
69
75
|
it "should install the package at the candidate_version if it is not already installed" do
|
70
|
-
expect(
|
71
|
-
|
72
|
-
|
76
|
+
expect(provider).to receive(:install_package).with(
|
77
|
+
new_resource.name,
|
78
|
+
provider.candidate_version
|
73
79
|
).and_return(true)
|
74
|
-
|
75
|
-
expect(
|
80
|
+
provider.run_action(:install)
|
81
|
+
expect(new_resource).to be_updated_by_last_action
|
76
82
|
end
|
77
83
|
|
78
84
|
it "should install the package at the version specified if it is not already installed" do
|
79
|
-
|
80
|
-
expect(
|
81
|
-
|
82
|
-
|
85
|
+
new_resource.version("1.0")
|
86
|
+
expect(provider).to receive(:install_package).with(
|
87
|
+
new_resource.name,
|
88
|
+
new_resource.version
|
83
89
|
).and_return(true)
|
84
|
-
|
85
|
-
expect(
|
90
|
+
provider.run_action(:install)
|
91
|
+
expect(new_resource).to be_updated_by_last_action
|
86
92
|
end
|
87
93
|
|
88
94
|
it "should install the package at the version specified if a different version is installed" do
|
89
|
-
|
90
|
-
allow(
|
91
|
-
expect(
|
92
|
-
|
93
|
-
|
95
|
+
new_resource.version("1.0")
|
96
|
+
allow(current_resource).to receive(:version).and_return("0.99")
|
97
|
+
expect(provider).to receive(:install_package).with(
|
98
|
+
new_resource.name,
|
99
|
+
new_resource.version
|
94
100
|
).and_return(true)
|
95
|
-
|
96
|
-
expect(
|
101
|
+
provider.run_action(:install)
|
102
|
+
expect(new_resource).to be_updated_by_last_action
|
97
103
|
end
|
98
104
|
|
99
105
|
it "should not install the package if it is already installed and no version is specified" do
|
100
|
-
|
101
|
-
expect(
|
102
|
-
|
103
|
-
expect(
|
106
|
+
current_resource.version("1.0")
|
107
|
+
expect(provider).not_to receive(:install_package)
|
108
|
+
provider.run_action(:install)
|
109
|
+
expect(new_resource).not_to be_updated_by_last_action
|
104
110
|
end
|
105
111
|
|
106
112
|
it "should not install the package if it is already installed at the version specified" do
|
107
|
-
|
108
|
-
|
109
|
-
expect(
|
110
|
-
|
111
|
-
expect(
|
113
|
+
current_resource.version("1.0")
|
114
|
+
new_resource.version("1.0")
|
115
|
+
expect(provider).not_to receive(:install_package)
|
116
|
+
provider.run_action(:install)
|
117
|
+
expect(new_resource).not_to be_updated_by_last_action
|
112
118
|
end
|
113
119
|
|
114
120
|
it "should call the candidate_version accessor only once if the package is already installed and no version is specified" do
|
115
|
-
|
116
|
-
allow(
|
117
|
-
|
121
|
+
current_resource.version("1.0")
|
122
|
+
allow(provider).to receive(:candidate_version).and_return("1.0")
|
123
|
+
provider.run_action(:install)
|
118
124
|
end
|
119
125
|
|
120
126
|
it "should call the candidate_version accessor only once if the package is already installed at the version specified" do
|
121
|
-
|
122
|
-
|
123
|
-
|
127
|
+
current_resource.version("1.0")
|
128
|
+
new_resource.version("1.0")
|
129
|
+
provider.run_action(:install)
|
124
130
|
end
|
125
131
|
|
126
132
|
it "should set the resource to updated if it installs the package" do
|
127
|
-
|
128
|
-
expect(
|
133
|
+
provider.run_action(:install)
|
134
|
+
expect(new_resource).to be_updated
|
129
135
|
end
|
130
136
|
|
131
137
|
end
|
132
138
|
|
133
139
|
describe "when upgrading the package" do
|
134
140
|
before(:each) do
|
135
|
-
allow(
|
141
|
+
allow(provider).to receive(:upgrade_package).and_return(true)
|
136
142
|
end
|
137
143
|
|
138
144
|
it "should upgrade the package if the current version is not the candidate version" do
|
139
|
-
expect(
|
140
|
-
|
141
|
-
|
145
|
+
expect(provider).to receive(:upgrade_package).with(
|
146
|
+
new_resource.name,
|
147
|
+
provider.candidate_version
|
142
148
|
).and_return(true)
|
143
|
-
|
144
|
-
expect(
|
149
|
+
provider.run_action(:upgrade)
|
150
|
+
expect(new_resource).to be_updated_by_last_action
|
145
151
|
end
|
146
152
|
|
147
153
|
it "should set the resource to updated if it installs the package" do
|
148
|
-
|
149
|
-
expect(
|
154
|
+
provider.run_action(:upgrade)
|
155
|
+
expect(new_resource).to be_updated
|
150
156
|
end
|
151
157
|
|
152
158
|
it "should not install the package if the current version is the candidate version" do
|
153
|
-
|
154
|
-
expect(
|
155
|
-
|
156
|
-
expect(
|
159
|
+
current_resource.version "1.0"
|
160
|
+
expect(provider).not_to receive(:upgrade_package)
|
161
|
+
provider.run_action(:upgrade)
|
162
|
+
expect(new_resource).not_to be_updated_by_last_action
|
157
163
|
end
|
158
164
|
|
159
165
|
it "should print the word 'uninstalled' if there was no original version" do
|
160
|
-
allow(
|
166
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
161
167
|
expect(Chef::Log).to receive(:info).with("package[emacs] upgraded emacs to 1.0")
|
162
|
-
|
163
|
-
expect(
|
168
|
+
provider.run_action(:upgrade)
|
169
|
+
expect(new_resource).to be_updated_by_last_action
|
164
170
|
end
|
165
171
|
|
166
172
|
it "should raise a Chef::Exceptions::Package if current version and candidate are nil" do
|
167
|
-
allow(
|
168
|
-
|
169
|
-
expect {
|
173
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
174
|
+
provider.candidate_version = nil
|
175
|
+
expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
|
170
176
|
end
|
171
177
|
|
172
178
|
it "should not install the package if candidate version is nil" do
|
173
|
-
|
174
|
-
|
175
|
-
expect(
|
176
|
-
|
177
|
-
expect(
|
179
|
+
current_resource.version "1.0"
|
180
|
+
provider.candidate_version = nil
|
181
|
+
expect(provider).not_to receive(:upgrade_package)
|
182
|
+
provider.run_action(:upgrade)
|
183
|
+
expect(new_resource).not_to be_updated_by_last_action
|
178
184
|
end
|
179
185
|
end
|
180
186
|
|
181
187
|
describe "When removing the package" do
|
182
188
|
before(:each) do
|
183
|
-
allow(
|
184
|
-
|
189
|
+
allow(provider).to receive(:remove_package).and_return(true)
|
190
|
+
current_resource.version '1.4.2'
|
185
191
|
end
|
186
192
|
|
187
193
|
it "should remove the package if it is installed" do
|
188
|
-
expect(
|
189
|
-
expect(
|
190
|
-
|
191
|
-
expect(
|
192
|
-
expect(
|
194
|
+
expect(provider).to be_removing_package
|
195
|
+
expect(provider).to receive(:remove_package).with('emacs', nil)
|
196
|
+
provider.run_action(:remove)
|
197
|
+
expect(new_resource).to be_updated
|
198
|
+
expect(new_resource).to be_updated_by_last_action
|
193
199
|
end
|
194
200
|
|
195
201
|
it "should remove the package at a specific version if it is installed at that version" do
|
196
|
-
|
197
|
-
expect(
|
198
|
-
expect(
|
199
|
-
|
200
|
-
expect(
|
202
|
+
new_resource.version "1.4.2"
|
203
|
+
expect(provider).to be_removing_package
|
204
|
+
expect(provider).to receive(:remove_package).with('emacs', '1.4.2')
|
205
|
+
provider.run_action(:remove)
|
206
|
+
expect(new_resource).to be_updated_by_last_action
|
201
207
|
end
|
202
208
|
|
203
209
|
it "should not remove the package at a specific version if it is not installed at that version" do
|
204
|
-
|
205
|
-
expect(
|
206
|
-
expect(
|
207
|
-
|
208
|
-
expect(
|
210
|
+
new_resource.version "1.0"
|
211
|
+
expect(provider).not_to be_removing_package
|
212
|
+
expect(provider).not_to receive(:remove_package)
|
213
|
+
provider.run_action(:remove)
|
214
|
+
expect(new_resource).not_to be_updated_by_last_action
|
209
215
|
end
|
210
216
|
|
211
217
|
it "should not remove the package if it is not installed" do
|
212
|
-
expect(
|
213
|
-
allow(
|
214
|
-
|
215
|
-
expect(
|
218
|
+
expect(provider).not_to receive(:remove_package)
|
219
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
220
|
+
provider.run_action(:remove)
|
221
|
+
expect(new_resource).not_to be_updated_by_last_action
|
216
222
|
end
|
217
223
|
|
218
224
|
it "should set the resource to updated if it removes the package" do
|
219
|
-
|
220
|
-
expect(
|
225
|
+
provider.run_action(:remove)
|
226
|
+
expect(new_resource).to be_updated
|
221
227
|
end
|
222
228
|
|
223
229
|
end
|
224
230
|
|
225
231
|
describe "When purging the package" do
|
226
232
|
before(:each) do
|
227
|
-
allow(
|
228
|
-
|
233
|
+
allow(provider).to receive(:purge_package).and_return(true)
|
234
|
+
current_resource.version '1.4.2'
|
229
235
|
end
|
230
236
|
|
231
237
|
it "should purge the package if it is installed" do
|
232
|
-
expect(
|
233
|
-
expect(
|
234
|
-
|
235
|
-
expect(
|
236
|
-
expect(
|
238
|
+
expect(provider).to be_removing_package
|
239
|
+
expect(provider).to receive(:purge_package).with('emacs', nil)
|
240
|
+
provider.run_action(:purge)
|
241
|
+
expect(new_resource).to be_updated
|
242
|
+
expect(new_resource).to be_updated_by_last_action
|
237
243
|
end
|
238
244
|
|
239
245
|
it "should purge the package at a specific version if it is installed at that version" do
|
240
|
-
|
241
|
-
expect(
|
242
|
-
expect(
|
243
|
-
|
244
|
-
expect(
|
246
|
+
new_resource.version "1.4.2"
|
247
|
+
expect(provider).to be_removing_package
|
248
|
+
expect(provider).to receive(:purge_package).with('emacs', '1.4.2')
|
249
|
+
provider.run_action(:purge)
|
250
|
+
expect(new_resource).to be_updated_by_last_action
|
245
251
|
end
|
246
252
|
|
247
253
|
it "should not purge the package at a specific version if it is not installed at that version" do
|
248
|
-
|
249
|
-
expect(
|
250
|
-
expect(
|
251
|
-
|
252
|
-
expect(
|
254
|
+
new_resource.version "1.0"
|
255
|
+
expect(provider).not_to be_removing_package
|
256
|
+
expect(provider).not_to receive(:purge_package)
|
257
|
+
provider.run_action(:purge)
|
258
|
+
expect(new_resource).not_to be_updated_by_last_action
|
253
259
|
end
|
254
260
|
|
255
261
|
it "should not purge the package if it is not installed" do
|
256
|
-
|
257
|
-
expect(
|
262
|
+
current_resource.instance_variable_set(:@version, nil)
|
263
|
+
expect(provider).not_to be_removing_package
|
258
264
|
|
259
|
-
expect(
|
260
|
-
|
261
|
-
expect(
|
265
|
+
expect(provider).not_to receive(:purge_package)
|
266
|
+
provider.run_action(:purge)
|
267
|
+
expect(new_resource).not_to be_updated_by_last_action
|
262
268
|
end
|
263
269
|
|
264
270
|
it "should set the resource to updated if it purges the package" do
|
265
|
-
|
266
|
-
expect(
|
271
|
+
provider.run_action(:purge)
|
272
|
+
expect(new_resource).to be_updated
|
267
273
|
end
|
268
274
|
|
269
275
|
end
|
270
276
|
|
271
277
|
describe "when reconfiguring the package" do
|
272
278
|
before(:each) do
|
273
|
-
allow(
|
279
|
+
allow(provider).to receive(:reconfig_package).and_return(true)
|
274
280
|
end
|
275
281
|
|
276
282
|
it "should info log, reconfigure the package and update the resource" do
|
277
|
-
allow(
|
278
|
-
allow(
|
279
|
-
expect(
|
280
|
-
allow(
|
281
|
-
allow(
|
283
|
+
allow(current_resource).to receive(:version).and_return('1.0')
|
284
|
+
allow(new_resource).to receive(:response_file).and_return(true)
|
285
|
+
expect(provider).to receive(:get_preseed_file).and_return('/var/cache/preseed-test')
|
286
|
+
allow(provider).to receive(:preseed_package).and_return(true)
|
287
|
+
allow(provider).to receive(:reconfig_package).and_return(true)
|
282
288
|
expect(Chef::Log).to receive(:info).with("package[emacs] reconfigured")
|
283
|
-
expect(
|
284
|
-
|
285
|
-
expect(
|
286
|
-
expect(
|
289
|
+
expect(provider).to receive(:reconfig_package)
|
290
|
+
provider.run_action(:reconfig)
|
291
|
+
expect(new_resource).to be_updated
|
292
|
+
expect(new_resource).to be_updated_by_last_action
|
287
293
|
end
|
288
294
|
|
289
295
|
it "should debug log and not reconfigure the package if the package is not installed" do
|
290
|
-
allow(
|
296
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
291
297
|
expect(Chef::Log).to receive(:debug).with("package[emacs] is NOT installed - nothing to do")
|
292
|
-
expect(
|
293
|
-
|
294
|
-
expect(
|
298
|
+
expect(provider).not_to receive(:reconfig_package)
|
299
|
+
provider.run_action(:reconfig)
|
300
|
+
expect(new_resource).not_to be_updated_by_last_action
|
295
301
|
end
|
296
302
|
|
297
303
|
it "should debug log and not reconfigure the package if no response_file is given" do
|
298
|
-
allow(
|
299
|
-
allow(
|
304
|
+
allow(current_resource).to receive(:version).and_return('1.0')
|
305
|
+
allow(new_resource).to receive(:response_file).and_return(nil)
|
300
306
|
expect(Chef::Log).to receive(:debug).with("package[emacs] no response_file provided - nothing to do")
|
301
|
-
expect(
|
302
|
-
|
303
|
-
expect(
|
307
|
+
expect(provider).not_to receive(:reconfig_package)
|
308
|
+
provider.run_action(:reconfig)
|
309
|
+
expect(new_resource).not_to be_updated_by_last_action
|
304
310
|
end
|
305
311
|
|
306
312
|
it "should debug log and not reconfigure the package if the response_file has not changed" do
|
307
|
-
allow(
|
308
|
-
allow(
|
309
|
-
expect(
|
310
|
-
allow(
|
313
|
+
allow(current_resource).to receive(:version).and_return('1.0')
|
314
|
+
allow(new_resource).to receive(:response_file).and_return(true)
|
315
|
+
expect(provider).to receive(:get_preseed_file).and_return(false)
|
316
|
+
allow(provider).to receive(:preseed_package).and_return(false)
|
311
317
|
expect(Chef::Log).to receive(:debug).with("package[emacs] preseeding has not changed - nothing to do")
|
312
|
-
expect(
|
313
|
-
|
314
|
-
expect(
|
318
|
+
expect(provider).not_to receive(:reconfig_package)
|
319
|
+
provider.run_action(:reconfig)
|
320
|
+
expect(new_resource).not_to be_updated_by_last_action
|
315
321
|
end
|
316
322
|
end
|
317
323
|
|
318
324
|
describe "when running commands to be implemented by subclasses" do
|
319
325
|
it "should raises UnsupportedAction for install" do
|
320
|
-
expect {
|
326
|
+
expect { provider.install_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
321
327
|
end
|
322
328
|
|
323
329
|
it "should raises UnsupportedAction for upgrade" do
|
324
|
-
expect {
|
330
|
+
expect { provider.upgrade_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
325
331
|
end
|
326
332
|
|
327
333
|
it "should raises UnsupportedAction for remove" do
|
328
|
-
expect {
|
334
|
+
expect { provider.remove_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
329
335
|
end
|
330
336
|
|
331
337
|
it "should raises UnsupportedAction for purge" do
|
332
|
-
expect {
|
338
|
+
expect { provider.purge_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
333
339
|
end
|
334
340
|
|
335
341
|
it "should raise UnsupportedAction for preseed_package" do
|
336
342
|
preseed_file = "/tmp/sun-jdk-package-preseed-file.seed"
|
337
|
-
expect {
|
343
|
+
expect { provider.preseed_package(preseed_file) }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
338
344
|
end
|
339
345
|
|
340
346
|
it "should raise UnsupportedAction for reconfig" do
|
341
|
-
expect {
|
347
|
+
expect { provider.reconfig_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction)
|
342
348
|
end
|
343
349
|
end
|
344
350
|
|
345
351
|
describe "when given a response file" do
|
346
|
-
|
347
|
-
|
348
|
-
Chef::Cookbook::FileVendor.fetch_from_disk(
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
@new_resource.response_file('java.response')
|
362
|
-
@new_resource.cookbook_name = 'java'
|
352
|
+
let(:cookbook_repo) { File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) }
|
353
|
+
let(:cookbook_loader) do
|
354
|
+
Chef::Cookbook::FileVendor.fetch_from_disk(cookbook_repo)
|
355
|
+
Chef::CookbookLoader.new(cookbook_repo)
|
356
|
+
end
|
357
|
+
let(:cookbook_collection) do
|
358
|
+
cookbook_loader.load_cookbooks
|
359
|
+
Chef::CookbookCollection.new(cookbook_loader)
|
360
|
+
end
|
361
|
+
let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
|
362
|
+
let(:new_resource) do
|
363
|
+
new_resource = Chef::Resource::Package.new('emacs')
|
364
|
+
new_resource.response_file('java.response')
|
365
|
+
new_resource.cookbook_name = 'java'
|
366
|
+
new_resource
|
363
367
|
end
|
364
368
|
|
365
369
|
describe "creating the cookbook file resource to fetch the response file" do
|
@@ -369,62 +373,60 @@ describe Chef::Provider::Package do
|
|
369
373
|
|
370
374
|
it "sets the preseed resource's runcontext to its own run context" do
|
371
375
|
allow(Chef::FileCache).to receive(:create_cache_path).and_return("/tmp/preseed/java")
|
372
|
-
expect(
|
373
|
-
expect(
|
376
|
+
expect(provider.preseed_resource('java', '6').run_context).not_to be_nil
|
377
|
+
expect(provider.preseed_resource('java', '6').run_context).to equal(provider.run_context)
|
374
378
|
end
|
375
379
|
|
376
380
|
it "should set the cookbook name of the remote file to the new resources cookbook name" do
|
377
|
-
expect(
|
381
|
+
expect(provider.preseed_resource('java', '6').cookbook_name).to eq('java')
|
378
382
|
end
|
379
383
|
|
380
384
|
it "should set remote files source to the new resources response file" do
|
381
|
-
expect(
|
385
|
+
expect(provider.preseed_resource('java', '6').source).to eq('java.response')
|
382
386
|
end
|
383
387
|
|
384
388
|
it "should never back up the cached response file" do
|
385
|
-
expect(
|
389
|
+
expect(provider.preseed_resource('java', '6').backup).to be_falsey
|
386
390
|
end
|
387
391
|
|
388
392
|
it "sets the install path of the resource to $file_cache/$cookbook/$pkg_name-$pkg_version.seed" do
|
389
|
-
expect(
|
393
|
+
expect(provider.preseed_resource('java', '6').path).to eq('/tmp/preseed/java/java-6.seed')
|
390
394
|
end
|
391
395
|
end
|
392
396
|
|
393
397
|
describe "when installing the preseed file to the cache location" do
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
398
|
+
let(:response_file_destination) { Dir.tmpdir + '/preseed--java--java-6.seed' }
|
399
|
+
let(:response_file_resource) {
|
400
|
+
response_file_resource = Chef::Resource::CookbookFile.new(response_file_destination, run_context)
|
401
|
+
response_file_resource.cookbook_name = 'java'
|
402
|
+
response_file_resource.backup(false)
|
403
|
+
response_file_resource.source('java.response')
|
404
|
+
response_file_resource
|
405
|
+
}
|
399
406
|
|
400
|
-
|
401
|
-
|
402
|
-
@response_file_resource.backup(false)
|
403
|
-
@response_file_resource.source('java.response')
|
404
|
-
|
405
|
-
|
406
|
-
expect(@provider).to receive(:preseed_resource).with('java', '6').and_return(@response_file_resource)
|
407
|
+
before do
|
408
|
+
expect(provider).to receive(:preseed_resource).with('java', '6').and_return(response_file_resource)
|
407
409
|
end
|
408
410
|
|
409
411
|
after do
|
410
|
-
FileUtils.rm(
|
412
|
+
FileUtils.rm(response_file_destination) if ::File.exist?(response_file_destination)
|
411
413
|
end
|
412
414
|
|
413
415
|
it "creates the preseed file in the cache" do
|
414
|
-
expect(
|
415
|
-
|
416
|
+
expect(response_file_resource).to receive(:run_action).with(:create)
|
417
|
+
provider.get_preseed_file("java", "6")
|
416
418
|
end
|
417
419
|
|
418
420
|
it "returns the path to the response file if the response file was updated" do
|
419
|
-
expect(
|
421
|
+
expect(provider.get_preseed_file("java", "6")).to eq(response_file_destination)
|
420
422
|
end
|
421
423
|
|
422
424
|
it "should return false if the response file has not been updated" do
|
423
|
-
|
424
|
-
expect(
|
425
|
+
response_file_resource.updated_by_last_action(false)
|
426
|
+
expect(response_file_resource).not_to be_updated_by_last_action
|
425
427
|
# don't let the response_file_resource set updated to true
|
426
|
-
expect(
|
427
|
-
expect(
|
428
|
+
expect(response_file_resource).to receive(:run_action).with(:create)
|
429
|
+
expect(provider.get_preseed_file("java", "6")).to be(false)
|
428
430
|
end
|
429
431
|
|
430
432
|
end
|
@@ -432,276 +434,403 @@ describe Chef::Provider::Package do
|
|
432
434
|
end
|
433
435
|
end
|
434
436
|
|
437
|
+
describe "Subclass with use_multipackage_api" do
|
438
|
+
class MyPackageResource < Chef::Resource::Package
|
439
|
+
end
|
440
|
+
|
441
|
+
class MyPackageProvider < Chef::Provider::Package
|
442
|
+
use_multipackage_api
|
443
|
+
end
|
444
|
+
|
445
|
+
let(:node) { Chef::Node.new }
|
446
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
447
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
448
|
+
let(:new_resource) { MyPackageResource.new("installs the packages") }
|
449
|
+
let(:current_resource) { MyPackageResource.new("installs the packages") }
|
450
|
+
let(:provider) do
|
451
|
+
provider = MyPackageProvider.new(new_resource, run_context)
|
452
|
+
provider.current_resource = current_resource
|
453
|
+
provider
|
454
|
+
end
|
455
|
+
|
456
|
+
it "has use_multipackage_api? methods on the class and instance" do
|
457
|
+
expect(MyPackageProvider.use_multipackage_api?).to be true
|
458
|
+
expect(provider.use_multipackage_api?).to be true
|
459
|
+
end
|
460
|
+
|
461
|
+
it "offers a_to_s to subclasses to convert an array of strings to a single string" do
|
462
|
+
expect(provider.send(:a_to_s, "a", nil, "b", "", "c", " ", "d e", "f-g")).to eq("a b c d e f-g")
|
463
|
+
end
|
464
|
+
|
465
|
+
it "when user passes string to package_name, passes arrays to install_package" do
|
466
|
+
new_resource.package_name "vim"
|
467
|
+
new_resource.version nil
|
468
|
+
provider.candidate_version = [ "1.0" ]
|
469
|
+
expect(provider).to receive(:install_package).with(
|
470
|
+
[ "vim" ],
|
471
|
+
[ "1.0" ]
|
472
|
+
).and_return(true)
|
473
|
+
provider.run_action(:install)
|
474
|
+
expect(new_resource).to be_updated_by_last_action
|
475
|
+
expect(new_resource.version).to eql(nil)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "when user pases string to package_name and version, passes arrays to install_package" do
|
479
|
+
new_resource.package_name "vim"
|
480
|
+
new_resource.version "1.0"
|
481
|
+
provider.candidate_version = [ "1.0" ]
|
482
|
+
expect(provider).to receive(:install_package).with(
|
483
|
+
[ "vim" ],
|
484
|
+
[ "1.0" ]
|
485
|
+
).and_return(true)
|
486
|
+
provider.run_action(:install)
|
487
|
+
expect(new_resource).to be_updated_by_last_action
|
488
|
+
expect(new_resource.version).to eql("1.0")
|
489
|
+
end
|
490
|
+
|
491
|
+
it "when user passes string to package_name, passes arrays to upgrade_package" do
|
492
|
+
new_resource.package_name "vim"
|
493
|
+
new_resource.version nil
|
494
|
+
provider.candidate_version = [ "1.0" ]
|
495
|
+
expect(provider).to receive(:upgrade_package).with(
|
496
|
+
[ "vim" ],
|
497
|
+
[ "1.0" ]
|
498
|
+
).and_return(true)
|
499
|
+
provider.run_action(:upgrade)
|
500
|
+
expect(new_resource).to be_updated_by_last_action
|
501
|
+
expect(new_resource.version).to eql(nil)
|
502
|
+
end
|
503
|
+
|
504
|
+
it "when user pases string to package_name and version, passes arrays to upgrade_package" do
|
505
|
+
new_resource.package_name "vim"
|
506
|
+
new_resource.version "1.0"
|
507
|
+
provider.candidate_version = [ "1.0" ]
|
508
|
+
expect(provider).to receive(:upgrade_package).with(
|
509
|
+
[ "vim" ],
|
510
|
+
[ "1.0" ]
|
511
|
+
).and_return(true)
|
512
|
+
provider.run_action(:upgrade)
|
513
|
+
expect(new_resource).to be_updated_by_last_action
|
514
|
+
expect(new_resource.version).to eql("1.0")
|
515
|
+
end
|
516
|
+
|
517
|
+
it "when user passes string to package_name, passes arrays to remove_package" do
|
518
|
+
new_resource.package_name "vim"
|
519
|
+
current_resource.package_name "vim"
|
520
|
+
current_resource.version [ "1.0" ]
|
521
|
+
provider.candidate_version = [ "1.0" ]
|
522
|
+
expect(provider).to receive(:remove_package).with(
|
523
|
+
[ "vim" ],
|
524
|
+
[ nil ]
|
525
|
+
).and_return(true)
|
526
|
+
provider.run_action(:remove)
|
527
|
+
expect(new_resource).to be_updated_by_last_action
|
528
|
+
expect(new_resource.version).to eql(nil)
|
529
|
+
end
|
530
|
+
|
531
|
+
it "when user passes string to package_name, passes arrays to purge_package" do
|
532
|
+
new_resource.package_name "vim"
|
533
|
+
current_resource.package_name "vim"
|
534
|
+
current_resource.version [ "1.0" ]
|
535
|
+
provider.candidate_version = [ "1.0" ]
|
536
|
+
expect(provider).to receive(:purge_package).with(
|
537
|
+
[ "vim" ],
|
538
|
+
[ nil ]
|
539
|
+
).and_return(true)
|
540
|
+
provider.run_action(:purge)
|
541
|
+
expect(new_resource).to be_updated_by_last_action
|
542
|
+
expect(new_resource.version).to eql(nil)
|
543
|
+
end
|
544
|
+
|
545
|
+
it "when user passes string to package_name, passes arrays to reconfig_package" do
|
546
|
+
new_resource.package_name "vim"
|
547
|
+
current_resource.package_name "vim"
|
548
|
+
current_resource.version [ "1.0" ]
|
549
|
+
allow(new_resource).to receive(:response_file).and_return(true)
|
550
|
+
expect(provider).to receive(:get_preseed_file).and_return('/var/cache/preseed-test')
|
551
|
+
allow(provider).to receive(:preseed_package).and_return(true)
|
552
|
+
allow(provider).to receive(:reconfig_package).and_return(true)
|
553
|
+
expect(provider).to receive(:reconfig_package).with(
|
554
|
+
[ "vim" ],
|
555
|
+
[ "1.0" ],
|
556
|
+
).and_return(true)
|
557
|
+
provider.run_action(:reconfig)
|
558
|
+
expect(new_resource).to be_updated_by_last_action
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
435
562
|
describe "Chef::Provider::Package - Multi" do
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
563
|
+
let(:node) { Chef::Node.new }
|
564
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
565
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
566
|
+
let(:new_resource) { Chef::Resource::Package.new(['emacs', 'vi']) }
|
567
|
+
let(:current_resource) { Chef::Resource::Package.new(['emacs', 'vi']) }
|
568
|
+
let(:candidate_version) { [ "1.0", "6.2" ] }
|
569
|
+
let(:provider) do
|
570
|
+
provider = Chef::Provider::Package.new(new_resource, run_context)
|
571
|
+
provider.current_resource = current_resource
|
572
|
+
provider.candidate_version = candidate_version
|
573
|
+
provider
|
445
574
|
end
|
446
575
|
|
447
576
|
describe "when installing multiple packages" do
|
448
577
|
before(:each) do
|
449
|
-
|
450
|
-
allow(
|
578
|
+
provider.current_resource = current_resource
|
579
|
+
allow(provider).to receive(:install_package).and_return(true)
|
451
580
|
end
|
452
581
|
|
453
582
|
it "installs the candidate versions when none are installed" do
|
454
|
-
expect(
|
583
|
+
expect(provider).to receive(:install_package).with(
|
455
584
|
["emacs", "vi"],
|
456
585
|
["1.0", "6.2"]
|
457
586
|
).and_return(true)
|
458
|
-
|
459
|
-
expect(
|
587
|
+
provider.run_action(:install)
|
588
|
+
expect(new_resource).to be_updated
|
460
589
|
end
|
461
590
|
|
462
591
|
it "installs the candidate versions when some are installed" do
|
463
|
-
expect(
|
592
|
+
expect(provider).to receive(:install_package).with(
|
464
593
|
[ 'vi' ],
|
465
594
|
[ '6.2' ]
|
466
595
|
).and_return(true)
|
467
|
-
|
468
|
-
|
469
|
-
expect(
|
596
|
+
current_resource.version(['1.0', nil])
|
597
|
+
provider.run_action(:install)
|
598
|
+
expect(new_resource).to be_updated
|
470
599
|
end
|
471
600
|
|
472
601
|
it "installs the specified version when some are out of date" do
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
expect(
|
602
|
+
current_resource.version(['1.0', '6.2'])
|
603
|
+
new_resource.version(['1.0', '6.1'])
|
604
|
+
provider.run_action(:install)
|
605
|
+
expect(new_resource).to be_updated
|
477
606
|
end
|
478
607
|
|
479
608
|
it "does not install any version if all are installed at the right version" do
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
expect(
|
609
|
+
current_resource.version(['1.0', '6.2'])
|
610
|
+
new_resource.version(['1.0', '6.2'])
|
611
|
+
provider.run_action(:install)
|
612
|
+
expect(new_resource).not_to be_updated_by_last_action
|
484
613
|
end
|
485
614
|
|
486
615
|
it "does not install any version if all are installed, and no version was specified" do
|
487
|
-
|
488
|
-
|
489
|
-
expect(
|
616
|
+
current_resource.version(['1.0', '6.2'])
|
617
|
+
provider.run_action(:install)
|
618
|
+
expect(new_resource).not_to be_updated_by_last_action
|
490
619
|
end
|
491
620
|
|
492
621
|
it "raises an exception if both are not installed and no caondidates are available" do
|
493
|
-
|
494
|
-
|
495
|
-
expect {
|
622
|
+
current_resource.version([nil, nil])
|
623
|
+
provider.candidate_version = [nil, nil]
|
624
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
|
496
625
|
end
|
497
626
|
|
498
627
|
it "raises an exception if one is not installed and no candidates are available" do
|
499
|
-
|
500
|
-
|
501
|
-
expect {
|
628
|
+
current_resource.version(['1.0', nil])
|
629
|
+
provider.candidate_version = ['1.0', nil]
|
630
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
|
502
631
|
end
|
503
632
|
|
504
633
|
it "does not raise an exception if the packages are installed or have a candidate" do
|
505
|
-
|
506
|
-
|
507
|
-
expect {
|
634
|
+
current_resource.version(['1.0', nil])
|
635
|
+
provider.candidate_version = [nil, '6.2']
|
636
|
+
expect { provider.run_action(:install) }.not_to raise_error
|
508
637
|
end
|
509
638
|
|
510
639
|
it "raises an exception if an explicit version is asked for, an old version is installed, but no candidate" do
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
expect {
|
640
|
+
new_resource.version ['1.0', '6.2']
|
641
|
+
current_resource.version(['1.0', '6.1'])
|
642
|
+
provider.candidate_version = ['1.0', nil]
|
643
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
|
515
644
|
end
|
516
645
|
|
517
646
|
it "does not raise an exception if an explicit version is asked for, and is installed, but no candidate" do
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
expect {
|
647
|
+
new_resource.version ['1.0', '6.2']
|
648
|
+
current_resource.version(['1.0', '6.2'])
|
649
|
+
provider.candidate_version = ['1.0', nil]
|
650
|
+
expect { provider.run_action(:install) }.not_to raise_error
|
522
651
|
end
|
523
652
|
|
524
653
|
it "raise an exception if an explicit version is asked for, and is not installed, and no candidate" do
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
expect {
|
654
|
+
new_resource.version ['1.0', '6.2']
|
655
|
+
current_resource.version(['1.0', nil])
|
656
|
+
provider.candidate_version = ['1.0', nil]
|
657
|
+
expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
|
529
658
|
end
|
530
659
|
|
531
660
|
it "does not raise an exception if an explicit version is asked for, and is not installed, and there is a candidate" do
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
expect {
|
661
|
+
new_resource.version ['1.0', '6.2']
|
662
|
+
current_resource.version(['1.0', nil])
|
663
|
+
provider.candidate_version = ['1.0', '6.2']
|
664
|
+
expect { provider.run_action(:install) }.not_to raise_error
|
536
665
|
end
|
537
666
|
end
|
538
667
|
|
539
668
|
describe "when upgrading multiple packages" do
|
540
669
|
before(:each) do
|
541
|
-
|
542
|
-
allow(
|
670
|
+
provider.current_resource = current_resource
|
671
|
+
allow(provider).to receive(:upgrade_package).and_return(true)
|
543
672
|
end
|
544
673
|
|
545
674
|
it "should upgrade the package if the current versions are not the candidate version" do
|
546
|
-
|
547
|
-
expect(
|
548
|
-
|
549
|
-
|
675
|
+
current_resource.version ['0.9', '6.1']
|
676
|
+
expect(provider).to receive(:upgrade_package).with(
|
677
|
+
new_resource.package_name,
|
678
|
+
provider.candidate_version
|
550
679
|
).and_return(true)
|
551
|
-
|
552
|
-
expect(
|
680
|
+
provider.run_action(:upgrade)
|
681
|
+
expect(new_resource).to be_updated_by_last_action
|
553
682
|
end
|
554
683
|
|
555
684
|
it "should upgrade the package if some of current versions are not the candidate versions" do
|
556
|
-
|
557
|
-
expect(
|
685
|
+
current_resource.version ['1.0', '6.1']
|
686
|
+
expect(provider).to receive(:upgrade_package).with(
|
558
687
|
["vi"],
|
559
688
|
["6.2"]
|
560
689
|
).and_return(true)
|
561
|
-
|
562
|
-
expect(
|
690
|
+
provider.run_action(:upgrade)
|
691
|
+
expect(new_resource).to be_updated_by_last_action
|
563
692
|
end
|
564
693
|
|
565
694
|
it "should not install the package if the current versions are the candidate version" do
|
566
|
-
|
567
|
-
expect(
|
568
|
-
|
569
|
-
expect(
|
695
|
+
current_resource.version ['1.0', '6.2']
|
696
|
+
expect(provider).not_to receive(:upgrade_package)
|
697
|
+
provider.run_action(:upgrade)
|
698
|
+
expect(new_resource).not_to be_updated_by_last_action
|
570
699
|
end
|
571
700
|
|
572
701
|
it "should raise an exception if both are not installed and no caondidates are available" do
|
573
|
-
|
574
|
-
|
575
|
-
expect {
|
702
|
+
current_resource.version([nil, nil])
|
703
|
+
provider.candidate_version = [nil, nil]
|
704
|
+
expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
|
576
705
|
end
|
577
706
|
|
578
707
|
it "should raise an exception if one is not installed and no candidates are available" do
|
579
|
-
|
580
|
-
|
581
|
-
expect {
|
708
|
+
current_resource.version(['1.0', nil])
|
709
|
+
provider.candidate_version = ['1.0', nil]
|
710
|
+
expect { provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package)
|
582
711
|
end
|
583
712
|
|
584
713
|
it "should not raise an exception if the packages are installed or have a candidate" do
|
585
|
-
|
586
|
-
|
587
|
-
expect {
|
714
|
+
current_resource.version(['1.0', nil])
|
715
|
+
provider.candidate_version = [nil, '6.2']
|
716
|
+
expect { provider.run_action(:upgrade) }.not_to raise_error
|
588
717
|
end
|
589
718
|
|
590
719
|
it "should not raise an exception if the packages are installed or have a candidate" do
|
591
|
-
|
592
|
-
|
593
|
-
expect {
|
720
|
+
current_resource.version(['1.0', nil])
|
721
|
+
provider.candidate_version = [nil, '6.2']
|
722
|
+
expect { provider.run_action(:upgrade) }.not_to raise_error
|
594
723
|
end
|
595
724
|
end
|
596
725
|
|
597
726
|
describe "When removing multiple packages " do
|
598
727
|
before(:each) do
|
599
|
-
allow(
|
600
|
-
|
728
|
+
allow(provider).to receive(:remove_package).and_return(true)
|
729
|
+
current_resource.version ['1.0', '6.2']
|
601
730
|
end
|
602
731
|
|
603
732
|
it "should remove the packages if all are installed" do
|
604
|
-
expect(
|
605
|
-
expect(
|
606
|
-
|
607
|
-
expect(
|
608
|
-
expect(
|
733
|
+
expect(provider).to be_removing_package
|
734
|
+
expect(provider).to receive(:remove_package).with(['emacs', 'vi'], nil)
|
735
|
+
provider.run_action(:remove)
|
736
|
+
expect(new_resource).to be_updated
|
737
|
+
expect(new_resource).to be_updated_by_last_action
|
609
738
|
end
|
610
739
|
|
611
740
|
it "should remove the packages if some are installed" do
|
612
|
-
|
613
|
-
expect(
|
614
|
-
expect(
|
615
|
-
|
616
|
-
expect(
|
617
|
-
expect(
|
741
|
+
current_resource.version ['1.0', nil]
|
742
|
+
expect(provider).to be_removing_package
|
743
|
+
expect(provider).to receive(:remove_package).with(['emacs', 'vi'], nil)
|
744
|
+
provider.run_action(:remove)
|
745
|
+
expect(new_resource).to be_updated
|
746
|
+
expect(new_resource).to be_updated_by_last_action
|
618
747
|
end
|
619
748
|
|
620
749
|
it "should remove the packages at a specific version if they are installed at that version" do
|
621
|
-
|
622
|
-
expect(
|
623
|
-
expect(
|
624
|
-
|
625
|
-
expect(
|
750
|
+
new_resource.version ['1.0', '6.2']
|
751
|
+
expect(provider).to be_removing_package
|
752
|
+
expect(provider).to receive(:remove_package).with(['emacs', 'vi'], ['1.0', '6.2'])
|
753
|
+
provider.run_action(:remove)
|
754
|
+
expect(new_resource).to be_updated_by_last_action
|
626
755
|
end
|
627
756
|
|
628
757
|
it "should remove the packages at a specific version any are is installed at that version" do
|
629
|
-
|
630
|
-
expect(
|
631
|
-
expect(
|
632
|
-
|
633
|
-
expect(
|
758
|
+
new_resource.version ['0.5', '6.2']
|
759
|
+
expect(provider).to be_removing_package
|
760
|
+
expect(provider).to receive(:remove_package).with(['emacs', 'vi'], ['0.5', '6.2'])
|
761
|
+
provider.run_action(:remove)
|
762
|
+
expect(new_resource).to be_updated_by_last_action
|
634
763
|
end
|
635
764
|
|
636
765
|
it "should not remove the packages at a specific version if they are not installed at that version" do
|
637
|
-
|
638
|
-
expect(
|
639
|
-
expect(
|
640
|
-
|
641
|
-
expect(
|
766
|
+
new_resource.version ['0.5', '6.0']
|
767
|
+
expect(provider).not_to be_removing_package
|
768
|
+
expect(provider).not_to receive(:remove_package)
|
769
|
+
provider.run_action(:remove)
|
770
|
+
expect(new_resource).not_to be_updated_by_last_action
|
642
771
|
end
|
643
772
|
|
644
773
|
it "should not remove the packages if they are not installed" do
|
645
|
-
expect(
|
646
|
-
allow(
|
647
|
-
|
648
|
-
expect(
|
774
|
+
expect(provider).not_to receive(:remove_package)
|
775
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
776
|
+
provider.run_action(:remove)
|
777
|
+
expect(new_resource).not_to be_updated_by_last_action
|
649
778
|
end
|
650
779
|
|
651
780
|
end
|
652
781
|
|
653
782
|
describe "When purging multiple packages " do
|
654
783
|
before(:each) do
|
655
|
-
allow(
|
656
|
-
|
784
|
+
allow(provider).to receive(:purge_package).and_return(true)
|
785
|
+
current_resource.version ['1.0', '6.2']
|
657
786
|
end
|
658
787
|
|
659
788
|
it "should purge the packages if all are installed" do
|
660
|
-
expect(
|
661
|
-
expect(
|
662
|
-
|
663
|
-
expect(
|
664
|
-
expect(
|
789
|
+
expect(provider).to be_removing_package
|
790
|
+
expect(provider).to receive(:purge_package).with(['emacs', 'vi'], nil)
|
791
|
+
provider.run_action(:purge)
|
792
|
+
expect(new_resource).to be_updated
|
793
|
+
expect(new_resource).to be_updated_by_last_action
|
665
794
|
end
|
666
795
|
|
667
796
|
it "should purge the packages if some are installed" do
|
668
|
-
|
669
|
-
expect(
|
670
|
-
expect(
|
671
|
-
|
672
|
-
expect(
|
673
|
-
expect(
|
797
|
+
current_resource.version ['1.0', nil]
|
798
|
+
expect(provider).to be_removing_package
|
799
|
+
expect(provider).to receive(:purge_package).with(['emacs', 'vi'], nil)
|
800
|
+
provider.run_action(:purge)
|
801
|
+
expect(new_resource).to be_updated
|
802
|
+
expect(new_resource).to be_updated_by_last_action
|
674
803
|
end
|
675
804
|
|
676
805
|
it "should purge the packages at a specific version if they are installed at that version" do
|
677
|
-
|
678
|
-
expect(
|
679
|
-
expect(
|
680
|
-
|
681
|
-
expect(
|
806
|
+
new_resource.version ['1.0', '6.2']
|
807
|
+
expect(provider).to be_removing_package
|
808
|
+
expect(provider).to receive(:purge_package).with(['emacs', 'vi'], ['1.0', '6.2'])
|
809
|
+
provider.run_action(:purge)
|
810
|
+
expect(new_resource).to be_updated_by_last_action
|
682
811
|
end
|
683
812
|
|
684
813
|
it "should purge the packages at a specific version any are is installed at that version" do
|
685
|
-
|
686
|
-
expect(
|
687
|
-
expect(
|
688
|
-
|
689
|
-
expect(
|
814
|
+
new_resource.version ['0.5', '6.2']
|
815
|
+
expect(provider).to be_removing_package
|
816
|
+
expect(provider).to receive(:purge_package).with(['emacs', 'vi'], ['0.5', '6.2'])
|
817
|
+
provider.run_action(:purge)
|
818
|
+
expect(new_resource).to be_updated_by_last_action
|
690
819
|
end
|
691
820
|
|
692
821
|
it "should not purge the packages at a specific version if they are not installed at that version" do
|
693
|
-
|
694
|
-
expect(
|
695
|
-
expect(
|
696
|
-
|
697
|
-
expect(
|
822
|
+
new_resource.version ['0.5', '6.0']
|
823
|
+
expect(provider).not_to be_removing_package
|
824
|
+
expect(provider).not_to receive(:purge_package)
|
825
|
+
provider.run_action(:purge)
|
826
|
+
expect(new_resource).not_to be_updated_by_last_action
|
698
827
|
end
|
699
828
|
|
700
829
|
it "should not purge the packages if they are not installed" do
|
701
|
-
expect(
|
702
|
-
allow(
|
703
|
-
|
704
|
-
expect(
|
830
|
+
expect(provider).not_to receive(:purge_package)
|
831
|
+
allow(current_resource).to receive(:version).and_return(nil)
|
832
|
+
provider.run_action(:purge)
|
833
|
+
expect(new_resource).not_to be_updated_by_last_action
|
705
834
|
end
|
706
835
|
end
|
707
836
|
|
@@ -710,30 +839,30 @@ describe "Chef::Provider::Package - Multi" do
|
|
710
839
|
stubbed_method = method == :shell_out_with_timeout! ? :shell_out! : :shell_out
|
711
840
|
[ %w{command arg1 arg2}, "command arg1 arg2" ].each do |command|
|
712
841
|
it "#{method} defaults to 900 seconds" do
|
713
|
-
expect(
|
714
|
-
|
842
|
+
expect(provider).to receive(stubbed_method).with(*command, timeout: 900)
|
843
|
+
provider.send(method, *command)
|
715
844
|
end
|
716
845
|
it "#{method} overrides the default timeout with its options" do
|
717
|
-
expect(
|
718
|
-
|
846
|
+
expect(provider).to receive(stubbed_method).with(*command, timeout: 1)
|
847
|
+
provider.send(method, *command, timeout: 1)
|
719
848
|
end
|
720
849
|
it "#{method} overrides both timeouts with the new_resource.timeout" do
|
721
|
-
|
722
|
-
expect(
|
723
|
-
|
850
|
+
new_resource.timeout(99)
|
851
|
+
expect(provider).to receive(stubbed_method).with(*command, timeout: 99)
|
852
|
+
provider.send(method, *command, timeout: 1)
|
724
853
|
end
|
725
854
|
it "#{method} defaults to 900 seconds and preserves options" do
|
726
|
-
expect(
|
727
|
-
|
855
|
+
expect(provider).to receive(stubbed_method).with(*command, env: nil, timeout: 900)
|
856
|
+
provider.send(method, *command, env: nil)
|
728
857
|
end
|
729
858
|
it "#{method} overrides the default timeout with its options and preserves options" do
|
730
|
-
expect(
|
731
|
-
|
859
|
+
expect(provider).to receive(stubbed_method).with(*command, timeout: 1, env: nil)
|
860
|
+
provider.send(method, *command, timeout: 1, env: nil)
|
732
861
|
end
|
733
862
|
it "#{method} overrides both timeouts with the new_resource.timeout and preseves options" do
|
734
|
-
|
735
|
-
expect(
|
736
|
-
|
863
|
+
new_resource.timeout(99)
|
864
|
+
expect(provider).to receive(stubbed_method).with(*command, timeout: 99, env: nil)
|
865
|
+
provider.send(method, *command, timeout: 1, env: nil)
|
737
866
|
end
|
738
867
|
end
|
739
868
|
end
|