summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-20 11:25:04 -0700
committerTim Smith <tsmith@chef.io>2018-03-20 11:25:53 -0700
commit14c167b0b014bfcbd351f6ecd53321bf931e69d1 (patch)
treefbd281e8cc6cf1f5e2f5564a6700314eb9c2582f
parent8e9ea543502781d4e0f71a9d577f639c256171b1 (diff)
downloadchef-windows_feature_fix.tar.gz
Support installing removed windows features from sourcewindows_feature_fix
This issue was reported on the cookbook after refactoring the resource. The issue is that we have a method to determine the features to install given a list of features we want to install. It wasn't taking into account that a removed feature can be installed if the user specifies a source. Now it properly takes that into account and should build the correct array of features to install. It also builds the install command in a cleaner way that avoids funky extra spaces at the end of the command. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_feature_dism.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index 5bbcce4ab0..42eafcf613 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -55,9 +55,11 @@ class Chef
unless features_to_install.empty?
message = "install Windows feature#{'s' if features_to_install.count > 1} #{features_to_install.join(',')}"
converge_by(message) do
- addsource = new_resource.source ? "/LimitAccess /Source:\"#{new_resource.source}\"" : ""
- addall = new_resource.all ? "/All" : ""
- shell_out!("dism.exe /online /enable-feature #{features_to_install.map { |f| "/featurename:#{f}" }.join(' ')} /norestart #{addsource} #{addall}", returns: [0, 42, 127, 3010], timeout: new_resource.timeout)
+ install_command = "#{dism} /online /enable-feature #{features_to_install.map { |f| "/featurename:#{f}" }.join(' ')} /norestart"
+ install_command << " /LimitAccess /Source:\"#{new_resource.source}\"" if new_resource.source
+ install_command << " /All" if new_resource.all
+
+ shell_out!(install_command, returns: [0, 42, 127, 3010], timeout: new_resource.timeout)
reload_cached_dism_data # Reload cached dism feature state
end
@@ -104,8 +106,16 @@ class Chef
action_class do
# @return [Array] features the user has requested to install which need installation
def features_to_install
- # the intersection of the features to install & disabled features are what needs installing
- @install ||= new_resource.feature_name & node["dism_features_cache"]["disabled"]
+ @install ||= begin
+ # disabled features are always available to install
+ available_for_install = node["dism_features_cache"]["disabled"]
+
+ # if the user passes a source then removed features are also available for installation
+ available_for_install.concat(node["dism_features_cache"]["removed"]) if new_resource.source
+
+ # the intersection of the features to install & disabled/removed(if passing source) features are what needs installing
+ new_resource.feature_name & available_for_install
+ end
end
# @return [Array] features the user has requested to remove which need removing