summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <454857+lamont-granquist@users.noreply.github.com>2021-11-30 12:32:37 -0800
committerGitHub <noreply@github.com>2021-11-30 12:32:37 -0800
commit93c80210750fa8ef383ef1395431e420e39302c7 (patch)
tree264f33c8641b43298fdc3971cd855927b017a52e
parent8b0cb6f585c9159cd2c5b2b9a78b27ca0039246f (diff)
parent8b267e2117bc8c4bad9667274a2665210a25adcd (diff)
downloadchef-use-powershell-exec-for-windows-feature-powershell.tar.gz
Merge branch 'main' into use-powershell-exec-for-windows-feature-powershelluse-powershell-exec-for-windows-feature-powershell
-rw-r--r--.rubocop.yml1
-rw-r--r--CHANGELOG.md18
-rw-r--r--Gemfile.lock38
-rw-r--r--VERSION2
-rw-r--r--chef-bin/lib/chef-bin/version.rb2
-rw-r--r--chef-config/lib/chef-config/version.rb2
-rw-r--r--chef-utils/lib/chef-utils/version.rb2
-rw-r--r--cspell.json6
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_powershell_package.rb10
-rw-r--r--knife/lib/chef/knife/version.rb2
-rw-r--r--lib/chef/mixin/why_run.rb10
-rw-r--r--lib/chef/provider.rb2
-rw-r--r--lib/chef/provider/mount/linux.rb18
-rw-r--r--lib/chef/provider/mount/mount.rb2
-rw-r--r--lib/chef/provider/package.rb81
-rw-r--r--lib/chef/provider/package/dnf.rb2
-rw-r--r--lib/chef/provider/package/powershell.rb23
-rw-r--r--lib/chef/resource/chef_client_config.rb23
-rw-r--r--lib/chef/resource/dnf_package.rb10
-rw-r--r--lib/chef/resource/support/client.erb7
-rw-r--r--lib/chef/version.rb2
-rw-r--r--omnibus/.tool-versions1
-rw-r--r--omnibus/Gemfile.lock34
-rw-r--r--omnibus_overrides.rb4
-rw-r--r--spec/functional/resource/dnf_package_spec.rb54
-rw-r--r--spec/unit/file_access_control_spec.rb2
-rw-r--r--spec/unit/mixin/why_run_spec.rb53
-rw-r--r--spec/unit/provider/group/groupadd_spec.rb1
-rw-r--r--spec/unit/provider/group/usermod_spec.rb4
-rw-r--r--spec/unit/provider/ifconfig_spec.rb2
-rw-r--r--spec/unit/provider/mount/linux_spec.rb19
-rw-r--r--spec/unit/provider/package/bff_spec.rb1
-rw-r--r--spec/unit/provider/package/powershell_spec.rb228
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb3
-rw-r--r--spec/unit/provider/package/solaris_spec.rb1
-rw-r--r--spec/unit/provider/service/arch_service_spec.rb4
-rw-r--r--spec/unit/provider/service/debian_service_spec.rb1
-rw-r--r--spec/unit/provider/service/gentoo_service_spec.rb1
-rw-r--r--spec/unit/provider/service/macosx_spec.rb1
-rw-r--r--spec/unit/provider/service/redhat_spec.rb5
-rw-r--r--spec/unit/provider/service/simple_service_spec.rb10
-rw-r--r--spec/unit/provider/user_spec.rb2
42 files changed, 452 insertions, 242 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 00ba2b7644..0f6a38295d 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -40,7 +40,6 @@ Chef/Ruby/LegacyPowershellOutMethods:
- 'lib/chef/mixin/powershell_out.rb'
- 'spec/functional/mixin/powershell_out_spec.rb'
- 'spec/unit/mixin/powershell_out_spec.rb'
- - 'lib/chef/provider/package/powershell.rb' # https://github.com/chef/chef/issues/10926
# set additional paths
Chef/Ruby/UnlessDefinedRequire:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c686d16ee..a8a8a8abe9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,17 +1,29 @@
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
This changelog lists individual merged pull requests to Chef Infra Client and geared towards developers. For a list of significant changes per release see the [Chef Infra Client Release Notes](https://docs.chef.io/release_notes_client/).
-<!-- latest_release 17.8.7 -->
-## [v17.8.7](https://github.com/chef/chef/tree/v17.8.7) (2021-11-17)
+<!-- latest_release 17.8.20 -->
+## [v17.8.20](https://github.com/chef/chef/tree/v17.8.20) (2021-11-30)
#### Merged Pull Requests
-- fix dpkg_package doesn&#39;t do version comparisons on upgrade [#11970](https://github.com/chef/chef/pull/11970) ([snehaldwivedi](https://github.com/snehaldwivedi))
+- use powershell exec in powershell resource [#12278](https://github.com/chef/chef/pull/12278) ([rishichawda](https://github.com/rishichawda))
<!-- latest_release -->
<!-- release_rollup since=17.7.29 -->
### Changes not yet released to stable
#### Merged Pull Requests
+- use powershell exec in powershell resource [#12278](https://github.com/chef/chef/pull/12278) ([rishichawda](https://github.com/rishichawda)) <!-- 17.8.20 -->
+- Smriti/10918 mount resource not idempotent [#11579](https://github.com/chef/chef/pull/11579) ([msys-sgarg](https://github.com/msys-sgarg)) <!-- 17.8.19 -->
+- Add allow_downgrade back to DNF [#12291](https://github.com/chef/chef/pull/12291) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 17.8.18 -->
+- Ruby 3.0.3 [#12323](https://github.com/chef/chef/pull/12323) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 17.8.17 -->
+- Bump omnibus-software from `461fc3e` to `8560231` in /omnibus [#12321](https://github.com/chef/chef/pull/12321) ([dependabot[bot]](https://github.com/dependabot[bot])) <!-- 17.8.16 -->
+- Add data collector config items for infra config [#12292](https://github.com/chef/chef/pull/12292) ([mvangoor](https://github.com/mvangoor)) <!-- 17.8.14 -->
+- Bump omnibus-software from `7501e20` to `461fc3e` in /omnibus [#12313](https://github.com/chef/chef/pull/12313) ([dependabot[bot]](https://github.com/dependabot[bot])) <!-- 17.8.13 -->
+- Do not run assertions for actions that are not being executed [#12282](https://github.com/chef/chef/pull/12282) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 17.8.12 -->
+- Bump kitchen-vagrant from 1.10.0 to 1.11.0 in /omnibus [#12307](https://github.com/chef/chef/pull/12307) ([dependabot[bot]](https://github.com/dependabot[bot])) <!-- 17.8.11 -->
+- Bump test-kitchen from 3.1.1 to 3.2.0 in /omnibus [#12296](https://github.com/chef/chef/pull/12296) ([dependabot[bot]](https://github.com/dependabot[bot])) <!-- 17.8.10 -->
+- Bump omnibus-software from `32876cd` to `7501e20` in /omnibus [#12294](https://github.com/chef/chef/pull/12294) ([dependabot[bot]](https://github.com/dependabot[bot])) <!-- 17.8.9 -->
+- Bump inspec-core-bin to 4.50.3 [#12297](https://github.com/chef/chef/pull/12297) ([chef-expeditor[bot]](https://github.com/chef-expeditor[bot])) <!-- 17.8.8 -->
- fix dpkg_package doesn&#39;t do version comparisons on upgrade [#11970](https://github.com/chef/chef/pull/11970) ([snehaldwivedi](https://github.com/snehaldwivedi)) <!-- 17.8.7 -->
- Implement compliance phase interval runs [#12226](https://github.com/chef/chef/pull/12226) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 17.8.6 -->
- fix invalid ffi type error after coerce in macos_userdefaults [#12234](https://github.com/chef/chef/pull/12234) ([rishichawda](https://github.com/rishichawda)) <!-- 17.8.5 -->
diff --git a/Gemfile.lock b/Gemfile.lock
index a473ab6580..9d56810524 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -35,12 +35,12 @@ GIT
PATH
remote: .
specs:
- chef (17.8.7)
+ chef (17.8.20)
addressable
aws-sdk-s3 (~> 1.91)
aws-sdk-secretsmanager (~> 1.46)
- chef-config (= 17.8.7)
- chef-utils (= 17.8.7)
+ chef-config (= 17.8.20)
+ chef-utils (= 17.8.20)
chef-vault
chef-zero (>= 14.0.11)
corefoundation (~> 0.3.4)
@@ -66,12 +66,12 @@ PATH
train-winrm (>= 0.2.5)
uuidtools (>= 2.1.5, < 3.0)
vault (~> 0.16)
- chef (17.8.7-universal-mingw32)
+ chef (17.8.20-universal-mingw32)
addressable
aws-sdk-s3 (~> 1.91)
aws-sdk-secretsmanager (~> 1.46)
- chef-config (= 17.8.7)
- chef-utils (= 17.8.7)
+ chef-config (= 17.8.20)
+ chef-utils (= 17.8.20)
chef-vault
chef-zero (>= 14.0.11)
corefoundation (~> 0.3.4)
@@ -112,15 +112,15 @@ PATH
PATH
remote: chef-bin
specs:
- chef-bin (17.8.7)
- chef (= 17.8.7)
+ chef-bin (17.8.20)
+ chef (= 17.8.20)
PATH
remote: chef-config
specs:
- chef-config (17.8.7)
+ chef-config (17.8.20)
addressable
- chef-utils (= 17.8.7)
+ chef-utils (= 17.8.20)
fuzzyurl
mixlib-config (>= 2.2.12, < 4.0)
mixlib-shellout (>= 2.0, < 4.0)
@@ -129,7 +129,7 @@ PATH
PATH
remote: chef-utils
specs:
- chef-utils (17.8.7)
+ chef-utils (17.8.20)
concurrent-ruby
GEM
@@ -142,8 +142,8 @@ GEM
mixlib-shellout (>= 2.0, < 4.0)
ast (2.4.2)
aws-eventstream (1.2.0)
- aws-partitions (1.532.0)
- aws-sdk-core (3.122.1)
+ aws-partitions (1.536.0)
+ aws-sdk-core (3.123.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
@@ -151,7 +151,7 @@ GEM
aws-sdk-kms (1.51.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sigv4 (~> 1.1)
- aws-sdk-s3 (1.106.0)
+ aws-sdk-s3 (1.108.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
@@ -225,7 +225,7 @@ GEM
hashie (4.1.0)
httpclient (2.8.3)
iniparse (1.5.0)
- inspec-core (4.49.0)
+ inspec-core (4.50.3)
addressable (~> 2.4)
chef-telemetry (~> 1.0, >= 1.0.8)
faraday (>= 0.9.0, < 1.5)
@@ -248,8 +248,8 @@ GEM
train-core (~> 3.0)
tty-prompt (~> 0.17)
tty-table (~> 0.10)
- inspec-core-bin (4.49.0)
- inspec-core (= 4.49.0)
+ inspec-core-bin (4.50.3)
+ inspec-core (= 4.50.3)
ipaddress (0.8.3)
iso8601 (0.13.0)
jmespath (1.4.0)
@@ -290,7 +290,7 @@ GEM
net-ssh (6.1.0)
nori (2.6.0)
parallel (1.21.0)
- parser (3.0.2.0)
+ parser (3.0.3.1)
ast (~> 2.4.1)
parslet (1.8.2)
pastel (0.8.0)
@@ -466,4 +466,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
- 2.2.22
+ 2.2.32
diff --git a/VERSION b/VERSION
index e91d411acf..d515d3c52b 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-17.8.7 \ No newline at end of file
+17.8.20 \ No newline at end of file
diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb
index 3bbf2684a5..56fb919641 100644
--- a/chef-bin/lib/chef-bin/version.rb
+++ b/chef-bin/lib/chef-bin/version.rb
@@ -21,7 +21,7 @@
module ChefBin
CHEFBIN_ROOT = File.expand_path("..", __dir__)
- VERSION = "17.8.7".freeze
+ VERSION = "17.8.20".freeze
end
#
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index d517f5666f..8c631f8e07 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -15,5 +15,5 @@
module ChefConfig
CHEFCONFIG_ROOT = File.expand_path("..", __dir__)
- VERSION = "17.8.7".freeze
+ VERSION = "17.8.20".freeze
end
diff --git a/chef-utils/lib/chef-utils/version.rb b/chef-utils/lib/chef-utils/version.rb
index 90c4b53c32..9fb3b1525d 100644
--- a/chef-utils/lib/chef-utils/version.rb
+++ b/chef-utils/lib/chef-utils/version.rb
@@ -16,5 +16,5 @@
module ChefUtils
CHEFUTILS_ROOT = File.expand_path("..", __dir__)
- VERSION = "17.8.7"
+ VERSION = "17.8.20"
end
diff --git a/cspell.json b/cspell.json
index 06118297c8..6f40be96c2 100644
--- a/cspell.json
+++ b/cspell.json
@@ -181,6 +181,8 @@
"CNAME",
"cname",
"codepage",
+ "codepath",
+ "codepaths",
"CODESEG",
"COLORINDEX",
"COLORREF",
@@ -610,6 +612,7 @@
"listprop",
"ljust",
"lltstype",
+ "losetup",
"LMEM",
"LMSHARE",
"LMSTR",
@@ -1338,6 +1341,9 @@
"unintuitive",
"unixy",
"Unjoin",
+ "unlazies",
+ "unlazied",
+ "unlazying",
"Unmanaged",
"unmanaged",
"unmerge",
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_powershell_package.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_powershell_package.rb
new file mode 100644
index 0000000000..ba40b39794
--- /dev/null
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_powershell_package.rb
@@ -0,0 +1,10 @@
+powershell_package "PSReadline"
+
+powershell_package "multi package install" do
+ package_name %w{PSReadline chocolatey}
+end
+
+powershell_package "remove all packages" do
+ package_name %w{PSReadline chocolatey}
+ action :remove
+end
diff --git a/knife/lib/chef/knife/version.rb b/knife/lib/chef/knife/version.rb
index 58d3ba3725..c406e7436e 100644
--- a/knife/lib/chef/knife/version.rb
+++ b/knife/lib/chef/knife/version.rb
@@ -17,7 +17,7 @@
class Chef
class Knife
KNIFE_ROOT = File.expand_path("../..", __dir__)
- VERSION = "17.8.7".freeze
+ VERSION = "17.8.20".freeze
end
end
diff --git a/lib/chef/mixin/why_run.rb b/lib/chef/mixin/why_run.rb
index efe327168e..357c4a655d 100644
--- a/lib/chef/mixin/why_run.rb
+++ b/lib/chef/mixin/why_run.rb
@@ -242,8 +242,12 @@ class Chef
end
end
- def initialize(resource, run_context)
- @resource, @run_context = resource, run_context
+ attr_accessor :action
+
+ def initialize(resource, run_context, action)
+ @resource = resource
+ @run_context = run_context
+ @action = action
@assertions = Hash.new { |h, k| h[k] = [] }
@blocked_actions = []
end
@@ -305,6 +309,8 @@ class Chef
# "You don't have sufficient privileges to delete #{@new_resource.path}")
# end
def assert(*actions)
+ return unless actions.include?(action.to_sym) || actions.include?(:all_actions)
+
assertion = Assertion.new
yield assertion
actions.each { |action| @assertions[action] << assertion }
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index e7d7ca84ff..80c58c09ee 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -269,7 +269,7 @@ class Chef
end
def requirements
- @requirements ||= ResourceRequirements.new(@new_resource, run_context)
+ @requirements ||= ResourceRequirements.new(@new_resource, run_context, action || new_resource.action)
end
def description(description = "NOT_PASSED")
diff --git a/lib/chef/provider/mount/linux.rb b/lib/chef/provider/mount/linux.rb
index 382e37d41a..83fbfab957 100644
--- a/lib/chef/provider/mount/linux.rb
+++ b/lib/chef/provider/mount/linux.rb
@@ -29,10 +29,16 @@ class Chef
# "findmnt" outputs the mount points with volume.
# Convert the mount_point of the resource to a real path in case it
# contains symlinks in its parents dirs.
+ def loop_mount_points
+ # get loop_mount_points only if not initialized earlier
+ @loop_mount_points ||= shell_out!("losetup -a").stdout
+
+ rescue Errno::ENOENT
+ @loop_mount_points = ""
+ end
def mounted?
mounted = false
-
real_mount_point = if ::File.exists? @new_resource.mount_point
::File.realpath(@new_resource.mount_point)
else
@@ -45,6 +51,14 @@ class Chef
when /\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\s/
mounted = true
logger.trace("Special device #{device_logstring} mounted as #{real_mount_point}")
+ # Permalink for loop type devices mount points https://rubular.com/r/a0bS4p2RvXsGxx
+ when %r{\A#{Regexp.escape(real_mount_point)}\s+\/dev\/loop+[0-9]+\s}
+ loop_mount_points.each_line do |mount_point|
+ if mount_point.include? device_real
+ mounted = true
+ break
+ end
+ end
# Permalink for multiple devices mounted to the same mount point(i.e. '/proc') https://rubular.com/r/a356yzspU7N9TY
when %r{\A#{Regexp.escape(real_mount_point)}\s+([/\w])+\s}
mounted = false
@@ -64,4 +78,4 @@ class Chef
end
end
end
-end
+end \ No newline at end of file
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 802ee11c23..2bc9d2c78f 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -279,4 +279,4 @@ class Chef
end
end
end
-end
+end \ No newline at end of file
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 65d2254258..82d7ed00cf 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -438,47 +438,81 @@ class Chef
@target_version_array ||=
begin
target_version_array = []
- each_package do |package_name, new_version, current_version, candidate_version|
+ each_package do |package_name, new_version, current_version, candidate_version, magic_version|
case action
when :upgrade
- if current_version.nil?
- # with use_magic_version there may be a package installed, but it fails the user's
- # requested new_resource.version constraints
+ if version_equals?(current_version, new_version)
+ # This is a short-circuit (mostly for the rubygems provider) to avoid needing to
+ # expensively query the candidate_version which must come later. This only checks
+ # exact matching, the check for fuzzy matching is later.
+ logger.trace("#{new_resource} #{package_name} #{new_version} is already installed")
+ target_version_array.push(nil)
+ elsif current_version.nil?
+ # This is a simple check to see if we have any currently installed version at all, this is
+ # safe to do before the allow_downgrade check so we check this before.
logger.trace("#{new_resource} has no existing installed version. Installing install #{candidate_version}")
target_version_array.push(candidate_version)
- elsif !use_magic_version? && version_equals?(current_version, new_version)
- # this is a short-circuit (mostly for the rubygems provider) to avoid needing to expensively query the candidate_version which must come later
- logger.trace("#{new_resource} #{package_name} #{new_version} is already installed")
+ elsif !allow_downgrade && version_compare(current_version, candidate_version) == 1
+ # This check for downgrading when allow_downgrade is false uses the current_version rather
+ # than the magic_version since we never want to downgrade even if the constraints are not met
+ # if the version is higher. This check does use the candidate_version and unlazies this so
+ # there will a perf hit on idempotent use when allow_downgrade is false which is unavoidable.
+ logger.trace("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)")
target_version_array.push(nil)
+ elsif magic_version.nil?
+ # This is the check for fuzzy matching of the installed_version, where if the installed version
+ # does not match the desired version constraints (but is not an exact match) then we need to
+ # install the candidate_version (this must come after the allow_downgrade check)
+ logger.trace("#{new_resource} has an installed version that does not match the version constraint. Installing install #{candidate_version}")
+ target_version_array.push(candidate_version)
elsif candidate_version.nil?
+ # This check necessarily unlazies the candidate_version and may be expensive (connecting to
+ # rubygems.org or whatever). It comes as late as possible.
logger.trace("#{new_resource} #{package_name} has no candidate_version to upgrade to")
target_version_array.push(nil)
elsif version_equals?(current_version, candidate_version)
+ # This check sees if the candidate_version is already installed or if we should upgrade/update the
+ # package. This is the normal idempotent behavior of :upgrade and is inherently expensive due to
+ # unlazying the candidate_version. To prevent the perf hit the version may be specified with a full
+ # version constraint. Then the cookbook can roll the version forward and use :upgrade to force version
+ # pinning.
logger.trace("#{new_resource} #{package_name} #{candidate_version} is already installed")
target_version_array.push(nil)
- elsif !allow_downgrade && version_compare(current_version, candidate_version) == 1
- logger.trace("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)")
- target_version_array.push(nil)
else
- logger.trace("#{new_resource} #{package_name} is out of date, will upgrade to #{candidate_version}")
+ logger.trace("#{new_resource} #{package_name} is out of date, will update to #{candidate_version}")
target_version_array.push(candidate_version)
end
when :install
- if new_version && !use_magic_version?
+ if current_version && new_version && !allow_downgrade && version_compare(current_version, new_version) == 1
+ # This is the idempotency guard for downgrades when downgrades are not allowed. This should perhaps raise
+ # an exception since we were told to install an exact package version but we are silently refusing to do so
+ # because a higher version is already installed. Maybe we need a flag for users to apply their preferred
+ # declarative philosophy? This has to come early and outside of the two code paths below.
+ logger.warn("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{new_version}. Skipping...)")
+ target_version_array.push(nil)
+ elsif new_version && !use_magic_version?
+ # This is for "non magic version using" subclasses to do comparisons between the current_version and the
+ # desired new_version. XXX: If we converted this to current_version_requirement_satisfied? and made it specific
+ # to the current version check and then eliminated the magic_version, we might be able to eliminate separate codepaths
+ # here, and eliminate the semantic confusion around the magic_version?
if version_requirement_satisfied?(current_version, new_version)
logger.trace("#{new_resource} #{package_name} #{current_version} satisfies #{new_version} requirement")
target_version_array.push(nil)
- elsif current_version && !allow_downgrade && version_compare(current_version, new_version) == 1
- logger.warn("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{new_version}. Skipping...)")
- target_version_array.push(nil)
else
+ # XXX: some subclasses seem to depend on this behavior where the new_version can be different from the
+ # candidate_version and we install the new_version, it seems like the candidate_version should be fixed to
+ # be resolved correctly to the new_version for those providers. although it may just be unit test bugs.
+ # it would be more correct to use the candidate_version here, but then it needs to be the correctly resolved
+ # candidate_version against the new_version constraint.
logger.trace("#{new_resource} #{package_name} #{current_version} needs updating to #{new_version}")
target_version_array.push(new_version)
end
- elsif current_version.nil?
- # with use_magic_version there may be a package installed, but it fails the user's
- # requested new_resource.version constraints
+ elsif magic_version.nil?
+ # This is for when we have a "magic version using" subclass and where the installed version does not match the
+ # constraint specified in the new_version, so we need to upgrade to the candidate_version. This is the only
+ # codepath in the :install branch which references the candidate_version so it is slow, but it is the path where
+ # we need to do work anyway. XXX: should we check for candidate_version.nil? somewhere around here?
logger.trace("#{new_resource} #{package_name} not installed, installing #{candidate_version}")
target_version_array.push(candidate_version)
else
@@ -512,8 +546,8 @@ class Chef
@packages_missing_candidates ||=
begin
missing = []
- each_package do |package_name, new_version, current_version, candidate_version|
- missing.push(package_name) if current_version.nil? && candidate_version.nil?
+ each_package do |package_name, new_version, current_version, candidate_version, magic_version|
+ missing.push(package_name) if magic_version.nil? && candidate_version.nil?
end
missing
end
@@ -536,7 +570,7 @@ class Chef
@forced_packages_missing_candidates ||=
begin
missing = []
- each_package do |package_name, new_version, current_version, candidate_version|
+ each_package do |package_name, new_version, current_version, candidate_version, magic_version|
next if new_version.nil? || current_version.nil?
if use_magic_version?
@@ -559,9 +593,10 @@ class Chef
def each_package
package_name_array.each_with_index do |package_name, i|
candidate_version = candidate_version_array[i]
- current_version = use_magic_version? ? magic_version[i] : current_version_array[i]
+ current_version = current_version_array[i]
+ magic_version = use_magic_version? ? magic_version_array[i] : current_version_array[i]
new_version = new_version_array[i]
- yield package_name, new_version, current_version, candidate_version
+ yield package_name, new_version, current_version, candidate_version, magic_version
end
end
diff --git a/lib/chef/provider/package/dnf.rb b/lib/chef/provider/package/dnf.rb
index 5c74ad0414..67bf24a411 100644
--- a/lib/chef/provider/package/dnf.rb
+++ b/lib/chef/provider/package/dnf.rb
@@ -98,7 +98,7 @@ class Chef
end
end
- def magic_version
+ def magic_version_array
package_name_array.each_with_index.map do |pkg, i|
magical_version(i).version_with_arch
end
diff --git a/lib/chef/provider/package/powershell.rb b/lib/chef/provider/package/powershell.rb
index 1c123d7952..2fe6cc2abc 100644
--- a/lib/chef/provider/package/powershell.rb
+++ b/lib/chef/provider/package/powershell.rb
@@ -17,13 +17,13 @@
require_relative "../package"
require_relative "../../resource/powershell_package"
-require_relative "../../mixin/powershell_out"
+require_relative "../../mixin/powershell_exec"
class Chef
class Provider
class Package
class Powershell < Chef::Provider::Package
- include Chef::Mixin::PowershellOut
+ include Chef::Mixin::PowershellExec
provides :powershell_package
@@ -54,9 +54,9 @@ class Chef
# Installs the package specified with the version passed else latest version will be installed
def install_package(names, versions)
names.each_with_index do |name, index|
- cmd = powershell_out(build_powershell_package_command("Install-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
+ cmd = powershell_exec(build_powershell_package_command("Install-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
next if cmd.nil?
- raise Chef::Exceptions::PowershellCmdletException, "Failed to install package due to catalog signing error, use skip_publisher_check to force install" if /SkipPublisherCheck/.match?(cmd.stderr)
+ raise Chef::Exceptions::PowershellCmdletException, "Failed to install package due to catalog signing error, use skip_publisher_check to force install" if /SkipPublisherCheck/.match?(cmd.error)
end
end
@@ -64,11 +64,12 @@ class Chef
def remove_package(names, versions)
names.each_with_index do |name, index|
if versions && !versions[index].nil?
- powershell_out(build_powershell_package_command("Uninstall-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
+ powershell_exec(build_powershell_package_command("Uninstall-Package '#{name}'", versions[index]), timeout: new_resource.timeout)
else
version = "0"
until version.empty?
- version = powershell_out(build_powershell_package_command("Uninstall-Package '#{name}'"), timeout: new_resource.timeout).stdout.strip
+ version = powershell_exec(build_powershell_package_command("Uninstall-Package '#{name}'"), timeout: new_resource.timeout).result
+ version = version.strip if version.respond_to?(:strip)
unless version.empty?
logger.info("Removed package '#{name}' with version #{version}")
end
@@ -82,13 +83,14 @@ class Chef
versions = []
new_resource.package_name.each_with_index do |name, index|
version = if new_resource.version && !new_resource.version[index].nil?
- powershell_out(build_powershell_package_command("Find-Package '#{name}'", new_resource.version[index]), timeout: new_resource.timeout).stdout.strip
+ powershell_exec(build_powershell_package_command("Find-Package '#{name}'", new_resource.version[index]), timeout: new_resource.timeout).result
else
- powershell_out(build_powershell_package_command("Find-Package '#{name}'"), timeout: new_resource.timeout).stdout.strip
+ powershell_exec(build_powershell_package_command("Find-Package '#{name}'"), timeout: new_resource.timeout).result
end
if version.empty?
version = nil
end
+ version = version.strip if version.respond_to?(:strip)
versions.push(version)
end
versions
@@ -99,13 +101,14 @@ class Chef
version_list = []
new_resource.package_name.each_with_index do |name, index|
version = if new_resource.version && !new_resource.version[index].nil?
- powershell_out(build_powershell_package_command("Get-Package '#{name}'", new_resource.version[index]), timeout: new_resource.timeout).stdout.strip
+ powershell_exec(build_powershell_package_command("Get-Package '#{name}'", new_resource.version[index]), timeout: new_resource.timeout).result
else
- powershell_out(build_powershell_package_command("Get-Package '#{name}'"), timeout: new_resource.timeout).stdout.strip
+ powershell_exec(build_powershell_package_command("Get-Package '#{name}'"), timeout: new_resource.timeout).result
end
if version.empty?
version = nil
end
+ version = version.strip if version.respond_to?(:strip)
version_list.push(version)
end
version_list
diff --git a/lib/chef/resource/chef_client_config.rb b/lib/chef/resource/chef_client_config.rb
index bd4ccbc478..ed5f3b26a8 100644
--- a/lib/chef/resource/chef_client_config.rb
+++ b/lib/chef/resource/chef_client_config.rb
@@ -87,6 +87,17 @@ class Chef
]
end
```
+
+ **Report directly to the [Chef Automate data collector endpoint](/automate/data_collection/#configure-chef-infra-client-to-use-the-data-collector-endpoint-in-chef-automate).**
+
+ ```ruby
+ chef_client_config 'Create client.rb' do
+ chef_server_url 'https://chef.example.dmz'
+ data_collector_server_url 'https://automate.example.dmz'
+ data_collector_token 'TEST_TOKEN_TEST'
+ end
+ ```
+
DOC
# @todo policy_file or policy_group being set requires the other to be set so enforce that.
@@ -231,6 +242,14 @@ class Chef
property :additional_config, String,
description: "Additional text to add at the bottom of the client.rb config. This can be used to run custom Ruby or to add less common config options"
+ property :data_collector_server_url, String,
+ description: "The data collector url (typically automate) to send node, converge and compliance data. Note: Data collection reporting to Automate should be performed directly by Chef Infra Server if possible, as this removes the need to distribute tokens to individual nodes.",
+ introduced: "17.8"
+
+ property :data_collector_token, String,
+ description: "The data collector token to interact with the data collector server url (Automate). Note: Data collection reporting to Automate should be performed directly by Chef Infra Server if possible, as this removes the need to distribute tokens to individual nodes.",
+ introduced: "17.8"
+
action :create, description: "Create a client.rb config file for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do
unless ::Dir.exist?(new_resource.config_directory)
directory new_resource.config_directory do
@@ -282,7 +301,9 @@ class Chef
ssl_verify_mode: new_resource.ssl_verify_mode,
start_handlers: format_handler(new_resource.start_handlers),
additional_config: new_resource.additional_config,
- policy_persist_run_list: new_resource.policy_persist_run_list
+ policy_persist_run_list: new_resource.policy_persist_run_list,
+ data_collector_server_url: new_resource.data_collector_server_url,
+ data_collector_token: new_resource.data_collector_token
)
mode "0640"
action :create
diff --git a/lib/chef/resource/dnf_package.rb b/lib/chef/resource/dnf_package.rb
index 80727de7d0..aad0192490 100644
--- a/lib/chef/resource/dnf_package.rb
+++ b/lib/chef/resource/dnf_package.rb
@@ -68,12 +68,10 @@ class Chef
end
}
- def allow_downgrade(arg = nil)
- unless arg.nil?
- Chef.deprecated(:dnf_package_allow_downgrade, "the allow_downgrade property on the dnf_package provider is not used, DNF supports downgrades by default.")
- end
- true
- end
+ property :allow_downgrade, [ TrueClass, FalseClass ],
+ description: "Allow downgrading a package to satisfy requested version requirements.",
+ default: true,
+ desired_state: false
end
end
end
diff --git a/lib/chef/resource/support/client.erb b/lib/chef/resource/support/client.erb
index 0a0db02249..8e96ca49e2 100644
--- a/lib/chef/resource/support/client.erb
+++ b/lib/chef/resource/support/client.erb
@@ -37,6 +37,13 @@ log_location <%= @log_location %>
log_location <%= @log_location.inspect %>
<% end -%>
<% end -%>
+<%# These data_collector options are special as they have a '.' -%>
+<% unless @data_collector_server_url.nil? || @data_collector_server_url.empty? %>
+data_collector.server_url <%= @data_collector_server_url %>
+<% end %>
+<% unless @data_collector_token.nil? || @data_collector_token.empty? %>
+data_collector.token <%= @data_collector_token %>
+<% end %>
<%# The code below is not DRY on purpose to improve readability -%>
<% unless @start_handlers.empty? -%>
# Do not crash if a start handler is missing / not installed yet
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index ab1d551e75..ef237e0df9 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -23,7 +23,7 @@ require_relative "version_string"
class Chef
CHEF_ROOT = File.expand_path("..", __dir__)
- VERSION = Chef::VersionString.new("17.8.7")
+ VERSION = Chef::VersionString.new("17.8.20")
end
#
diff --git a/omnibus/.tool-versions b/omnibus/.tool-versions
new file mode 100644
index 0000000000..1ade73219b
--- /dev/null
+++ b/omnibus/.tool-versions
@@ -0,0 +1 @@
+ruby 2.7.4
diff --git a/omnibus/Gemfile.lock b/omnibus/Gemfile.lock
index aaf22c7c2a..1acbb12fd9 100644
--- a/omnibus/Gemfile.lock
+++ b/omnibus/Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/chef/omnibus-software.git
- revision: 32876cd385807cd29b7b33cee219ad028dcc6f5f
+ revision: 85602312dd75745571728606c3ef77faabddf1d9
branch: main
specs:
omnibus-software (4.0.0)
@@ -33,8 +33,8 @@ GEM
artifactory (3.0.15)
awesome_print (1.9.2)
aws-eventstream (1.2.0)
- aws-partitions (1.530.0)
- aws-sdk-core (3.122.1)
+ aws-partitions (1.536.0)
+ aws-sdk-core (3.123.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
@@ -42,7 +42,7 @@ GEM
aws-sdk-kms (1.51.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sigv4 (~> 1.1)
- aws-sdk-s3 (1.105.1)
+ aws-sdk-s3 (1.108.0)
aws-sdk-core (~> 3, >= 3.122.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
@@ -65,12 +65,12 @@ GEM
solve (~> 4.0)
thor (>= 0.20)
builder (3.2.4)
- chef (16.16.13)
+ chef (16.17.4)
addressable
bcrypt_pbkdf (~> 1.1)
bundler (>= 1.10)
- chef-config (= 16.16.13)
- chef-utils (= 16.16.13)
+ chef-config (= 16.17.4)
+ chef-utils (= 16.17.4)
chef-vault
chef-zero (>= 14.0.11)
diff-lcs (>= 1.2.4, < 1.4.0)
@@ -102,12 +102,12 @@ GEM
tty-screen (~> 0.6)
tty-table (~> 0.11)
uuidtools (>= 2.1.5, < 3.0)
- chef (16.16.13-universal-mingw32)
+ chef (16.17.4-universal-mingw32)
addressable
bcrypt_pbkdf (~> 1.1)
bundler (>= 1.10)
- chef-config (= 16.16.13)
- chef-utils (= 16.16.13)
+ chef-config (= 16.17.4)
+ chef-utils (= 16.17.4)
chef-vault
chef-zero (>= 14.0.11)
diff-lcs (>= 1.2.4, < 1.4.0)
@@ -151,9 +151,9 @@ GEM
win32-taskscheduler (~> 2.0)
wmi-lite (~> 1.0)
chef-cleanroom (1.0.4)
- chef-config (16.16.13)
+ chef-config (16.17.4)
addressable
- chef-utils (= 16.16.13)
+ chef-utils (= 16.17.4)
fuzzyurl
mixlib-config (>= 2.2.12, < 4.0)
mixlib-shellout (>= 2.0, < 4.0)
@@ -161,7 +161,7 @@ GEM
chef-telemetry (1.1.1)
chef-config
concurrent-ruby (~> 1.0)
- chef-utils (16.16.13)
+ chef-utils (16.17.4)
chef-vault (4.1.4)
chef-zero (15.0.11)
ffi-yajl (~> 2.2)
@@ -212,7 +212,7 @@ GEM
highline (2.0.3)
httpclient (2.8.3)
iniparse (1.5.0)
- inspec-core (4.49.0)
+ inspec-core (4.50.3)
addressable (~> 2.4)
chef-telemetry (~> 1.0, >= 1.0.8)
faraday (>= 0.9.0, < 1.5)
@@ -240,7 +240,7 @@ GEM
iso8601 (0.13.0)
jmespath (1.4.0)
json (2.6.1)
- kitchen-vagrant (1.10.0)
+ kitchen-vagrant (1.11.0)
test-kitchen (>= 1.4, < 4)
libyajl2 (2.1.0)
license-acceptance (2.1.13)
@@ -363,7 +363,7 @@ GEM
strings-ansi (0.2.0)
structured_warnings (0.4.0)
syslog-logger (1.6.8)
- test-kitchen (3.1.1)
+ test-kitchen (3.2.1)
bcrypt_pbkdf (~> 1.0)
chef-utils (>= 16.4.35)
ed25519 (~> 1.2)
@@ -478,4 +478,4 @@ DEPENDENCIES
winrm-fs (~> 1.0)
BUNDLED WITH
- 2.2.22
+ 2.2.32
diff --git a/omnibus_overrides.rb b/omnibus_overrides.rb
index 59979f2703..ee21ae5713 100644
--- a/omnibus_overrides.rb
+++ b/omnibus_overrides.rb
@@ -16,8 +16,8 @@ override "ncurses", version: "5.9"
override "nokogiri", version: "1.11.0"
override "openssl", version: mac_os_x? ? "1.1.1l" : "1.0.2zb"
override "pkg-config-lite", version: "0.28-1"
-override "bundler", version: "2.2.22"
-override "ruby", version: "3.0.2"
+override "bundler", version: "2.2.32"
+override "ruby", version: "3.0.3"
override "ruby-windows-devkit-bash", version: "3.1.23-4-msys-1.0.18"
override "util-macros", version: "1.19.0"
override "xproto", version: "7.0.28"
diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb
index 9e03db5123..35af5d5c1a 100644
--- a/spec/functional/resource/dnf_package_spec.rb
+++ b/spec/functional/resource/dnf_package_spec.rb
@@ -455,7 +455,7 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do
end
context "downgrades" do
- it "downgrades the package when allow_downgrade" do
+ it "downgrades the package when allow_downgrade is true" do
flush_cache
preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
dnf_package "chef_rpm" do
@@ -470,6 +470,18 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do
action :install
end.should_not_be_updated
end
+
+ it "does not downgrade the package when allow_downgrade is false" do
+ flush_cache
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ dnf_package "chef_rpm" do
+ options default_options
+ allow_downgrade false
+ version "1.2-1"
+ action :install
+ end.should_not_be_updated
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
end
context "with arches", :intel_64bit do
@@ -763,6 +775,17 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do
end.should_not_be_updated
end
+ it "downgrade on a local file with allow_downgrade false does not downgrade" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ dnf_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do
+ options default_options
+ allow_downgrade false
+ version "1.2-1"
+ action :install
+ end.should_not_be_updated
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
it "does not downgrade the package with :install" do
preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
dnf_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do
@@ -1027,25 +1050,6 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do
action :install
end.should_not_be_updated
end
-
- it "throws a deprecation warning with allow_downgrade" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect(Chef).to receive(:deprecated).at_least(:once).with(:dnf_package_allow_downgrade, /^the allow_downgrade property on the dnf_package provider is not used/)
- preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
- dnf_package "chef_rpm" do
- options default_options
- version "1.2"
- allow_downgrade true
- action :install
- end.should_be_updated
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}")
- dnf_package "chef_rpm" do
- options default_options
- version "1.2"
- allow_downgrade true
- action :install
- end.should_not_be_updated
- end
end
context "with source arguments" do
@@ -1092,6 +1096,16 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do
end.should_not_be_updated
end
+ it "does not downgrade the package when allow_downgrade is false" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ dnf_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do
+ options default_options
+ allow_downgrade false
+ action :upgrade
+ end.should_not_be_updated
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
it "upgrades the package" do
preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
dnf_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm" do
diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb
index dfa0bcf673..3b533ec014 100644
--- a/spec/unit/file_access_control_spec.rb
+++ b/spec/unit/file_access_control_spec.rb
@@ -35,7 +35,7 @@ describe Chef::FileAccessControl do
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, {}, @events)
@current_resource = Chef::Resource::File.new("/tmp/different_file.txt")
- @provider_requirements = Chef::Provider::ResourceRequirements.new(@resource, @run_context)
+ @provider_requirements = Chef::Provider::ResourceRequirements.new(@resource, @run_context, :create)
@provider = double("File provider", requirements: @provider_requirements, manage_symlink_access?: false)
@fac = Chef::FileAccessControl.new(@current_resource, @resource, @provider)
diff --git a/spec/unit/mixin/why_run_spec.rb b/spec/unit/mixin/why_run_spec.rb
new file mode 100644
index 0000000000..7e56433fea
--- /dev/null
+++ b/spec/unit/mixin/why_run_spec.rb
@@ -0,0 +1,53 @@
+#
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+
+describe Chef::Mixin::WhyRun::ResourceRequirements do
+ class TestResource < Chef::Resource
+ action_class do
+ def define_resource_requirements
+ requirements.assert(:boom) do |a|
+ a.assertion { raise "boom1" }
+ a.failure_message("#{raise "boom2"}")
+ a.whyrun("#{raise "boom3"}")
+ end
+ end
+ end
+
+ action :boom do
+ # nothing
+ end
+
+ action :noboom do
+ # nothing
+ end
+ end
+
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:resource) { TestResource.new("name", run_context) }
+
+ it "raises an exception for an action where the assertions raise exceptions" do
+ expect { resource.run_action(:boom) }.to raise_error(StandardError, /boom2/)
+ end
+
+ it "does not raise an exception for an action which has no assertions" do
+ resource.run_action(:noboom)
+ end
+end
diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb
index 50ee766cdb..70e5b4a39e 100644
--- a/spec/unit/provider/group/groupadd_spec.rb
+++ b/spec/unit/provider/group/groupadd_spec.rb
@@ -169,6 +169,7 @@ describe Chef::Provider::Group::Groupadd do
before do
allow(File).to receive(:exist?).and_return(false)
+ provider.action = :modify
provider.define_resource_requirements
end
diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb
index e552516063..caac1857cf 100644
--- a/spec/unit/provider/group/usermod_spec.rb
+++ b/spec/unit/provider/group/usermod_spec.rb
@@ -58,18 +58,18 @@ describe Chef::Provider::Group::Usermod do
end
it "should raise an error when setting the entire group directly" do
+ @provider.action = :modify
@provider.define_resource_requirements
@provider.load_current_resource
@provider.instance_variable_set("@group_exists", true)
- @provider.action = :modify
expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider}, must set append true in group")
end
it "should raise an error when excluded_members are set" do
+ @provider.action = :modify
@provider.define_resource_requirements
@provider.load_current_resource
@provider.instance_variable_set("@group_exists", true)
- @provider.action = :modify
@new_resource.append(true)
@new_resource.excluded_members(["someone"])
expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider}")
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index 668a3ca9d9..166fe24304 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -61,6 +61,7 @@ describe Chef::Provider::Ifconfig do
expect(@provider.instance_variable_get("@status").exitstatus).not_to eq(0)
end
it "should thrown an exception when ifconfig fails" do
+ @provider.action = :add
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error Chef::Exceptions::Ifconfig
end
@@ -81,6 +82,7 @@ describe Chef::Provider::Ifconfig do
expect(@provider.instance_variable_get("@status").exitstatus).not_to eq(0)
end
it "should thrown an exception when ifconfig fails" do
+ @provider.action = :add
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error Chef::Exceptions::Ifconfig
end
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb
index 3e41f895d1..188777a19b 100644
--- a/spec/unit/provider/mount/linux_spec.rb
+++ b/spec/unit/provider/mount/linux_spec.rb
@@ -10,9 +10,9 @@ describe Chef::Provider::Mount::Linux do
let(:new_resource) do
new_resource = Chef::Resource::Mount.new("/tmp/foo")
- new_resource.device "/dev/sdz1"
+ new_resource.device "/dev/sdz1"
new_resource.device_type :device
- new_resource.fstype "ext3"
+ new_resource.fstype "ext3"
new_resource.supports remount: false
new_resource
end
@@ -32,6 +32,7 @@ describe Chef::Provider::Mount::Linux do
context "to see if the volume is mounted" do
it "should set mounted true if the mount point is found in the mounts list" do
+ allow(provider).to receive(:shell_out!).with("losetup --list").and_return(double(stdout: "/tmp/foo"))
allow(provider).to receive(:shell_out!).and_return(double(stdout: "/tmp/foo /dev/sdz1 type ext3 (rw)\n"))
provider.load_current_resource
expect(provider.current_resource.mounted).to be_truthy
@@ -104,4 +105,16 @@ describe Chef::Provider::Mount::Linux do
end
end
-end
+ context "to check if loop resource is mounted" do
+ it "should set mounted true in case of loop resource" do
+ new_resource.options "loop"
+ mount = "/tmp/foo /dev/loop16 iso660 cifs ro\n"
+ losetup = "/dev/loop16 0 0 1 1 /dev/sdz1 \n"
+ allow(provider).to receive(:shell_out!).with("findmnt -rn").and_return(double(stdout: mount))
+ allow(provider).to receive(:shell_out!).with("losetup -a").and_return(double(stdout: losetup))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
+ end
+ end
+
+end \ No newline at end of file
diff --git a/spec/unit/provider/package/bff_spec.rb b/spec/unit/provider/package/bff_spec.rb
index 680e5cf22a..b32b7714e4 100644
--- a/spec/unit/provider/package/bff_spec.rb
+++ b/spec/unit/provider/package/bff_spec.rb
@@ -61,6 +61,7 @@ describe Chef::Provider::Package::Bff do
allow(@provider).to receive(:shell_out_compacted).and_return(@empty_status)
allow(::File).to receive(:exist?).with(@new_resource.source).and_return(false)
@provider.load_current_resource
+ @provider.action = :install
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package)
end
diff --git a/spec/unit/provider/package/powershell_spec.rb b/spec/unit/provider/package/powershell_spec.rb
index 8bf95b9b14..501ad46c7b 100644
--- a/spec/unit/provider/package/powershell_spec.rb
+++ b/spec/unit/provider/package/powershell_spec.rb
@@ -17,10 +17,10 @@
#
require "spec_helper"
-require "chef/mixin/powershell_out"
+require "chef/mixin/powershell_exec"
describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
- include Chef::Mixin::PowershellOut
+ include Chef::Mixin::PowershellExec
let(:timeout) { 900 }
let(:source) { nil }
@@ -35,63 +35,63 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
end
let(:package_xcertificate_installed) do
- double("powershell_out", stdout: "2.1.0.0\r\n")
+ double("powershell_exec", result: "2.1.0.0\r\n")
end
let(:package_xcertificate_installed_2_0_0_0) do
- double("powershell_out", stdout: "2.0.0.0\r\n")
+ double("powershell_exec", result: "2.0.0.0\r\n")
end
let(:package_xcertificate_available) do
- double("powershell_out", stdout: "2.1.0.0\r\n")
+ double("powershell_exec", result: "2.1.0.0\r\n")
end
let(:package_xcertificate_available_2_0_0_0) do
- double("powershell_out", stdout: "2.0.0.0\r\n")
+ double("powershell_exec", result: "2.0.0.0\r\n")
end
let(:package_xcertificate_not_installed) do
- double("powershell_out", stdout: "")
+ double("powershell_exec", result: "")
end
let(:package_xcertificate_not_available) do
- double("powershell_out", stdout: "")
+ double("powershell_exec", result: "")
end
let(:package_xnetworking_installed) do
- double("powershell_out", stdout: "2.12.0.0\r\n")
+ double("powershell_exec", result: "2.12.0.0\r\n")
end
let(:package_xnetworking_installed_2_11_0_0) do
- double("powershell_out", stdout: "2.11.0.0\r\n")
+ double("powershell_exec", result: "2.11.0.0\r\n")
end
let(:package_xnetworking_available) do
- double("powershell_out", stdout: "2.12.0.0\r\n")
+ double("powershell_exec", result: "2.12.0.0\r\n")
end
let(:package_xnetworking_available_2_11_0_0) do
- double("powershell_out", stdout: "2.11.0.0\r\n")
+ double("powershell_exec", result: "2.11.0.0\r\n")
end
let(:package_xnetworking_not_installed) do
- double("powershell_out", stdout: "")
+ double("powershell_exec", result: "")
end
let(:package_xnetworking_not_available) do
- double("powershell_out", stdout: "")
+ double("powershell_exec", result: "")
end
let(:package_7zip_available) do
- double("powershell_out", stdout: "16.02\r\n")
+ double("powershell_exec", result: "16.02\r\n")
end
let(:package_7zip_not_installed) do
- double("powershell_out", stdout: "")
+ double("powershell_exec", result: "")
end
let(:powershell_installed_version) do
- double("powershell_out", stdout: "5")
+ double("powershell_exec", result: "5")
end
let(:tls_set_command) { "if ([Net.ServicePointManager]::SecurityProtocol -lt [Net.SecurityProtocolType]::Tls12) { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 };" }
@@ -122,14 +122,14 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
describe "#candidate_version" do
it "should set the candidate_version to the latest version when not pinning" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
new_resource.package_name(["xNetworking"])
new_resource.version(nil)
expect(provider.candidate_version).to eql(["2.12.0.0"])
end
it "should use the candidate_version from the correct source" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
new_resource.package_name(["xNetworking"])
new_resource.version(nil)
new_resource.source("MyGallery")
@@ -137,60 +137,60 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
end
it "should set the candidate_version to the latest version when not pinning and package name is space separated" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
new_resource.package_name(["7-Zip 16.02 (x64)"])
new_resource.version(nil)
expect(provider.candidate_version).to eql(["16.02"])
end
it "should set the candidate_version to pinned version if available" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.0.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available_2_0_0_0)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.0.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available_2_0_0_0)
new_resource.package_name(["xCertificate"])
new_resource.version(["2.0.0.0"])
expect(provider.candidate_version).to eql(["2.0.0.0"])
end
it "should set the candidate_version to nil if there is no candidate" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
new_resource.package_name(["xCertificate"])
expect(provider.candidate_version).to eql([nil])
end
it "should set the candidate_version correctly when there are two packages to install" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
expect(provider.candidate_version).to eql(["2.1.0.0", "2.12.0.0"])
end
it "should set the candidate_version correctly when only the first is installable" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
expect(provider.candidate_version).to eql(["2.1.0.0", nil])
end
it "should set the candidate_version correctly when only the last is installable" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
expect(provider.candidate_version).to eql([nil, "2.12.0.0"])
end
it "should set the candidate_version correctly when neither are is installable and version is passed as nil array" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
new_resource.package_name(%w{xNetworking xCertificate})
new_resource.version([nil, nil])
expect(provider.candidate_version).to eql([nil, nil])
end
it "should set the candidate_version correctly when neither are is installable and version is not passed" do
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
new_resource.package_name(%w{xNetworking xCertificate})
new_resource.version(nil)
expect(provider.candidate_version).to eql([nil, nil])
@@ -322,10 +322,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
provider.load_current_resource
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -335,10 +335,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
new_resource.source("MyGallery")
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -348,10 +348,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
new_resource.skip_publisher_check(true)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -SkipPublisherCheck ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -SkipPublisherCheck ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -SkipPublisherCheck ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -SkipPublisherCheck ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -360,10 +360,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
provider.load_current_resource
new_resource.package_name(["7-Zip 16.02 (x64)"])
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_not_installed)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 16.02 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_7zip_not_installed)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package '7-Zip 16.02 (x64)' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 16.02 ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -375,10 +375,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
provider.load_current_resource
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -387,9 +387,9 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "should not install packages that are up-to-date" do
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
expect(provider).not_to receive(:install_package)
provider.run_action(:install)
@@ -399,9 +399,9 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "should not install packages that are up-to-date" do
new_resource.package_name(["xNetworking"])
new_resource.version(["2.11.0.0"])
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
expect(provider).not_to receive(:install_package)
provider.run_action(:install)
@@ -413,13 +413,13 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
# new_version.resource[0]
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version([nil, "2.11.0.0"])
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available_2_11_0_0)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.11.0.0 ).Version", { timeout: new_resource.timeout })
provider.load_current_resource
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
@@ -428,13 +428,13 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "should split up commands when given two packages, one with a version pin" do
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(["2.1.0.0", nil])
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
provider.load_current_resource
provider.run_action(:install)
@@ -444,13 +444,13 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "should do multipackage installs when given two packages without constraints" do
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 ).Version", { timeout: new_resource.timeout })
provider.load_current_resource
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
@@ -460,13 +460,13 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
new_resource.source("MyGallery")
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -Source MyGallery ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.12.0.0 -Source MyGallery ).Version", { timeout: new_resource.timeout })
provider.load_current_resource
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
@@ -477,10 +477,10 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
new_resource.options(%w{-AcceptLicense -Verbose})
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -AcceptLicense -Verbose ).Version", { timeout: new_resource.timeout })
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Install-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -AcceptLicense -Verbose ).Version", { timeout: new_resource.timeout })
provider.run_action(:install)
expect(new_resource).to be_updated_by_last_action
end
@@ -491,9 +491,9 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
provider.load_current_resource
new_resource.package_name(["xCertificate"])
new_resource.version(["2.1.0.0"])
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
expect(provider).not_to receive(:remove_package)
provider.run_action(:remove)
expect(new_resource).not_to be_updated_by_last_action
@@ -503,11 +503,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
new_resource.package_name(["xCertificate"])
new_resource.version(["2.1.0.0"])
new_resource.source("MyGallery")
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 -Source MyGallery).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
@@ -515,11 +515,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "does nothing when all the packages are already removed" do
new_resource.package_name(%w{xCertificate xNetworking})
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xNetworking' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xnetworking_not_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
expect(provider).not_to receive(:remove_package)
provider.run_action(:remove)
@@ -529,11 +529,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "removes a package when version is specified" do
new_resource.package_name(["xCertificate"])
new_resource.version(["2.1.0.0"])
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -RequiredVersion 2.1.0.0 ).Version", { timeout: new_resource.timeout })
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
@@ -541,11 +541,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "removes a package when version is not specified" do
new_resource.package_name(["xCertificate"])
new_resource.version(nil)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
@@ -553,11 +553,11 @@ describe Chef::Provider::Package::Powershell, :windows_only, :windows_gte_10 do
it "should remove a package using provided options" do
new_resource.package_name(["xCertificate"])
new_resource.options(%w{-AllVersions})
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
- allow(provider).to receive(:powershell_out).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Find-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Get-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_available)
+ allow(provider).to receive(:powershell_exec).with("$PSVersionTable.PSVersion.Major").and_return(powershell_installed_version)
provider.load_current_resource
- expect(provider).to receive(:powershell_out).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -AllVersions ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
+ expect(provider).to receive(:powershell_exec).with("#{tls_set_command} ( Uninstall-Package 'xCertificate' -Force -ForceBootstrap -WarningAction SilentlyContinue -AllVersions ).Version", { timeout: new_resource.timeout }).and_return(package_xcertificate_not_available)
provider.run_action(:remove)
expect(new_resource).to be_updated_by_last_action
end
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 6ef63d3961..a4ffc1712e 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -410,6 +410,9 @@ describe Chef::Provider::Package::Rubygems do
# Rubygems uses these two interally
allow(RbConfig::CONFIG).to receive(:[]).with("arch").and_call_original
allow(RbConfig::CONFIG).to receive(:[]).with("ruby_install_name").and_call_original
+ allow(RbConfig::CONFIG).to receive(:[]).with("ruby_version").and_call_original
+ allow(RbConfig::CONFIG).to receive(:[]).with("rubylibprefix").and_call_original
+ allow(RbConfig::CONFIG).to receive(:[]).with("vendordir").and_call_original
allow(File).to receive(:executable?).and_return false
allow(File).to receive(:executable?).with("#{bindir}/gem").and_return true
# XXX: we can't stub the provider object directly here because referencing it will create it and that
diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb
index c07367c221..874f030605 100644
--- a/spec/unit/provider/package/solaris_spec.rb
+++ b/spec/unit/provider/package/solaris_spec.rb
@@ -65,6 +65,7 @@ describe Chef::Provider::Package::Solaris do
allow(@provider).to receive(:shell_out_compacted).and_return(@status)
allow(::File).to receive(:exist?).and_return(false)
@provider.load_current_resource
+ @provider.action = :install
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package)
end
diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb
index c92af83de5..496e876a49 100644
--- a/spec/unit/provider/service/arch_service_spec.rb
+++ b/spec/unit/provider/service/arch_service_spec.rb
@@ -95,15 +95,15 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do
it "should raise error if the node has a nil ps property and no other means to get status" do
@node.automatic_attrs[:command] = { ps: nil }
- @provider.define_resource_requirements
@provider.action = :start
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
it "should raise error if the node has an empty ps property and no other means to get status" do
@node.automatic_attrs[:command] = { ps: "" }
- @provider.define_resource_requirements
@provider.action = :start
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb
index 0ae1d28cd3..c3a478d249 100644
--- a/spec/unit/provider/service/debian_service_spec.rb
+++ b/spec/unit/provider/service/debian_service_spec.rb
@@ -50,6 +50,7 @@ describe Chef::Provider::Service::Debian do
it "ensures /usr/sbin/update-rc.d is available" do
expect(File).to receive(:exist?).with("/usr/sbin/update-rc.d").and_return(false)
+ @provider.action = :start
@provider.define_resource_requirements
expect do
@provider.process_resource_requirements
diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb
index f195fbe40b..efab722ac8 100644
--- a/spec/unit/provider/service/gentoo_service_spec.rb
+++ b/spec/unit/provider/service/gentoo_service_spec.rb
@@ -42,6 +42,7 @@ describe Chef::Provider::Service::Gentoo do
describe "load_current_resource" do
it "should raise Chef::Exceptions::Service if /sbin/rc-update does not exist" do
expect(File).to receive(:exist?).with("/sbin/rc-update").and_return(false)
+ @provider.action = :start
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb
index eafc857cf1..ebde71776a 100644
--- a/spec/unit/provider/service/macosx_spec.rb
+++ b/spec/unit/provider/service/macosx_spec.rb
@@ -237,6 +237,7 @@ describe Chef::Provider::Service::Macosx do
allow(Dir).to receive(:glob).and_return([(plist).to_s,
"/Users/wtf/something.plist"])
provider.load_current_resource
+ provider.action = :enable
provider.define_resource_requirements
expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb
index d5d2c7ddc0..1bf07b7f2c 100644
--- a/spec/unit/provider/service/redhat_spec.rb
+++ b/spec/unit/provider/service/redhat_spec.rb
@@ -34,6 +34,7 @@ shared_examples_for "define_resource_requirements_common" do
expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
chkconfig = double("Chkconfig", exitstatus: 0, stdout: "", stderr: "service chef supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add chef')")
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", returns: [0, 1]).and_return(chkconfig)
+ @provider.action = :start
@provider.load_current_resource
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.not_to raise_error
@@ -147,12 +148,12 @@ describe "Chef::Provider::Service::Redhat" do
chkconfig = double("Chkconfig", existatus: 1, stdout: "", stderr: "error reading information on service chef: No such file or directory")
expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", returns: [0, 1]).and_return(chkconfig)
@provider.load_current_resource
- @provider.define_resource_requirements
end
%w{start reload restart enable}.each do |action|
it "should raise an error when the action is #{action}" do
@provider.action = action
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
end
@@ -161,12 +162,14 @@ describe "Chef::Provider::Service::Redhat" do
it "should not raise an error when the action is #{action} and init_command is set" do
@new_resource.init_command("/etc/init.d/chef")
@provider.action = action
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.not_to raise_error
end
it "should not raise an error when the action is #{action} and #{action}_command is set" do
@new_resource.send("#{action}_command", "/etc/init.d/chef #{action}")
@provider.action = action
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.not_to raise_error
end
end
diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb
index 2546f9cef7..e114d3e314 100644
--- a/spec/unit/provider/service/simple_service_spec.rb
+++ b/spec/unit/provider/service/simple_service_spec.rb
@@ -52,12 +52,14 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
it "should raise error if the node has a nil ps property and no other means to get status" do
@node.automatic_attrs[:command] = { ps: nil }
+ @provider.action = :start
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
it "should raise error if the node has an empty ps property and no other means to get status" do
@node.automatic_attrs[:command] = { ps: "" }
+ @provider.action = :start
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
@@ -112,8 +114,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
end
it "should raise an exception if no start command is specified" do
- @provider.define_resource_requirements
@provider.action = :start
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
end
@@ -126,8 +128,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
end
it "should raise an exception if no stop command is specified" do
- @provider.define_resource_requirements
@provider.action = :stop
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
end
@@ -140,8 +142,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
end
it "should raise an exception if the resource doesn't support restart, no restart command is provided, and no stop command is provided" do
- @provider.define_resource_requirements
@provider.action = :restart
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
end
@@ -155,8 +157,8 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do
describe Chef::Provider::Service::Simple, "reload_service" do
it "should raise an exception if reload is requested but no command is specified" do
- @provider.define_resource_requirements
@provider.action = :reload
+ @provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 16428de1a9..c8ad656f06 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -170,6 +170,7 @@ describe Chef::Provider::User do
sp_warn: 7, sp_inact: -1, sp_expire: -1, sp_flag: -1)
expect(Shadow::Passwd).to receive(:getspnam).with("notarealuser").and_return(passwd_info)
@provider.load_current_resource
+ @provider.action = :create
@provider.define_resource_requirements
@provider.process_resource_requirements
end
@@ -180,6 +181,7 @@ describe Chef::Provider::User do
it "should fail assertions when ruby-shadow cannot be loaded" do
expect(@provider).to receive(:require).with("shadow") { raise LoadError }
@provider.load_current_resource
+ @provider.action = :create
@provider.define_resource_requirements
expect { @provider.process_resource_requirements }.to raise_error Chef::Exceptions::MissingLibrary
end