summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-11-30 16:41:05 -0800
committerGitHub <noreply@github.com>2021-11-30 16:41:05 -0800
commit16aaea15f91f705a9f87b59005bed699419c248a (patch)
tree68d9119d1fad1a7a3c4212486656d209d5d00b87
parent0a7cf0895db830050d9674644b7718e19ca68d61 (diff)
parent93c80210750fa8ef383ef1395431e420e39302c7 (diff)
downloadchef-16aaea15f91f705a9f87b59005bed699419c248a.tar.gz
Merge pull request #11983 from chef/use-powershell-exec-for-windows-feature-powershell
use powershell_exec instead of powershell_out in windows_feature_powershell
-rw-r--r--.rubocop.yml1
-rw-r--r--kitchen-tests/Gemfile1
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/windows.rb6
-rw-r--r--lib/chef/resource/windows_feature_powershell.rb14
4 files changed, 13 insertions, 9 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 5779258102..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/resource/windows_feature_powershell.rb' # https://github.com/chef/chef/issues/10927
# set additional paths
Chef/Ruby/UnlessDefinedRequire:
diff --git a/kitchen-tests/Gemfile b/kitchen-tests/Gemfile
index af870fb182..202bcf19d2 100644
--- a/kitchen-tests/Gemfile
+++ b/kitchen-tests/Gemfile
@@ -6,6 +6,7 @@ gem "knife", path: "../knife"
gem "ohai", git: "https://github.com/chef/ohai.git", branch: "main" # avoids failures when we bump chef major
gem "berkshelf", git: "https://github.com/berkshelf/berkshelf.git", branch: "main"
gem "kitchen-dokken", ">= 2.0"
+gem "kitchen-vagrant", ">= 1.0"
gem "kitchen-inspec", git: "https://github.com/chef/kitchen-inspec.git", branch: "main"
gem "inspec"
gem "test-kitchen", git: "https://github.com/test-kitchen/test-kitchen.git", branch: "master"
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
index c6ea3a9928..454eb04aaf 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/windows.rb
@@ -191,4 +191,8 @@ windows_update_settings "Disable Windows Update" do
disable_automatic_updates true
end
-include_recipe "::_chef_gem" \ No newline at end of file
+windows_feature_powershell "RSAT-AD-PowerShell" do
+ action :install
+end
+
+include_recipe "::_chef_gem"
diff --git a/lib/chef/resource/windows_feature_powershell.rb b/lib/chef/resource/windows_feature_powershell.rb
index e9889eb954..70c7de5783 100644
--- a/lib/chef/resource/windows_feature_powershell.rb
+++ b/lib/chef/resource/windows_feature_powershell.rb
@@ -100,8 +100,8 @@ class Chef
install_command << " -Source \"#{new_resource.source}\"" if new_resource.source
install_command << " -IncludeManagementTools" if new_resource.management_tools
- cmd = powershell_out!(install_command, timeout: new_resource.timeout)
- Chef::Log.info(cmd.stdout)
+ cmd = powershell_exec!(install_command, timeout: new_resource.timeout)
+ Chef::Log.info(cmd.result)
reload_cached_powershell_data # Reload cached powershell feature state
end
@@ -115,8 +115,8 @@ class Chef
unless features_to_remove.empty?
converge_by("remove Windows feature#{"s" if features_to_remove.count > 1} #{features_to_remove.join(",")}") do
- cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
- Chef::Log.info(cmd.stdout)
+ cmd = powershell_exec!("Uninstall-WindowsFeature #{features_to_remove.join(",")}", timeout: new_resource.timeout)
+ Chef::Log.info(cmd.result)
reload_cached_powershell_data # Reload cached powershell feature state
end
@@ -132,8 +132,8 @@ class Chef
unless features_to_delete.empty?
converge_by("delete Windows feature#{"s" if features_to_delete.count > 1} #{features_to_delete.join(",")} from the image") do
- cmd = powershell_out!("Uninstall-WindowsFeature #{features_to_delete.join(",")} -Remove", timeout: new_resource.timeout)
- Chef::Log.info(cmd.stdout)
+ cmd = powershell_exec!("Uninstall-WindowsFeature #{features_to_delete.join(",")} -Remove", timeout: new_resource.timeout)
+ Chef::Log.info(cmd.result)
reload_cached_powershell_data # Reload cached powershell feature state
end
@@ -215,7 +215,7 @@ class Chef
# fetch the list of available feature names and state in JSON and parse the JSON
def parsed_feature_list
# Grab raw feature information from WindowsFeature
- raw_list_of_features = powershell_out!("Get-WindowsFeature | Select-Object -Property Name,InstallState | ConvertTo-Json -Compress", timeout: new_resource.timeout).stdout
+ raw_list_of_features = powershell_exec!("Get-WindowsFeature | Select-Object -Property Name,InstallState", timeout: new_resource.timeout).result
Chef::JSONCompat.from_json(raw_list_of_features)
end