diff options
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 22 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | chef-bin/lib/chef-bin/version.rb | 2 | ||||
-rw-r--r-- | chef-config/lib/chef-config/version.rb | 2 | ||||
-rw-r--r-- | chef-utils/lib/chef-utils/version.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/powershell_exec.rb | 11 | ||||
-rw-r--r-- | lib/chef/powershell.rb | 14 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rw-r--r-- | spec/unit/mixin/powershell_exec_spec.rb | 10 |
11 files changed, 55 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3072a7085e..07f71ad0e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,16 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 16.0.249 --> -## [v16.0.249](https://github.com/chef/chef/tree/v16.0.249) (2020-04-27) +<!-- latest_release 16.0.250 --> +## [v16.0.250](https://github.com/chef/chef/tree/v16.0.250) (2020-04-27) #### Merged Pull Requests -- Bump inspec-core-bin to 4.18.108 [#9743](https://github.com/chef/chef/pull/9743) ([chef-expeditor[bot]](https://github.com/chef-expeditor[bot])) +- Add powershell_exec! helper to make conversion from powershell_out! easier [#9742](https://github.com/chef/chef/pull/9742) ([tas50](https://github.com/tas50)) <!-- latest_release --> <!-- release_rollup since=15.6.10 --> ### Changes not yet released to stable #### Merged Pull Requests +- Add powershell_exec! helper to make conversion from powershell_out! easier [#9742](https://github.com/chef/chef/pull/9742) ([tas50](https://github.com/tas50)) <!-- 16.0.250 --> - Bump inspec-core-bin to 4.18.108 [#9743](https://github.com/chef/chef/pull/9743) ([chef-expeditor[bot]](https://github.com/chef-expeditor[bot])) <!-- 16.0.249 --> - Remove the Windows version check in windows_share [#9741](https://github.com/chef/chef/pull/9741) ([tas50](https://github.com/tas50)) <!-- 16.0.248 --> - Test and better document the locale resource [#9736](https://github.com/chef/chef/pull/9736) ([tas50](https://github.com/tas50)) <!-- 16.0.247 --> @@ -82,6 +82,7 @@ eval_gemfile("./Gemfile.local") if File.exist?("./Gemfile.local") # These lines added for Windows development only. # For FFI to call into PowerShell we need the binaries and assemblies located # in the Ruby bindir. +# The Powershell DLL source lives here: https://github.com/chef/chef-powershell-shim # # We copy (and overwrite) these files every time "bundle <exec|install>" is # executed, just in case they have changed. diff --git a/Gemfile.lock b/Gemfile.lock index 0f7d063626..e2ba4c472a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,12 +27,12 @@ GIT PATH remote: . specs: - chef (16.0.249) + chef (16.0.250) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 16.0.249) - chef-utils (= 16.0.249) + chef-config (= 16.0.250) + chef-utils (= 16.0.250) chef-vault chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) @@ -61,12 +61,12 @@ PATH train-winrm (>= 0.2.5) tty-screen (~> 0.6) uuidtools (~> 2.1.5) - chef (16.0.249-universal-mingw32) + chef (16.0.250-universal-mingw32) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 16.0.249) - chef-utils (= 16.0.249) + chef-config (= 16.0.250) + chef-utils (= 16.0.250) chef-vault chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) @@ -111,15 +111,15 @@ PATH PATH remote: chef-bin specs: - chef-bin (16.0.249) - chef (= 16.0.249) + chef-bin (16.0.250) + chef (= 16.0.250) PATH remote: chef-config specs: - chef-config (16.0.249) + chef-config (16.0.250) addressable - chef-utils (= 16.0.249) + chef-utils (= 16.0.250) fuzzyurl mixlib-config (>= 2.2.12, < 4.0) mixlib-shellout (>= 2.0, < 4.0) @@ -128,7 +128,7 @@ PATH PATH remote: chef-utils specs: - chef-utils (16.0.249) + chef-utils (16.0.250) GEM remote: https://rubygems.org/ @@ -1 +1 @@ -16.0.249
\ No newline at end of file +16.0.250
\ 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 97a7d57a75..9e349c1c7f 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("../..", __FILE__) - VERSION = "16.0.249".freeze + VERSION = "16.0.250".freeze end # diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index f9d18e0872..834092b602 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("../..", __FILE__) - VERSION = "16.0.249".freeze + VERSION = "16.0.250".freeze end diff --git a/chef-utils/lib/chef-utils/version.rb b/chef-utils/lib/chef-utils/version.rb index 4452bc0019..801c26d936 100644 --- a/chef-utils/lib/chef-utils/version.rb +++ b/chef-utils/lib/chef-utils/version.rb @@ -15,5 +15,5 @@ module ChefUtils CHEFUTILS_ROOT = File.expand_path("../..", __FILE__) - VERSION = "16.0.249".freeze + VERSION = "16.0.250".freeze end diff --git a/lib/chef/mixin/powershell_exec.rb b/lib/chef/mixin/powershell_exec.rb index 1a60a3d480..e3410e007f 100644 --- a/lib/chef/mixin/powershell_exec.rb +++ b/lib/chef/mixin/powershell_exec.rb @@ -20,7 +20,7 @@ require_relative "../powershell" # The powershell_exec mixin provides in-process access to PowerShell engine via # a COM interop (installed by the Chef Client installer). # -# powershell_exec returns a Chef::PowerShell object that provides 3 methods: +# powershell_exec returns a Chef::PowerShell object that provides 4 methods: # # .result - returns a hash representing the results returned by executing the # PowerShell script block @@ -28,6 +28,7 @@ require_relative "../powershell" # PowerShell error stream during execution # .error? - returns true if there were error messages written to the PowerShell # error stream during execution +# .error! - raise Chef::PowerShell::CommandFailed if there was an error # # Some examples of usage: # @@ -100,6 +101,14 @@ class Chef def powershell_exec(script) Chef::PowerShell.new(script) end + + # The same as the #powershell_exec method except this will raise + # Chef::PowerShell::CommandFailed if the command fails + def powershell_exec!(script) + cmd = Chef::PowerShell.new(script) + cmd.error! + cmd + end end end end diff --git a/lib/chef/powershell.rb b/lib/chef/powershell.rb index b1f8c5396c..9790a3c10f 100644 --- a/lib/chef/powershell.rb +++ b/lib/chef/powershell.rb @@ -39,12 +39,26 @@ class Chef exec(script) end + # + # Was there an error running the command + # + # @return [Boolean] + # def error? return true if errors.count > 0 false end + class CommandFailed < RuntimeError; end + + # + # @raise [Chef::PowerShell::CommandFailed] raise if the command failed + # + def error! + raise Chef::PowerShell::CommandFailed, "Unexpected exit in PowerShell command: #{@errors}" if error? + end + private def exec(script) diff --git a/lib/chef/version.rb b/lib/chef/version.rb index c602897d5d..f41639cf8c 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("../..", __FILE__) - VERSION = Chef::VersionString.new("16.0.249") + VERSION = Chef::VersionString.new("16.0.250") end # diff --git a/spec/unit/mixin/powershell_exec_spec.rb b/spec/unit/mixin/powershell_exec_spec.rb index bf2285175b..8c3e0a4b88 100644 --- a/spec/unit/mixin/powershell_exec_spec.rb +++ b/spec/unit/mixin/powershell_exec_spec.rb @@ -40,4 +40,14 @@ describe Chef::Mixin::PowershellExec, :windows_only do expect(execution.errors[0]).to include("Runtime exception: this-should-error") end end + + describe "#powershell_exec!" do + it "runs a basic command and returns a Chef::PowerShell object" do + expect(object.powershell_exec("$PSVersionTable")).to be_kind_of(Chef::PowerShell::CommandFailed) + end + + it "raises an error if the command fails" do + expect { object.powershell_exec("$PSVersionTable") }.to raise_error(Chef::Exceptions::Script) + end + end end |