summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-06-07 16:42:42 -0700
committerTim Smith <tsmith@chef.io>2018-06-07 16:42:42 -0700
commit2db7b665ea175ae8da24ffed1a2835e12a03a5a7 (patch)
treeff195d756ad5942d5f8fd9f90919722e2cf2fc29
parentc0ded1066ef2497c6c72f436eed7c06cbc824e3d (diff)
downloadchef-2db7b665ea175ae8da24ffed1a2835e12a03a5a7.tar.gz
Add helper method to dism as well
This just makes it easier to read. Windows kernel versions hurt your head after a while. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_feature_dism.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index ebd52c4db7..0364432571 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -30,7 +30,7 @@ class Chef
property :feature_name, [Array, String],
description: "The name of the feature/role(s) to install if it differs from the resource name.",
- coerce: proc { |x| to_lowercase_array(x) },
+ coerce: proc { |x| to_formatted_array(x) },
name_property: true
property :source, String,
@@ -44,12 +44,18 @@ class Chef
description: "Specifies a timeout (in seconds) for feature install.",
default: 600
- def to_lowercase_array(x)
+ # @return [Array] lowercase the array unless we're on < Windows 2012
+ def to_formatted_array(x)
x = x.split(/\s*,\s*/) if x.is_a?(String) # split multiple forms of a comma separated list
- # dism on windows < 2012 is case sensitive so only downcase when on 2012+
- # @todo when we're really ready to remove support for Windows 2008 R2 this check can go away
- node["platform_version"].to_f < 6.2 ? x : x.map(&:downcase)
+ # feature installs on windows < 2012 are case sensitive so only downcase when on 2012+
+ older_than_2012_or_8? ? x : x.map(&:downcase)
+ end
+
+ # a simple helper to determine if we're on a windows release pre-2012 / 8
+ # @return [Boolean] Is the system older than Windows 8 / 2012
+ def older_than_2012_or_8?
+ node["platform_version"].to_f < 6.2
end
action :install do
@@ -200,7 +206,7 @@ class Chef
# dism on windows 2012+ isn't case sensitive so it's best to compare
# lowercase lists so the user input doesn't need to be case sensitive
# @todo when we're ready to remove windows 2008R2 the gating here can go away
- feature_details.downcase! unless node["platform_version"].to_f < 6.2
+ feature_details.downcase! unless older_than_2012_or_8?
node.override["dism_features_cache"][feature_type] << feature_details
end
@@ -208,7 +214,7 @@ class Chef
# @return [void]
def fail_if_removed
return if new_resource.source # if someone provides a source then all is well
- if node["platform_version"].to_f > 6.2
+ if node["platform_version"].to_f > 6.2 # 2012R2 or later
return if registry_key_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing') && registry_value_exists?('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Servicing', name: "LocalSourcePath") # if source is defined in the registry, still fine
end
removed = new_resource.feature_name & node["dism_features_cache"]["removed"]